/* AstroFetch — Observatory Theme */

@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Source+Code+Pro:wght@400;500;600&display=swap');

:root {
    /* Deep space palette */
    --bg-primary: #090d1a;
    --bg-secondary: #0c1222;
    --bg-sidebar: #0e1528;
    --bg-input: #111a2e;
    --bg-user-msg: #14223a;
    --bg-assistant-msg: #0f1829;
    --bg-tool: #0b1220;
    --bg-hover: rgba(232, 168, 56, 0.04);

    /* Warm text tones */
    --text-primary: #e2ddd5;
    --text-secondary: #9a9590;
    --text-muted: #5e5a56;

    /* Amber/gold starlight accent */
    --accent: #d4a041;
    --accent-hover: #e4b254;
    --accent-glow: rgba(212, 160, 65, 0.12);
    --accent-subtle: rgba(212, 160, 65, 0.06);

    /* Supporting colors */
    --violet: #9b8afb;
    --border: #1a2240;
    --border-subtle: rgba(255, 255, 255, 0.04);
    --error: #e85d52;
    --error-bg: rgba(232, 93, 82, 0.08);
    --success: #4ecca3;
    --success-bg: rgba(78, 204, 163, 0.08);

    /* OAuth brand colors */
    --google-blue: #4285f4;
    --orcid-green: #a6ce39;

    /* Spacing & shape */
    --radius: 10px;
    --radius-lg: 14px;
    --sidebar-width: 272px;

    /* Typography — NASA/IPAC-adjacent */
    --font-body: 'Source Sans 3', 'Source Sans Pro', Helvetica, Arial, sans-serif;
    --font-display: Helvetica, 'Source Sans 3', Arial, sans-serif;
    --font-mono: 'Source Code Pro', 'SF Mono', 'Consolas', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    font-feature-settings: 'kern' 1, 'liga' 1;
    -webkit-font-smoothing: antialiased;
    font-size: 137.5%;
}

/* ==================== Layout ==================== */

#app {
    display: flex;
    height: 100vh;
}

/* ==================== Sidebar ==================== */

#sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

/* Faint top edge glow */
#sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-glow), transparent);
}

#sidebar.collapsed {
    width: 0;
    border-right: none;
}

.sidebar-header {
    position: relative;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border);
}

.brand-logo {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 6px;
}

.sidebar-header #sidebar-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    background: rgba(9, 13, 26, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    border-radius: 4px;
    padding: 2px 6px;
}

.sidebar-header h1 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.beta-badge {
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    background: var(--accent);
    color: var(--bg-primary);
    padding: 1px 5px;
    border-radius: 3px;
    line-height: 1.4;
    vertical-align: middle;
}

#sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

#sidebar-toggle:hover {
    background: var(--accent-subtle);
    color: var(--text-secondary);
}

/* ==================== Auth ==================== */

#auth-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.auth-hint {
    color: var(--text-muted);
    font-size: 0.84rem;
    margin-bottom: 8px;
    letter-spacing: 0.01em;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

#user-name {
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1;
}

.icon-btn:hover {
    color: var(--accent);
    background: var(--accent-subtle);
}

.icon-btn svg {
    width: 14px;
    height: 14px;
}

/* ==================== Buttons ==================== */

.btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 6px;
    transition: opacity 0.15s, transform 0.1s;
    letter-spacing: 0.01em;
}

.btn:hover {
    opacity: 0.88;
}

.btn:active {
    transform: scale(0.98);
}

.btn-google {
    background: var(--google-blue);
    color: #fff;
}

.btn-orcid {
    background: var(--orcid-green);
    color: #1a1a1a;
}

.btn-primary {
    background: var(--accent);
    color: #0a0e1a;
    font-weight: 600;
    margin: 14px 16px;
    width: calc(100% - 32px);
    letter-spacing: 0.02em;
}

.btn-primary:hover {
    background: var(--accent-hover);
    opacity: 1;
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.84rem;
    text-decoration: none;
    transition: color 0.15s;
}

.btn-link:hover {
    color: var(--accent);
}

/* ==================== Selectors ==================== */

#archive-selector,
#model-selector {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

#archive-selector label,
#model-selector label {
    display: block;
    font-family: var(--font-body);
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

#profile-select,
#model-select {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-body);
    font-size: 0.88rem;
    transition: border-color 0.15s;
}

#profile-select:focus,
#model-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ==================== Chat List ==================== */

#chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    transition: background 0.15s;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--accent-glow);
    border-left: 2px solid var(--accent);
}

.chat-item-title {
    font-size: 0.90rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-item-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-left: 8px;
    flex-shrink: 0;
}

.chat-item-date {
    font-size: 0.74rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.chat-item-model {
    font-size: 0.66rem;
    color: var(--text-muted);
    opacity: 0.65;
    white-space: nowrap;
}

.chat-item-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}

.chat-item:hover .chat-item-actions {
    opacity: 1;
}

.chat-item-rename,
.chat-item-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 1.05rem;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
    line-height: 1;
}

.chat-item-rename:hover {
    color: var(--accent);
    background: var(--accent-subtle);
}

.chat-item-delete:hover {
    color: var(--error);
    background: var(--error-bg);
}

.chat-item-rename-input {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: var(--font-body);
    font-size: 0.90rem;
    width: 100%;
    outline: none;
}

/* ==================== Guest Banner ==================== */

#guest-banner {
    padding: 12px 16px;
    background: var(--accent-subtle);
    border-top: 1px solid var(--border);
    font-size: 0.84rem;
    color: var(--text-secondary);
}

/* ==================== Main Chat Area ==================== */

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(212, 160, 65, 0.02) 0%, transparent 60%),
        var(--bg-primary);
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    scroll-behavior: smooth;
}

/* ==================== User Messages ==================== */

.message {
    max-width: 780px;
    margin: 0 auto 16px;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.65;
}

.message-user {
    background: var(--bg-user-msg);
    margin-left: 80px;
    border: 1px solid var(--border);
}

.message-assistant {
    background: var(--bg-assistant-msg);
}

.message-role {
    font-family: var(--font-display);
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.message-content {
    font-size: 1.0rem;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.65;
}

.message-content p {
    margin-bottom: 0.5em;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* ==================== Turn Container (Streaming) ==================== */

.turn {
    max-width: 780px;
    margin: 0 auto 16px;
}

.turn-text {
    background: var(--bg-assistant-msg);
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 4px;
    line-height: 1.65;
    font-size: 1.0rem;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.turn-text p { margin-bottom: 0.5em; }
.turn-text p:last-child { margin-bottom: 0; }

/* ==================== Tool Blocks ==================== */

.tool-block {
    background: var(--bg-tool);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 6px 0;
    overflow: hidden;
    font-size: 0.88rem;
}

.tool-block-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--text-secondary);
    font-weight: 600;
    font-family: var(--font-body);
    letter-spacing: 0.01em;
}

.tool-block-header .spinner {
    width: 13px;
    height: 13px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

.tool-check {
    color: var(--success);
    font-weight: bold;
    font-size: 0.92rem;
    flex-shrink: 0;
}

.tool-block-name {
    flex: 1;
}

.tool-block-input {
    padding: 0 12px 8px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-all;
    border-top: 1px solid var(--border-subtle);
    padding-top: 6px;
    margin-top: 0;
}

.tool-block-input code {
    background: none;
    padding: 0;
    font-size: inherit;
    color: var(--text-secondary);
}

.tool-block-input pre {
    margin: 0;
    background: none;
    padding: 0;
}

.tool-block-input pre code {
    font-size: 0.82rem;
    line-height: 1.55;
}

.tool-block-result {
    padding: 0 12px 8px;
    color: var(--success);
    font-size: 0.84rem;
    font-family: var(--font-body);
}

.tool-block-result:empty {
    display: none;
}

.code-output {
    margin: 0;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.25);
    border-top: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

.code-output:empty {
    display: none;
}

.tool-block.complete {
    border-color: rgba(78, 204, 163, 0.15);
}

.tool-block.error {
    border-color: rgba(220, 80, 80, 0.25);
}

.tool-block.error .tool-block-result {
    color: var(--error, #dc5050);
}

.tool-error-icon {
    color: var(--error, #dc5050);
    font-weight: bold;
    font-size: 0.92rem;
    flex-shrink: 0;
}

.tool-error-details {
    border-top: 1px solid var(--border-subtle);
    padding: 0 12px 8px;
    font-size: 0.82rem;
}

.tool-error-details summary {
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 0 4px;
    user-select: none;
    font-family: var(--font-body);
}

.tool-error-details summary:hover {
    color: var(--text-secondary);
}

.tool-error-trace {
    margin: 4px 0 0;
    padding: 8px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 4px;
    color: var(--error, #dc5050);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}

.stopped-note {
    color: var(--text-muted);
    font-size: 0.84rem;
    font-style: italic;
    padding: 4px 0;
}

/* ==================== Loading Indicator ==================== */

.loading-indicator {
    max-width: 780px;
    margin: 8px auto;
    display: flex;
    justify-content: center;
}

.loading-indicator-inner {
    display: inline-flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--bg-assistant-msg);
    border-radius: var(--radius);
}

/* Rotating word display */
.loading-word-container {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
    justify-content: center;
}

.loading-word {
    font-family: var(--font-body);
    font-size: 0.88rem;
    font-style: italic;
    color: var(--text-secondary);
    transition: opacity 0.4s ease;
    white-space: nowrap;
}

.loading-word.fade-out {
    opacity: 0;
}

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

/* Spinning star (default/IRSA animation) */
.spinning-star {
    position: relative;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinning-star .star-core {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent), 0 0 16px rgba(212, 160, 65, 0.3);
    animation: star-pulse 2s ease-in-out infinite;
}

.spinning-star .star-rays {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    animation: spin 8s linear infinite;
}

.spinning-star .star-rays::before,
.spinning-star .star-rays::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    background: var(--accent);
    border-radius: 1px;
    opacity: 0.4;
}

.spinning-star .star-rays::before {
    width: 24px;
    height: 1px;
    margin-left: -12px;
    margin-top: -0.5px;
}

.spinning-star .star-rays::after {
    width: 1px;
    height: 24px;
    margin-left: -0.5px;
    margin-top: -12px;
}

@keyframes star-pulse {
    0%, 100% { box-shadow: 0 0 8px var(--accent), 0 0 16px rgba(212, 160, 65, 0.3); }
    50% { box-shadow: 0 0 12px var(--accent), 0 0 24px rgba(212, 160, 65, 0.5); }
}

/* ==================== Block Feedback ==================== */

.block-feedback {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.turn-text:hover .block-feedback,
.tool-block:hover .block-feedback,
.plot-container:hover .block-feedback,
.table-container:hover .block-feedback,
.block-feedback.has-feedback {
    opacity: 1;
}

.block-feedback { position: relative; }

.star-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 1px;
    border-radius: 3px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    transition: color 0.1s, transform 0.1s;
}

.star-btn svg {
    fill: transparent;
    stroke: currentColor;
}

.star-btn.filled svg {
    fill: var(--accent);
    stroke: var(--accent);
}

.star-btn.hover svg {
    fill: var(--accent-hover);
    stroke: var(--accent-hover);
}

.star-btn:hover {
    transform: scale(1.12);
}

.feedback-popover {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    width: 250px;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.feedback-popover textarea {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-body);
    font-size: 0.84rem;
    resize: vertical;
    min-height: 50px;
    margin-bottom: 6px;
}

.feedback-popover textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.feedback-submit-btn {
    display: block;
    width: 100%;
    padding: 5px 10px;
    background: var(--accent);
    color: #0a0e1a;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 600;
}

.feedback-submit-btn:hover {
    background: var(--accent-hover);
}

/* ==================== Markdown Rendering ==================== */

.message-content h1, .message-content h2, .message-content h3,
.turn-text h1, .turn-text h2, .turn-text h3 {
    font-family: var(--font-display);
    margin-top: 0.8em;
    margin-bottom: 0.4em;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.message-content h1, .turn-text h1 { font-size: 1.35rem; font-weight: 700; }
.message-content h2, .turn-text h2 { font-size: 1.15rem; font-weight: 600; }
.message-content h3, .turn-text h3 { font-size: 1.02rem; font-weight: 600; }

.message-content code, .turn-text code {
    background: rgba(212, 160, 65, 0.06);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.88em;
    color: var(--accent-hover);
}

.message-content pre, .turn-text pre {
    background: rgba(0, 0, 0, 0.35);
    padding: 12px 14px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid var(--border);
}

.message-content pre code, .turn-text pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 0.86rem;
    line-height: 1.55;
}

.message-content ul, .message-content ol,
.turn-text ul, .turn-text ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.message-content a, .turn-text a {
    color: var(--violet);
    text-decoration: none;
    transition: color 0.15s;
}

.message-content a:hover, .turn-text a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* Markdown tables */
.message-content table, .turn-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 0.88rem;
}

.message-content th, .message-content td,
.turn-text th, .turn-text td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.message-content th, .turn-text th {
    background: rgba(0, 0, 0, 0.25);
    font-weight: 600;
    font-size: 0.84rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ==================== Thinking Block ==================== */

.thinking-block {
    margin: 6px 0;
    border-left: 2px solid var(--text-muted);
    background: rgba(0, 0, 0, 0.12);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 8px 12px 8px 14px;
}

.thinking-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.84rem;
    padding: 0;
    transition: color 0.15s;
}

.thinking-toggle:hover {
    color: var(--text-secondary);
}

.thinking-content {
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.88rem;
    font-style: italic;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 6px;
}

.thinking-content.collapsed {
    display: none;
}

/* ==================== Plots ==================== */

.plot-container {
    margin: 10px 0;
    text-align: center;
}

.plot-container img {
    max-width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.plot-description {
    font-size: 0.84rem;
    color: var(--text-muted);
    margin-top: 6px;
    font-style: italic;
}

/* ==================== Data Tables ==================== */

.table-container {
    margin: 8px 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-tool);
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.84rem;
    color: var(--text-secondary);
}

.table-download-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 3px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.80rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: background 0.15s, border-color 0.15s;
}

.table-download-btn:hover {
    background: var(--accent-subtle);
    border-color: var(--accent);
}

.table-scroll {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 400px;
}

.data-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.84rem;
    font-family: var(--font-mono);
}

.data-table th {
    position: sticky;
    top: 0;
    background: var(--bg-sidebar);
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--text-secondary);
    z-index: 1;
    letter-spacing: 0.02em;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    padding-right: 20px;
    transition: color 0.15s;
}

.data-table th.sortable:hover {
    color: var(--accent);
}

.data-table th.sortable::after {
    content: '\2195';
    position: absolute;
    right: 4px;
    opacity: 0.25;
    font-size: 0.74rem;
}

.data-table th.sort-asc::after {
    content: '\25B2';
    opacity: 0.7;
    color: var(--accent);
}

.data-table th.sort-desc::after {
    content: '\25BC';
    opacity: 0.7;
    color: var(--accent);
}

.col-unit {
    font-weight: normal;
    opacity: 0.45;
    font-size: 0.74rem;
}

.data-table td {
    padding: 4px 10px;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
    color: var(--text-primary);
}

.data-table td a {
    color: var(--violet);
    text-decoration: none;
}

.data-table td a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

.table-footer {
    padding: 6px 14px;
    font-size: 0.80rem;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.12);
    border-top: 1px solid var(--border-subtle);
}

/* ==================== Error Messages ==================== */

.error-message {
    background: var(--error-bg);
    border: 1px solid rgba(232, 93, 82, 0.25);
    border-radius: var(--radius);
    padding: 10px 14px;
    color: var(--error);
    font-size: 0.95rem;
    margin: 8px auto;
    max-width: 780px;
}

/* ==================== Input Area ==================== */

#input-area {
    padding: 12px 20px 16px;
    background: transparent;
    max-width: 840px;
    margin: 0 auto;
    width: 100%;
}

#input-area-inner {
    display: flex;
    align-items: flex-end;
    background: var(--bg-input);
    border: none;
    border-radius: 22px;
    padding: 6px 6px 6px 18px;
    transition: box-shadow 0.2s;
}

#input-area-inner:focus-within {
    box-shadow: 0 0 0 2px rgba(212, 160, 65, 0.25);
}

#user-input {
    flex: 1;
    padding: 5px 8px 5px 0;
    background: transparent;
    color: var(--text-primary);
    border: none;
    font-family: var(--font-body);
    font-size: 0.95rem;
    resize: none;
    min-height: 24px;
    max-height: 150px;
    line-height: 1.5;
    overflow-y: auto;
    word-wrap: break-word;
}

#user-input:focus {
    outline: none;
}

#user-input::placeholder {
    color: var(--text-muted);
}

#send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    background: var(--accent);
    color: #0a0e1a;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
    margin-bottom: 1px;
}

#send-btn:hover {
    background: var(--accent-hover);
}

#send-btn:active {
    transform: scale(0.93);
}

#send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#send-btn.stop {
    background: var(--error);
    color: #fff;
}

#send-btn.stop:hover {
    background: #f47067;
}

/* ==================== Context Warning ==================== */

.context-warning {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    min-width: 30px;
    color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
    margin-bottom: 3px;
    border-radius: 50%;
    transition: background 0.15s;
}

.context-warning:hover,
.context-warning:focus {
    background: rgba(212, 160, 65, 0.1);
    outline: none;
}

.context-warning-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 10px);
    right: -10px;
    width: 280px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: 0.84rem;
    line-height: 1.5;
    color: var(--text-primary);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 50;
}

.context-warning-tooltip strong {
    display: block;
    color: var(--accent);
    margin-bottom: 6px;
    font-size: 0.88rem;
}

.context-warning-tooltip p {
    margin: 0 0 8px;
    color: var(--text-secondary);
}

.context-warning-tooltip p:last-child {
    margin-bottom: 0;
}

.context-warning:hover .context-warning-tooltip,
.context-warning:focus .context-warning-tooltip {
    display: block;
}

/* ==================== Disclaimer ==================== */

#disclaimer {
    text-align: center;
    font-size: 0.74rem;
    color: var(--text-muted);
    padding: 4px 20px 12px;
    max-width: 840px;
    margin: 0 auto;
    width: 100%;
    line-height: 1.4;
}

#disclaimer a {
    color: var(--text-muted);
    text-decoration: underline;
    transition: color 0.15s;
}

#disclaimer a:hover {
    color: var(--accent);
}

/* ==================== Sidebar Drag Handle ==================== */

#sidebar-drag-handle {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
    background: transparent;
    transition: background 0.15s;
}

#sidebar-drag-handle:hover,
#sidebar-drag-handle.dragging {
    background: var(--accent);
    opacity: 0.4;
}

#sidebar.collapsed #sidebar-drag-handle {
    display: none;
}

#sidebar.resizing {
    transition: none;
}

/* ==================== Sidebar Expand Button ==================== */

#sidebar-expand-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 50;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.15s, color 0.15s;
}

#sidebar-expand-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent);
}

#sidebar.collapsed ~ #sidebar-expand-btn {
    display: block;
}

/* ==================== Sidebar Overlay ==================== */

#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* ==================== Admin Link ==================== */
/* admin-link is now an .icon-btn in user-actions */

/* ==================== Scrollbar ==================== */

::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==================== Responsive ==================== */

@supports (height: 100dvh) {
    body, #app { height: 100dvh; }
}

@media (max-width: 768px) {
    body, #app {
        height: 100dvh;
        height: 100vh;
    }

    #sidebar {
        position: fixed;
        z-index: 100;
        height: 100dvh;
        height: 100vh;
        top: 0;
        left: 0;
    }

    #sidebar.collapsed {
        width: 0;
    }

    /* Show overlay when sidebar is open on mobile */
    #sidebar:not(.collapsed) ~ #sidebar-overlay {
        display: block;
    }

    /* Expand button on mobile */
    #sidebar.collapsed ~ #sidebar-expand-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        font-size: 1.3rem;
    }

    /* Touch-friendly sizes */
    .btn, #new-chat-btn {
        min-height: 44px;
        font-size: 1rem;
    }

    .chat-item {
        padding: 12px 16px;
        min-height: 44px;
    }

    .chat-item-actions {
        opacity: 1;
    }

    .chat-item-rename, .chat-item-delete {
        padding: 8px 10px;
        min-width: 36px;
        min-height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .message-user {
        margin-left: 20px;
    }

    /* Input area for mobile keyboard */
    #input-area {
        padding: 8px 10px 12px;
    }

    #user-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    #send-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }

    .context-warning-tooltip {
        right: -40px;
        width: 260px;
    }

    #messages {
        padding: 16px 12px;
    }

    .message {
        padding: 10px 12px;
    }

    /* Table scroll indicator */
    .table-scroll {
        position: relative;
    }

    .table-scroll::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to right, transparent, rgba(9, 13, 26, 0.7));
        pointer-events: none;
    }

    .table-scroll.scrolled-end::after {
        opacity: 0;
    }

    /* Feedback always visible on touch */
    .block-feedback {
        opacity: 1;
    }

    .feedback-btn {
        padding: 6px 8px;
        font-size: 0.88rem;
    }

    /* Feedback popover as bottom sheet */
    .feedback-popover {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        padding: 16px;
        z-index: 300;
    }

    /* Disclaimer */
    #disclaimer {
        font-size: 0.68rem;
        padding: 4px 12px 8px;
    }

    /* Hide drag handle on mobile */
    #sidebar-drag-handle {
        display: none;
    }
}

/* --- API Keys Modal --- */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-hint {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.api-key-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.api-key-provider {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 80px;
    text-transform: capitalize;
}

.api-key-masked {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.api-key-url {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.api-key-delete {
    margin-left: auto;
    color: var(--error) !important;
    font-size: 0.8rem;
}

.api-keys-empty {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

.api-key-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.api-key-form select,
.api-key-form input {
    flex: 1;
    min-width: 120px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.api-key-form input[hidden] {
    display: none;
}

.api-key-form .btn {
    flex-shrink: 0;
}

/* icon-btn styles handle api-keys-btn now */

/* ==================== Evaluation Mode Gate ==================== */

.eval-banner {
    background: var(--accent-subtle);
    border: 1px solid var(--accent);
    color: var(--text-primary);
    padding: 8px 14px;
    margin: 0 16px 8px 16px;
    border-radius: var(--radius);
    font-size: 0.88rem;
    text-align: center;
    box-shadow: 0 0 8px rgba(212, 160, 65, 0.15);
}

body.eval-blocked #user-input,
body.eval-blocked #send-btn {
    opacity: 0.45;
    pointer-events: none;
}
