/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Global utility: visually hides content while keeping it in the a11y tree
   (screen readers, find-in-page). Used by static/js/insights_charts.js's
   per-chart hidden data table -- must work anywhere, not just inside
   .app-shell, so it is intentionally NOT scoped. */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

/* Login Page Styles */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 450px;
    width: 100%;
    padding: 50px 40px;
    text-align: center;
}

.logo h1 {
    font-size: 3em;
    margin-bottom: 10px;
    color: #667eea;
}

.tagline {
    color: #666;
    font-size: 1.1em;
    margin-bottom: 40px;
}

.login-content h2 {
    font-size: 2em;
    margin-bottom: 10px;
    color: #333;
}

.subtitle {
    color: #666;
    margin-bottom: 30px;
    line-height: 1.5;
}

.google-login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: white;
    border: 2px solid #ddd;
    padding: 14px 32px;
    border-radius: 50px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    margin-bottom: 30px;
}

.google-login-btn:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}

.google-icon {
    width: 20px;
    height: 20px;
}

.features {
    display: flex;
    justify-content: space-around;
    margin-top: 40px;
    padding-top: 30px;
    border-top: 1px solid #eee;
}

.feature {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 0.9em;
}

.feature-icon {
    font-size: 1.8em;
}

.login-footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    color: #999;
    font-size: 0.9em;
}

/* Search Page Styles */
.search-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo {
    font-size: 1.5em;
    color: #667eea;
    font-weight: bold;
}

.stats {
    color: #666;
    font-size: 0.9em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info a[title="Settings"] {
    padding: 4px;
    border-radius: 4px;
    opacity: 0.85;
    transition: all 0.2s ease;
    font-size: 18px;
    line-height: 1;
    vertical-align: middle;
    text-decoration: none;
}

.user-info a[title="Settings"]:hover {
    background-color: rgba(102, 126, 234, 0.1);
    opacity: 1;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #667eea;
}

.user-name {
    font-weight: 500;
    color: #333;
}

.logout-btn {
    background: #667eea;
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.logout-btn:hover {
    background: #5568d3;
    transform: translateY(-1px);
}

/* Search Section */
.search-section {
    padding: 60px 40px 40px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

.search-box {
    display: flex;
    background: white;
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    transition: all 0.3s ease;
}

.search-box:focus-within {
    box-shadow: 0 6px 30px rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}

.search-input {
    flex: 1;
    border: none;
    padding: 20px 30px;
    font-size: 1.1em;
    outline: none;
}

.search-btn {
    background: #667eea;
    border: none;
    padding: 20px 30px;
    cursor: pointer;
    color: white;
    transition: all 0.3s ease;
}

.search-btn:hover {
    background: #5568d3;
}

/* Example Queries */
.example-queries {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
    align-items: center;
}

.example-label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9em;
    font-weight: 500;
}

.example-query {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.example-query:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 40px;
    color: white;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Results */
.results-container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 0 40px 40px;
}

.results-header {
    color: white;
    margin-bottom: 20px;
    font-size: 0.95em;
}

.result-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
}

.result-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

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

.result-title {
    font-size: 1.2em;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.result-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.result-type {
    background: #667eea;
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 500;
    text-transform: uppercase;
}

.result-score {
    color: #999;
    font-size: 0.85em;
}

.result-metadata {
    color: #666;
    font-size: 0.85em;
    margin-bottom: 12px;
}

.result-preview {
    color: #555;
    line-height: 1.6;
    font-size: 0.95em;
}

.result-id {
    color: #999;
    font-size: 0.8em;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 80px 40px;
    color: white;
}

.empty-state svg {
    margin-bottom: 20px;
    opacity: 0.6;
}

.empty-state h3 {
    font-size: 1.8em;
    margin-bottom: 10px;
}

.empty-state p {
    font-size: 1.1em;
    opacity: 0.8;
}

/* Error Pages */
.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    color: white;
    text-align: center;
    padding: 40px;
}

.error-container h1 {
    font-size: 6em;
    margin-bottom: 20px;
}

.error-container h2 {
    font-size: 2em;
    margin-bottom: 10px;
}

.error-container p {
    font-size: 1.2em;
    margin-bottom: 30px;
    opacity: 0.9;
}

.btn {
    background: white;
    color: #667eea;
    padding: 12px 30px;
    border-radius: 25px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 15px;
        padding: 20px;
    }

    .search-section {
        padding: 40px 20px 20px;
    }

    .results-container {
        padding: 0 20px 20px;
    }

    /* Collapse the Ask two-column layout to a single stacked column. */
    .ask-mode .workspace {
        flex-direction: column;
        padding: 16px 20px 0;
        gap: 16px;
    }

    .conversations-list {
        flex: 1 1 auto;
        width: 100%;
        position: static;
        max-height: 220px;
    }

    .example-queries {
        justify-content: center;
    }

    .login-box {
        padding: 40px 30px;
    }

    .features {
        flex-direction: column;
        gap: 15px;
    }
}

/* Form Styles */
.login-form {
    margin: 20px 0;
    text-align: left;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 0.9em;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    transition: all 0.3s ease;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-help {
    display: block;
    margin-top: 5px;
    color: #999;
    font-size: 0.85em;
}

.btn-primary {
    width: 100%;
    background: #667eea;
    color: white;
    padding: 14px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 10px;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* Alert Styles */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9em;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

/* Divider */
.divider {
    display: flex;
    align-items: center;
    margin: 25px 0;
    color: #999;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #ddd;
}

.divider span {
    padding: 0 15px;
    font-size: 0.9em;
}

/* Auth Links */
.auth-links {
    margin-top: 20px;
    font-size: 0.9em;
    color: #666;
}

.auth-links a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.auth-links a:hover {
    text-decoration: underline;
}

.auth-links span {
    margin: 0 10px;
    color: #ddd;
}

/* ===== Dark auth pages (login/register) ===== */
.auth-shell {
    --bg: #212121;
    --surface: #2f2f2f;
    --surface-hover: #383838;
    --border: #3a3a3a;
    --text: #ececec;
    --text-muted: #9b9b9b;
    --text-faint: #737373;
    --accent: #ff8f4d;
    --accent-strong: #ff6a2b;
    --accent-2: #e63030;

    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 50% -10%, rgba(255, 106, 43, 0.20), transparent 60%),
        var(--bg);
}

.auth-shell .login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    max-width: 420px;
    width: 100%;
    padding: 44px 40px;
    text-align: center;
}

.auth-shell .logo h1 {
    color: var(--text);
    font-size: 2.4em;
    margin-bottom: 8px;
}

.auth-shell .brand-lockup {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
}

.auth-shell .brand-lockup .brand-torch {
    height: 52px;
    width: auto;
    display: block;
    filter: drop-shadow(0 3px 14px rgba(255, 106, 43, 0.55));
}

.auth-shell .brand-lockup .brand-word {
    font-size: 2em;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}

.auth-shell .brand-lockup .brand-tld {
    color: var(--accent);
}

.auth-shell .tagline {
    color: var(--text-muted);
    margin-bottom: 32px;
}

.auth-shell .login-content h2 {
    color: var(--text);
    font-size: 1.6em;
    margin-bottom: 8px;
}

.auth-shell .subtitle {
    color: var(--text-muted);
    margin-bottom: 26px;
}

.auth-shell .form-group label {
    color: var(--text-muted);
}

.auth-shell .form-input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
}

.auth-shell .form-input::placeholder {
    color: var(--text-faint);
}

.auth-shell .form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 143, 77, 0.18);
}

.auth-shell .form-help {
    color: var(--text-faint);
}

.auth-shell .btn-primary {
    background: linear-gradient(135deg, var(--accent-strong), var(--accent-2));
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(255, 106, 43, 0.35);
}

.auth-shell .btn-primary:hover {
    filter: brightness(1.05);
    box-shadow: 0 10px 28px rgba(255, 106, 43, 0.45);
    transform: translateY(-1px);
}

.auth-shell .auth-links {
    color: var(--text-muted);
}

.auth-shell .auth-links a {
    color: var(--accent);
}

.auth-shell .auth-links span {
    color: var(--border);
}

.auth-shell .divider {
    color: var(--text-faint);
}

.auth-shell .divider::before,
.auth-shell .divider::after {
    border-bottom: 1px solid var(--border);
}

.auth-shell .google-login-btn {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
}

.auth-shell .google-login-btn:hover {
    border-color: var(--accent);
    background: #404040;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transform: translateY(-2px);
}

.auth-shell .features {
    border-top: 1px solid var(--border);
}

.auth-shell .feature {
    color: var(--text-muted);
}

.auth-shell .login-footer {
    border-top: 1px solid var(--border);
    color: var(--text-faint);
}

.auth-shell .alert-error {
    background: rgba(248, 215, 218, 0.12);
    color: #f1b0b7;
    border-color: rgba(245, 198, 203, 0.25);
}

.auth-shell .alert-success {
    background: rgba(212, 237, 218, 0.12);
    color: #a3d9b1;
    border-color: rgba(195, 230, 203, 0.25);
}

.auth-shell .alert-info {
    background: rgba(209, 236, 241, 0.12);
    color: #a6d8e3;
    border-color: rgba(190, 229, 235, 0.25);
}

.auth-shell .alert-warning {
    background: rgba(255, 243, 205, 0.12);
    color: #e6cf8a;
    border-color: rgba(255, 234, 167, 0.25);
}

/* ===== Ask / RAG mode ===== */
.mode-toggle {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 14px;
}

.mode-option {
    border: none;
    background: transparent;
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
}

.mode-option.active {
    background: #fff;
    color: #667eea;
}

.mode-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 12px;
}

.mode-row .mode-toggle {
    margin-bottom: 0;
}

.new-chat-btn {
    border: 1px solid rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* Conversation thread */
.chat-thread {
    display: flex;
    flex-direction: column;
    gap: 18px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 0 40px 40px;
}

/* Sticky follow-up composer */
.composer-wrap {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    padding: 16px 40px 24px;
}

.composer {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    background: white;
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.composer:focus-within {
    box-shadow: 0 6px 30px rgba(102, 126, 234, 0.4);
}

.composer-input {
    flex: 1;
    border: none;
    padding: 16px 26px;
    font-size: 1.05em;
    outline: none;
}

.chat-turn {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-question {
    align-self: flex-end;
    max-width: 80%;
    background: #fff;
    color: #333;
    padding: 12px 16px;
    border-radius: 14px 14px 2px 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    font-weight: 500;
}

.thinking-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #667eea;
    animation: thinking 1.2s infinite ease-in-out both;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking {
    0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

.answer-panel {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #667eea;
}

.answer-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #667eea;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8em;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.answer-model {
    color: #aaa;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.answer-body {
    font-size: 1.05em;
    line-height: 1.65;
    color: #222;
}

/* Markdown formatting inside answers */
.answer-body strong,
.answer-body b {
    font-weight: 600;
}

.answer-body em,
.answer-body i {
    font-style: italic;
}

.answer-body ul,
.answer-body ol {
    margin: 0.5em 0 0.5em 1.25em;
    padding: 0;
}

.answer-body li {
    margin-bottom: 0.25em;
}

.answer-body code {
    background: #f4f4f4;
    padding: 2px 5px;
    border-radius: 3px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.9em;
}

.answer-body pre {
    background: #f4f4f4;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.answer-body pre code {
    background: none;
    padding: 0;
}

.answer-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.8em 0;
    font-size: 0.95em;
    display: block;
    overflow-x: auto;
}

.answer-body th,
.answer-body td {
    border: 1px solid #e0e0e0;
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
}

.answer-body thead th {
    background: #f4f4f4;
    font-weight: 600;
}

.answer-error {
    color: #e67e22;
    background: #fff7ed;
    padding: 12px 14px;
    border-radius: 8px;
}

.cite-link {
    color: #667eea;
    font-weight: 600;
    text-decoration: none;
    padding: 0 1px;
}

.cite-link:hover {
    text-decoration: underline;
}

.web-link {
    color: #667eea;
    font-weight: 500;
    text-decoration: none;
    border-bottom: 1px solid rgba(102, 126, 234, 0.35);
}

.web-link:hover {
    border-bottom-color: currentColor;
}

.web-link::after {
    content: "\2197";
    display: inline-block;
    margin-left: 2px;
    font-size: 0.85em;
    opacity: 0.7;
}

.answer-sources {
    margin-top: 18px;
    border-top: 1px solid #eee;
    padding-top: 14px;
}

.sources-header {
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #888;
    margin-bottom: 10px;
}

/* Source chips with hover popover */
.source-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.citation-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f3f4fb;
    border: 1px solid #e6e8f5;
    border-radius: 18px;
    padding: 5px 10px 5px 8px;
    cursor: default;
    line-height: 1;
}

.citation-chip:hover {
    background: #eef0fb;
    border-color: #c9cef0;
}

.chip-icon {
    font-size: 1.1em;
    line-height: 1;
}

.chip-num {
    background: #667eea;
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72em;
    font-weight: 600;
}

.citation-popover {
    position: absolute;
    left: 0;
    top: calc(100% + 8px);
    width: 260px;
    max-width: 80vw;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    padding: 12px 14px;
    z-index: 50;
    display: none;
    flex-direction: column;
    gap: 6px;
    cursor: auto;
}

/* Transparent bridge so the popover stays open while the cursor moves to it. */
.citation-popover::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -8px;
    height: 8px;
}

.citation-chip:hover .citation-popover {
    display: flex;
}

.citation-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 8px 0;
}

.citation-num {
    flex: 0 0 24px;
    height: 24px;
    width: 24px;
    text-align: center;
    line-height: 24px;
    background: #eef0fb;
    color: #667eea;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85em;
}

.citation-title {
    color: #222;
    font-weight: 600;
    text-decoration: none;
}

.citation-title:hover {
    color: #667eea;
}

.citation-sub {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 2px;
    font-size: 0.82em;
    color: #888;
}

.source-link {
    color: #16a34a;
    text-decoration: none;
    font-weight: 500;
}

.source-link:hover {
    text-decoration: underline;
}

a.result-title {
    text-decoration: none;
    color: inherit;
}

a.result-title:hover {
    color: #667eea;
}

/* ===== Workspace layout (sidebar + main column) ===== */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
}

.main-col {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

/* In Ask mode the workspace becomes a two-column layout:
   a fixed-width history rail on the left and a flexible main column. */
.ask-mode .workspace {
    flex-direction: row;
    align-items: flex-start;
    gap: 24px;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 40px 0;
}

/* Conversations list (Ask history rail) */
.conversations-list {
    flex: 0 0 260px;
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
}

/* When the sidebar is present, the main column's inner sections should no
   longer center against the full viewport width or add their own side padding. */
.ask-mode .search-section,
.ask-mode .chat-thread,
.ask-mode .results-container,
.ask-mode .composer-wrap {
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    padding-left: 0;
    padding-right: 0;
}

.ask-mode .search-section {
    padding-top: 0;
    padding-bottom: 32px;
}

.ask-mode .composer-wrap {
    padding-left: 0;
    padding-right: 0;
}

.ask-mode .composer {
    max-width: none;
}

.conv-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8em;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
    padding: 0 4px;
}

.conv-item {
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 2px;
    font-size: 0.85em;
    position: relative;
    padding-right: 24px;
}

.conv-item:hover {
    background: #f0f0f0;
}

.conv-item.active {
    background: #e6e9f5;
    font-weight: 500;
}

.conv-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #222;
}

.conv-meta {
    font-size: 0.7em;
    color: #888;
    margin-top: 2px;
}

.conv-empty {
    font-size: 0.8em;
    color: #888;
    padding: 4px;
}

.conv-item {
    position: relative;
}

.conv-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: #888;
    font-size: 14px;
    line-height: 1;
    padding: 2px 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.conv-item:hover .conv-delete {
    opacity: 0.6;
}

.conv-item:hover .conv-delete:hover {
    color: #e74c3c;
    opacity: 1;
}

/* ===== Document detail ===== */
.doc-detail {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.doc-detail-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.doc-detail-title {
    font-size: 1.8em;
    color: #222;
    margin-bottom: 20px;
}

.doc-detail-fields {
    background: #f8f9fc;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 20px;
}

.doc-detail-field {
    display: flex;
    gap: 10px;
    padding: 4px 0;
    font-size: 0.92em;
}

.doc-detail-key {
    flex: 0 0 130px;
    color: #888;
    text-transform: capitalize;
}

.doc-detail-value {
    color: #222;
}

.doc-detail-content {
    line-height: 1.7;
    color: #333;
    white-space: pre-wrap;
}

/* =====================================================================
   App shell — ChatGPT / Claude / Glean-style layout (dark)
   Scoped under .app-shell so login/settings/document/error pages are
   unaffected. Overrides earlier light styles for reused class names.
   ===================================================================== */
.app-shell {
    --bg: #212121;
    --sidebar-bg: #171717;
    --surface: #2f2f2f;
    --surface-hover: #2a2a2a;
    --border: #3a3a3a;
    --text: #ececec;
    --text-muted: #9b9b9b;
    --text-faint: #737373;
    --accent: #8b9bff;
    --accent-strong: #667eea;

    position: fixed;
    inset: 0;
    display: flex;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    color-scheme: dark;
    /* var(--border) #3a3a3a is too low-contrast to read as a scrollbar thumb
       against #212121/#2f2f2f; scrollbar-color is inherited so this themes
       every inner scroller under the shell. */
    scrollbar-color: #4d4d4d transparent;
}

/* scrollbar-width is not inherited, so blanket-apply it under the shell. */
.app-shell * {
    scrollbar-width: thin;
}

/* ---------- Sidebar ---------- */
.app-shell .sidebar {
    flex: 0 0 260px;
    width: 260px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    min-height: 0;
}

.app-shell .sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 4px;
}

.app-shell .brand {
    font-size: 1.05em;
    font-weight: 700;
    color: var(--text);
}

.app-shell .icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    line-height: 0;
}

.app-shell .icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.app-shell .new-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 10px;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    text-align: left;
    font-family: inherit;
}

.app-shell .new-chat:hover {
    background: rgba(255, 255, 255, 0.06);
}

.app-shell .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 10px 6px;
}

.app-shell .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.95em;
    text-align: left;
    font-family: inherit;
}

.app-shell .nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.app-shell .nav-item.active {
    background: rgba(255, 255, 255, 0.10);
}

.app-shell .nav-item svg {
    opacity: 0.85;
    flex: 0 0 auto;
}

.app-shell .sidebar-section {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 6px 10px 4px;
}

.app-shell .section-label {
    font-size: 0.72em;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    padding: 8px 10px 6px;
    font-weight: 600;
}

.app-shell .conv-items {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.app-shell .conv-item {
    position: relative;
    padding: 8px 30px 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text);
    margin-bottom: 0;
    font-size: 1em;
}

.app-shell .conv-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.app-shell .conv-item.active {
    background: rgba(255, 255, 255, 0.10);
    font-weight: 400;
}

.app-shell .conv-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    font-size: 0.9em;
}

.app-shell .conv-meta {
    display: none;
}

.app-shell .conv-empty {
    color: var(--text-faint);
    font-size: 0.85em;
    padding: 8px 10px;
}

.app-shell .conv-delete {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    padding: 2px 6px;
    cursor: pointer;
    opacity: 0;
    border-radius: 6px;
    transition: opacity 0.15s;
}

.app-shell .conv-item:hover .conv-delete {
    opacity: 0.7;
}

.app-shell .conv-delete:hover {
    color: #f87171;
    opacity: 1;
    background: rgba(255, 255, 255, 0.06);
}

.app-shell .sidebar-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.app-shell .sidebar-foot .user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    flex: 0 0 auto;
}

.app-shell .foot-user {
    min-width: 0;
    flex: 1;
}

.app-shell .foot-name {
    font-size: 0.9em;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell .foot-sub {
    font-size: 0.75em;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell .sidebar-foot a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px;
    border-radius: 8px;
    line-height: 0;
    flex: 0 0 auto;
}

.app-shell .sidebar-foot a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.app-shell .sidebar-foot a.active {
    background: rgba(255, 255, 255, 0.10);
    color: var(--text);
}

/* ---------- Main column ---------- */
.app-shell .main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.app-shell .topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    min-height: 52px;
    color: var(--text-muted);
    font-size: 0.9em;
}

.app-shell .hamburger {
    display: none;
}

.app-shell .thread-area {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Welcome / empty state */
.app-shell .welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 26px;
    padding: 20px 24px 60px;
    text-align: center;
}

.app-shell .greeting {
    font-size: 2em;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.app-shell .suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 720px;
}

.app-shell .suggestion {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    font-family: inherit;
}

.app-shell .suggestion:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* ---------- Composer (single, moved between hosts) ---------- */
.app-shell .composer-host {
    width: 100%;
    display: flex;
    justify-content: center;
}

.app-shell .composer {
    width: 100%;
    max-width: 760px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 26px;
    padding: 8px 8px 8px 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.app-shell .composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.app-shell .composer:focus-within {
    border-color: #565869;
}

/* Attach button */
.app-shell .composer-attach {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-faint);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.app-shell .composer-attach:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

/* Pending-attachment preview strip */
.app-shell .composer-attachments {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 6px 0;
}

.app-shell .composer-attachments.has-items {
    display: flex;
}

.app-shell .attach-chip {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 220px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.82em;
    color: var(--text);
}

.app-shell .attach-chip .attach-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-shell .attach-chip a {
    display: flex;
    align-items: center;
    gap: 6px;
    color: inherit;
    text-decoration: none;
    overflow: hidden;
}

.app-shell .attach-chip-image {
    padding: 0;
    width: 64px;
    height: 64px;
    overflow: hidden;
}

.app-shell .attach-chip-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.app-shell .attach-remove {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: #343541;
    color: #ececf1;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.app-shell .attach-remove:hover {
    background: #4a4b57;
}

.app-shell .attach-error {
    width: 100%;
    color: #ff8a8a;
    font-size: 0.8em;
    padding: 2px 6px;
}

.app-shell .composer.composer-dragover {
    border-color: var(--accent, #10a37f);
    border-style: dashed;
}

/* Attachment chips shown on a sent chat turn */
.app-shell .turn-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
    justify-content: flex-end;
}

.app-shell .composer-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1em;
    outline: none;
    resize: none;
    padding: 9px 0;
    max-height: 200px;
    line-height: 1.5;
    font-family: inherit;
}

.app-shell .composer-input::placeholder {
    color: var(--text-faint);
}

.app-shell .composer-send {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--text);
    color: #171717;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
}

.app-shell .composer-send:hover {
    opacity: 0.85;
}

.app-shell .composer-send:disabled {
    opacity: 0.3;
    cursor: default;
}

.app-shell .composer-region {
    padding: 10px 24px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.app-shell .composer-region .composer-host,
.app-shell .welcome .composer-host {
    max-width: 760px;
}

.app-shell .composer-footnote {
    font-size: 0.75em;
    color: var(--text-faint);
}

/* State toggling: empty (centered) vs active (thread + bottom composer) */
.app-shell .main.state-empty .chat-thread,
.app-shell .main.state-empty .results-container,
.app-shell .main.state-empty .composer-region {
    display: none;
}

.app-shell .main.state-active .welcome {
    display: none;
}

/* ---------- Loading ---------- */
.app-shell .loading {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    padding: 4px 0 8px;
    flex-direction: row;
}

.app-shell .spinner {
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ---------- Chat thread & results shared width ---------- */
.app-shell .chat-thread,
.app-shell .results-container {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 20px 24px 32px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.app-shell .chat-thread {
    gap: 26px;
}

.app-shell .results-container {
    gap: 14px;
}

/* ---------- Chat turns (dark) ---------- */
.app-shell .chat-turn {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.app-shell .chat-question {
    align-self: flex-end;
    max-width: 85%;
    background: var(--surface);
    color: var(--text);
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: none;
    font-weight: 400;
}

.app-shell .answer-panel {
    background: transparent;
    border: none;
    border-left: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
    color: var(--text);
}

.app-shell .answer-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72em;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
}

.app-shell .answer-model {
    color: var(--text-faint);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.app-shell .answer-body {
    font-size: 1em;
    line-height: 1.7;
    color: var(--text);
}

.app-shell .answer-body p {
    margin: 0.6em 0;
}

.app-shell .answer-body ul,
.app-shell .answer-body ol {
    margin: 0.6em 0 0.6em 1.3em;
    padding: 0;
}

.app-shell .answer-body li {
    margin-bottom: 0.3em;
}

.app-shell .answer-body code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
}

.app-shell .answer-body pre {
    background: #1a1a1a;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.6em 0;
}

.app-shell .answer-body pre code {
    background: none;
    padding: 0;
}

.app-shell .answer-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.8em 0;
    font-size: 0.95em;
    display: block;
    overflow-x: auto;
}

.app-shell .answer-body th,
.app-shell .answer-body td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
}

.app-shell .answer-body thead th {
    background: rgba(255, 255, 255, 0.06);
    font-weight: 600;
}

.app-shell .answer-body tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.app-shell .answer-error {
    color: #fca5a5;
    background: rgba(248, 113, 113, 0.10);
    border: 1px solid rgba(248, 113, 113, 0.25);
    padding: 12px 14px;
    border-radius: 8px;
}

/* Recovery action inside an error (e.g. "Buy credits" when out of credits):
   an error the user can act on should not be a dead end. */
.app-shell .answer-error-action {
    color: #fecaca;
    font-weight: 600;
    text-decoration: underline;
    white-space: nowrap;
}

.app-shell .answer-error-action:hover {
    color: #fff;
}

.app-shell .thinking-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.app-shell .thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: thinking 1.2s infinite ease-in-out both;
}

.app-shell .thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.app-shell .thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Shared busy indicator (static/js/thinking.js): dots + label + elapsed clock. */
.thinking-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #9aa0aa;
    font-size: 0.9rem;
}

.app-shell .thinking-indicator { color: var(--text-muted); }

.thinking-indicator .thinking-label {
    animation: thinking-pulse 1.8s ease-in-out infinite;
}

.thinking-indicator .thinking-elapsed {
    font-variant-numeric: tabular-nums;
    opacity: 0.65;
}

.thinking-indicator .thinking-elapsed[hidden] { display: none; }

@keyframes thinking-pulse {
    0%, 100% { opacity: 0.65; }
    50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .thinking-dots span,
    .thinking-indicator .thinking-label { animation: none; }
}

.app-shell .cite-link {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
    padding: 0 1px;
}

.app-shell .cite-link:hover {
    text-decoration: underline;
}

.app-shell .web-link {
    color: var(--accent);
    font-weight: 500;
    text-decoration: none;
    border-bottom: 1px solid rgba(139, 155, 255, 0.35);
}

.app-shell .web-link:hover {
    border-bottom-color: currentColor;
}

.app-shell .web-link::after {
    content: "\2197";
    display: inline-block;
    margin-left: 2px;
    font-size: 0.85em;
    opacity: 0.7;
}

/* ---------- Sources / citations (dark) ---------- */
.app-shell .answer-sources {
    margin-top: 16px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

.app-shell .sources-header {
    font-size: 0.72em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    margin-bottom: 10px;
}

.app-shell .source-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.app-shell .citation-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 5px 10px 5px 8px;
    cursor: default;
    line-height: 1;
}

.app-shell .citation-chip:hover {
    background: var(--surface-hover);
    border-color: #4a4a4a;
}

.app-shell .chip-icon {
    font-size: 1.05em;
    line-height: 1;
}

.app-shell .chip-num {
    background: var(--accent-strong);
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72em;
    font-weight: 600;
}

.app-shell .citation-popover {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    top: auto;
    width: 260px;
    max-width: 80vw;
    background: #2a2a2a;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    padding: 12px 14px;
    z-index: 50;
    display: none;
    flex-direction: column;
    gap: 6px;
    cursor: auto;
}

.app-shell .citation-popover::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -8px;
    top: auto;
    height: 8px;
}

.app-shell .citation-chip:hover .citation-popover {
    display: flex;
}

.app-shell .citation-title {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.app-shell .citation-title:hover {
    color: var(--accent);
}

.app-shell .citation-sub {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 2px;
    font-size: 0.82em;
    color: var(--text-muted);
}

.app-shell .source-link {
    color: #4ade80;
    text-decoration: none;
    font-weight: 500;
}

.app-shell .source-link:hover {
    text-decoration: underline;
}

/* ---------- Search results (dark) ---------- */
.app-shell .results-header {
    color: var(--text-muted);
    font-size: 0.9em;
    margin-bottom: 6px;
}

.app-shell .result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 0;
    box-shadow: none;
    cursor: pointer;
    transition: background 0.15s;
}

.app-shell .result-card:hover {
    background: var(--surface-hover);
    transform: none;
    box-shadow: none;
}

.app-shell .result-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.app-shell a.result-title {
    text-decoration: none;
    color: var(--text);
}

.app-shell a.result-title:hover {
    color: var(--accent);
}

.app-shell .result-type {
    background: var(--accent-strong);
    color: #fff;
}

.app-shell .result-score {
    color: var(--text-faint);
}

.app-shell .result-metadata {
    color: var(--text-muted);
}

.app-shell .result-preview {
    color: var(--text-muted);
}

.app-shell .result-id {
    color: var(--text-faint);
    border-top: 1px solid var(--border);
}

/* ---------- Mobile sidebar ---------- */
.app-shell .sidebar-scrim {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

@media (max-width: 820px) {
    .app-shell .sidebar {
        position: absolute;
        z-index: 100;
        height: 100%;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .app-shell.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
    }

    .app-shell.sidebar-open .sidebar-scrim {
        display: block;
    }

    .app-shell .hamburger {
        display: inline-flex;
    }

    .app-shell .composer,
    .app-shell .chat-thread,
    .app-shell .results-container,
    .app-shell .welcome .composer-host,
    .app-shell .composer-region .composer-host {
        max-width: 100%;
    }

    /* Settings narrow-viewport overrides live with the settings block below,
       after the base rules they need to override. */
}

/* =====================================================================
   Settings page (dark, inside .app-shell)
   ===================================================================== */
.app-shell .topbar-title {
    font-weight: 600;
    color: var(--text);
    font-size: 1em;
}

.app-shell .topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-shell .topbar-share,
.app-shell .topbar-unshare {
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.82em;
    padding: 4px 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.app-shell .topbar-share:hover,
.app-shell .topbar-unshare:hover {
    color: var(--text);
    border-color: var(--accent);
}

.app-shell .topbar-unshare {
    border-color: transparent;
}

.app-shell .share-banner {
    flex-shrink: 0;
    margin: 8px 20px 0;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-muted);
    font-size: 0.88em;
}

.app-shell.share-view .composer-region,
.app-shell.share-view .welcome,
.app-shell.share-view .topbar-share,
.app-shell.share-view .topbar-unshare,
.app-shell.share-view .topbar-model {
    display: none !important;
}

.app-shell .topbar-model {
    margin-left: 0;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82em;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.app-shell .topbar-model::before {
    content: '🧠';
    margin-right: 5px;
}

.app-shell .topbar-model:hover {
    color: var(--text);
    border-color: var(--accent);
}

/* Running credit total for the open chat (topbar) + the per-answer chip that
   itemizes one turn's charge. Both speak only in credits -- never tokens. */
.app-shell .topbar-cost {
    color: var(--text-muted);
    font-size: 0.82em;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    white-space: nowrap;
}

.app-shell.share-view .topbar-cost {
    display: none !important;
}

.app-shell .answer-cost {
    margin-top: 12px;
}

.app-shell .cost-chip {
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-faint);
    font-size: 0.76em;
    font-family: inherit;
    padding: 3px 10px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.app-shell .cost-chip:disabled {
    cursor: default;
}

.app-shell .cost-chip:not(:disabled):hover,
.app-shell .cost-chip.open {
    color: var(--text);
    border-color: var(--accent);
}

.app-shell .cost-why {
    margin-left: 5px;
    opacity: 0.85;
}

.app-shell .cost-detail {
    margin-top: 8px;
    max-width: 340px;
    font-size: 0.78em;
    color: var(--text-muted);
}

.app-shell .cost-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 3px 0;
}

.app-shell .settings-view {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden; /* never let settings push the page sideways */
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 8px 24px 48px;
    box-sizing: border-box;
}

.app-shell .settings-intro {
    color: var(--text-muted);
    margin-bottom: 18px;
}

/* Section tabs — one row on wide viewports. All seven fit the 960px column
   with room to spare; overflow-x is a fallback for unusually wide font metrics
   only. Below 820px they wrap into a grid instead (see the media query below). */
.app-shell .settings-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    padding-bottom: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.app-shell .settings-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    white-space: nowrap;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    padding: 10px 12px;
    margin-bottom: -1px;
    cursor: pointer;
    font-size: 0.92em;
    font-weight: 500;
    font-family: inherit;
}

.app-shell .settings-tab:hover {
    color: var(--text);
}

.app-shell .settings-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.app-shell .tab-icon {
    font-size: 1.05em;
    opacity: 0.9;
}

/* Panels */
.app-shell .settings-panel {
    display: none;
}

.app-shell .settings-panel.active {
    display: block;
}

.app-shell .settings-section {
    margin-bottom: 28px;
}

.app-shell .settings-section > strong {
    display: block;
    color: var(--text);
    margin-bottom: 10px;
    font-size: 0.92em;
}

.app-shell .settings-section h3 {
    color: var(--text);
    margin-bottom: 14px;
    font-size: 1.05em;
    font-weight: 600;
}

.app-shell .settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
}

.app-shell .settings-item-info {
    flex: 1;
    min-width: 0;
}

.app-shell .settings-item-info strong {
    display: block;
    margin-bottom: 4px;
    color: var(--text);
    font-size: 0.95em;
}

.app-shell .settings-item-info p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9em;
    line-height: 1.5;
}

.app-shell .settings-item-info small {
    color: var(--text-faint);
}

.app-shell .settings-item-action {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

/* Model tab select (dark override of the light-theme .form-input default) */
.app-shell .settings-item-action select.form-input {
    width: auto;
    min-width: 260px;
    background: #1f1f1f;
    border: 2px solid var(--border, #3a3a3a);
    color: var(--text, #ececec);
}

.app-shell .settings-item-action select.form-input:focus {
    border-color: var(--accent, #8b9bff);
    box-shadow: 0 0 0 3px rgba(139, 155, 255, 0.15);
}

/* Forms inside the app shell (dark override of the light-theme form
   defaults, which are written for the white login/auth pages). Covers the
   company profile form, the permissions invite form, and anything else
   reusing .form-group/.form-input here. */
.app-shell .form-group label {
    color: var(--text);
}

.app-shell .form-input {
    background: #1f1f1f;
    border: 2px solid var(--border);
    color: var(--text);
}

.app-shell .form-input::placeholder {
    color: var(--text-faint);
}

.app-shell .form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(139, 155, 255, 0.15);
}

/* ---------------------------------------------------------------------
   Settings, narrow viewports.
   These must stay AFTER the base settings rules above: the selectors are
   the same specificity, so source order is what decides the winner.
   --------------------------------------------------------------------- */
@media (max-width: 820px) {
    .app-shell .settings-view {
        padding: 16px 20px 48px;
    }

    /* Wrap tabs onto as many rows as fit rather than scrolling them out of
       sight. Equal-width tracks keep the rows tidy instead of ragged. */
    .app-shell .settings-tabs {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
        gap: 2px 4px;
        /* Both axes must be visible: a lone `overflow-x: visible` against a
           non-visible overflow-y computes back to `auto` and re-adds the bar. */
        overflow-x: visible;
        overflow-y: visible;
    }

    .app-shell .settings-tab {
        justify-content: center;
    }

    /* Stack each row so the label keeps full width above its control */
    .app-shell .settings-item {
        flex-direction: column;
        align-items: stretch;
    }

    .app-shell .settings-item-action {
        width: 100%;
        flex-shrink: 1;
    }

    .app-shell .settings-item-action select.form-input {
        min-width: 0;
        width: 100%;
    }
}

.app-shell .mined-suggestions h4 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
}

.app-shell .mined-confidence {
    display: inline-block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    margin-left: 0.35rem;
    vertical-align: middle;
}

.app-shell .mined-confidence-high {
    background: rgba(72, 187, 120, 0.2);
    color: #68d391;
}

.app-shell .mined-confidence-medium {
    background: rgba(237, 137, 54, 0.2);
    color: #f6ad55;
}

.app-shell .mined-confidence-low {
    background: rgba(160, 174, 192, 0.2);
    color: #a0aec0;
}

.app-shell .mined-suggestion-row a {
    color: var(--accent, #8b9bff);
}

/* Permissions tab */
.app-shell .perm-scopes {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.app-shell .perm-scope-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85em;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.app-shell .perm-scope-toggle input[type="checkbox"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
}

.app-shell .perm-scope-toggle input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Badges */
.app-shell .badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 0.8em;
    font-weight: 600;
}

.app-shell .badge-success {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
}

.app-shell .badge-warning {
    background: rgba(250, 204, 21, 0.15);
    color: #facc15;
}

.app-shell .badge-inactive {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
}

/* Buttons */
.app-shell .btn-primary,
.app-shell .btn-secondary,
.app-shell .btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    /* Reset the legacy full-width .btn-primary (auth pages) so app-shell
       buttons size to their content and sit on one line. */
    width: auto;
    margin: 0;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    font-family: inherit;
    transition: opacity 0.15s, background 0.15s;
}

.app-shell .btn-primary {
    background: var(--text);
    color: #171717;
}

.app-shell .btn-primary:hover {
    opacity: 0.85;
}

.app-shell .btn-secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.app-shell .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.06);
}

.app-shell .btn-secondary:disabled {
    opacity: 0.4;
    cursor: default;
}

.app-shell .btn-danger {
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.3);
}

.app-shell .btn-danger:hover {
    background: rgba(248, 113, 113, 0.2);
}

.app-shell .text-muted {
    color: var(--text-faint);
    font-size: 0.8em;
}

/* Alerts (flash messages) */
.app-shell .alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9em;
    border: 1px solid transparent;
}

.app-shell .alert-success {
    background: rgba(74, 222, 128, 0.12);
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.25);
}

.app-shell .alert-error {
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.25);
}

.app-shell .alert-info {
    background: rgba(139, 155, 255, 0.12);
    color: var(--accent);
    border-color: rgba(139, 155, 255, 0.25);
}

.app-shell .alert-warning {
    background: rgba(250, 204, 21, 0.12);
    color: #facc15;
    border-color: rgba(250, 204, 21, 0.25);
}

/* =====================================================================
   Document detail page (dark, inside .app-shell)
   ===================================================================== */
.app-shell .topbar-back {
    margin-left: auto;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9em;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: color 0.15s, border-color 0.15s;
}

.app-shell .topbar-back:hover {
    color: var(--text);
    border-color: var(--accent);
}

.app-shell .doc-detail-view {
    flex: 1;
    overflow-y: auto;
    padding: 8px 24px 32px;
}

.app-shell .doc-detail {
    max-width: 860px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
}

.app-shell .doc-detail-title {
    color: var(--text);
}

.app-shell .doc-detail-fields {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
}

.app-shell .doc-detail-key {
    color: var(--text-muted);
}

.app-shell .doc-detail-value {
    color: var(--text);
}

.app-shell .doc-detail-value a {
    color: var(--accent);
}

.app-shell .doc-detail-content {
    color: var(--text);
}

@media (max-width: 768px) {
    .app-shell .doc-detail {
        padding: 20px;
    }
}

/* Modal (rendered outside .app-shell, so no CSS var inheritance — hard-coded dark colors) */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--surface, #2f2f2f);
    color: var(--text, #ececec);
    border: 1px solid var(--border, #3a3a3a);
    padding: 30px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
}

.modal-content h3 {
    margin-bottom: 15px;
    color: inherit;
}

.modal-content p {
    color: var(--text-muted, #9b9b9b);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal .form-input {
    background: #1f1f1f;
    border: 2px solid var(--border, #3a3a3a);
    color: var(--text, #ececec);
}

.modal .form-input:focus {
    border-color: var(--accent, #8b9bff);
    box-shadow: 0 0 0 3px rgba(139, 155, 255, 0.15);
}

.modal .btn-primary,
.modal .btn-secondary,
.modal .btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    font-family: inherit;
    transition: opacity 0.15s, background 0.15s;
}

.modal .btn-primary {
    background: #ececec;
    color: #171717;
}

.modal .btn-primary:hover {
    opacity: 0.85;
}

.modal .btn-secondary {
    background: transparent;
    color: #ececec;
    border-color: #3a3a3a;
}

.modal .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.06);
}

.modal .btn-danger {
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.3);
}

.modal .btn-danger:hover {
    background: rgba(248, 113, 113, 0.2);
}

/* Ask attach chooser (Slack-style) — modal is outside .app-shell */
.attach-modal-content {
    max-width: 440px;
    padding: 20px 22px 22px;
}

.attach-modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.attach-modal-header h3 {
    flex: 1;
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}

.attach-modal-close,
.attach-modal-back {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #9b9b9b;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.attach-modal-close:hover,
.attach-modal-back:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ececec;
}

.attach-chooser-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.attach-chooser-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #3a3a3a;
    background: #262626;
    color: #ececec;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}

.attach-chooser-item:hover {
    background: #303030;
    border-color: #4a4a4a;
}

.attach-chooser-icon {
    font-size: 1.25rem;
    line-height: 1.4;
}

.attach-chooser-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.attach-chooser-label {
    font-weight: 600;
    font-size: 0.95rem;
}

.attach-chooser-hint {
    font-size: 0.8rem;
    color: #9b9b9b;
    line-height: 1.35;
}

.attach-field-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #9b9b9b;
    margin: 4px 0 6px;
}

.attach-optional {
    font-weight: 400;
    opacity: 0.8;
}

.attach-field {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 12px;
}

.attach-snippet-area {
    min-height: 140px;
    resize: vertical;
    font-family: inherit;
}

.attach-field-error {
    color: #fca5a5;
    font-size: 0.85rem;
    margin: -4px 0 12px;
}

.attach-docs-section {
    margin-bottom: 14px;
}

.attach-docs-section-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #9b9b9b;
    margin-bottom: 8px;
}

.attach-docs-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}

.attach-docs-chip {
    flex: 0 0 auto;
    max-width: 180px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid #3a3a3a;
    background: #262626;
    color: #ececec;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attach-docs-chip:hover {
    background: #303030;
    border-color: #4a4a4a;
}

.attach-docs-results {
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.attach-docs-result {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #3a3a3a;
    background: #262626;
    color: #ececec;
    font-family: inherit;
    cursor: pointer;
}

.attach-docs-result:hover {
    background: #303030;
}

.attach-docs-result-title {
    font-size: 0.9rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attach-docs-result-meta {
    font-size: 0.75rem;
    color: #9b9b9b;
    margin-top: 2px;
}

.attach-docs-empty {
    font-size: 0.85rem;
    color: #9b9b9b;
    padding: 8px 0;
}

.app-shell .attach-chip .attach-icon {
    flex: 0 0 auto;
}

/* end attach modal */

.code-input {
    text-align: center;
    font-size: 1.5em;
    letter-spacing: 0.5em;
    font-family: 'Courier New', monospace;
}

/* Toast notifications */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 320px;
}

.toast {
    padding: 12px 18px;
    border-radius: 8px;
    color: white;
    font-size: 0.9em;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    background: #22c55e;
}

.toast-error {
    background: #ef4444;
}

/* ==========================================================================
   Image lightbox — appended to <body> (sibling of .app-shell), so it cannot
   inherit the app-shell CSS custom properties; use hard-coded dark values.
   ========================================================================== */
.img-lightbox {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 32px;
}

.img-lightbox.open {
    display: flex;
}

.img-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    cursor: zoom-out;
}

.img-lightbox-body {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    max-width: 100%;
    max-height: 100%;
}

.img-lightbox-img {
    max-width: min(1100px, 92vw);
    max-height: 82vh;
    border-radius: 10px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
    object-fit: contain;
}

.img-lightbox-actions {
    display: flex;
    gap: 8px;
}

.img-lightbox-btn {
    background: #2a2a2e;
    color: #f5f5f5;
    border: 1px solid #3a3a3e;
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}

.img-lightbox-btn:hover {
    background: #3a3a3e;
}

.img-lightbox-close {
    padding: 7px 12px;
    font-weight: 600;
}

/* ==========================================================================
   Image search: chat thumbnails + /images upload/search page
   Scoped under .app-shell (dark theme). Uses the same --surface/--border/etc.
   custom properties declared on .app-shell.
   ========================================================================== */

/* Inline image thumbnails inside a chat answer (from the search_images tool). */
.app-shell .answer-body img {
    max-width: 260px;
    max-height: 200px;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin: 8px 8px 4px 0;
    vertical-align: top;
    object-fit: cover;
    cursor: zoom-in;
}

.app-shell .attach-chip-image img {
    cursor: zoom-in;
}

.app-shell .media-view {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    padding: 24px 20px 60px;
    box-sizing: border-box;
}

.app-shell .upload-zone {
    border: 2px dashed var(--border);
    border-radius: 14px;
    padding: 32px 20px;
    text-align: center;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.app-shell .upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(102, 126, 234, 0.08);
}

.app-shell .upload-zone svg {
    color: var(--accent);
    opacity: 0.85;
}

.app-shell .upload-hint {
    margin: 12px 0 10px;
    color: var(--text);
}

.app-shell .upload-btn {
    display: inline-block;
    cursor: pointer;
}

.app-shell .upload-sub {
    margin-top: 14px;
    color: var(--text-muted, #9aa0aa);
}

.app-shell .upload-status {
    margin-top: 12px;
    font-size: 0.9em;
    color: var(--accent);
    min-height: 1.2em;
}

.app-shell .media-search {
    display: flex;
    gap: 10px;
    margin: 22px 0 18px;
}

.app-shell .media-query-input {
    flex: 1;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.95em;
    outline: none;
}

.app-shell .media-query-input:focus {
    border-color: var(--accent);
}

/* Documents page: browse/search results reuse the .result-card rules. */
.app-shell .doc-results {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* View switcher (Explorer-style: icons / tiles / list / details / cards) */
.app-shell .doc-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin: 0 0 10px;
}

.app-shell .view-switcher {
    display: flex;
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
}

.app-shell .view-switcher button {
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    padding: 5px 7px;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.app-shell .view-switcher button:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.app-shell .view-switcher button.active {
    color: var(--accent);
    background: var(--bg);
}

/* Icons view: thumbnail-style grid of large type icons */
.app-shell .doc-grid-icons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
}

.app-shell .doc-icon-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px 10px;
    border-radius: 10px;
    text-align: center;
    text-decoration: none;
    color: var(--text);
}

.app-shell .doc-icon-cell:hover {
    background: var(--surface-hover);
}

.app-shell .doc-icon-glyph {
    font-size: 34px;
    line-height: 1;
}

.app-shell .doc-icon-title {
    font-size: 0.78em;
    line-height: 1.25;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Tiles view: medium grid, icon + name + type/source */
.app-shell .doc-grid-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 10px;
}

.app-shell .doc-tile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text);
    min-width: 0;
}

.app-shell .doc-tile:hover {
    border-color: var(--accent);
}

.app-shell .doc-tile-glyph {
    font-size: 24px;
    flex-shrink: 0;
}

.app-shell .doc-tile-text {
    min-width: 0;
}

.app-shell .doc-tile-title {
    font-size: 0.88em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell .doc-tile-sub {
    font-size: 0.74em;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* List view: one compact row per document */
.app-shell .doc-list {
    display: flex;
    flex-direction: column;
}

.app-shell .doc-list-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 8px;
    border-radius: 7px;
    text-decoration: none;
    color: var(--text);
    min-width: 0;
}

.app-shell .doc-list-row:hover {
    background: var(--surface-hover);
}

.app-shell .doc-list-title {
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell .doc-list-type {
    font-size: 0.74em;
    color: var(--text-faint);
    flex-shrink: 0;
}

/* Details view: table */
.app-shell .doc-table-wrap {
    overflow-x: auto;
}

.app-shell .doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.87em;
}

.app-shell .doc-table th {
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.82em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.app-shell .doc-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    max-width: 340px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell .doc-table tbody tr:hover {
    background: var(--surface-hover);
}

.app-shell .doc-table a.result-title {
    font-size: 1em;
}

/* =====================================================================
   Insights dashboard (docs/plans/insights_dashboard.plan.md, M3+M4+M5).
   Page: templates/insights.html. Controller: static/js/insights.js.
   Chart primitives: static/js/insights_charts.js (statTile/barsH/barsV/
   agingBar) -- the class names below marked "required by insights_charts.js"
   are referenced directly from that file's JSDoc contract, not just from
   insights.js, so don't rename them without checking there too.
   ===================================================================== */

.app-shell .insights-view {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    box-sizing: border-box;
}

/* Split from .insights-view: the view is the full-width scroll container
   (so its scrollbar hugs the window/main-column edge, not a centered
   column), and this inner wrapper centers the content within it. */
.app-shell .insights-inner {
    max-width: 1180px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
    padding: 24px 20px 60px;
}

/* ---- Freshness strip (always first) ---- */
.app-shell .insights-freshness {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 18px;
}

.app-shell .insights-freshness-text {
    color: var(--text);
    font-size: 0.92em;
    flex: 1 1 auto;
    min-width: 180px;
}

.app-shell .insights-freshness-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.app-shell .insights-provider-chip {
    display: inline-block;
    font-size: 0.78em;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
    text-decoration: none;
}

.app-shell .insights-provider-chip-warn {
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.4);
}

.app-shell .insights-refresh-btn {
    flex-shrink: 0;
}

.app-shell .insights-freshness-thinking {
    font-size: 0.8em;
    color: var(--text-muted);
}

/* ---- Welcome / connect state (both providers not_connected) ---- */
.app-shell .insights-welcome {
    margin-bottom: 22px;
}

.app-shell .insights-welcome h2 {
    font-size: 1.15em;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 12px;
}

.app-shell .insights-welcome-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.app-shell .insights-connect-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    text-decoration: none;
    color: var(--text);
}

.app-shell .insights-connect-card:hover {
    border-color: var(--accent);
}

.app-shell .insights-connect-card-title {
    font-weight: 600;
    margin-bottom: 6px;
}

.app-shell .insights-connect-card-body {
    color: var(--text-muted);
    font-size: 0.86em;
}

/* ---- Card grid ---- */
.app-shell .insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.app-shell .insight-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.app-shell .insight-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-shell .insight-card-title {
    font-size: 1em;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.app-shell .insight-card-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    /* A wide table belongs in its own .doc-table-wrap rather than making
       the card body itself a scroll container. */
}

.app-shell .insight-card-message {
    color: var(--text-muted);
    font-size: 0.9em;
}

.app-shell .insight-card-note {
    color: var(--text-faint);
    font-size: 0.78em;
}

.app-shell .insight-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: auto;
    flex-wrap: wrap;
}

.app-shell .insight-card-asof {
    font-size: 0.74em;
    color: var(--text-faint);
}

/* Drill-down: the whole button is the hit target (>=44px tall including
   padding), never a bare bar/segment -- accessibility criteria in the plan. */
.app-shell .insight-card-ask {
    background: none;
    border: 1px solid var(--border);
    color: var(--accent);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.82em;
    font: inherit;
    cursor: pointer;
    min-height: 44px;
}

.app-shell .insight-card-ask:hover {
    border-color: var(--accent);
    background: var(--surface-hover);
}

.app-shell .insights-locked-card {
    text-align: left;
}

/* ---- Chart-support classes (required by insights_charts.js) ---- */
.app-shell .insights-chart {
    display: block;
    width: 100%;
}

.app-shell .insights-stat-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.app-shell .insights-stat-label {
    font-size: 0.85em;
    color: var(--text-muted);
}

.app-shell .insights-stat-value-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
}

.app-shell .insights-stat-value {
    font-size: 1.6em;
    font-weight: 700;
    color: var(--text);
}

.app-shell .insights-stat-caption {
    font-size: 0.82em;
    color: var(--text-faint);
}

/* Small status/flag chip -- text IS the signal, color only reinforces it.
   Used both inside chart specs (statTile's flagLabel) and by hand-built
   widgets (todo due tags, "worth a follow-up?"). */
.app-shell .insights-tag {
    display: inline-block;
    font-size: 0.72em;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    white-space: nowrap;
}

.app-shell .insights-tag-serious {
    background: rgba(248, 113, 113, 0.14);
    color: #fca5a5;
}

/* ---- Shared chart legend (a swatch + label pair; barsH's primary/costs
   key, reused as the per-entry wrapper -- agingBar's legend has its own
   per-segment item since its color/opacity is data-driven, not a fixed
   primary/secondary pair) ---- */
.app-shell .insights-chart-legend {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 6px;
    grid-column: 1 / -1;
}

.app-shell .insights-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78em;
    color: var(--text-muted);
}

.app-shell .insights-legend-swatch {
    display: inline-block;
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.app-shell .insights-legend-swatch-primary {
    background: var(--accent);
}

.app-shell .insights-legend-swatch-secondary {
    background: var(--text-muted);
}

/* ---- Horizontal paired bars (project_pl: billed vs. costs per job) ----
   The chart root IS this grid -- a flexible name/track column plus a
   max-content value column -- so every row's cells drop into place via
   ordinary grid auto-flow, no per-row wrapper needed. */
.app-shell .insights-hbar-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    column-gap: 8px;
    row-gap: 2px;
}

.app-shell .insights-hbar-head {
    grid-column: 1 / -1;
    margin-top: 10px;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.app-shell .insights-hbar-name {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-shell .insights-hbar-direct {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.app-shell .insights-hbar-direct-flagged {
    color: #fca5a5;
}

.app-shell .insights-hbar-track {
    height: 10px;
    align-self: center;
    min-width: 0;
}

.app-shell .insights-hbar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
}

.app-shell .insights-hbar-fill-secondary {
    background: var(--text-muted);
}

.app-shell .insights-hbar-value {
    font-size: 0.78em;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    align-self: center;
    white-space: nowrap;
}

.app-shell .insights-hbar-value-secondary {
    color: var(--text-muted);
}

/* ---- Vertical bars (monthly_billed) ---- */
.app-shell .insights-bars-v {
    display: block;
}

.app-shell .insights-vbar-plot {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 120px;
    /* Headroom for the tallest bar's value cap: bars size against the
       content box (below this padding) and the cap overflows upward into
       it, staying inside the plot instead of above the chart. */
    padding-top: 16px;
    border-bottom: 1px solid var(--border);
}

.app-shell .insights-vbar-col {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
}

.app-shell .insights-vbar-cap {
    font-size: 0.62em;
    color: var(--text);
    white-space: nowrap;
}

.app-shell .insights-vbar-bar {
    width: 100%;
    max-width: 22px;
    background: var(--accent);
    border-radius: 4px 4px 0 0;
}

.app-shell .insights-vbar-bar-dim {
    background: var(--text-muted);
}

.app-shell .insights-vbar-labels {
    display: flex;
    gap: 2px;
    margin-top: 6px;
}

.app-shell .insights-vbar-label-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.app-shell .insights-vbar-label {
    font-size: 0.66em;
    color: var(--text-muted);
}

.app-shell .insights-vbar-suffix {
    font-size: 0.6em;
    font-style: italic;
    color: var(--text-muted);
}

/* ---- Aging stacked bar (ar_summary) ---- */
.app-shell .insights-aging-bar {
    display: block;
}

.app-shell .insights-aging-total {
    font-size: 1.1em;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.app-shell .insights-aging-stack {
    display: flex;
    height: 18px;
    gap: 2px;
    border-radius: 4px;
    overflow: hidden;
}

.app-shell .insights-aging-seg {
    background: var(--accent);
}

.app-shell .insights-aging-seg-flagged {
    background: #fca5a5;
    opacity: 1;
}

.app-shell .insights-aging-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 4px 12px;
    margin-top: 8px;
}

.app-shell .insights-aging-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78em;
    color: var(--text-muted);
}

.app-shell .insights-aging-legend-item-flagged {
    color: #fca5a5;
}

/* ---- Stat chips (todos_digest: Overdue / Due this week) ---- */
.app-shell .insights-chip-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.app-shell .insights-stat-chip {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    min-width: 100px;
}

.app-shell .insights-stat-chip-value {
    font-size: 1.3em;
    font-weight: 700;
    color: var(--text);
}

.app-shell .insights-stat-chip-label {
    font-size: 0.76em;
    color: var(--text-muted);
}

.app-shell .insights-stat-chip-flagged .insights-stat-chip-value {
    color: #fca5a5;
}

/* ---- To-do groups (todos_digest) ---- */
.app-shell .insights-todo-groups {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.app-shell .insights-todo-group-title {
    font-size: 0.82em;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.app-shell .insights-todo-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.app-shell .insights-todo-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.86em;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

.app-shell .insights-todo-list li a {
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-shell .insights-todo-list li a:hover {
    color: var(--accent);
}

/* ---- Top lists (ap_summary / open_estimates) ---- */
.app-shell .insights-top-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app-shell .insights-top-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.87em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

.app-shell .insights-top-name {
    color: var(--text);
    flex: 1 1 auto;
    min-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-shell .insights-top-amount {
    color: var(--text);
    font-weight: 600;
}

.app-shell .insights-top-sub {
    color: var(--text-faint);
    font-size: 0.85em;
    width: 100%;
}

/* ---- Needs-attention callouts (reuses .wf-status-pill colors) ---- */
.app-shell .insights-callout-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-shell .insights-callout-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.app-shell .insights-callout-text {
    color: var(--text);
    font-size: 0.88em;
}

@media (max-width: 820px) {
    .app-shell .insights-grid { grid-template-columns: 1fr; }
    .app-shell .insights-welcome-cards { grid-template-columns: 1fr; }
    .app-shell .insights-freshness { flex-direction: column; align-items: stretch; }
}

.app-shell .image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}

.app-shell .image-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.app-shell .image-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
    background: #1a1a1a;
}

.app-shell .image-card-meta {
    padding: 10px 12px;
}

.app-shell .image-card-title {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell .image-card-score {
    margin-top: 4px;
    font-size: 0.8em;
    color: var(--text-muted, #9aa0aa);
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

/* =========================================================================
   Workflows page (templates/workflows.html) — scoped under .app-shell so it
   inherits --surface/--border/--text/--accent. The publish modal is a
   sibling of .app-shell and uses the shared .modal hard-coded dark styles.
   ========================================================================= */

.app-shell .workflows-view {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

.app-shell .wf-empty {
    text-align: center;
    color: var(--text-muted, #9aa0aa);
    padding: 60px 20px;
}

.app-shell .wf-empty-sub {
    font-size: 0.9em;
    max-width: 480px;
    margin: 10px auto 18px;
}

.app-shell .wf-muted { color: var(--text-muted, #9aa0aa); font-size: 0.85em; }

/* ---- list ---- */
.app-shell .wf-list-head {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

/* Archived workflows are read-only history: dimmed until hovered. */
.app-shell .wf-card-archived { opacity: 0.6; }
.app-shell .wf-card-archived:hover { opacity: 1; }

.app-shell .wf-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.app-shell .wf-card:hover { border-color: var(--accent, #8b9bff); }

.app-shell .wf-card-name { font-weight: 600; margin-bottom: 6px; }

.app-shell .wf-card-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.app-shell .wf-card-actions { display: flex; gap: 8px; flex-shrink: 0; }

.app-shell .wf-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8em;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-muted, #9aa0aa);
    background: transparent;
}

.app-shell .wf-status-pill {
    font-size: 0.75em;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted, #9aa0aa);
}

.app-shell .wf-status-active,
.app-shell .wf-status-succeeded { background: rgba(74, 222, 128, 0.12); color: #86efac; }
.app-shell .wf-status-running,
.app-shell .wf-status-queued { background: rgba(139, 155, 255, 0.14); color: #b3befe; }
.app-shell .wf-status-failed,
.app-shell .wf-status-halted_drift,
.app-shell .wf-status-timed_out { background: rgba(248, 113, 113, 0.12); color: #fca5a5; }
.app-shell .wf-status-paused,
.app-shell .wf-status-cancelled,
.app-shell .wf-status-draft { background: rgba(250, 204, 21, 0.10); color: #fde68a; }

/* ---- builder split ---- */
.app-shell .wf-builder-split {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(300px, 420px);
    gap: 18px;
    height: calc(100vh - 140px);
}

.app-shell .wf-chat-pane {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.app-shell .wf-chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.app-shell .wf-msg {
    max-width: 92%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.92em;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.app-shell .wf-msg-user {
    align-self: flex-end;
    background: rgba(139, 155, 255, 0.15);
}

.app-shell .wf-msg-assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.04);
}

/* The pending bubble holds .thinking-indicator, which does its own dimming. */
.app-shell .wf-msg-pending { opacity: 1; }

.app-shell .wf-msg code { font-size: 0.9em; }

.app-shell .wf-question-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 0 16px;
}

/* Sits inside the flex-wrap chip row above, so it needs to claim its own
   full-width line rather than sitting inline with the first chip. */
.app-shell .wf-question-text {
    flex: 0 0 100%;
    font-size: 0.85em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.app-shell .wf-chip-option {
    cursor: pointer;
    background: rgba(139, 155, 255, 0.10);
    color: var(--text);
    border-color: rgba(139, 155, 255, 0.35);
}

.app-shell .wf-chip-option:hover { background: rgba(139, 155, 255, 0.2); }

.app-shell .wf-composer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.app-shell .wf-composer textarea {
    flex: 1;
    resize: none;
    background: #1f1f1f;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.92em;
}

.app-shell .wf-composer textarea:focus {
    outline: none;
    border-color: var(--accent, #8b9bff);
}

/* ---- preview pane ---- */
.app-shell .wf-preview-pane {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    overflow-y: auto;
}

.app-shell .wf-preview-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.app-shell .btn-link {
    background: none;
    border: none;
    color: var(--accent, #8b9bff);
    cursor: pointer;
    font-size: 0.85em;
    padding: 0;
    font-family: inherit;
}

.app-shell .btn-link:hover { text-decoration: underline; }

.app-shell #wf-json-editor {
    width: 100%;
    min-height: 260px;
    background: #1f1f1f;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: ui-monospace, monospace;
    font-size: 0.8em;
    padding: 10px;
    margin-bottom: 8px;
}

.app-shell .wf-errors {
    border: 1px solid rgba(248, 113, 113, 0.35);
    background: rgba(248, 113, 113, 0.08);
    color: #fca5a5;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.85em;
}

.app-shell .wf-builder-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.app-shell .wf-run-status { font-size: 0.85em; color: var(--text-muted, #9aa0aa); }

/* ---- DAG ---- */
.app-shell .wf-dag { overflow-y: auto; }

.app-shell .wf-dag-empty {
    color: var(--text-muted, #9aa0aa);
    font-size: 0.9em;
    padding: 30px 10px;
    text-align: center;
}

.app-shell .wf-dag-flow {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.app-shell .wf-dag-connector {
    display: flex;
    justify-content: center;
    color: var(--text-muted, #9aa0aa);
}

/* Trigger header above the first step (workflow_dag.js): how the workflow
   starts, phrased by workflow_phrasing.triggerLabel -- never a raw cron
   expression. */
.app-shell .wf-dag-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    align-self: center;
    border: 1px dashed var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 0.85em;
    color: var(--text-muted, #9aa0aa);
    background: rgba(255, 255, 255, 0.02);
}

.app-shell .wf-dag-trigger-icon { line-height: 1; }

.app-shell .wf-node {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
}

.app-shell .wf-node-succeeded { border-color: rgba(74, 222, 128, 0.5); }
.app-shell .wf-node-running { border-color: var(--accent, #8b9bff); }
.app-shell .wf-node-failed { border-color: rgba(248, 113, 113, 0.6); }
.app-shell .wf-node-skipped { opacity: 0.55; }

.app-shell .wf-node-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted, #9aa0aa);
}

.app-shell .wf-node-status { margin-left: auto; font-weight: 700; }

.app-shell .wf-node-title { font-weight: 600; margin-top: 3px; }

/* Plain-English step description (workflow_phrasing.js) -- prose, not code:
   deliberately NOT monospace, and it wraps rather than clipping. */
.app-shell .wf-node-sub {
    font-size: 0.86em;
    line-height: 1.45;
    margin-top: 2px;
    color: var(--text-muted, #9aa0aa);
    overflow-wrap: anywhere;
}

.app-shell .wf-node-stats { font-size: 0.8em; color: var(--text-muted, #9aa0aa); margin-top: 4px; }

.app-shell .wf-node-error {
    font-size: 0.8em;
    color: #fca5a5;
    margin-top: 4px;
    overflow-wrap: anywhere;
}

/* ---- run detail ---- */
.app-shell .wf-run-head {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    margin-bottom: 14px;
}

.app-shell .wf-run-split {
    display: grid;
    grid-template-columns: minmax(260px, 360px) 1fr;
    gap: 18px;
}

.app-shell .wf-detail-label {
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #9aa0aa);
    margin: 14px 0 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-shell .wf-step {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 6px;
    font-size: 0.9em;
}

.app-shell .wf-step-name { font-weight: 600; }

.app-shell .wf-step details { width: 100%; }

.app-shell .wf-step pre {
    font-size: 0.78em;
    overflow-x: auto;
    background: #1f1f1f;
    border-radius: 6px;
    padding: 8px;
    margin-top: 6px;
}

.app-shell #wf-created-list li,
.app-shell .wf-dlq-row {
    font-size: 0.9em;
    margin-bottom: 4px;
}

.app-shell #wf-created-list { list-style: none; padding-left: 0; }

.app-shell #wf-created-list a { color: var(--accent, #8b9bff); }

/* ---- publish modal extras (sibling of .app-shell: hard-coded colors) ---- */
.wf-publish-modal-content { max-width: 480px; }

.wf-publish-modal-content .wf-detail-label {
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9b9b9b;
    margin: 14px 0 6px;
}

.wf-publish-modal-content .wf-detail-label.wf-warn { color: #fde68a; }

.wf-publish-modal-content ul { padding-left: 18px; color: #ececec; font-size: 0.9em; }

.wf-publish-modal-content code { color: #b3befe; }

.wf-publish-confirm-label {
    display: block;
    margin: 16px 0 6px;
    font-size: 0.9em;
    color: #ececec;
}

#wf-publish-name {
    width: 100%;
    background: #1f1f1f;
    border: 2px solid #3a3a3a;
    border-radius: 8px;
    color: #ececec;
    padding: 8px 12px;
    font-family: inherit;
}

#wf-publish-name:focus { outline: none; border-color: #8b9bff; }

#wf-publish-error { margin-top: 12px; color: #fca5a5; font-size: 0.85em; }

.wf-empty-sub { color: #9b9b9b; }

@media (max-width: 900px) {
    .app-shell .wf-builder-split { grid-template-columns: 1fr; height: auto; }
    .app-shell .wf-run-split { grid-template-columns: 1fr; }
    .app-shell .wf-chat-pane { min-height: 50vh; }
}

/* The workflows page toggles visibility via the `hidden` attribute; make it
   win over any display rule (buttons are inline-flex, .modal is flex). */
.app-shell [hidden],
.modal[hidden] {
    display: none !important;
}

/* =========================================================================
   Walkthrough (docs/plans/walkthrough_discovery_interview.plan.md): a single
   two-pane view, chat thread on the left/top + "What we've picked up" on the
   right/below. Bubbles and the composer reuse .wf-msg/.wf-msg-user/
   .wf-msg-assistant/.wf-composer above rather than duplicating them.
   ========================================================================= */

.app-shell .walkthrough-view {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

.app-shell .walkthrough-split {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(280px, 380px);
    gap: 18px;
    height: calc(100vh - 140px);
}

.app-shell .walkthrough-chat-pane {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.app-shell .walkthrough-side-pane {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    overflow-y: auto;
}

.app-shell .wt-side-head {
    font-weight: 600;
}

/* ---- coverage meter ---- */
.app-shell .wt-meter {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app-shell .wt-meter-track {
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.app-shell .wt-meter-fill {
    height: 100%;
    width: 0%;
    background: var(--accent, #8b9bff);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.app-shell .wt-meter-label {
    font-size: 0.8em;
    color: var(--text-muted, #9aa0aa);
}

/* ---- discoveries ---- */
.app-shell .wt-discoveries {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.app-shell .wt-group {
    margin-bottom: 10px;
}

.app-shell .wt-group-label {
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted, #9aa0aa);
    margin: 10px 0 6px;
}

.app-shell .wt-discovery {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    font-size: 0.87em;
    line-height: 1.4;
}

.app-shell .wt-discovery-text {
    flex: 1;
}

.app-shell .wt-discovery-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.app-shell .wt-discovery-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted, #9aa0aa);
    cursor: pointer;
    width: 24px;
    height: 24px;
    line-height: 1;
    font-size: 0.85em;
}

.app-shell .wt-discovery-btn.wt-confirm:hover {
    color: #86efac;
    border-color: rgba(74, 222, 128, 0.4);
}

.app-shell .wt-discovery-btn.wt-dismiss:hover {
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.4);
}

/* ---- composer additions (Skip sits between the textarea and Send) ---- */
.app-shell .walkthrough-chat-pane .wf-composer {
    align-items: flex-end;
}

@media (max-width: 820px) {
    .app-shell .walkthrough-split { grid-template-columns: 1fr; height: auto; }
    .app-shell .walkthrough-chat-pane { min-height: 50vh; }
}

/* ===== Write approval card (app-shell chat) =====
   Shown when the assistant proposes a write. The write only happens when the
   user clicks Confirm here -- the assistant cannot approve its own proposal,
   so this card is the human-in-the-loop step, not a decoration. */
.app-shell .approval-card {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    background: var(--surface);
    padding: 16px 18px;
    margin: 14px 0;
    color: var(--text);
}

.app-shell .approval-title {
    font-weight: 600;
    font-size: 0.98em;
    margin-bottom: 12px;
}

.app-shell .approval-fields {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.app-shell .approval-row {
    display: flex;
    gap: 12px;
    align-items: baseline;
    font-size: 0.92em;
}

.app-shell .approval-key {
    flex: 0 0 34%;
    max-width: 190px;
    color: var(--text-muted);
}

.app-shell .approval-val {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

.app-shell .approval-actions {
    display: flex;
    gap: 10px;
}

.app-shell .approval-actions button {
    font: inherit;
    font-size: 0.9em;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid var(--border);
}

.app-shell .approval-actions .btn-approve {
    background: var(--accent);
    border-color: var(--accent);
    color: #1a1a1a;
}

.app-shell .approval-actions .btn-decline {
    background: transparent;
    color: var(--text-muted);
}

.app-shell .approval-actions button:disabled {
    opacity: 0.55;
    cursor: default;
}

.app-shell .approval-status {
    margin-top: 10px;
    font-size: 0.88em;
    color: var(--text-muted);
}

.app-shell .approval-done {
    margin: 14px 0;
    padding: 10px 14px;
    border-left: 3px solid var(--border);
    color: var(--text-muted);
    font-size: 0.92em;
}

@media (max-width: 640px) {
    .app-shell .approval-row {
        flex-direction: column;
        gap: 2px;
    }

    .app-shell .approval-key {
        flex-basis: auto;
        max-width: none;
    }
}
