/* ===== DESIGN TOKENS ===== */
:root {
    --primary: #1a3c6e;
    --primary-dark: #0f2847;
    --primary-rgb: 26, 60, 110;
    --accent: #e87722;
    --accent-rgb: 232, 119, 34;
    --bg: #ffffff;
    --card-bg: #ffffff;
    --border: #dce1e8;
    --text: #1e293b;
    --text-muted: #5a6577;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    --radius: 16px;
    --radius-sm: 10px;
    --transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

#appLayout {
    display: flex;
    min-height: 100vh;
}

.left-panel {
    width: 300px;
    background: #f8fafc;
    border-right: 1px solid var(--border);
    padding: 1rem;
    position: sticky;
    top: 0;
    max-height: 100vh;
    overflow-y: auto;
    transition: width 0.25s ease, padding 0.25s ease;
}

.left-panel.collapsed {
    width: 56px;
    padding: 1rem 0.45rem;
}

.left-panel.collapsed .panel-section,
.left-panel.collapsed .panel-header h3 {
    display: none;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.9rem;
}

.panel-header-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.panel-admin-btn {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    padding: 0.3rem 0.5rem;
    font-size: 0.72rem;
    cursor: pointer;
}

.panel-admin-btn.active {
    background: var(--text);
    color: #fff;
    border-color: var(--text);
}

.panel-header h3 {
    font-size: 0.95rem;
    color: var(--text);
}

.panel-collapse-btn {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    width: 28px;
    height: 28px;
    cursor: pointer;
}

.panel-section {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem;
    margin-bottom: 0.8rem;
}

.panel-section-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 0.6rem;
}

/* Model selector (admin panel) */
.model-selector-wrap {
    margin-bottom: 0.5rem;
}

.model-select-label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.model-select {
    width: 100%;
    padding: 0.42rem 0.55rem;
    font-size: 0.83rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    appearance: auto;
}

.model-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.domain-node {
    margin-bottom: 0.55rem;
}

.domain-btn,
.subdomain-btn,
.ingestion-node,
.panel-btn {
    width: 100%;
    text-align: left;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    padding: 0.42rem 0.55rem;
    font-size: 0.83rem;
    cursor: pointer;
    margin-bottom: 0.35rem;
}

.domain-btn.active,
.subdomain-btn.active,
.ingestion-node.active {
    border-color: var(--primary-dark);
    background: rgba(var(--primary-rgb), 0.12);
}

.subdomain-list {
    margin-left: 0.65rem;
}

.selection-summary {
    margin-top: 0.5rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.ingestion-children {
    margin-left: 0.65rem;
}

.panel-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
    margin-top: 0.4rem;
}

.panel-btn {
    text-align: center;
}

.panel-btn.primary {
    background: var(--text);
    color: #fff;
}

.ingestion-preview,
.ingestion-status {
    margin-top: 0.6rem;
    font-size: 0.78rem;
    color: var(--text);
}

.ingestion-error {
    color: #b91c1c;
    font-weight: 600;
}

.panel-empty {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* =============================================
   GOVT HEADER BAR
   ============================================= */
.govt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--card-bg);
    border-bottom: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    position: relative;
}

.govt-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--primary), var(--primary-dark));
}

.govt-header-left {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.govt-emblem {
    height: 66px;
    width: auto;
    object-fit: contain;
}

.govt-wordmark {
    height: 60px;
    width: auto;
    object-fit: contain;
}

.govt-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.govt-title {
    font-family: 'Outfit', 'Inter', system-ui, sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.5px;
}

.govt-dept {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* =============================================
   LANDING STATE
   ============================================= */
.landing-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    padding: 1rem 2rem 0.75rem;
    background: linear-gradient(180deg, #f0f4ff 0%, #f8fafc 40%, #ffffff 100%);
    transition: opacity var(--transition), transform var(--transition);
}

.landing-brand {
    text-align: center;
    margin: clamp(0.75rem, 3vh, 2rem) 0 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.landing-logo-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.shield-icon {
    flex-shrink: 0;
    object-fit: contain;
}

.landing-title {
    font-family: 'Outfit', 'Inter', system-ui, sans-serif;
    font-size: clamp(2.2rem, 5vw, 3.2rem);
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.landing-subtitle {
    font-size: 1.2rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.3px;
}

.landing-powered {
    font-size: 0.92rem;
    color: #2c3e50;
    font-style: italic;
    font-weight: 400;
    margin-top: 0.25rem;
    letter-spacing: 0.2px;
}

.powered-brand {
    font-weight: 700;
    font-size: 0.96rem;
    color: #1a3050;
    letter-spacing: 0.3px;
}

.landing-search {
    width: 100%;
    max-width: 860px;
    margin-bottom: 0.6rem;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    max-width: 860px;
    margin-bottom: 0.75rem;
}

.suggestion-chip {
    background: rgba(var(--primary-rgb), 0.08);
    color: var(--primary-dark);
    border: 1px solid rgba(var(--primary-rgb), 0.2);
    border-radius: 9999px;
    padding: 0.4rem 1rem;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.suggestion-chip:hover {
    background: rgba(var(--primary-rgb), 0.16);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.landing-footer {
    margin-top: auto;
    padding-top: 0.5rem;
    padding-bottom: 0.25rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.disclaimer-text {
    font-size: 0.78rem;
    color: var(--text-muted);
    max-width: 540px;
    margin: 0 auto 0.5rem;
    line-height: 1.5;
    font-style: italic;
}

.about-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
.about-link:hover {
    text-decoration: underline;
}

/* ── About Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal-card {
    background: var(--surface);
    border-radius: 1rem;
    padding: 2rem 2.25rem;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-card h2 {
    margin: 0 0 0.75rem;
    font-size: 1.25rem;
    color: var(--primary);
}
.modal-card h3 {
    margin: 1.25rem 0 0.5rem;
    font-size: 1rem;
    color: var(--text);
}
.modal-card p {
    line-height: 1.6;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.modal-card ul {
    padding-left: 1.25rem;
    margin: 0;
}
.modal-card li {
    margin-bottom: 0.6rem;
    line-height: 1.55;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.landing-settings-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
}

.landing-settings-wrapper {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.landing-settings-wrapper .landing-settings-btn {
    position: static;
}

.sticky-settings-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.model-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    opacity: 0.8;
    letter-spacing: 0.2px;
}

/* ===== TOKEN USAGE FOOTER ===== */
.token-usage {
    margin-top: 1rem;
    padding: 0.6rem 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    letter-spacing: 0.3px;
}


/* ===== SEARCH PILL (shared between landing & sticky) ===== */
.search-pill {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 0.35rem 0.35rem 0.35rem 0.25rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-pill:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15), var(--shadow-lg);
}

.domain-prefix {
    background: linear-gradient(135deg, rgba(var(--primary-rgb), 0.12), rgba(var(--primary-rgb), 0.06));
    border: none;
    color: var(--primary-dark);
    padding: 0.6rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    min-width: 110px;
    text-align: center;
}

.pill-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 0.25rem;
    flex-shrink: 0;
}

.query-input {
    flex: 1;
    display: block;
    border: 0 !important;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    padding: 0.65rem 0.75rem;
    font-size: 1rem;
    outline: none;
    min-width: 0;
    width: 100%;
    margin: 0;
    resize: none;
    overflow-y: hidden;
    line-height: 1.5;
    min-height: 44px;
    max-height: 160px;
    font-family: inherit;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none !important;
}

.query-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.search-pill button {
    background: var(--primary);
    color: white;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}

.search-pill button:hover {
    background: var(--primary-dark);
    transform: scale(1.08);
}

/* ===== MIC BUTTON ===== */
.mic-btn {
    background: transparent !important;
    color: var(--text-muted) !important;
    width: 36px !important;
    height: 36px !important;
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
    margin-right: -4px;
}

.mic-btn:hover {
    background: rgba(var(--primary-rgb), 0.08) !important;
    color: var(--primary-dark) !important;
    transform: none !important;
}

.mic-btn.listening {
    color: #dc2626 !important;
    background: rgba(220, 38, 38, 0.08) !important;
    animation: micPulse 1.5s ease-in-out infinite;
}

@keyframes micPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.3);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(220, 38, 38, 0);
    }
}

.search-pill.compact .mic-btn {
    width: 30px !important;
    height: 30px !important;
}

.search-pill.compact {
    padding: 0.2rem 0.2rem 0.2rem 0.15rem;
    box-shadow: var(--shadow);
}

.search-pill.compact .domain-prefix {
    padding: 0.45rem 0.7rem;
    font-size: 0.8rem;
    min-width: 90px;
}

.search-pill.compact .query-input {
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
    min-height: 36px;
    max-height: 120px;
}

.search-pill.compact button {
    width: 36px;
    height: 36px;
}

/* Clear button */
.clear-btn {
    width: 36px;
    height: 36px;
    background: rgba(239, 68, 68, 0.08);
    border: none;
    color: #ef4444;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
    line-height: 1;
}

.clear-btn:hover {
    color: #dc2626;
    background: rgba(239, 68, 68, 0.15);
}

/* =============================================
   STICKY HEADER (Results State)
   ============================================= */
.sticky-header {
    display: none;
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(248, 249, 251, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    animation: slideDown 0.35s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.sticky-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 80px;
}

.sticky-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.sticky-brand:hover {
    opacity: 0.7;
}

.sticky-shield {
    flex-shrink: 0;
    object-fit: contain;
}

.sticky-brand-text {
    font-family: 'Outfit', 'Inter', system-ui, sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.3px;
}

.sticky-emblem {
    height: 64px;
    width: auto;
    object-fit: contain;
}

.sticky-wordmark-img {
    height: 52px;
    width: auto;
    object-fit: contain;
}

.sticky-search {
    flex: 1;
    max-width: 860px;
}

.sticky-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--border);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.icon-btn:hover {
    background: #f1f5f9;
    transform: translateY(-1px);
}

/* =============================================
   RESULTS VIEW
   ============================================= */
.results-view {
    display: none;
    padding: 1.5rem;
    animation: fadeUp 0.4s ease;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-container {
    max-width: 860px;
    margin: 0 auto;
}

.results-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 2rem;
    box-shadow: var(--shadow-lg);
}

/* ===== RESULTS STATE TOGGLE ===== */
#app.results-mode .landing-view {
    display: none;
}

#app.results-mode .sticky-header {
    display: block;
}

#app.results-mode .results-view {
    display: block;
}

/* ===== RESPONSE / ANSWER AREA ===== */
.response-header {
    margin-bottom: 1.25rem;
}

.badge {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary-dark);
    padding: 0.35rem 0.9rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid rgba(var(--primary-rgb), 0.2);
}

.response-text {
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text);
    margin-bottom: 1.5rem;
}

.response-text strong,
.modal-body strong {
    font-weight: 700;
    color: var(--text);
}

.response-text p,
.modal-body p {
    margin-bottom: 0.85rem;
}

.response-text h1,
.response-text h2,
.response-text h3 {
    margin: 1.25rem 0 0.6rem 0;
    color: var(--primary-dark);
}

.response-text ul,
.response-text ol {
    margin-left: 1.5rem;
    margin-bottom: 0.85rem;
}

/* ===== REASONING BOX ===== */
.thought-container {
    background: rgba(var(--primary-rgb), 0.04);
    border-left: 4px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-bottom: 1.25rem;
    overflow: hidden;
    transition: all 0.3s ease;
}

.thought-header {
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-dark);
}

.thought-header:hover {
    background: rgba(var(--primary-rgb), 0.08);
}

.thought-content {
    padding: 14px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    border-top: 1px solid rgba(var(--primary-rgb), 0.1);
    background: white;
    line-height: 1.7;
    max-height: 400px;
    overflow-y: auto;
}

.thought-container.collapsed .thought-content {
    display: none;
}

.thought-header .toggle-icon {
    transition: transform 0.3s ease;
}

.thought-container.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

/* ===== SOURCES / CITATIONS ===== */

.citation-link {
    color: #2563eb;
    font-weight: 700;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: transparent;
    transition: text-decoration-color 0.15s;
}

.citation-link:hover {
    text-decoration-color: #2563eb;
}

.sources-wrapper {
    border-top: 1px solid var(--border);
    padding-top: 1.25rem;
}

.sources-wrapper h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.source-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.source-chip {
    background: #f8f9fb;
    border: 1px solid var(--border);
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    transition: all 0.2s;
    cursor: pointer;
    color: var(--text);
    line-height: 1.4;
    border-left: 4px solid var(--border);
}

/* Source type colour bands */
.source-chip.source-mcc         { border-left-color: #1a6b3c; background: #f0f9f4; }
.source-chip.source-compilation  { border-left-color: #2563eb; background: #eff4ff; }
.source-chip.source-compendium   { border-left-color: #9333ea; background: #f5f0ff; }
.source-chip.source-ceo          { border-left-color: #d97706; background: #fffbeb; }

.source-chip:hover {
    background: #edf0f4;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.source-id {
    font-weight: 800;
    margin-right: 0.4rem;
}

.source-id.source-mcc         { color: #1a6b3c; }
.source-id.source-compilation  { color: #2563eb; }
.source-id.source-compendium   { color: #9333ea; }
.source-id.source-ceo          { color: #d97706; }

/* Inline citation link colours per source type */
.citation-link.source-mcc         { color: #1a6b3c; }
.citation-link.source-compilation  { color: #2563eb; }
.citation-link.source-compendium   { color: #9333ea; }
.citation-link.source-ceo          { color: #d97706; }

/* Section heading colours per source type */
h3.heading-mcc         { color: #1a6b3c; }
h3.heading-compilation  { color: #2563eb; }
h3.heading-compendium   { color: #9333ea; }
h3.heading-ceo          { color: #d97706; }

/* ===== MODALS ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.modal-content.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    max-width: 800px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content.compact {
    max-width: 400px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.85rem;
}

.modal-header h2 {
    font-size: 1.3rem;
    color: var(--text);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--text);
}

.setting-item {
    margin-bottom: 1.25rem;
}

.left-panel .setting-item {
    margin-bottom: 0;
}

.setting-item label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.setting-item select {
    width: 100%;
    padding: 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    outline: none;
    background: #f8f9fb;
    font-size: 0.9rem;
}

.admin-secret-input {
    width: 100%;
    padding: 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    outline: none;
    background: #f8f9fb;
    font-size: 0.9rem;
}

.modal-body {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text);
}

/* ===== STATUS / LOADING ===== */
.status-msg {
    color: var(--primary-dark);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-msg::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 3px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}

/* ===== RESPONSIVE ===== */

/* Ensure no horizontal overflow at all widths */
#app {
    overflow-x: hidden;
    width: 100%;
}

/* --- Tablet and below (≤768px) --- */
@media (max-width: 768px) {
    #appLayout {
        flex-direction: column;
    }

    .left-panel {
        position: static;
        width: 100%;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .left-panel.collapsed {
        width: 100%;
        padding: 0.75rem;
    }

    .left-panel.collapsed .panel-section,
    .left-panel.collapsed .panel-header h3 {
        display: block;
    }

    .landing-title {
        font-size: 2rem;
    }

    .shield-icon {
        width: 48px;
        height: 48px;
    }

    .landing-search {
        padding: 0 0.5rem;
        max-width: 100%;
    }

    .landing-subtitle {
        font-size: 0.9rem;
    }

    /* Search pill: prevent overflow */
    .search-pill {
        max-width: 100%;
    }

    .domain-prefix {
        min-width: 90px;
        font-size: 0.8rem;
        padding: 0.5rem 0.65rem;
        flex-shrink: 0;
    }

    .query-input {
        min-width: 0;
        width: 100%;
        max-height: 140px;
    }

    /* Sticky header: compact layout */
    .sticky-inner {
        gap: 0.5rem;
        height: 56px;
        padding: 0;
    }

    .sticky-wordmark-img {
        display: none;
    }

    .sticky-emblem {
        height: 40px;
    }

    .sticky-search {
        max-width: none;
        min-width: 0;
        flex: 1;
    }

    .search-pill.compact .domain-prefix {
        min-width: 70px;
        font-size: 0.75rem;
        padding: 0.4rem 0.5rem;
    }

    .results-card {
        padding: 1.25rem;
    }

    .source-chips {
        grid-template-columns: 1fr;
    }

    /* Settings button in landing */
    .landing-settings-wrapper {
        top: 1rem;
        right: 1rem;
    }

    /* Modal adjustments */
    .modal {
        padding: 1rem;
    }

    .modal-content.card {
        max-height: 90vh;
    }
}

/* --- Mobile (≤480px) --- */
@media (max-width: 480px) {
    .landing-view {
        padding: 1rem 0.75rem 1.5rem;
    }

    .landing-brand {
        margin-top: 3.25rem;
    }

    .landing-title {
        font-size: 1.6rem;
    }

    .shield-icon {
        width: 40px;
        height: 40px;
    }

    .landing-search {
        padding: 0;
    }

    /* Further shrink domain prefix */
    .domain-prefix {
        min-width: 72px;
        font-size: 0.75rem;
        padding: 0.45rem 0.5rem;
    }

    .query-input {
        font-size: 0.88rem;
        padding: 0.5rem 0.4rem;
        min-height: 40px;
    }

    .search-pill button {
        width: 36px;
        height: 36px;
    }

    .mic-btn {
        width: 30px !important;
        height: 30px !important;
    }

    .pill-divider {
        margin: 0 0.15rem;
    }

    .sticky-header {
        padding: 0 0.5rem;
    }

    .sticky-inner {
        gap: 0.35rem;
        height: 50px;
    }

    .sticky-emblem {
        height: 34px;
    }

    .search-pill.compact .domain-prefix {
        min-width: 60px;
        font-size: 0.7rem;
    }

    .search-pill.compact .query-input {
        padding: 0.35rem 0.3rem;
        font-size: 0.82rem;
    }

    .search-pill.compact button {
        width: 32px;
        height: 32px;
    }

    .results-view {
        padding: 0.75rem;
    }

    .results-card {
        padding: 1rem;
    }

    .response-text {
        font-size: 0.95rem;
        line-height: 1.7;
    }

    /* Token usage wrapping */
    .token-usage {
        flex-wrap: wrap;
        font-size: 0.7rem;
    }
}

/* --- Very narrow screens (≤360px) --- */
@media (max-width: 360px) {
    .domain-prefix {
        min-width: 60px;
        font-size: 0.7rem;
        padding: 0.4rem 0.4rem;
    }

    .query-input {
        font-size: 0.82rem;
        padding: 0.45rem 0.3rem;
    }

    .landing-logo {
        max-width: 170px;
    }

    .landing-subtitle {
        font-size: 0.8rem;
    }

    .sticky-brand {
        display: none;
    }
}

/* ===== THINKING ANIMATION ===== */
@keyframes pulse-border {
    0% {
        border-color: var(--primary);
        box-shadow: 0 0 0 0 rgba(var(--primary-rgb), 0.4);
    }

    70% {
        border-color: var(--primary-dark);
        box-shadow: 0 0 0 6px rgba(var(--primary-rgb), 0);
    }

    100% {
        border-color: var(--primary);
        box-shadow: 0 0 0 0 rgba(var(--primary-rgb), 0);
    }
}

.thought-container.thinking {
    animation: pulse-border 2s infinite;
}

.thought-header .status-text {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--primary);
    margin-left: 8px;
    opacity: 0.8;
}

/* ===== FOLLOW-UP BAR ===== */
.follow-up-bar {
    margin-top: 1rem;
    animation: fadeUp 0.3s ease;
}

.follow-up-inner {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 0.3rem 0.3rem 0.3rem 1rem;
    box-shadow: var(--shadow);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.follow-up-inner:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15), var(--shadow);
}

.follow-up-inner input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 0.6rem 0.5rem;
    font-size: 0.95rem;
    outline: none;
    font-family: inherit;
    min-width: 0;
}

.follow-up-inner input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.follow-up-inner button {
    background: var(--primary-dark);
    color: white;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}

.follow-up-inner button:hover {
    background: var(--primary);
    transform: scale(1.08);
}

/* ===== FOLLOW-UP INDICATOR ===== */
.follow-up-indicator {
    margin-top: 0.5rem;
    font-size: 0.78rem;
    color: var(--primary-dark);
    font-weight: 500;
    font-style: italic;
    padding: 0.3rem 0.75rem;
    background: rgba(var(--primary-rgb), 0.06);
    border-radius: 2rem;
    display: inline-block;
    border: 1px solid rgba(var(--primary-rgb), 0.15);
}

/* ===== REWRITTEN QUERY PILL ===== */
.rewritten-query-pill {
    margin: 0.5rem 0 0.75rem;
    padding: 0.4rem 0.85rem;
    background: rgba(var(--primary-rgb), 0.06);
    border: 1px solid rgba(var(--primary-rgb), 0.18);
    border-radius: 2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-block;
    transition: background 0.2s, border-color 0.2s;
    animation: fadeUp 0.3s ease;
}

.rewritten-query-pill:hover {
    background: rgba(var(--primary-rgb), 0.13);
    border-color: var(--primary);
}

.rq-label {
    font-weight: 600;
    color: var(--primary-dark);
}

.rq-text {
    font-style: italic;
}

/* ===== DOMAIN HINT BANNER ===== */
.domain-hint-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0 0.75rem;
    padding: 0.6rem 1rem;
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: #92400e;
    animation: fadeUp 0.3s ease;
    flex-wrap: wrap;
}

.dh-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.dh-text {
    flex: 1;
    min-width: 0;
}

.dh-text strong {
    text-transform: capitalize;
}

.dh-switch {
    background: #f59e0b;
    color: #fff;
    border: none;
    padding: 0.35rem 0.85rem;
    border-radius: 2rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
    text-transform: capitalize;
}

.dh-switch:hover {
    background: #d97706;
}

.dh-dismiss {
    background: none;
    border: none;
    color: #92400e;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.dh-dismiss:hover {
    opacity: 1;
}

/* ===== DOMAIN CORRECTION CARD ===== */
.domain-correction-card {
    text-align: center;
    padding: 2.5rem 2rem;
    animation: fadeUp 0.3s ease;
}

.dc-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    color: #f59e0b;
}

.domain-correction-card h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.domain-correction-card p {
    color: var(--text-muted);
    font-size: 0.92rem;
    margin-bottom: 0.25rem;
}

.domain-correction-card p strong {
    text-transform: capitalize;
}

.dc-sub {
    font-size: 0.82rem !important;
    color: #92400e !important;
    margin-bottom: 1.25rem !important;
}

.dc-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.dc-primary {
    background: var(--primary-dark);
    color: #fff;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 2rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    text-transform: capitalize;
}

.dc-primary:hover {
    background: var(--primary);
    transform: scale(1.04);
}

.dc-secondary {
    background: none;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 0.6rem 1.5rem;
    border-radius: 2rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
    text-transform: capitalize;
}

.dc-secondary:hover {
    border-color: var(--text-muted);
    color: var(--text);
}