/* ============================================================
   SOLOMON — Design System
   Warm-neutral minimalism following DesignSpecs.md
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&family=JetBrains+Mono:wght@400&display=swap');

/* --- CSS Variables: Light Mode --- */
:root {
    --bg:             #F5F0E8;
    --surface:        #FDFAF5;
    --surface-alt:    #EDE8DE;
    --border:         #DDD8CE;
    --text-primary:   #1A1714;
    --text-secondary: #6B6560;
    --accent:         #C97B4B;
    --accent-hover:   #b86d3e;
    --user-bubble:    #E8E3D8;
    --ai-response:    #FDFAF5;
    --destructive:    #C0392B;
    --shadow-1:       0 2px 8px rgba(0,0,0,0.05);
    --shadow-2:       0 4px 16px rgba(0,0,0,0.10);
    --shadow-3:       0 8px 32px rgba(0,0,0,0.14);

    --font-sans:    'Open Sans', system-ui, -apple-system, sans-serif;
    --font-mono:    'JetBrains Mono', monospace;

    --radius-sm:    6px;
    --radius-md:    8px;
    --radius-lg:    16px;

    --sidebar-w:    260px;
    --content-max:  720px;

    --transition-fast:  150ms ease-out;
    --transition-mid:   250ms ease-out;

    --surface-focused:  #ffffff;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
    --bg:             #1C1917;
    --surface:        #292524;
    --surface-alt:    #211F1D;
    --border:         #3D3A37;
    --text-primary:   #F5F0E8;
    --text-secondary: #A09890;
    --user-bubble:    #333028;
    --ai-response:    #292524;
    --surface-focused: var(--surface);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
    /* Loading indicators are essential UI feedback — keep them animated even with reduced motion */
    .streaming-indicator span { animation: si-pulse 1.3s ease-in-out infinite !important; }
    .streaming-indicator span:nth-child(2) { animation-delay: 0.22s !important; }
    .streaming-indicator span:nth-child(3) { animation-delay: 0.44s !important; }
    .spinner { animation: spin 0.7s linear infinite !important; }
    .result-panel-body.streaming::after,
    .merge-panel-body.streaming::after { animation: blink 1s step-end infinite !important; }
}

/* --- App Shell --- */
.app-shell {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* iOS PWA only: anchor the app shell across the full viewport so iOS cannot
   leave a default-white strip below it, lock the document so iOS cannot
   scroll the page up on input focus, and push content up with padding-bottom
   when the soft keyboard / QuickType bar is open (binary state, not a
   continuous chase). html/body get explicit bg so any iOS overscroll glitch
   shows the theme color instead of system white.
   Scoped to standalone mode so desktop and regular Safari are untouched. */
@media (display-mode: standalone) {
    html, body {
        overflow: hidden;
        overscroll-behavior: none;
        background: var(--bg);
    }
    .app-shell {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: auto;
        box-sizing: border-box;
    }
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--surface-alt);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: row;
    overflow: hidden;
    transition: width var(--transition-mid), min-width var(--transition-mid);
    flex-shrink: 0;
}

/* Collapsed: shrink to icon strip width only */
.sidebar.collapsed { width: 48px; min-width: 48px; }

/* Icon strip — always visible, left edge */
.sidebar-icon-strip {
    width: 48px;
    min-width: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    gap: 4px;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
}
/* In expanded mode the icon strip is hidden — full sidebar takes over */
.sidebar:not(.collapsed) .sidebar-icon-strip { display: none; }

.strip-btn {
    width: 36px; height: 36px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    color: var(--text-secondary);
    transition: background var(--transition-fast), color var(--transition-fast);
}
.strip-btn:hover { background: var(--border); color: var(--text-primary); }

/* Full sidebar panel — hidden when collapsed */
.sidebar-full {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.sidebar.collapsed .sidebar-full { display: none; }

.sidebar-header {
    padding: 16px 12px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-logo-wrap {
    flex: 1;
    display: flex;
    align-items: center;
}
.sidebar-logo {
    height: 38px;
    width: auto;
    display: block;
    padding-left: 5px;
    padding-bottom: 8px;
}
.sidebar-logo-dark { display: none; }
[data-theme="dark"] .sidebar-logo-light { display: none; }
[data-theme="dark"] .sidebar-logo-dark { display: block; }

.sidebar-new-chat { margin: 12px; flex-shrink: 0; }

.sidebar-search {
    padding: 0 12px 8px;
    flex-shrink: 0;
}
.sidebar-search input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast);
}
.sidebar-search input:focus { border-color: var(--accent); }
.sidebar-search input::placeholder { color: var(--text-secondary); }

.sidebar-history {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.sidebar-section-label {
    font-size: 11px;
    font-weight: 600;
    color: color-mix(in srgb, var(--text-primary) 55%, var(--text-secondary));
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 10px 8px 3px 2px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 14px;
    color: var(--text-primary);
}
.history-item:hover { background: var(--border); }
.history-item.active { background: color-mix(in srgb, var(--accent) 12%, var(--surface-alt)); font-weight: 500; }
.history-item-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Hover action overlay */
.history-item { position: relative; }
.history-item-actions {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    display: flex; align-items: center; gap: 2px;
    opacity: 0; pointer-events: none;
    transition: opacity var(--transition-fast);
    background: var(--border);
    border-radius: 5px;
    padding: 2px 3px;
}
.history-item:hover .history-item-actions { opacity: 1; pointer-events: auto; }
.history-item-action {
    color: var(--text-secondary); background: none; border: none;
    cursor: pointer; padding: 2px; border-radius: 4px;
    display: flex; align-items: center;
}
.history-item-action:hover { color: var(--text-primary); }
.history-item-delete:hover { color: var(--destructive); }
.history-item-pin:hover { color: var(--accent); }
.history-item-pin.pinned { color: var(--accent); }

.history-item.imported .history-item-text { font-style: italic; color: var(--text-secondary); }
.imported-badge {
    display: inline-block;
    font-size: 9px;
    font-style: normal;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    border-radius: 3px;
    padding: 1px 4px;
    margin-right: 4px;
    vertical-align: middle;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
    overflow: hidden;
}

/* --- Top Bar --- */
.top-bar {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    flex-wrap: wrap;
    min-height: 56px;
}
.top-bar-left { display: flex; align-items: center; gap: 8px; }
.top-bar-center { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.top-bar-right { display: flex; align-items: center; gap: 8px; }
.top-bar-right .view-selector { margin-left: 8px; }

/* --- Mode Tabs --- */
.mode-tabs {
    display: flex;
    gap: 2px;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    padding: 3px;
}
.mode-tab {
    padding: 4px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: none;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}
.mode-tab.active {
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-1);
}

/* --- Model Bar --- */
.model-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.model-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 6px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 13px;
    color: var(--text-primary);
    user-select: none;
}
.model-chip:hover { border-color: var(--accent); }
.model-chip.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.model-chip.inactive { opacity: 0.4; border-color: var(--border); background: var(--surface-alt); }
.model-chip-auto { cursor: default; }
.model-chip-auto:hover { border-color: var(--accent); }

.model-selector-auto-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    background: color-mix(in srgb, var(--accent) 6%, var(--surface));
    border: 1.5px solid color-mix(in srgb, var(--accent) 30%, var(--border));
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 16px;
    line-height: 1.5;
}

.model-chip-icon {
    width: 20px; height: 20px;
    border-radius: 5px;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 700;
    flex-shrink: 0;
}
.provider-logo {
    width: 15px; height: 15px;
    object-fit: contain;
    filter: brightness(0) invert(1);
}
/* Gemini gradient must render in its natural colors */
.provider-google .provider-logo {
    filter: none;
    width: 16px; height: 16px;
}
.model-chip-name { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.add-model-btn {
    display: flex; align-items: center; gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1.5px dashed var(--border);
    background: none; cursor: pointer;
    font-size: 13px; color: var(--text-secondary);
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}
.add-model-btn:hover { border-color: var(--accent); color: var(--accent); }

.select-all-btn {
    font-size: 13px; font-weight: 600; color: var(--accent-hover); cursor: pointer;
    background: none; border: none; padding: 4px 6px;
    border-radius: var(--radius-sm); transition: background var(--transition-fast);
    font-family: var(--font-sans);
}
.select-all-btn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* --- Chat / Results Area --- */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0 0;
}

.empty-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    height: 100%; gap: 12px;
    padding: 48px 24px; text-align: center;
}
.empty-state-title { font-size: 28px; font-weight: 500; color: var(--text-primary); }
.empty-state-sub { font-size: 15px; color: var(--text-secondary); max-width: 380px; line-height: 1.6; }

/* --- Turns --- */
.turns-list { padding: 0 24px; }

.turn-block { margin-bottom: 32px; }

.turn-prompt {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 16px;
    padding: 0 4px;
    gap: 8px;
}
.turn-prompt-copy {
    opacity: 0;
    flex-shrink: 0;
    transition: opacity var(--transition-fast);
}
.turn-prompt:hover .turn-prompt-copy { opacity: 0.55; }
.turn-prompt-copy:hover { opacity: 1 !important; }

.turn-prompt-bubble {
    background: var(--user-bubble);
    border-radius: 16px 16px 4px 16px;
    padding: 12px 18px;
    max-width: 72%;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    word-break: break-word;
    animation: bubble-in 0.22s ease;
}
@keyframes bubble-in {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}
/* Long-prompt clamp + hover-to-expand overlay */
.turn-prompt-bubble.tp-has-full {
    position: relative;
    cursor: default;
}
.turn-prompt-bubble.tp-has-full .turn-prompt-inner {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.turn-prompt-hover-full {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 12px 18px;           /* match bubble padding */
    background: var(--user-bubble);
    border-radius: 16px 16px 4px 16px;  /* match bubble */
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    z-index: 50;
    word-break: break-word;
    line-height: 1.6;
    font-size: 15px;
    color: var(--text-primary);
}
.turn-prompt-bubble.tp-has-full:hover .turn-prompt-hover-full { display: block; }

/* Markdown rendered inside prompt bubbles */
.turn-prompt-bubble .pmh1 { font-weight: 700; font-size: 1.05em; display: block; margin: 2px 0 1px; }
.turn-prompt-bubble .pmh2 { font-weight: 700; display: block; margin: 2px 0 1px; }
.turn-prompt-bubble .pmh3 { font-weight: 600; display: block; margin: 2px 0 1px; }
.turn-prompt-bubble .pml  { margin: 3px 0; padding-left: 18px; }
.turn-prompt-bubble .pml-p { display: block; }

/* Streaming dots indicator */
.streaming-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 4px 0;
    justify-content: flex-end;
    padding-right: 8px;
}
.streaming-indicator span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block;
    animation: si-pulse 1.3s ease-in-out infinite;
    opacity: 0.75;
}
.streaming-indicator span:nth-child(2) { animation-delay: 0.22s; }
.streaming-indicator span:nth-child(3) { animation-delay: 0.44s; }
@keyframes si-pulse {
    0%, 80%, 100% { transform: scale(0.65); opacity: 0.35; }
    40%           { transform: scale(1.0);  opacity: 1; }
}

/* --- Results Grid --- */
.results-scroll-area {
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.results-grid {
    display: grid;
    gap: 12px;
    padding: 0 4px;
    align-items: start;
}
.results-grid.cols-1 { grid-template-columns: 1fr; }
.results-grid.cols-2 { grid-template-columns: repeat(2, minmax(320px, 1fr)); }
.results-grid.cols-3 { grid-template-columns: repeat(3, minmax(280px, 1fr)); }
.results-grid.cols-4 { grid-template-columns: repeat(4, minmax(240px, 1fr)); }

/* --- Carousel Modes --- */
.results-scroll-area.view-cols-1,
.results-scroll-area.view-cols-2,
.results-scroll-area.view-cols-4 {
    overflow: hidden;
    padding-bottom: 4px;
}

/* Carousel grid: flex row, no padding so % widths resolve cleanly against scroll-area width */
.results-scroll-area.view-cols-1 .results-grid,
.results-scroll-area.view-cols-2 .results-grid {
    display: flex;
    gap: 24px;          /* wider gap for 1 and 2 col — more breathing room */
    padding: 0;
    align-items: start;
    transition: transform 350ms cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}
.results-scroll-area.view-cols-4 .results-grid {
    display: flex;
    gap: 12px;          /* keep compact for 4 col */
    padding: 0;
    align-items: start;
    transition: transform 350ms cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

/* Single view: card is 60% of scroll-area width; ~20% peeks on each side */
.results-scroll-area.view-cols-1 .result-panel {
    flex: 0 0 60%;
    min-width: 0;
}

/* Two-card view: exactly two cards fill the scroll-area (2 × card + 1 gap = 100%)
   gap=24px → each card = (100% - 24px) / 2 = 50% - 12px */
.results-scroll-area.view-cols-2 .result-panel {
    flex: 0 0 calc(50% - 12px);
    min-width: 0;
}

/* Four-card view: exactly four cards fill the scroll-area (4 × card + 3 gaps = 100%)
   gap=12px → each card = (100% - 36px) / 4 = 25% - 9px */
.results-scroll-area.view-cols-4 .result-panel {
    flex: 0 0 calc(25% - 9px);
    min-width: 0;
}

/* 4-col view with fewer than 4 cards — expand cards to fill width with wider gap */
.results-scroll-area.view-cols-4.cards-1 .results-grid,
.results-scroll-area.view-cols-4.cards-2 .results-grid,
.results-scroll-area.view-cols-4.cards-3 .results-grid { gap: 24px; }

/* gap=24px, 1 card: matches single-col peek style */
.results-scroll-area.view-cols-4.cards-1 .result-panel { flex: 0 0 60%; }
/* gap=24px, 2 cards: (100% - 24px) / 2 = 50% - 12px */
.results-scroll-area.view-cols-4.cards-2 .result-panel { flex: 0 0 calc(50% - 12px); }
/* gap=24px, 3 cards: (100% - 48px) / 3 = 33.333% - 16px */
.results-scroll-area.view-cols-4.cards-3 .result-panel { flex: 0 0 calc(33.333% - 16px); }

/* --- Carousel Navigation --- */
.carousel-container { position: relative; }

.carousel-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 52px; height: 52px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-2);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--accent);
    transition: opacity var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
    opacity: 0.85;
}
.carousel-nav-btn:hover { opacity: 1; background: var(--surface-alt); box-shadow: var(--shadow-3); }
.carousel-nav-btn.nav-disabled { opacity: 0; pointer-events: none; }
.carousel-nav-prev { left: 6px; }
.carousel-nav-next { right: 6px; }

/* --- Result Panel --- */
.result-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-1);
    transition: box-shadow var(--transition-fast), background var(--transition-mid);
}
.result-panel:hover { box-shadow: var(--shadow-2); }
.result-panel.clickable-panel { cursor: pointer; }

/* Focused card = pure white. In single-view, only the center card is focused;
   the side peeks stay at var(--surface) (off-white). In 2-col and 4-col/auto
   views, all visible cards are marked focused so they're all pure white. */
.result-panel.focused {
    background: var(--surface-focused);
}
.result-panel.focused .result-panel-header {
    background: var(--surface-focused);
}

.result-panel-header {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px;
    background: var(--surface);
    border-radius: 11px 11px 0 0;
}
.result-panel-model { display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0; }
.result-panel-model-name {
    font-size: 16px; font-weight: 500; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.result-panel-actions { display: flex; align-items: center; gap: 2px; }

.result-panel-body {
    padding: 14px 16px;
    font-size: 16px;
    line-height: 1.75;
    color: var(--text-primary);
    overflow-wrap: break-word;
    min-height: 80px;
}

/* Markdown typography — matched to Open Sans / SearchUmbrella reference */
.result-panel-body p             { margin: 0 0 1em; }
.result-panel-body p:last-child  { margin-bottom: 0; }
.result-panel-body h1            { font-size: 1.35em; font-weight: 700; margin: 1.2em 0 0.75em; }
.result-panel-body h2            { font-size: 1.25em; font-weight: 700; margin: 1.2em 0 0.7em; }
.result-panel-body h3            { font-size: 1.17em; font-weight: 700; margin: 1.17em 0 0.65em; }
.result-panel-body ul,
.result-panel-body ol            { margin: 1em 0; padding-left: 1.75em; }
.result-panel-body ul:last-child,
.result-panel-body ol:last-child { margin-bottom: 0; }
.result-panel-body li            { margin: 0; }
.result-panel-body.streaming::after {
    content: '▋';
    animation: blink 1s step-end infinite;
    color: var(--accent);
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.result-panel-error {
    padding: 14px 16px;
    color: var(--destructive);
    font-size: 14px;
}

.result-panel-footer {
    padding: 7px 12px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--text-secondary);
}

/* Code in results */
.result-panel-body pre {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    margin: 8px 0;
    white-space: pre;
}
.result-panel-body code {
    font-family: var(--font-mono); font-size: 13px;
    background: var(--surface-alt); padding: 2px 5px;
    border-radius: 4px; border: 1px solid var(--border);
}
.result-panel-body pre code { background: none; padding: 0; border: none; }
/* Tables in results and merge */
.result-panel-body .table-wrapper,
.merge-panel-body .table-wrapper {
    overflow-x: auto;
    margin: 8px 0;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}
.result-panel-body table,
.merge-panel-body table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
    line-height: 1.5;
}
.result-panel-body th,
.result-panel-body td,
.merge-panel-body th,
.merge-panel-body td {
    border: 1px solid var(--border);
    padding: 7px 12px;
    text-align: left;
    white-space: nowrap;
}
.result-panel-body th,
.merge-panel-body th {
    background: var(--surface-alt);
    font-weight: 600;
    position: sticky;
    top: 0;
}
.result-panel-body tbody tr:nth-child(even) td,
.merge-panel-body tbody tr:nth-child(even) td {
    background: var(--surface-alt);
}
.result-panel-body a, .merge-panel-body a {
    color: var(--accent); text-decoration: underline; text-underline-offset: 2px;
}
.result-panel-body a:hover, .merge-panel-body a:hover { opacity: 0.8; }

/* --- Input Bar --- */
.input-bar-wrapper {
    padding: 20px 16px;
    background: var(--bg);
    flex-shrink: 0;
}
.input-bar-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: calc(var(--content-max) + 54px);
    margin: 0 auto;
    position: relative;  /* for absolutely-positioned .scroll-top-slot */
    padding-left: 50px;  /* reserve visual space for scroll-top-slot without it being a flex item */
}
/* Scroll-to-top: absolutely positioned so it NEVER participates in flex layout.
   Without this, the button would steal width from the prompt area AND cause
   flex cross-axis height recalculation when it appears/disappears. */
.scroll-top-slot {
    position: absolute;
    left: 0;
    bottom: 3px;
}
.input-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.scroll-top-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    width: 40px; height: 40px;
    border-radius: var(--radius-md);
    background: none; border: none;
    cursor: pointer;
    color: #6b5f57;
    flex-shrink: 0;
    margin-bottom: 3px;
    transition: all var(--transition-fast);
    animation: fade-in-btn 0.15s ease;
}
.scroll-top-btn:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.scroll-top-label {
    font-size: 9px; font-weight: 700; letter-spacing: 0.04em;
    line-height: 1; font-family: var(--font-sans);
}
@keyframes fade-in-btn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.quill-btn {
    width: 40px; height: 40px;
    border-radius: var(--radius-md);
    background: none; border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #6b5f57;
    flex-shrink: 0;
    margin-bottom: 3px;
    transition: all var(--transition-fast);
}
.quill-btn:hover:not(:disabled) { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.quill-btn.active { color: var(--accent); }
.quill-btn:disabled { opacity: 0.35; cursor: default; }

.input-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input-bar:focus-within {
    border-color: var(--accent);
    box-shadow: 0 2px 12px rgba(201,123,75,0.12);
}
/* Wrapper provides vertical centering independent of textarea height.
   DO NOT REMOVE — this decouples centering from textarea sizing. */
.prompt-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    min-height: 36px; /* match send-btn height so wrapper fills the row */
    min-width: 0;
}
.prompt-wrapper textarea {
    width: 100%; background: none; border: none; outline: none;
    resize: none; font-family: var(--font-sans); font-size: 15px;
    line-height: 1.6; color: var(--text-primary);
    max-height: 180px; overflow-y: auto;
    /* Vertical padding centers the text within the textarea. This absorbs any
       mismatch between rows="1" height and scrollHeight (the bug that broke
       centering 4 times). Even a 2-3px error is invisible across 12px of padding.
       DO NOT remove this padding — it is the centering mechanism. */
    padding: 6px 0;
}
.prompt-wrapper textarea::placeholder { color: var(--text-secondary); }

.send-btn {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--accent); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: white;
    transition: background var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast);
    flex-shrink: 0;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.35; cursor: default; transform: none; }

.stop-btn {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--surface-alt); border: 1px solid var(--border);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast); flex-shrink: 0;
}
.stop-btn:hover { color: var(--destructive); border-color: var(--destructive); }

.web-search-btn {
    width: 36px; height: 36px; border-radius: 10px;
    background: none; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--border);
    transition: all var(--transition-fast); flex-shrink: 0;
}
.web-search-btn:hover:not(:disabled) { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.web-search-btn.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.web-search-btn:disabled { opacity: 0.35; cursor: default; }

.attach-btn {
    width: 36px; height: 36px; border-radius: 10px;
    background: none; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--border);
    transition: all var(--transition-fast); flex-shrink: 0;
}
.attach-btn:hover:not(:disabled) { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.attach-btn:disabled { opacity: 0.35; cursor: default; }

.attached-files {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 0 10px 8px;
}
.file-chip {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; padding: 3px 8px 3px 7px;
    font-size: 12px; color: var(--text-secondary);
    max-width: 220px;
}
.file-chip svg { flex-shrink: 0; color: var(--accent); }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip-image { padding: 3px 8px 3px 3px; }
.file-chip-thumb {
    width: 28px; height: 28px; border-radius: 4px;
    object-fit: cover; flex-shrink: 0;
    border: 1px solid var(--border);
}
.file-chip-remove {
    background: none; border: none; cursor: pointer;
    color: var(--text-secondary); font-size: 14px; line-height: 1;
    padding: 0 0 0 2px; flex-shrink: 0;
    transition: color var(--transition-fast);
}
.file-chip-remove:hover { color: var(--destructive); }

.input-bar-wrapper.drag-over .input-bar {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
    background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}

/* --- Rich Text Editor --- */
.re-backdrop {
    position: fixed; inset: 0; z-index: 399;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: merge-backdrop-in 0.15s ease;
}
.rich-editor {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 32px);
    max-width: calc(var(--content-max) + 54px);
    z-index: 400;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    display: flex;
    flex-direction: column;
    max-height: 65vh;
    overflow: hidden;
    animation: re-slide-up 0.15s ease;
}
@keyframes re-slide-up {
    from { opacity: 0; transform: translate(-50%, calc(-50% + 10px)); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}
.re-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface-alt);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.re-toolbar-group { display: flex; align-items: center; gap: 3px; }
.re-toolbar-sep {
    width: 1px; height: 22px;
    background: var(--border);
    margin: 0 5px;
    flex-shrink: 0;
}
.re-toolbar-btn {
    min-width: 38px; height: 38px;
    padding: 0 7px;
    border-radius: var(--radius-sm);
    background: none; border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 15px; font-weight: 700;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.re-toolbar-btn:hover { background: var(--surface); color: var(--text-primary); }
.re-toolbar-btn.re-tb-copied { color: #4caf50; }
.re-close-btn {
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    background: none; border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    flex-shrink: 0;
    margin-left: 2px;
}
.re-close-btn:hover { background: var(--surface); color: var(--text-primary); }
.re-copy-btn {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: var(--surface); border: 1px solid var(--border);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.re-copy-btn:hover { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.re-copy-btn.copied { color: #4caf50; border-color: #4caf50; }
.re-content {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    min-height: 480px;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.65;
    color: var(--text-primary);
    background: white;
    outline: none;
}
[data-theme="dark"] .re-content { background: var(--surface); }
.re-content:empty::before {
    content: 'Draft a more detailed prompt here…';
    color: var(--text-secondary);
    pointer-events: none;
}
.re-content h1 { font-size: 20px; font-weight: 700; margin: 10px 0 4px; }
.re-content h2 { font-size: 17px; font-weight: 700; margin: 8px 0 4px; }
.re-content h3 { font-size: 15px; font-weight: 600; margin: 6px 0 4px; }
.re-content ul { padding-left: 22px; margin: 4px 0; }
.re-content ol { padding-left: 22px; margin: 4px 0; }
.re-content li { margin: 2px 0; }
.re-content p { margin: 0 0 6px; }
.re-attached-files {
    padding: 6px 12px 0;
    border-top: 1px solid var(--border);
}
.re-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
    flex-shrink: 0;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.re-submit-btn {
    width: auto !important;
    padding: 0 16px !important;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
}

/* --- Merge Saves Bar (top-bar-right) --- */
.merge-saves-bar {
    display: flex; align-items: center; gap: 2px;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    padding: 3px 5px 3px 7px;
}
.merge-saves-btn {
    width: 26px; height: 26px;
    border: none; border-radius: 5px;
    font-family: var(--font-sans); font-size: 12px; font-weight: 600;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    background: none;
    transition: all var(--transition-fast);
    opacity: 0.35;
}
.merge-saves-btn.active {
    opacity: 1;
    color: var(--accent);
}
.merge-saves-btn.active:hover {
    background: var(--surface);
    color: var(--accent);
    box-shadow: var(--shadow-1);
}
.merge-saves-btn.viewing {
    background: var(--surface);
    color: var(--accent);
    box-shadow: var(--shadow-1);
    opacity: 1;
}
.merge-saves-btn:disabled { cursor: default; }

/* --- Merge Panel Slot Pills (inside merge panel header) --- */
.merge-slot-pill {
    min-width: 22px; height: 22px; padding: 0 6px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans); font-size: 11px; font-weight: 700;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    background: var(--surface-alt);
    transition: all var(--transition-fast);
}
.merge-slot-pill:hover { border-color: var(--accent); color: var(--accent); }
.merge-slot-pill.viewing {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    border-color: var(--accent);
    color: var(--accent);
}

/* --- View Selector --- */
.view-selector {
    display: flex; gap: 2px;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    padding: 3px;
}
.view-btn {
    padding: 5px 8px; border: none; background: none;
    border-radius: 5px; cursor: pointer; color: var(--text-secondary);
    transition: all var(--transition-fast); display: flex; align-items: center;
}
.view-btn.active { background: var(--surface); color: var(--text-primary); box-shadow: var(--shadow-1); }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius-md);
    font-family: var(--font-sans); font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all var(--transition-fast);
    border: none; white-space: nowrap; text-decoration: none;
    line-height: 1;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-alt); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text-primary); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon {
    width: 32px; height: 32px; padding: 0; border-radius: var(--radius-md);
    justify-content: center; background: transparent; border: none;
    color: var(--text-secondary); cursor: pointer;
    display: inline-flex; align-items: center;
    transition: all var(--transition-fast);
}
.btn-icon:hover { background: var(--surface-alt); color: var(--text-primary); }
.merge-stop-btn:hover,
.result-panel-stop-btn:hover { color: var(--accent) !important; background: color-mix(in srgb, var(--accent) 10%, transparent) !important; }

/* --- Modal --- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(26, 23, 20, 0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 24px;
    backdrop-filter: blur(2px);
}
.modal {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-3);
    width: 100%; max-width: 680px;
    max-height: 82vh;
    display: flex; flex-direction: column;
    overflow: hidden;
    animation: modal-in 200ms ease-out;
}
@keyframes modal-in {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.modal-title { font-size: 18px; font-weight: 500; color: var(--text-primary); }
.modal-body { flex: 1; overflow-y: auto; padding: 16px 24px; }
.modal-footer {
    padding: 14px 24px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
    flex-shrink: 0;
}

/* --- Model Selector Modal --- */
.model-selector-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.model-selector-tab {
    flex: 1; padding: 8px;
    border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--surface-alt); cursor: pointer;
    text-align: center; font-size: 14px; font-weight: 500;
    color: var(--text-secondary); transition: all var(--transition-fast);
    font-family: var(--font-sans);
}
.model-selector-tab.active {
    background: var(--surface);
    color: var(--text-primary);
    border-color: var(--accent);
}

.model-selector-slots {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}
.model-slot-card {
    background: var(--surface-alt);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
    min-height: 70px;
    display: flex; flex-direction: column; gap: 4px;
    position: relative; cursor: default;
    transition: border-color var(--transition-fast);
}
.model-slot-card.filled { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.model-slot-label { font-size: 11px; color: var(--text-secondary); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.model-slot-name { font-size: 13px; color: var(--text-primary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-slot-clear {
    position: absolute; top: 6px; right: 6px;
    background: none; border: none; cursor: pointer;
    color: var(--text-secondary); padding: 2px; border-radius: 4px;
    display: flex; align-items: center; transition: color var(--transition-fast);
}
.model-slot-clear:hover { color: var(--destructive); }
.model-slot-empty { color: var(--text-secondary); font-size: 12px; }

.model-search-input {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--surface-alt); color: var(--text-primary);
    font-family: var(--font-sans); font-size: 14px; outline: none;
    margin-bottom: 12px;
    transition: border-color var(--transition-fast);
}
.model-search-input:focus { border-color: var(--accent); }
.model-search-input::placeholder { color: var(--text-secondary); }

.model-provider-group { margin-bottom: 12px; }
.model-provider-name {
    font-size: 11px; font-weight: 600; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.06em;
    padding: 4px 0; border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.model-option {
    display: flex; flex-direction: column;
    padding: 0; border-radius: var(--radius-md);
    cursor: pointer; transition: background var(--transition-fast);
    overflow: hidden;
}
.model-option:hover { background: var(--surface-alt); }
.model-option.selected { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.model-option.selected:hover { background: color-mix(in srgb, var(--accent) 15%, var(--surface)); }

/* Inner row — always visible */
.model-option-row {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 8px;
}

.model-option-name { font-size: 14px; color: var(--text-primary); flex: 1; }
.model-option-ctx { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.model-option-slot {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--accent); color: white;
    font-size: 10px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

/* Expandable details strip */
.model-option-details {
    max-height: 0;
    overflow: hidden;
    padding: 0 8px;
    opacity: 0;
    /* Close: fast. Open: JS Task.Delay handles the 1s wait; this just animates the reveal. */
    transition: max-height 150ms ease-in, padding 150ms ease-in, opacity 100ms ease-in;
}
/* .expanded class is added by Blazor after the 1s JS delay fires */
.model-option.expanded .model-option-details {
    max-height: 120px;
    padding: 0 8px 10px;
    opacity: 1;
    transition: max-height 240ms ease-out, padding 240ms ease-out, opacity 200ms ease-out;
}

.model-detail-stub {
    font-style: italic;
    opacity: 0.7;
}
.model-detail-stub code {
    font-family: var(--font-mono);
    font-size: 11px;
    font-style: normal;
    background: var(--surface-alt);
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid var(--border);
}

.model-detail-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-bottom: 7px;
    /* Clamp to 3 lines */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.model-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.model-detail-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 99px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}
.model-option.selected .model-detail-pill {
    background: color-mix(in srgb, var(--accent) 5%, var(--surface));
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

/* --- Model Name Swap Trigger --- */
.model-name-swap { position: relative; min-width: 0; display: flex; align-items: center; }

.model-name-swap-btn {
    background: none; border: none; cursor: pointer;
    display: flex; align-items: center; gap: 3px;
    padding: 2px 4px; border-radius: var(--radius-sm);
    color: inherit; font-family: var(--font-sans);
    transition: background var(--transition-fast);
    min-width: 0;
}
.model-name-swap-btn:hover { background: color-mix(in srgb, var(--text-primary) 7%, transparent); }

.swap-chevron {
    color: var(--text-secondary);
    flex-shrink: 0; opacity: 0.55;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.model-name-swap-btn:hover .swap-chevron { opacity: 1; }
.model-name-swap-btn[aria-expanded="true"] .swap-chevron { transform: rotate(180deg); opacity: 1; }

/* --- Swap Menu --- */
.swap-wrapper { position: relative; }
.swap-menu {
    position: absolute; top: calc(100% + 4px); left: 0;
    min-width: 220px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-2); z-index: 50; padding: 4px;
    max-height: 300px; overflow-y: auto;
}
.swap-menu-item {
    padding: 8px 10px; border-radius: 6px; cursor: pointer;
    font-size: 13px; color: var(--text-primary);
    transition: background var(--transition-fast);
    display: flex; align-items: center; gap: 8px;
}
.swap-menu-item:hover { background: var(--surface-alt); }

/* --- Provider colors --- */
.provider-openai    { background: #000; color: #fff; }
.provider-anthropic { background: #C97B4B; color: #fff; }
.provider-google    { background: #fff; color: #4285F4; border: 1px solid #e0ddd8; }
.provider-meta      { background: #0866FF; color: #fff; }
.provider-mistral   { background: #FF6B35; color: #fff; }
.provider-x-ai      { background: #1a1a1a; color: #fff; border: 1px solid #444; }
.provider-xai       { background: #1a1a1a; color: #fff; border: 1px solid #444; }
.provider-deepseek  { background: #4A90E2; color: #fff; }
.provider-moonshotai { background: #6B5CE7; color: #fff; }
.provider-perplexity { background: #20808D; color: #fff; }
.provider-qwen      { background: #7C3AED; color: #fff; }
.provider-default   { background: var(--surface-alt); color: var(--text-secondary); border: 1px solid var(--border); }

/* --- Tooltip --- */
.tooltip-wrapper { position: relative; display: inline-flex; }
.tooltip {
    position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: var(--text-primary); color: var(--surface);
    font-size: 12px; padding: 5px 9px; border-radius: var(--radius-sm);
    white-space: nowrap; pointer-events: none; opacity: 0;
    transition: opacity var(--transition-fast); z-index: 200;
}
.tooltip-wrapper:hover .tooltip { opacity: 1; transition-delay: 400ms; }
.tooltip-wrapper.tooltip-below .tooltip { bottom: auto; top: calc(100% + 8px); }

/* --- Toast --- */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--text-primary); color: var(--surface);
    padding: 10px 20px; border-radius: 24px;
    font-size: 14px; z-index: 300;
    animation: toast-in 200ms ease-out;
    box-shadow: var(--shadow-2);
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* --- Spinner --- */
.spinner {
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Focus rings --- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Scrollbars --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* --- Confirm Dialog --- */
.confirm-dialog { max-width: 400px; }
.confirm-dialog .modal-body { padding: 20px 24px; font-size: 15px; color: var(--text-secondary); line-height: 1.6; }

/* --- Merge Button --- */
.merge-btn {
    width: 40px; height: 40px;
    border-radius: var(--radius-md);
    background: none; border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #6b5f57;
    flex-shrink: 0;
    margin-bottom: 3px;
    transition: all var(--transition-fast);
}
.merge-btn:hover:not(:disabled) { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.merge-btn.active { color: var(--accent); }
.merge-btn:disabled { opacity: 0.35; cursor: default; }

/* --- Merge Popup --- */
.merge-backdrop {
    position: fixed; inset: 0; z-index: 399;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: merge-backdrop-in 0.15s ease;
}
@keyframes merge-backdrop-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.merge-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 340px;
    z-index: 400;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: merge-slide-up 0.15s ease;
}
@keyframes merge-slide-up {
    from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}
.merge-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    flex-shrink: 0;
}
.merge-popup-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.merge-popup-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    max-height: 520px;
}
.merge-section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 8px;
}
.merge-section-label:first-child { margin-top: 0; }
.merge-optional {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-style: italic;
    opacity: 0.75;
}
.merge-model-checks {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.merge-check-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    padding: 3px 0;
}
.merge-check-item input[type="checkbox"] {
    width: 15px; height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}
.merge-select {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}
.merge-select:focus { border-color: var(--accent); }
.merge-textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: #ffffff;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition-fast);
}
[data-theme="dark"] .merge-textarea { background: var(--surface-alt); }
.merge-textarea:focus { border-color: var(--accent); }
.merge-textarea::placeholder { color: var(--text-secondary); }
.merge-textarea.merge-textarea-muted { opacity: 0.45; }
.merge-textarea.merge-textarea-muted:focus { opacity: 1; border-color: var(--accent); }
.merge-prompts-trigger.merge-prompts-trigger-muted { opacity: 0.45; }
.merge-popup-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
    flex-shrink: 0;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* --- Favorite Prompts Button --- */
.fav-prompts-btn {
    width: 40px; height: 40px;
    border-radius: var(--radius-md);
    background: none; border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #6b5f57;
    flex-shrink: 0;
    margin-bottom: 3px;
    transition: all var(--transition-fast);
}
.fav-prompts-btn:hover:not(:disabled) { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.fav-prompts-btn.active { color: var(--accent); }
.fav-prompts-btn:disabled { opacity: 0.35; cursor: default; }

/* --- Favorite Prompts Popup --- */
.fp-backdrop {
    position: fixed; inset: 0; z-index: 399;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: merge-backdrop-in 0.15s ease;
}
.fp-popup {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 480px;
    max-width: calc(100vw - 32px);
    max-height: 90vh;
    z-index: 400;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: merge-slide-up 0.15s ease;
}
.fp-popup.fp-popup-editor {
    width: 600px;
    max-width: calc(100vw - 32px);
}

/* List view body — no overflow-y clip so the absolute dropdown menu renders fully;
   min-height ensures space for 6-8 items before scrolling is ever needed */
.fp-list-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 340px;
    max-height: 560px;
    overflow-y: auto;
}

/* Web search label in footer */
.fp-ws-label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Placeholder hint text in editor label */
.fp-ph-hint {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
    margin-left: 4px;
}
.fp-ph-hint code {
    font-size: 11px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    color: var(--accent);
    border-radius: 3px;
    padding: 1px 4px;
}

/* Empty state */
.fp-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 0 8px;
    color: var(--text-secondary);
    font-size: 13px;
}
.fp-empty-state p { margin: 0; }

/* Placeholder fill-in fields (list view) */
.fp-ph-fields {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 2px;
}
.fp-ph-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.fp-ph-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 110px;
    flex-shrink: 0;
    text-align: right;
}
.fp-ph-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition-fast);
}
.fp-ph-input:focus { border-color: var(--accent); }
.fp-ph-input::placeholder { color: var(--text-secondary); }

/* Preview section header — flex row so Edit button sits on the right */
.fp-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Edit toggle button next to the PREVIEW label */
.fp-edit-toggle-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 2px 7px 2px 5px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.fp-edit-toggle-btn:hover {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Prompt body preview (list view) */
.fp-preview {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    max-height: 220px;
    overflow-y: auto;
    margin-top: 2px;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    outline: none;
}

/* Inline edit mode — white background, accent border */
.fp-preview.fp-preview-editing {
    background: #ffffff;
    border-color: var(--accent);
    cursor: text;
    min-height: 100px;
}
[data-theme="dark"] .fp-preview.fp-preview-editing {
    background: color-mix(in srgb, var(--surface-focused) 80%, #ffffff 20%);
}
.fp-preview h1 { font-size: 15px; font-weight: 700; margin: 8px 0 4px; }
.fp-preview h2 { font-size: 14px; font-weight: 600; margin: 6px 0 3px; }
.fp-preview p  { margin: 4px 0; }
.fp-preview ul, .fp-preview ol { margin: 4px 0; padding-left: 20px; }
.fp-preview li { margin: 2px 0; }
.fp-ph-mark {
    background: rgba(234, 179, 8, 0.25);
    color: #92400e;
    border-radius: 3px;
    padding: 1px 3px;
    font-weight: 500;
}
.fp-ph-mark.fp-ph-filled {
    background: rgba(34, 197, 94, 0.2);
    color: #166534;
}
[data-theme="dark"] .fp-ph-mark { background: rgba(234, 179, 8, 0.2); color: #fbbf24; }
[data-theme="dark"] .fp-ph-mark.fp-ph-filled { background: rgba(34, 197, 94, 0.15); color: #4ade80; }

/* Editor view body */
.fp-editor-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex: 1;
}
.fp-toolbar {
    margin-top: 0;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border-bottom: none;
}
/* Push copy button to the far right of the favorite-prompts toolbar; blend it into toolbar */
.fp-toolbar .re-copy-btn { margin-left: auto; background: transparent; border-color: transparent; }
.fp-toolbar .re-copy-btn:hover { background: var(--surface); border-color: var(--border); }
.fp-editor-content {
    min-height: 280px;
    max-height: 420px;
    overflow-y: auto;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    background: #ffffff;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.6;
    outline: none;
    cursor: text;
    transition: border-color var(--transition-fast);
}
[data-theme="dark"] .fp-editor-content { background: var(--surface); }
.fp-editor-content:focus { border-color: var(--accent); }
.fp-editor-content h1 { font-size: 16px; font-weight: 700; margin: 8px 0 4px; }
.fp-editor-content h2 { font-size: 14px; font-weight: 600; margin: 6px 0 3px; }
.fp-editor-content ul, .fp-editor-content ol { padding-left: 20px; }
.fp-editor-content li { margin: 2px 0; }
.fp-editor-content:empty::before {
    content: 'Write your prompt here… Use [Company Name] or [Ticker] for fill-in fields.';
    color: var(--text-secondary);
    opacity: 0.6;
    pointer-events: none;
}

/* Detected placeholder chips */
.fp-detected-phs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.fp-detected-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}
.fp-ph-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

/* --- Merge Result Panel --- */
.merge-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: clamp(360px, 44vw, 660px);
    z-index: 200;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -6px 0 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 320ms cubic-bezier(0.4, 0, 0.2, 1);
}
.merge-panel.visible { transform: translateX(0); }

.merge-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 48px;
}
.merge-panel-model-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--text-primary);
}
.merge-panel-model-name {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.merge-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 22px;
    font-size: 16px;
    line-height: 1.75;
    color: var(--text-primary);
    overflow-wrap: break-word;
}
.merge-panel-body p             { margin: 0 0 1em; }
.merge-panel-body p:last-child  { margin-bottom: 0; }
.merge-panel-body h1            { font-size: 1.35em; font-weight: 700; margin: 1.2em 0 0.75em; }
.merge-panel-body h2            { font-size: 1.25em; font-weight: 700; margin: 1.2em 0 0.7em; }
.merge-panel-body h3            { font-size: 1.17em; font-weight: 700; margin: 1.17em 0 0.65em; }
.merge-panel-body h4            { font-size: 1.08em; font-weight: 700; margin: 1.1em 0 0.6em; color: #1a3a6b; }
.merge-panel-body h5            { font-size: 1em;    font-weight: 700; margin: 1em 0 0.5em;   color: #1a3a6b; }
.merge-panel-body h6            { font-size: 0.9em;  font-weight: 700; margin: 1em 0 0.5em;   color: #1a3a6b; }
[data-theme="dark"] .merge-panel-body h4,
[data-theme="dark"] .merge-panel-body h5,
[data-theme="dark"] .merge-panel-body h6 { color: #7FB3E0; }
.merge-panel-body ul,
.merge-panel-body ol            { margin: 1em 0; padding-left: 1.75em; }
.merge-panel-body ul:last-child,
.merge-panel-body ol:last-child { margin-bottom: 0; }
.merge-panel-body li            { margin: 0; }
.merge-panel-body pre {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    margin: 8px 0;
    white-space: pre;
}
.merge-panel-body code {
    font-family: var(--font-mono); font-size: 13px;
    background: var(--surface-alt); padding: 2px 5px;
    border-radius: 4px; border: 1px solid var(--border);
}
.merge-panel-body pre code { background: none; padding: 0; border: none; }
.merge-panel-body.streaming::after {
    content: '▋';
    animation: blink 1s step-end infinite;
    color: var(--accent);
}

/* --- Custom prompts dropdown --- */
.merge-prompts-dropdown { position: relative; width: 100%; }
.merge-prompts-trigger {
    width: 100%;
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: border-color var(--transition-fast);
}
.merge-prompts-trigger:hover,
.merge-prompts-trigger:focus { border-color: var(--accent); outline: none; }
.merge-prompts-trigger-text {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--text-primary);
}
.merge-prompts-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-2);
    z-index: 500;
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
}
.drag-handle {
    display: flex; align-items: center; justify-content: center;
    width: 20px; height: 100%; min-height: 32px;
    background: none; border: none; padding: 0 2px;
    color: var(--text-secondary); opacity: 0.35;
    cursor: grab; touch-action: none; flex-shrink: 0;
    transition: opacity var(--transition-fast);
}
.drag-handle:hover { opacity: 0.75; }
.drag-handle:active { cursor: grabbing; opacity: 1; }
.merge-prompts-item {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background var(--transition-fast);
}
.merge-prompts-item:hover { background: var(--surface-alt); }
.merge-prompts-item.selected { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.merge-prompts-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-prompts-edit-btn {
    opacity: 0;
    background: none; border: none; cursor: pointer;
    color: var(--text-secondary);
    padding: 3px 4px; border-radius: 4px;
    display: flex; align-items: center;
    transition: opacity var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
    flex-shrink: 0;
}
.merge-prompts-item:hover .merge-prompts-edit-btn { opacity: 0.65; }
.merge-prompts-edit-btn:hover { opacity: 1 !important; color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.merge-prompts-add {
    display: flex; align-items: center; gap: 7px;
    padding: 7px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    margin-top: 2px; padding-top: 9px;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.merge-prompts-add:hover { background: var(--surface-alt); color: var(--accent); }

/* --- Prompt editor dialog --- */
.merge-editor-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 14px 0 5px;
}
.merge-editor-label:first-child { margin-top: 0; }
.merge-editor-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: white;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition-fast);
}
[data-theme="dark"] .merge-editor-input { background: var(--surface-alt); }
.merge-editor-input:focus { border-color: var(--accent); }
.merge-editor-input::placeholder { color: var(--text-secondary); }
.merge-editor-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: white;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    min-height: 130px;
    outline: none;
    transition: border-color var(--transition-fast);
}
[data-theme="dark"] .merge-editor-textarea { background: var(--surface-alt); }
.merge-editor-textarea:focus { border-color: var(--accent); }
.merge-editor-textarea::placeholder { color: var(--text-secondary); }

/* --- Card Expand Overlay --- */
.card-expand-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(26, 23, 20, 0.5);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center;
    animation: cardOverlayIn 0.2s ease;
}
.card-expand-overlay.collapsing {
    animation: cardOverlayOut 0.18s ease forwards;
}
.card-expand-inner {
    width: min(825px, 90vw);
    height: 88vh;
    display: flex; flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0,0,0,0.28);
    animation: cardExpandIn 0.22s cubic-bezier(0.34, 1.2, 0.64, 1);
}
.card-expand-inner.collapsing {
    animation: cardExpandOut 0.18s ease forwards;
}
.card-expand-inner .result-panel {
    border: none; border-radius: 0; box-shadow: none;
    height: 100%; display: flex; flex-direction: column; overflow: hidden;
}
.card-expand-inner .result-panel:hover { box-shadow: none; }
.card-expand-inner .result-panel-header {
    border-radius: 0;
    background: var(--surface-focused);
    flex-shrink: 0;
}
.card-expand-inner .result-panel-body {
    flex: 1; overflow-y: auto;
    padding: 18px 22px;
    font-size: 16px;
}
.card-expand-inner .result-panel-footer { flex-shrink: 0; }
.card-expand-inner .result-panel-error { flex-shrink: 0; }

@keyframes cardOverlayIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes cardOverlayOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes cardExpandIn {
    from { transform: scale(0.93); opacity: 0; }
    to   { transform: scale(1.0);  opacity: 1; }
}
@keyframes cardExpandOut {
    from { transform: scale(1.0);  opacity: 1; }
    to   { transform: scale(0.93); opacity: 0; }
}

/* --- Profile Menu --- */
.profile-menu-container {
    position: relative;
}

/* The profile button itself */
.profile-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: var(--radius-md);
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-primary);
    transition: background var(--transition-fast);
    font-family: var(--font-sans);
    text-align: left;
}
.profile-btn:hover { background: var(--border); }

.profile-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    letter-spacing: 0.03em;
}

.profile-btn-name {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Small avatar in the collapsed strip */
.profile-avatar-strip {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    letter-spacing: 0.03em;
}
.strip-profile-btn:hover .profile-avatar-strip {
    opacity: 0.85;
}

/* Pop-up menu */
.profile-menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 199;
}

.profile-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-3);
    z-index: 200;
    overflow: hidden;
    min-width: 200px;
}

.profile-menu-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
}

.profile-avatar-sm {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    letter-spacing: 0.03em;
}

.profile-menu-user-info {
    min-width: 0;
}
.profile-menu-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

.profile-menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    text-align: left;
    transition: background var(--transition-fast);
}
.profile-menu-item:hover { background: var(--surface-alt); }
.profile-menu-item svg { color: var(--text-secondary); flex-shrink: 0; }

/* --- Available Models Dialog --- */
.available-models-modal {
    max-width: 540px;
    width: 100%;
}

.available-models-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.6;
}

.available-models-list {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 20px;
    max-height: 260px;
    overflow-y: auto;
}

.available-models-empty {
    padding: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

.available-models-row {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.available-models-row:last-child { border-bottom: none; }
.available-models-row:hover { background: var(--surface-alt); }

.available-models-id {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.available-models-delete {
    width: 24px; height: 24px;
    border: none; background: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 4px;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: all var(--transition-fast);
}
.available-models-delete:hover { color: var(--destructive); background: color-mix(in srgb, var(--destructive) 10%, transparent); }

.available-models-add-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.available-models-add-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.available-models-textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 10px 12px;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition-fast);
    line-height: 1.6;
}
.available-models-textarea:focus { border-color: var(--accent); }
.available-models-textarea::placeholder { color: var(--text-secondary); opacity: 0.6; }

.available-models-add-btn { align-self: flex-start; }

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.available-models-error {
    font-size: 12px;
    color: var(--destructive);
    flex: 1;
}

/* --- Login Page --- */

.login-page {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg); padding: 24px;
    overflow-y: auto;
}

.login-card {
    background: var(--surface-focused); border: 1px solid var(--border);
    border-radius: 16px; padding: 40px 44px;
    width: 100%; max-width: 400px; box-shadow: var(--shadow-2);
}

.login-logo { height: 28px; width: auto; display: block; margin-bottom: 2px; }
.login-logo-dark { display: none; }
[data-theme="dark"] .login-logo-light { display: none; }
[data-theme="dark"] .login-logo-dark { display: block; }
.login-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 32px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-field label { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.login-field input {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text-primary); font-size: 14px;
    outline: none; transition: border-color 0.15s;
}
.login-field input:focus { border-color: var(--accent); }
.login-field input:disabled { opacity: 0.6; cursor: not-allowed; }
.login-btn { width: 100%; justify-content: center; padding: 11px; font-size: 14px; font-weight: 600; margin-top: 4px; gap: 8px; }
.login-error {
    background: rgba(220, 38, 38, 0.08); border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--destructive);
}
.login-forgot { text-align: center; font-size: 12px; color: var(--text-secondary); }
.login-link {
    background: none; border: none; padding: 0; cursor: pointer;
    font-size: 13px; color: var(--accent); text-align: center;
    text-decoration: underline; text-underline-offset: 2px;
}
.login-link:hover { opacity: 0.8; }
.login-step-title { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.login-step-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; line-height: 1.5; }
.login-spinner {
    display: inline-block; width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
    border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0;
}

/* --- Manage Users Modal --- */

.manage-users-modal { width: 560px; max-width: 96vw; max-height: 80vh; display: flex; flex-direction: column; }
.manage-users-list { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; margin-bottom: 4px; }
.manage-users-loading, .manage-users-empty { padding: 16px 0; font-size: 13px; color: var(--text-secondary); text-align: center; }
.manage-users-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; background: var(--surface); }
.manage-users-avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
    color: #fff; font-size: 12px; font-weight: 600;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.manage-users-info { flex: 1; min-width: 0; }
.manage-users-name { font-size: 13px; font-weight: 500; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.manage-users-email { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.manage-users-status { flex-shrink: 0; }
.status-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.status-active { background: rgba(34, 197, 94, 0.12); color: #16a34a; }
.status-pending { background: rgba(234, 179, 8, 0.12); color: #a16207; }
.manage-users-resend {
    font-size: 11px; padding: 3px 9px; height: auto;
    color: var(--text-secondary); border-color: var(--border);
    background: transparent; white-space: nowrap;
}
.manage-users-resend:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); background: transparent; }
.manage-users-delete { color: var(--text-secondary); opacity: 0.6; }
.manage-users-delete:hover { opacity: 1; color: var(--destructive); }
.manage-users-confirm {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 10px 12px; background: rgba(220, 38, 38, 0.06);
    border: 1px solid rgba(220, 38, 38, 0.2); border-radius: 8px;
    font-size: 13px; color: var(--text-primary); margin-top: 8px;
}
.manage-users-confirm-actions { display: flex; gap: 8px; margin-left: auto; }
.manage-users-error { font-size: 12px; color: var(--destructive); margin-top: 6px; }
.manage-users-success { font-size: 12px; color: #16a34a; margin-top: 6px; }
.manage-users-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.manage-users-add { display: flex; flex-direction: column; gap: 10px; }
.manage-users-add-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.manage-users-add-fields { display: flex; gap: 8px; flex-wrap: wrap; }
.manage-users-add-fields input {
    flex: 1; min-width: 140px; padding: 8px 11px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text-primary); font-size: 13px;
    outline: none; transition: border-color 0.15s;
}
.manage-users-add-fields input:focus { border-color: var(--accent); }
.manage-users-add-fields input.input-error { border-color: var(--destructive); }
.manage-users-add-fields input:disabled { opacity: 0.6; }
.profile-menu-signout { color: var(--destructive) !important; }
.profile-menu-signout svg { color: var(--destructive) !important; }

/* --- Mobile --- */
@media (max-width: 767px) {
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; height: 100dvh; z-index: 80;
        transform: translateX(-100%); width: var(--sidebar-w) !important;
        min-width: var(--sidebar-w) !important;
    }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-3); }
    .sidebar-overlay {
        position: fixed; inset: 0;
        background: rgba(26, 23, 20, 0.4); z-index: 79;
    }
    .results-grid.cols-3,
    .results-grid.cols-4 { grid-template-columns: minmax(280px, 1fr); }
    .model-selector-slots { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   MEETING SUMMARIZER — scoped sub-app (blue accent)
   ============================================================ */

[data-app="meeting-notes"] {
    --accent:        #4B7DC9;
    --accent-hover:  #3E6AB1;
}

.mn-shell {
    position: fixed;
    inset: 0;
    left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--bg);
    z-index: 40;
    overflow: hidden;
}

.app-shell.sidebar-collapsed .mn-shell { left: 48px; }

/* Top bar */
.mn-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}
.mn-topbar-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 600;
    color: var(--accent);
}
.mn-exit-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.mn-exit-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* Grid */
.mn-grid {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(340px, 1fr) minmax(340px, 1fr);
    gap: 16px;
    padding: 16px;
    overflow: hidden;
    min-height: 0;
}
.mn-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    min-width: 0;
}
.mn-col-left .mn-transcript-card { flex: 1 1 60%; min-height: 0; }
.mn-col-left .mn-processing-card { flex: 0 0 auto; }

/* Card */
.mn-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.mn-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.mn-card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.mn-card-actions { display: flex; gap: 6px; align-items: center; }
.mn-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.mn-speakers { flex: 1; }
.mn-wordcount { font-weight: 600; color: var(--text-primary); }

/* Transcript textarea */
.mn-transcript {
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: 14px 16px;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background: #ffffff;
    border: none;
    outline: none;
    resize: none;
}
[data-theme="dark"] .mn-transcript { background: var(--surface); }
.mn-transcript::placeholder { color: var(--text-secondary); opacity: 0.7; }

.mn-header-search {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    flex: 1;
    margin: 0 12px;
    min-width: 0;
}
.mn-header-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    min-width: 0;
}
.mn-header-search-input::placeholder { color: var(--text-secondary); opacity: 0.7; }
.mn-header-search-input:disabled { cursor: not-allowed; opacity: 0.5; }
.mn-transcript-search-clear {
    display: inline-flex;
    padding: 3px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
}
.mn-transcript-search-clear:hover { color: var(--text-primary); background: rgba(0,0,0,0.06); }
.mn-search-mode-toggle {
    display: none;
    align-items: center;
    padding: 2px 7px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    flex-shrink: 0;
}
.mn-header-search:focus-within .mn-search-mode-toggle,
.mn-header-search.has-query .mn-search-mode-toggle { display: inline-flex; }
.mn-search-mode-toggle:hover:not(:disabled) { color: var(--text-primary); border-color: var(--text-secondary); }
.mn-search-mode-toggle.exact { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.mn-search-mode-toggle.exact:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.mn-search-mode-toggle:disabled { opacity: 0.4; cursor: not-allowed; }

.mn-transcript-filtered {
    padding: 12px 16px;
    overflow-y: auto;
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-primary);
}
.mn-filter-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}
.mn-filter-row {
    padding: 6px 0;
    border-bottom: 1px dashed var(--border);
    white-space: pre-wrap;
    word-break: break-word;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    border-radius: 4px;
    padding-left: 6px;
    padding-right: 6px;
    margin: 0 -6px;
}
.mn-filter-row:last-child { border-bottom: none; }
.mn-filter-row:hover {
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    color: var(--accent);
}
.mn-filter-row mark {
    background: color-mix(in srgb, var(--accent) 30%, transparent);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}
.mn-filter-empty {
    padding: 24px 0;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

/* --- Transcript context (full-view) --- */
.mn-transcript-context {
    padding: 12px 16px;
    overflow-y: auto;
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-primary);
}
.mn-context-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 10px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.mn-context-back {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    white-space: nowrap;
}
.mn-context-info {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mn-context-line {
    padding: 3px 0;
    white-space: pre-wrap;
    word-break: break-word;
}
.mn-context-line mark {
    background: color-mix(in srgb, var(--accent) 30%, transparent);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

.mn-dropdown-backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 45;
}

/* Processing card */
.mn-processing-card { padding-bottom: 14px; overflow: visible; }
.mn-controls-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    padding: 14px 16px 10px;
}
.mn-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.mn-field-grow { flex: 1; }
.mn-field-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Dropdowns */
.mn-dropdown { position: relative; }
.mn-dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-width: 0;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    transition: border-color var(--transition-fast);
}
[data-theme="dark"] .mn-dropdown-trigger { background: var(--surface-alt); }
.mn-dropdown-trigger:hover { border-color: var(--accent); }
.mn-dropdown-trigger > span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mn-dropdown-menu {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-2);
    z-index: 50;
    max-height: 320px;
    overflow-y: auto;
    padding: 4px;
}
.mn-dropdown-menu-models { min-width: 260px; }
.mn-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    font-size: 13px;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.mn-dropdown-item:hover { background: var(--surface-alt); }
.mn-dropdown-item.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.mn-dropdown-item-edit {
    display: inline-flex;
    padding: 3px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.mn-dropdown-item:hover .mn-dropdown-item-edit { opacity: 1; }
.mn-dropdown-item-edit:hover { color: var(--accent); background: rgba(0,0,0,0.04); }
.mn-dropdown-group-label {
    padding: 6px 10px 3px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.mn-dropdown-empty { padding: 14px 10px; font-size: 12px; color: var(--text-secondary); text-align: center; }
.mn-dropdown-add {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.mn-dropdown-add:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* Buttons */
.mn-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.mn-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.mn-btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.mn-btn-ghost:hover:not(:disabled) { color: var(--text-primary); border-color: var(--text-secondary); }
.mn-btn-secondary {
    background: #ffffff;
    color: var(--text-primary);
    border-color: var(--border);
}
[data-theme="dark"] .mn-btn-secondary { background: var(--surface-alt); }
.mn-btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.mn-btn-primary {
    background: var(--accent);
    color: #ffffff;
}
.mn-btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.mn-btn-copied { background: #2E7D4F !important; }
.mn-generate-btn {
    margin: 4px 16px 0;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    justify-content: center;
    position: relative;
}
.mn-stop-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    padding: 3px 10px;
    font-size: 12px;
    background: rgba(255,255,255,0.2);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 4px;
    cursor: pointer;
}

/* Summary body (contenteditable) */
.mn-summary-card { flex: 1; min-height: 0; }
.mn-summary-body {
    flex: 1;
    min-height: 0;
    padding: 18px 22px;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    background: #ffffff;
    overflow-y: auto;
    outline: none;
}
[data-theme="dark"] .mn-summary-body { background: var(--surface); }
.mn-summary-body:empty::before {
    content: 'Summary will appear here. After it generates, click anywhere to edit.';
    color: var(--text-secondary);
    opacity: 0.7;
}
.mn-summary-body.generating { background: #fcfbf7; }
[data-theme="dark"] .mn-summary-body.generating { background: var(--surface); }
.mn-summary-body h1 { font-size: 20px; font-weight: 700; margin: 20px 0 10px; }
.mn-summary-body h2 { font-size: 18px; font-weight: 700; margin: 18px 0 10px; }
.mn-summary-body h3 { font-size: 16px; font-weight: 600; margin: 14px 0 8px; }
.mn-summary-body h1:first-child,
.mn-summary-body h2:first-child,
.mn-summary-body h3:first-child { margin-top: 0; }
.mn-summary-body p { margin: 0 0 12px; }
.mn-summary-body ul,
.mn-summary-body ol { margin: 0 0 14px; padding-left: 28px; }
.mn-summary-body li { margin: 4px 0; }
.mn-summary-body strong { font-weight: 700; }
.mn-summary-body em { font-style: italic; }
.mn-summary-body code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--surface-alt);
    padding: 1px 5px;
    border-radius: 3px;
}
.mn-summary-body .mn-md-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 14px;
    margin: 8px 0 16px;
}
.mn-summary-body .mn-md-table th,
.mn-summary-body .mn-md-table td {
    border: 1px solid var(--border);
    padding: 7px 12px;
    text-align: left;
}
.mn-summary-body .mn-md-table thead { background: var(--surface-alt); font-weight: 600; }
.mn-summary-body .mn-stamp {
    margin-top: 18px;
    font-style: italic;
    color: var(--text-secondary);
}

/* Versions bar */
.mn-versions-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
    flex-shrink: 0;
}
.mn-versions-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.mn-version-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 4px 3px 10px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
}
[data-theme="dark"] .mn-version-chip { background: var(--surface-alt); }
.mn-version-load {
    background: transparent;
    border: none;
    padding: 0;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 500;
}
.mn-version-load:hover { color: var(--accent); }
.mn-version-chip.active {
    border: 1.5px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.mn-version-chip.active .mn-version-load { color: var(--accent); font-weight: 600; }
.mn-version-del {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
}
.mn-version-del:hover { background: var(--surface-alt); color: var(--destructive); }
.mn-save-version-btn { padding: 4px 10px; font-size: 12px; }

/* Email trigger button in versions bar — right-aligned */
.mn-email-trigger {
    margin-left: auto;
    padding: 4px 10px;
    font-size: 12px;
    color: var(--accent);
    border: 1px solid var(--accent);
    background: transparent;
}
.mn-email-trigger:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    color: var(--accent);
}

/* Email side panel */
.mn-email-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 199;
    animation: mn-fade-in 180ms ease-out;
}
@keyframes mn-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.mn-email-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: clamp(360px, 44vw, 620px);
    z-index: 200;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -6px 0 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 320ms cubic-bezier(0.4, 0, 0.2, 1);
}
.mn-email-panel.visible { transform: translateX(0); }
.mn-email-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 48px;
    color: var(--accent);
}
.mn-email-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}
.mn-email-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.mn-email-generate-btn {
    padding: 5px 10px;
    font-size: 12px;
    gap: 5px;
}

/* Email-panel dropdowns drop DOWN (controls sit at top of panel) */
.mn-email-panel .mn-dropdown-menu {
    bottom: auto;
    top: calc(100% + 4px);
}
/* Click-outside backdrop scoped to the email panel stacking context */
.mn-email-dropdown-backdrop {
    position: absolute;
    inset: 0;
    background: transparent;
    z-index: 45;
}
.mn-email-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
}
.mn-email-close:hover { background: rgba(0,0,0,0.06); color: var(--text-primary); }
.mn-email-controls {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface);
    overflow: visible;
}
.mn-email-body-wrap {
    flex: 1;
    overflow-y: auto;
    background: #ffffff;
    min-height: 0;
}
[data-theme="dark"] .mn-email-body-wrap { background: var(--surface); }
.mn-email-body {
    padding: 18px 22px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    outline: none;
    min-height: 100%;
}
.mn-email-body.generating { cursor: wait; }
.mn-email-body p             { margin: 0 0 1em; }
.mn-email-body p:last-child  { margin-bottom: 0; }
.mn-email-body h1            { font-size: 1.35em; font-weight: 700; margin: 1.2em 0 0.75em; }
.mn-email-body h2            { font-size: 1.25em; font-weight: 700; margin: 1.2em 0 0.7em; }
.mn-email-body h3            { font-size: 1.17em; font-weight: 700; margin: 1.17em 0 0.65em; }
.mn-email-body ul,
.mn-email-body ol            { margin: 1em 0; padding-left: 1.75em; }
.mn-email-body li            { margin: 0; }
.mn-email-body strong        { font-weight: 700; }
.mn-email-body em            { font-style: italic; }
.mn-email-body code          {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--surface-alt);
    padding: 1px 5px;
    border-radius: 3px;
}
.mn-email-body .mn-stamp {
    margin-top: 18px;
    font-style: italic;
    color: var(--text-secondary);
}
.mn-email-versions-bar { flex-wrap: wrap; }
.mn-email-copy { margin-left: auto; padding: 6px 12px; font-size: 12px; }

/* Spinner */
.mn-spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Library modal */
.lib-popup {
    max-width: 900px;
    width: 92vw;
    height: 70vh;
    display: flex;
    flex-direction: column;
}
.lib-body {
    flex: 1;
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 0;
    overflow: hidden;
}
.lib-list {
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 8px;
}
.lib-list-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 2px;
}
.lib-list-item:hover { background: var(--surface-alt); }
.lib-list-item.selected { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.lib-list-item.mine {
    border-left: 3px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.lib-list-item.mine .lib-list-item-name { color: var(--accent); }
.lib-list-item.mine.selected { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.lib-list-item.theirs { opacity: 0.78; }
.lib-list-item.theirs:hover { opacity: 1; }
.lib-list-item.theirs.selected { opacity: 1; }
.lib-section-label {
    padding: 10px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}
.lib-section-divider {
    margin: 8px 6px;
    border-top: 1px solid var(--border);
}
.lib-list-item-name { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 3px; }
.lib-list-item-meta {
    display: flex;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
}
.lib-owner { font-weight: 500; }
.lib-detail { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; }
.lib-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}
.lib-detail-title { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.lib-detail-sub { font-size: 12px; color: var(--text-secondary); }
.lib-detail-body {
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-primary);
    flex: 1;
}
.lib-detail-body h1 { font-size: 17px; font-weight: 700; margin: 10px 0 6px; }
.lib-detail-body h2 { font-size: 15px; font-weight: 700; margin: 8px 0 6px; }
.lib-detail-body p { margin: 0 0 10px; }
.lib-detail-body ul, .lib-detail-body ol { margin: 0 0 10px; padding-left: 24px; }
.lib-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Find & Replace modal */
.fr-popup { max-width: 440px; }
.fr-body { padding: 16px; display: flex; flex-direction: column; }
.fr-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}
.fr-checkbox input { cursor: pointer; }
.fr-result {
    margin-top: 14px;
    padding: 8px 12px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--accent);
    font-weight: 500;
}

/* Exit confirm popup */
.mn-confirm-popup { max-width: 440px; }
.mn-confirm-body {
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

/* Responsive */
@media (max-width: 900px) {
    .mn-grid { grid-template-columns: 1fr; grid-template-rows: auto auto auto; overflow-y: auto; }
    .mn-col-left .mn-transcript-card { min-height: 240px; }
    .mn-col-right { min-height: 300px; }
    .mn-controls-row { flex-wrap: wrap; }
    .lib-body { grid-template-columns: 1fr; }
    .lib-list { max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
}

/* --- Usage Tracker Modal --- */
.usage-tracker-modal { max-width: 500px; }

.usage-body { background: #ffffff; padding: 20px 24px 24px; }
[data-theme="dark"] .usage-body { background: var(--surface-alt); }

.usage-loading {
    text-align: center;
    padding: 36px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.usage-table {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 22px;
    font-variant-numeric: tabular-nums;
}

.usage-table-header {
    display: grid;
    grid-template-columns: 1fr 72px 88px;
    padding: 9px 16px;
    background: var(--surface-alt);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.usage-table-header span:not(:first-child),
.usage-table-row .usage-num,
.usage-table-row .usage-cost,
.usage-table-total .usage-num,
.usage-table-total .usage-cost { text-align: right; }

.usage-table-row {
    display: grid;
    grid-template-columns: 1fr 72px 88px;
    padding: 11px 16px;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    transition: background 120ms;
}

.usage-table-row:last-of-type { border-bottom: none; }
.usage-table-row:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }

.usage-table-total {
    display: grid;
    grid-template-columns: 1fr 72px 88px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface-alt);
    border-top: 2px solid var(--border);
}

.usage-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.usage-models { display: flex; flex-direction: column; gap: 12px; }

.usage-model-row { display: flex; flex-direction: column; gap: 5px; }

.usage-model-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.usage-model-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.usage-model-stat {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.usage-model-bar-wrap {
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.usage-model-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    min-width: 2px;
    transition: width 500ms ease-out;
}

/* ===== Company Dashboard ===== */

/* Scoped green accent so the dashboard reads as a distinct section
   (mirrors the [data-app="meeting-notes"] blue pattern). */
[data-app="company-dashboard"] {
    --accent: #4A8A5C;
    --accent-hover: #3D7349;
}
[data-app="company-dashboard"][data-theme="dark"] {
    --accent: #6FB07F;
    --accent-hover: #5C9C6C;
}

.cd-shell {
    position: fixed;
    inset: 0;
    left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--bg);
    z-index: 40;
    overflow: auto;
}
.app-shell.sidebar-collapsed .cd-shell { left: 48px; }

.cd-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}
.cd-topbar-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 600;
    color: var(--accent);
}
.cd-exit-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.cd-exit-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.cd-timeframe-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 14px 22px 0;
    flex-shrink: 0;
}
.cd-tab {
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.cd-tab:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}
.cd-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.cd-custom-range {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
    padding: 12px 22px 0;
}
.cd-range-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cd-range-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.cd-range-field input[type="date"] {
    padding: 6px 10px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-width: 150px;
}
.cd-range-hint { font-family: inherit; }
.cd-range-field input[type="date"]:focus {
    outline: none;
    border-color: var(--accent);
}
.cd-range-hint {
    font-size: 12px;
    color: var(--text-secondary);
    padding-bottom: 7px;
}

.cd-loading,
.cd-empty {
    padding: 40px 22px;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

.cd-summary-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    padding: 16px 22px 0;
}
.cd-summary-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
}
.cd-summary-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.cd-summary-value {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 4px;
}

.cd-section {
    padding: 18px 22px;
}
.cd-section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

/* User table */
.cd-user-table {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.cd-user-row {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) 1fr 1fr 1fr;
    gap: 16px;
    padding: 12px 18px;
    align-items: center;
    border-bottom: 1px solid var(--border);
}
.cd-user-row:last-child { border-bottom: none; }
.cd-user-header {
    background: var(--surface-alt);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    font-weight: 600;
}
.cd-user-total {
    background: var(--surface-alt);
    border-top: 2px solid var(--border);
    font-weight: 600;
}
.cd-user-total .cd-col-num,
.cd-user-total .cd-user-name { font-weight: 600; }
.cd-col-name {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0;
}
.cd-col-num {
    text-align: right;
    font-size: 14px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.cd-sort-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: inherit;
    font: inherit;
    padding: 0;
    text-transform: inherit;
    letter-spacing: inherit;
    font-weight: inherit;
}
.cd-sort-btn:hover { color: var(--text-primary); }
.cd-sort-btn.active { color: var(--accent); }

.cd-bar-wrap {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    pointer-events: none;
    padding-right: 6px;
}
.cd-user-bar {
    height: 28px;
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    border-left: 3px solid var(--accent);
    border-radius: 3px;
    min-width: 3px;
    transition: width 350ms ease-out;
}
.cd-user-name {
    position: relative;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    z-index: 1;
    padding-left: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Top 5 Models bar chart */
.cd-top-models-chart {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 22px 18px 14px;
    align-items: end;
    min-height: 280px;
}
.cd-bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
}
.cd-bar-track {
    width: 100%;
    max-width: 80px;
    height: 180px;
    background: transparent;
    display: flex;
    align-items: flex-end;
    overflow: visible;
}
.cd-bar-fill {
    position: relative;
    width: 100%;
    background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #000));
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: height 500ms ease-out;
}
.cd-bar-stat {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.cd-bar-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.25;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
    max-width: 100%;
}
.cd-bar-cost {
    font-size: 13px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
    .cd-user-row { grid-template-columns: minmax(140px, 1.4fr) 1fr 1fr 1fr; gap: 10px; padding: 10px 12px; }
    .cd-summary-bar { padding: 12px 14px 0; }
    .cd-section { padding: 14px; }
    .cd-top-models-chart { grid-template-columns: repeat(5, 1fr); gap: 8px; }
    .cd-bar-track { height: 130px; }
}
