/* Shared Mini Office tool styles (Sheet Lite, Docs Lite) */
.office-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--tool-border);
    border-radius: var(--tool-radius-sm);
    background: rgba(255, 255, 255, 0.02);
}

.office-toolbar .tool-field {
    margin: 0;
    min-width: 140px;
}

.office-toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.office-toolbar-group + .office-toolbar-group {
    padding-left: 0.55rem;
    border-left: 1px solid var(--tool-border);
}

.office-status-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    align-items: center;
    font-size: 0.86rem;
    color: var(--tool-muted);
}

.office-unsaved {
    color: var(--accent-warm);
    font-weight: 600;
}

.office-unsaved.is-clean {
    color: var(--accent);
}

.office-panel-scroll {
    overflow: auto;
    max-height: min(68vh, 640px);
    border: 1px solid var(--tool-border);
    border-radius: var(--tool-radius-sm);
    background: rgba(255, 255, 255, 0.02);
}

/* Sheet grid */
.sheet-wrap {
    position: relative;
    overflow: auto;
    max-height: min(68vh, 640px);
    border: 1px solid var(--tool-border);
    border-radius: var(--tool-radius-sm);
}

.sheet-table {
    border-collapse: collapse;
    min-width: 100%;
    font-size: 0.88rem;
}

.sheet-table th,
.sheet-table td.sheet-td {
    border: 1px solid var(--tool-border);
    padding: 0;
    min-width: 96px;
    background: rgba(0, 0, 0, 0.15);
    vertical-align: middle;
}

.sheet-table th {
    background: rgba(97, 208, 148, 0.08);
    color: var(--tool-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    padding: 0.35rem 0.25rem;
    position: sticky;
    top: 0;
    z-index: 2;
}

.sheet-table th.row-head {
    position: sticky;
    left: 0;
    z-index: 3;
    min-width: 42px;
    width: 42px;
}

.sheet-table th.corner {
    position: sticky;
    left: 0;
    top: 0;
    z-index: 5;
}

.sheet-td {
    cursor: cell;
    position: relative;
}

.sheet-td.is-selected {
    background: rgba(97, 208, 148, 0.12);
    box-shadow: inset 0 0 0 2px var(--tool-accent);
    z-index: 1;
}

.sheet-td.is-selected.is-editing {
    background: rgba(97, 208, 148, 0.08);
}

.sheet-td.is-formula .sheet-cell-display {
    color: #9cc0ff;
}

.sheet-td.is-range-preview {
    background: rgba(97, 208, 148, 0.18);
    box-shadow: inset 0 0 0 1px rgba(97, 208, 148, 0.55);
}

.sheet-cell-display {
    display: block;
    min-height: 34px;
    padding: 0.45rem 0.5rem;
    color: var(--tool-text);
    font-family: var(--font-mono);
    font-size: 0.84rem;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheet-cell-editor {
    position: absolute;
    z-index: 12;
    margin: 0;
    padding: 0.45rem 0.5rem;
    border: 2px solid var(--tool-accent);
    border-radius: 0;
    background: var(--tool-bg);
    color: var(--tool-text);
    font-family: var(--font-mono);
    font-size: 0.84rem;
    line-height: 1.35;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
    outline: none;
}

.sheet-cell-editor[hidden] {
    display: none !important;
}

.sheet-formula-suggest {
    position: absolute;
    z-index: 20;
    min-width: 220px;
    max-width: 320px;
    margin: 0;
    padding: 4px;
    list-style: none;
    border: 1px solid var(--tool-border-strong);
    border-radius: var(--tool-radius-sm);
    background: var(--tool-bg);
    box-shadow: var(--tool-shadow);
}

.sheet-formula-suggest[hidden] {
    display: none !important;
}

.sheet-formula-suggest.is-portal {
    position: fixed;
    z-index: 10050;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

.sheet-formula-suggest-item {
    display: block;
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--tool-text);
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.sheet-formula-suggest-item strong {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.86rem;
}

.sheet-formula-suggest-item span {
    display: block;
    margin-top: 2px;
    color: var(--tool-muted);
    font-size: 0.76rem;
}

.sheet-formula-suggest-item:hover,
.sheet-formula-suggest-item:focus-visible,
.sheet-formula-suggest-item.is-active {
    background: rgba(97, 208, 148, 0.14);
    outline: none;
}

/* Sheet Lite — controls guide below grid */
.sheet-controls-guide {
    border: 1px solid var(--tool-border);
    border-radius: var(--tool-radius-sm);
    background: var(--tool-panel);
    padding: 0.85rem 1rem 1rem;
}

.sheet-controls-guide summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--tool-text);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sheet-controls-guide summary::-webkit-details-marker {
    display: none;
}

.sheet-controls-guide summary::before {
    content: '▸';
    color: var(--tool-accent);
    font-size: 0.9rem;
    transition: transform 0.15s ease;
}

.sheet-controls-guide[open] summary::before {
    transform: rotate(90deg);
}

.sheet-guide-intro {
    margin: 0.65rem 0 0.85rem;
    color: var(--tool-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.sheet-guide-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem 1.25rem;
}

.sheet-guide-block h3 {
    margin: 0 0 0.45rem;
    font-size: 0.88rem;
    color: var(--tool-accent-2);
}

.sheet-guide-block ul,
.sheet-guide-block ol {
    margin: 0;
    padding-left: 1.15rem;
    color: var(--tool-muted);
    font-size: 0.86rem;
    line-height: 1.55;
}

.sheet-guide-block li + li {
    margin-top: 0.25rem;
}

.sheet-guide-block code {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: #9cc0ff;
}

.sheet-controls-guide kbd {
    display: inline-block;
    min-width: 1.35rem;
    padding: 0.1rem 0.35rem;
    border: 1px solid var(--tool-border-strong);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--tool-text);
    font-family: var(--font-mono);
    font-size: 0.76rem;
    text-align: center;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
}

@media (max-width: 720px) {
    .sheet-guide-grid {
        grid-template-columns: 1fr;
    }
}

/* Docs editor */
.docs-editor-wrap {
    border: 1px solid var(--tool-border);
    border-radius: var(--tool-radius-sm);
    background: rgba(255, 255, 255, 0.03);
    min-height: 420px;
}

.docs-editor {
    min-height: 400px;
    padding: 1.25rem 1.5rem;
    outline: none;
    line-height: 1.65;
    color: var(--tool-text);
}

.docs-editor h1,
.docs-editor h2,
.docs-editor h3 {
    margin: 0.8rem 0 0.45rem;
}

.docs-editor p {
    margin: 0 0 0.75rem;
}

.docs-editor ul,
.docs-editor ol {
    margin: 0 0 0.75rem 1.25rem;
}

.docs-editor table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75rem 0;
}

.docs-editor td,
.docs-editor th {
    border: 1px solid var(--tool-border);
    padding: 0.4rem 0.55rem;
    min-width: 60px;
}

.docs-editor a {
    color: var(--tool-accent);
}

@media (max-width: 720px) {
    .office-toolbar-group + .office-toolbar-group {
        border-left: 0;
        padding-left: 0;
        width: 100%;
    }

    .sheet-table th,
    .sheet-table td.sheet-td {
        min-width: 72px;
    }
}

/* Light theme — Mini Office readability */
[data-theme="light"] .office-toolbar {
    background: #ffffff;
    border-color: rgba(20, 40, 25, 0.14);
}

[data-theme="light"] .office-status-bar {
    color: #374151;
}

[data-theme="light"] .office-unsaved {
    color: #c87a20;
}

[data-theme="light"] .office-unsaved.is-clean {
    color: var(--accent-strong);
}

[data-theme="light"] .office-panel-scroll,
[data-theme="light"] .sheet-wrap {
    background: #ffffff;
    border-color: rgba(20, 40, 25, 0.12);
}

[data-theme="light"] .sheet-table th,
[data-theme="light"] .sheet-table td.sheet-td {
    background: #ffffff;
    border-color: rgba(20, 40, 25, 0.18);
}

[data-theme="light"] .sheet-table th {
    background: #eef7ef;
    color: #1f2937;
}

[data-theme="light"] .sheet-td.is-selected {
    background: rgba(40, 160, 110, 0.18);
    box-shadow: inset 0 0 0 2px #15803d, inset 0 0 0 3px rgba(21, 128, 61, 0.25);
}

[data-theme="light"] .sheet-td.is-selected.is-editing {
    background: rgba(40, 160, 110, 0.1);
}

[data-theme="light"] .sheet-cell {
    color: #152018;
}

[data-theme="light"] .sheet-cell:focus {
    background: rgba(40, 160, 110, 0.12);
    box-shadow: inset 0 0 0 1px var(--accent-strong);
}

[data-theme="light"] .sheet-td.is-formula .sheet-cell-display {
    color: #1a5fb4;
}

[data-theme="light"] .sheet-cell-editor {
    background: #ffffff;
    color: #111827;
    border-color: #15803d;
    box-shadow: 0 0 0 2px rgba(21, 128, 61, 0.28), 0 4px 14px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .sheet-formula-suggest,
[data-theme="light"] .sheet-formula-suggest.is-portal {
    background: #ffffff;
    border: 1px solid rgba(21, 128, 61, 0.35);
    color: #111827;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}

[data-theme="light"] .sheet-formula-suggest-item {
    color: #111827;
}

[data-theme="light"] .sheet-formula-suggest-item span {
    color: #4b5563;
}

[data-theme="light"] .sheet-formula-suggest-item:hover,
[data-theme="light"] .sheet-formula-suggest-item:focus-visible,
[data-theme="light"] .sheet-formula-suggest-item.is-active {
    background: rgba(40, 160, 110, 0.16);
}

[data-theme="light"] .sheet-table td.is-range-preview {
    background: rgba(40, 160, 110, 0.16);
}

[data-theme="light"] .sheet-controls-guide {
    background: #ffffff;
    border-color: rgba(20, 40, 25, 0.12);
}

[data-theme="light"] .sheet-controls-guide summary {
    color: #111827;
}

[data-theme="light"] .sheet-guide-block code {
    color: #1a5fb4;
}

[data-theme="light"] .sheet-controls-guide kbd {
    background: #f3f4f6;
    border-color: rgba(20, 40, 25, 0.2);
    color: #111827;
}

[data-theme="light"] .docs-editor-wrap {
    background: #ffffff;
    border-color: rgba(20, 40, 25, 0.12);
}

[data-theme="light"] .docs-editor {
    color: #142018;
}

[data-theme="light"] .docs-editor td,
[data-theme="light"] .docs-editor th {
    color: #152018;
    background: #ffffff;
}
