/* Spreadsheet page styles */

.sheet-page {
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.sheet-page .page-header {
    flex-shrink: 0;
}

/* Two-panel layout: grid + chat */
.sheet-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 16px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.sheet-grid-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.sheet-chat-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Grid toolbar */
.sheet-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.sheet-toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sheet-toolbar-sep {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}

.sheet-cell-ref {
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 4px 10px;
    min-width: 60px;
    text-align: center;
}

.sheet-formula-bar {
    flex: 1;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--text-primary);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 4px 10px;
    outline: none;
}

.sheet-formula-bar:focus {
    border-color: var(--accent-blue);
}

/* Grid container */
.sheet-grid-wrap {
    flex: 1;
    overflow: auto;
    position: relative;
}

.sheet-grid {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    table-layout: fixed;
}

.sheet-grid th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-elevated);
    color: var(--text-tertiary);
    font-weight: 500;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border-subtle);
    text-align: center;
    user-select: none;
    min-width: 80px;
}

.sheet-grid th.row-header {
    position: sticky;
    left: 0;
    z-index: 3;
    width: 44px;
    min-width: 44px;
    text-align: center;
}

.sheet-grid td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-subtle);
    border-right: 1px solid var(--border-subtle);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: cell;
    height: 28px;
}

.sheet-grid td.row-num {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--bg-elevated);
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    text-align: center;
    font-weight: 500;
    cursor: default;
    user-select: none;
}

.sheet-grid td.selected {
    outline: 2px solid var(--accent-blue);
    outline-offset: -1px;
    background: rgba(74, 163, 161, 0.08);
}

.sheet-grid td.editing {
    padding: 0;
}

.sheet-grid td.editing input {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: inherit;
    font-size: inherit;
    padding: 4px 8px;
}

/* Sheet tabs */
.sheet-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 10px;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
    overflow-x: auto;
}

.sheet-tab {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    border: 1px solid transparent;
    background: none;
    transition: all 0.12s ease;
}

.sheet-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sheet-tab.active {
    background: rgba(74, 163, 161, 0.12);
    border-color: rgba(74, 163, 161, 0.3);
    color: var(--accent-blue);
}

.sheet-tab-add {
    font-size: var(--text-base);
    color: var(--text-tertiary);
    padding: 2px 8px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px dashed var(--border);
    background: none;
    transition: all 0.12s ease;
}

.sheet-tab-add:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* Chat panel */
.sheet-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.sheet-chat-title {
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sheet-chat-badge {
    font-size: var(--text-xs);
    padding: 2px 7px;
    border-radius: 10px;
    background: rgba(74, 163, 161, 0.15);
    color: var(--accent-blue);
    font-weight: 600;
}

.sheet-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sheet-chat-msg {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sheet-chat-msg-header {
    display: flex;
    align-items: center;
    gap: 6px;
}

.sheet-chat-msg-role {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sheet-chat-msg-role.user {
    color: var(--accent-blue);
}

.sheet-chat-msg-role.assistant {
    color: var(--accent-purple);
}

.sheet-chat-msg-time {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.sheet-chat-msg-body {
    font-size: var(--text-sm);
    color: var(--text-primary);
    line-height: 1.5;
    background: var(--bg-elevated);
    border-radius: 10px;
    padding: 10px 12px;
    word-break: break-word;
}

.sheet-chat-msg-body code {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    background: var(--bg-base);
    padding: 2px 5px;
    border-radius: 4px;
}

.sheet-chat-msg-body pre {
    background: var(--bg-base);
    border-radius: 8px;
    padding: 10px;
    overflow-x: auto;
    margin: 6px 0;
}

.sheet-chat-msg-body pre code {
    padding: 0;
    background: none;
}

/* Chat input area */
.sheet-chat-input-area {
    padding: 10px 14px;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.sheet-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 8px;
    transition: border-color 0.12s ease;
}

.sheet-chat-input-wrap:focus-within {
    border-color: var(--accent-blue);
}

.sheet-chat-textarea {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    resize: none;
    line-height: 1.4;
    max-height: 120px;
    padding: 4px 0;
}

.sheet-chat-textarea::placeholder {
    color: var(--text-tertiary);
}

.sheet-chat-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: var(--accent-blue);
    color: var(--bg-base);
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.12s ease;
}

.sheet-chat-send:hover {
    opacity: 0.85;
}

.sheet-chat-send:disabled {
    opacity: 0.4;
    cursor: default;
}

.sheet-chat-send svg {
    width: 16px;
    height: 16px;
}

/* Loading / empty states */
.sheet-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
    font-size: var(--text-base);
    gap: 8px;
}

.sheet-loading .spin {
    animation: spin 0.8s linear infinite;
    width: 16px;
    height: 16px;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* File picker */
.sheet-file-picker {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    padding: 40px;
}

.sheet-drop-zone {
    border: 2px dashed var(--border);
    border-radius: 16px;
    padding: 48px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s ease;
    width: 100%;
    max-width: 480px;
}

.sheet-drop-zone:hover {
    border-color: var(--accent-blue);
    background: rgba(74, 163, 161, 0.04);
}

.sheet-drop-zone-icon {
    font-size: var(--text-3xl);
    margin-bottom: 12px;
    color: var(--text-tertiary);
}

.sheet-drop-zone-text {
    font-size: var(--text-base);
    color: var(--text-secondary);
}

.sheet-drop-zone-hint {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    margin-top: 6px;
}

/* Status bar */
.sheet-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 14px;
    border-top: 1px solid var(--border-subtle);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    flex-shrink: 0;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .sheet-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 300px;
    }

    .sheet-page {
        padding: 0 8px 8px;
    }
}
