/* ============================================================
   TRIP — Edge I/O Technical ChatBot · style.css
   Flat surfaces · hairline borders · single green accent
   Integrated from the Claude Design handoff bundle (2026-06-11):
   prototype selectors remapped onto the app's contractual DOM.
   ============================================================ */

/* ---------- TOKENS ---------- */
:root,
[data-theme="dark"] {
    --bg: #0A0E14;
    --surface: #111722;
    --surface-2: #18202E;
    --border: #1C2533;
    --border-strong: #2B3850;

    --text: #E8EDF4;
    --text-2: #94A0B4;
    --text-3: #5E6A7E;

    --accent: #3DCD58;
    --accent-text: #3DCD58;
    --on-accent: #08130B;
    --accent-soft: rgba(61, 205, 88, .12);
    --accent-ring: rgba(61, 205, 88, .35);
    --accent-dim: var(--accent-soft);

    --danger: #E5655E;
    --danger-soft: rgba(229, 101, 94, .13);
    --danger-dim: var(--danger-soft);
    --warning: #D9A03F;
    --warning-soft: rgba(217, 160, 63, .13);
    --warning-rgb: 217, 160, 63;
    --danger-rgb: 229, 101, 94;

    --scrim: rgba(4, 7, 12, .62);
    --shadow-panel: 0 18px 50px -12px rgba(0, 0, 0, .55), 0 1px 0 rgba(255, 255, 255, .02) inset;
    --shadow-drawer: 0 0 40px rgba(0, 0, 0, .4);
    --focus-ring: 0 0 0 3px var(--accent-soft);

    --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="light"] {
    --bg: #F7F8FA;
    --surface: #FFFFFF;
    --surface-2: #F0F2F6;
    --border: #E3E7EE;
    --border-strong: #D2D8E2;

    --text: #171C26;
    --text-2: #5A6675;
    --text-3: #8A93A3;

    --accent: #3DCD58;
    --accent-text: #177D33;
    --on-accent: #08130B;
    --accent-soft: rgba(23, 125, 51, .10);
    --accent-ring: rgba(61, 205, 88, .40);

    --danger: #D24840;
    --danger-soft: rgba(210, 72, 64, .10);
    --warning-rgb: 185, 131, 46;
    --danger-rgb: 210, 72, 64;
    --warning-soft: rgba(185, 131, 46, .12);

    --scrim: rgba(23, 28, 38, .34);
    --shadow-panel: 0 18px 50px -12px rgba(23, 28, 38, .25);
    --shadow-drawer: 0 0 40px rgba(23, 28, 38, .25);
}

/* ---------- MOTION ---------- */
:root {
    --ease: cubic-bezier(0.2, 0, 0, 1);
    --t-fast: 90ms;
    --t-base: 180ms;
    --t-panel: 200ms;
    --t-theme: 200ms;
}

/* ---------- BASE ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
.hidden { display: none !important; }

html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 13px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background var(--t-theme) var(--ease), color var(--t-theme) var(--ease);
}

/* theme cross-fade on the structural surfaces */
.app, .sidebar, .main, .topbar, .input-bar, .panel, .messages,
.action-btn, .icon-btn, .tag, .conv-item, .suggestion-chip, .banner,
.nav-item, .candidate-item, .radio-card-inner, .toast, .msg-bubble, .source-chip,
.settings-select, .settings-input, .session-row {
    transition: background-color var(--t-theme) var(--ease),
                border-color var(--t-theme) var(--ease),
                color var(--t-theme) var(--ease);
}

/* mono micro-label helper */
.nav-label, .sources-label, .msg-meta, .panel-eyebrow,
.session-key, .session-val, .presets-label, .confidence-label, .conf-value,
.topbar-credit, .tag, .suggestion-icon, .candidate-id, .chip-score,
.src-badge, .rerank-score, .conv-meta, .chunk-filter-count, .wf-step,
.welcome-badge, .source-detail-tag, .settings-hint code {
    font-family: var(--font-mono);
}

::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 2px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ============================================================
   LAYOUT
   ============================================================ */
.app {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: 100vh;
    height: 100vh;
    overflow: hidden;
}
.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    position: relative;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 14px 12px 12px;
    z-index: 40;
}

.sidebar-brand { padding: 2px 4px 12px; }
.brand-logo-plate {
    display: flex;
    align-items: center;
    background: #FFFFFF;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 10px;
}
.brand-logo { display: block; height: 24px; width: auto; }
.brand-text h1 {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--text-3);
    margin: 10px 2px 0;
    font-family: var(--font-mono);
}

.sidebar-nav { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
.nav-group { padding: 10px 4px 4px; }
.nav-group:last-child { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.nav-label {
    display: block;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-3);
    padding: 0 6px 7px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 12.5px;
    color: var(--text-2);
}
.nav-item:hover { background: var(--surface-2); }
.nav-icon { display: inline-flex; width: 14px; height: 14px; color: var(--text-3); flex: none; }
.nav-icon svg { width: 14px; height: 14px; }
.nav-item > span:not(.nav-icon):not(.status-dot) { flex: 1; }

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 1.5px;
    flex: none;
    background: var(--text-3);
}
.status-dot.online { background: var(--accent); }
.status-dot.offline { background: var(--danger); }
.status-dot.unknown { background: var(--text-3); }

.session-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 7px 10px;
    margin-bottom: 4px;
}
.session-key {
    min-width: 34px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-3);
}
.session-val { font-size: 11.5px; color: var(--text-2); }

/* ---------- Conversation history ---------- */
.conv-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0 2px;
}
.conv-empty {
    text-align: center;
    padding: 30px 10px;
    color: var(--text-2);
    font-size: 12.5px;
    margin: 0;
}
.conv-empty::before {
    content: "";
    display: block;
    width: 26px;
    height: 26px;
    margin: 0 auto 10px;
    border: 1.5px dashed var(--border-strong);
    border-radius: 6px;
}
.conv-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    position: relative;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); border-color: var(--border-strong); }
.conv-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 2px;
    background: var(--accent);
    border-radius: 2px;
}
.conv-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.conv-title {
    font-size: 12.5px;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item.active .conv-title { color: var(--text); }
.conv-meta { font-size: 10px; color: var(--text-3); letter-spacing: .04em; }
.conv-delete {
    flex: none;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 0;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: grid;
    place-items: center;
    opacity: 0;
    transition: opacity var(--t-fast) var(--ease),
                background-color var(--t-fast) var(--ease),
                color var(--t-fast) var(--ease);
}
.conv-item:hover .conv-delete, .conv-delete:focus-visible { opacity: 1; }
.conv-delete:hover { background: var(--danger-soft); color: var(--danger); }

.sidebar-footer { padding-top: 10px; border-top: 1px solid var(--border); margin-top: 6px; }
.sidebar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    padding: 8px 13px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    transition: background-color var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                transform var(--t-fast) var(--ease);
}
.sidebar-btn:active { transform: translateY(.5px); }
.sidebar-btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); font-weight: 600; }
.sidebar-btn-primary:hover { background: #46D862; }

/* ============================================================
   STATUS BANNER
   ============================================================ */
.banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 80;
    background: var(--warning-soft);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(6px);
    animation: bannerIn var(--t-panel) var(--ease);
}
.banner-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    font-size: 12.5px;
    color: var(--text);
}
.banner-inner::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 2px;
    background: var(--warning);
    flex: none;
    animation: ledPulse 1.6s ease-in-out infinite;
}
@keyframes bannerIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes ledPulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    height: 56px;
    flex: none;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.topbar-title { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-title h2 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -.01em; white-space: nowrap; }
.topbar-tags { display: flex; gap: 6px; min-width: 0; overflow: hidden; }
.tag {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 3px 7px;
    white-space: nowrap;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar-credit {
    font-size: 9.5px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-3);
    margin-right: 6px;
    white-space: nowrap;
}

.icon-btn, .theme-toggle {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    display: grid;
    place-items: center;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-2);
    cursor: pointer;
    padding: 0;
    transition: background-color var(--t-fast) var(--ease),
                color var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease);
}
.icon-btn:hover, .theme-toggle:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn:active, .theme-toggle:active { transform: translateY(.5px); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn:disabled:hover { background: transparent; border-color: transparent; color: var(--text-2); }
.icon-btn svg, .theme-toggle svg { width: 15px; height: 15px; }
.mobile-toggle { display: none; }
.drawer-scrim { display: none; }

/* ============================================================
   CHAT
   ============================================================ */
.messages {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    padding: 30px 24px 18px;
}
.messages > .msg, .messages > .skeleton, .welcome { max-width: 760px; margin-left: auto; margin-right: auto; }

/* ---------- Welcome ---------- */
.welcome { padding: 38px 0 8px; }
.welcome-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 11px;
}
.welcome-badge svg { width: 12px; height: 12px; color: var(--accent-text); }
.welcome h2 {
    font-size: 17px;
    line-height: 1.45;
    font-weight: 600;
    letter-spacing: -.015em;
    margin: 18px 0 10px;
    text-wrap: pretty;
}
.welcome p { color: var(--text-2); font-size: 13px; margin: 0 0 24px; max-width: 62ch; }
.presets-label {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-3);
    margin-bottom: 10px;
}
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suggestion-chip {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 13px 14px;
    cursor: pointer;
    color: var(--text);
    font: inherit;
    transition: border-color var(--t-base) var(--ease),
                background-color var(--t-base) var(--ease),
                transform var(--t-base) var(--ease);
}
.suggestion-chip:hover { border-color: var(--border-strong); background: var(--surface-2); transform: translateY(-1px); }
.suggestion-icon {
    font-size: 10px;
    letter-spacing: .06em;
    color: var(--accent-text);
    background: var(--accent-soft);
    border-radius: 4px;
    padding: 3px 5px;
    flex: none;
    margin-top: 1px;
}
.suggestion-text { font-size: 12.5px; line-height: 1.4; color: var(--text); }

/* ---------- Messages ---------- */
.msg {
    display: flex;
    flex-direction: column;
    margin-bottom: 26px;
    animation: msgIn var(--t-base) var(--ease);
}
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg-avatar { display: none; }
.msg-body { display: flex; flex-direction: column; min-width: 0; }
.msg-meta {
    order: -1;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-3);
    margin-bottom: 7px;
    display: flex;
    gap: 8px;
    align-items: center;
}
.msg-meta .msg-role { color: var(--text-2); }

.msg-bubble {
    width: fit-content;
    max-width: 80%;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    padding: 10px 13px;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--text);
    background: var(--surface);
}
.msg-user .msg-body { align-items: flex-end; }
.msg-user .msg-meta { justify-content: flex-end; }
.msg-user .msg-bubble { border-top-right-radius: 4px; background: var(--surface-2); }

/* assistant answers read as a document, not a bubble */
.msg-bot .msg-bubble {
    border: 0;
    background: transparent;
    padding: 0;
    max-width: 100%;
    width: 100%;
    border-radius: 0;
    font-size: 13.5px;
    line-height: 1.65;
}

.msg-system .msg-bubble {
    border-color: var(--border);
    background: var(--surface);
    color: var(--text-2);
    font-size: 12.5px;
}
.msg-error .msg-bubble {
    border-color: var(--danger);
    background: var(--danger-soft);
    color: var(--text);
    font-size: 12.5px;
}

/* markdown inside answers */
.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4 {
    font-size: 13px;
    margin: 16px 0 7px;
    font-weight: 600;
}
.msg-content ul, .msg-content ol { margin: 0 0 12px; padding-left: 18px; }
.msg-content li { margin: 3px 0; }
.msg-content strong { font-weight: 600; color: var(--text); }
.msg-content a { color: var(--accent-text); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.msg-content code {
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
}
.msg-content pre {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 0 0 12px;
}
.msg-content pre code {
    background: none;
    border: 0;
    padding: 0;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-2);
    display: block;
}
.msg-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 12px;
    font-size: 12.5px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.msg-content th {
    text-align: left;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .07em;
    font-weight: 500;
    padding: 8px 11px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
}
.msg-content td { padding: 8px 11px; border-bottom: 1px solid var(--border); color: var(--text); }
.msg-content tr:last-child td { border-bottom: 0; }

/* streaming caret */
.msg-streaming .msg-content::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 14px;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--accent);
    border-radius: 1px;
    animation: blink 1s steps(1) infinite;
}
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ---------- Skeleton ---------- */
.skeleton { margin-bottom: 26px; }
.skeleton .msg-avatar { display: none; }
.skeleton-bubble { display: flex; flex-direction: column; gap: 9px; padding-top: 2px; }
.skeleton-line {
    height: 11px;
    border-radius: 4px;
    background: var(--surface-2);
    animation: skpulse 1.6s ease-in-out infinite;
}
.skeleton-line:nth-child(1) { width: 92%; }
.skeleton-line:nth-child(2) { width: 78%; animation-delay: .15s; }
.skeleton-line:nth-child(3) { width: 64%; animation-delay: .3s; }
@keyframes skpulse { 0%, 100% { opacity: .4; } 50% { opacity: .85; } }

/* ============================================================
   SOURCES
   ============================================================ */
.sources-slot { margin-top: 13px; }
.sources-container { display: flex; flex-direction: column; gap: 9px; }
.sources-label {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-3);
}
.confidence-bar { display: flex; align-items: center; gap: 9px; }
.confidence-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-3);
}
.confidence-track {
    flex: 1;
    max-width: 180px;
    height: 4px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
}
.confidence-fill { height: 100%; border-radius: 2px; background: var(--text-3); transition: width var(--t-base) var(--ease); }
.confidence-fill.high { background: var(--accent); }
.confidence-fill.medium { background: var(--warning); }
.confidence-fill.low { background: var(--danger); }
.conf-value { font-size: 10px; color: var(--text-2); }

.source-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.source-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 5px 9px;
    cursor: pointer;
    font-size: 11.5px;
    color: var(--text-2);
    transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.source-chip:hover { border-color: var(--border-strong); background: var(--surface-2); }
.source-chip-hotfix { border-color: var(--danger); }

.chip-score {
    font-size: 10px;
    letter-spacing: .04em;
    padding: 2px 5px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text-2);
}
.chip-score.high { color: var(--accent-text); background: var(--accent-soft); }
.chip-score.medium { color: var(--warning); background: var(--warning-soft); }
.chip-score.low { color: var(--text-3); }

.src-badge {
    font-size: 9px;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 2px 5px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text-2);
}
.src-badge-hotfix { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }
.src-badge-variant { background: var(--accent-soft); color: var(--accent-text); }
.rerank-score { font-size: 9.5px; color: var(--text-3); }

.source-detail {
    display: none;
    border: 1px solid var(--border);
    border-left: 2px solid var(--accent);
    border-radius: 8px;
    background: var(--surface);
    padding: 12px 14px;
    margin-top: 9px;
    overflow: hidden;
}
.source-detail.open { display: block; animation: detailIn var(--t-panel) var(--ease); }
@keyframes detailIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.source-detail-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.source-detail-tag {
    font-size: 10px;
    color: var(--text-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
}
.source-detail-text { font-size: 12.5px; color: var(--text-2); line-height: 1.6; }
.sd-actions { display: flex; gap: 8px; margin-top: 11px; }
.sd-actions .action-btn { padding: 5px 10px; font-size: 11.5px; }

/* ============================================================
   COMPOSER
   ============================================================ */
.input-bar {
    flex: none;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 14px 24px 16px;
}
.input-container {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 8px 8px 13px;
    transition: border-color var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}
.input-container:focus-within { border-color: var(--accent-ring); box-shadow: var(--focus-ring); }
#user-input {
    flex: 1;
    background: none;
    border: 0;
    color: var(--text);
    font: inherit;
    font-size: 13.5px;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 160px;
    padding: 5px 0;
}
#user-input::placeholder { color: var(--text-3); }
.send-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 8px;
    flex: none;
    border: 0;
    background: var(--accent);
    color: var(--on-accent);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}
.send-btn:hover { background: #46D862; }
.send-btn:active { transform: translateY(.5px); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.send-btn:disabled:hover { background: var(--accent); }
.send-btn svg { width: 15px; height: 15px; }
.input-hint {
    max-width: 760px;
    margin: 8px auto 0;
    padding: 0 2px;
    font-size: 11px;
    color: var(--text-3);
}

/* ── Image attachment (multimodal) ── */
.attach-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 8px;
    flex: none;
    border: 0;
    background: none;
    color: var(--text-3);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.attach-btn:hover { background: var(--surface); color: var(--text-2); }
.attach-btn:active { transform: translateY(.5px); }
.attach-btn svg { width: 17px; height: 17px; }
.image-preview {
    max-width: 760px;
    margin: 0 auto 8px;
    display: flex;
    align-items: flex-start;
}
.image-preview img {
    max-height: 96px;
    max-width: 160px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    object-fit: cover;
    display: block;
}
.image-remove {
    margin: -6px 0 0 -10px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.image-remove:hover { color: var(--danger); border-color: var(--danger); }
.msg-image {
    display: block;
    max-width: 100%;
    max-height: 280px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border-strong);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    padding: 8px 13px;
    border: 1px solid transparent;
    transition: background-color var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                color var(--t-fast) var(--ease),
                transform var(--t-fast) var(--ease);
}
.action-btn:active { transform: translateY(.5px); }
.action-btn:disabled { opacity: .4; cursor: not-allowed; }
.action-btn-ghost:disabled:hover { background: var(--surface-2); border-color: var(--border); }
.action-btn-primary, .action-btn-success { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.action-btn-primary:hover, .action-btn-success:hover { background: #46D862; }
.action-btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.action-btn-ghost:hover { background: var(--surface); border-color: var(--border-strong); }
.action-btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.action-btn-danger:hover { background: var(--danger-soft); }

/* ============================================================
   PANELS — centered modals over a scrim
   ============================================================ */
/* CSS-only scrim: painted, non-interactive (close via the panel's ✕) */
body:has(.panel:not(.hidden))::before {
    content: "";
    position: fixed;
    inset: 0;
    background: var(--scrim);
    z-index: 90;
    pointer-events: none;
    animation: fadeIn var(--t-panel) var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
    position: fixed;
    z-index: 100;
    left: 50%;
    top: 50%;
    width: min(460px, calc(100vw - 40px));
    max-height: calc(100vh - 60px);
    transform: translate(-50%, -50%);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-panel);
    animation: panelIn var(--t-panel) var(--ease);
}
#wf-a-panel, #settings-panel { width: min(620px, calc(100vw - 40px)); }
@keyframes panelIn {
    from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--border);
}
.panel-eyebrow {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-3);
    display: block;
    margin-bottom: 5px;
}
.panel-eyebrow-danger { color: var(--danger); }
.panel-header h3 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.panel-body {
    padding: 16px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.panel-body label { font-size: 12.5px; color: var(--text-2); }
.panel-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 2px; }

/* fields */
textarea#error-explanation, .correction-textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 10px 12px;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    resize: vertical;
    line-height: 1.55;
}
textarea#error-explanation:focus, .correction-textarea:focus {
    outline: none;
    border-color: var(--accent-ring);
    box-shadow: var(--focus-ring);
}
.correction-textarea { font-family: var(--font-mono); font-size: 12px; }

/* radio cards */
.radio-group { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.radio-card { display: block; cursor: pointer; position: relative; }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card-inner {
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 11px 12px;
    transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
    height: 100%;
}
.radio-card:hover .radio-card-inner { border-color: var(--border-strong); }
.radio-card input:checked + .radio-card-inner { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input:focus-visible + .radio-card-inner { box-shadow: var(--focus-ring); }
.radio-card-inner strong { font-size: 12.5px; font-weight: 500; color: var(--text); }
.radio-card-inner small { font-size: 11px; color: var(--text-3); line-height: 1.4; }

/* ---------- Workflow A ---------- */
.wf-stepper { display: flex; margin: 0 0 4px; padding: 0; }
.wf-step {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    position: relative;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-3);
}
.wf-step-num {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 1.5px solid var(--border-strong);
    background: var(--surface);
    z-index: 1;
    font-size: 0;
    display: block;
}
.wf-step.active { color: var(--text-2); }
.wf-step.active .wf-step-num { border-color: var(--accent); box-shadow: var(--focus-ring); }
.wf-step.completed { color: var(--text-2); }
.wf-step.completed .wf-step-num { background: var(--accent); border-color: var(--accent); }
.wf-step-line { flex: 1; height: 1.5px; background: var(--border); margin-top: 6px; min-width: 14px; }
.wf-step-line.done { background: var(--accent); }

.chunk-filter-input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 7px 11px;
    color: var(--text);
    font: inherit;
    font-size: 12.5px;
}
.chunk-filter-input:focus { outline: none; border-color: var(--accent-ring); box-shadow: var(--focus-ring); }
.chunk-filter-count { font-size: 10.5px; color: var(--text-3); white-space: nowrap; }

.candidate-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
    max-height: 230px;
    overflow-y: auto;
}
.candidate-item {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 10px 12px;
    cursor: pointer;
    background: var(--surface-2);
    transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.candidate-item:hover { border-color: var(--border-strong); }
.candidate-item.selected { border-color: var(--accent-ring); background: var(--accent-soft); }
.candidate-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.candidate-id { font-size: 11px; color: var(--text-2); }
.candidate-meta { font-size: 10.5px; color: var(--text-3); margin-bottom: 5px; }
.chunk-text-preview { margin: 0; font-size: 12px; color: var(--text-2); line-height: 1.5; }
.chunk-text-preview mark { background: var(--accent-soft); color: var(--accent-text); border-radius: 2px; padding: 0 1px; }
.chunk-expand-btn {
    margin-top: 6px;
    background: none;
    border: 0;
    color: var(--text-3);
    font-size: 10.5px;
    font-family: var(--font-mono);
    cursor: pointer;
    padding: 0;
}
.chunk-expand-btn:hover { color: var(--accent-text); }

.list-empty { font-size: 12.5px; color: var(--text-3); padding: 8px 2px; margin: 0; }
.list-error { font-size: 12.5px; color: var(--danger); padding: 8px 2px; margin: 0; }

/* ---------- Settings ---------- */
.settings-row { padding: 4px 0 12px; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: 0; padding-bottom: 0; }
.settings-row > label {
    display: block;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--text-3);
    font-family: var(--font-mono);
    margin-bottom: 7px;
}
.settings-select, .settings-input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 8px 12px;
    color: var(--text);
    font: inherit;
    font-size: 12.5px;
}
.settings-select { min-width: 180px; appearance: none; padding-right: 30px; cursor: pointer;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235E6A7E' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}
.settings-input { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 12px; }
.settings-select:focus, .settings-input:focus { outline: none; border-color: var(--accent-ring); box-shadow: var(--focus-ring); }
.settings-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.settings-hint { font-size: 11px; color: var(--text-3); margin: 7px 0 0; line-height: 1.5; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 120;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 240px;
    max-width: 340px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 11px 13px;
    font-size: 12.5px;
    color: var(--text);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity var(--t-panel) var(--ease), transform var(--t-panel) var(--ease);
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 2px;
    flex: none;
    background: var(--accent);
}
.toast.error::before { background: var(--danger); }
.toast.warning::before { background: var(--warning); }

/* ============================================================
   EDGE IO DIAGRAM CARDS (CDC addendum v2.1 UX)
   ============================================================ */
.msg-edge-io .msg-bubble { background: var(--surface-2); border: 1px solid var(--border-strong); max-width: 520px; }
.edge-io-card { border-radius: 12px; overflow: hidden; }
.edge-io-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--accent-soft);
    border-bottom: 1px solid var(--border);
}
.edge-io-icon { font-size: 16px; line-height: 1; }
.edge-io-title { font-size: 12.5px; font-weight: 600; color: var(--accent-text); }
.edge-io-body { padding: 12px; font-size: 12.5px; color: var(--text); line-height: 1.55; }
.edge-io-body p { margin: 0 0 10px; }
.edge-io-body p:last-child { margin-bottom: 0; }
.edge-io-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.edge-io-actions .edge-io-btn { flex: 1 1 auto; }
.edge-io-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.edge-io-btn:hover { background: var(--surface-3); border-color: var(--accent-ring); }
.edge-io-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.edge-io-btn.primary:hover { filter: brightness(1.08); }
.edge-io-hint { color: var(--text-3); font-size: 11.5px; margin: 10px 0 6px; }
.edge-io-suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.edge-io-suggestion {
    display: inline-flex;
    align-items: center;
    padding: 6px 11px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.edge-io-suggestion:hover { background: var(--accent-soft); border-color: var(--accent-ring); color: var(--accent-text); }
.edge-io-suggestion:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 1px; }
.edge-io-card.error .edge-io-header { background: rgba(var(--danger-rgb, 220, 53, 69), .12); }
.edge-io-card.error .edge-io-title { color: var(--danger); }
.edge-io-card.recoverable .edge-io-header { background: rgba(var(--warning-rgb, 255, 193, 7), .12); }
.edge-io-card.recoverable .edge-io-title { color: var(--warning); }
.edge-io-card .edge-io-suggestion:disabled,
.edge-io-card .edge-io-btn:disabled,
.edge-io-card input:disabled { opacity: .55; cursor: not-allowed; }

/* Clarification card focus/accessibility refinements */
.edge-io-clarify-input input:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 1px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
.edge-io-turn { margin-left: auto; font-size: 11px; font-weight: 500; color: var(--text-3); }
.edge-io-unknown { color: var(--warning); font-size: 12px; margin: 8px 0 4px; }
.edge-io-unknown strong { font-weight: 600; }
.edge-io-clarify-input { display: flex; gap: 8px; margin-top: 12px; }
.edge-io-clarify-input input {
    flex: 1 1 auto;
    min-width: 120px;
    padding: 6px 10px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
}
.edge-io-clarify-input input:focus { outline: none; border-color: var(--accent-ring); }

/* Edge IO XML preview modal */
.edge-io-preview-modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.edge-io-preview-modal.hidden { display: none; }
.edge-io-preview-backdrop { position: absolute; inset: 0; background: var(--scrim); }
.edge-io-preview-panel {
    position: relative;
    width: 90vw;
    max-width: 900px;
    max-height: 86vh;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.edge-io-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--accent-soft);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-text);
    gap: 12px;
}
.edge-io-preview-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.edge-io-preview-actions .edge-io-btn {
    padding: 5px 10px;
    font-size: 11.5px;
}
.edge-io-preview-close {
    background: transparent;
    border: none;
    font-size: 20px;
    line-height: 1;
    color: var(--text);
    cursor: pointer;
    padding: 0 2px;
}
.edge-io-preview-body {
    flex: 1 1 auto;
    padding: 16px;
    margin: 0;
    overflow: auto;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface-2);
    white-space: pre-wrap;
    word-break: break-word;
}

@media (max-width: 768px) {
    .edge-io-preview-panel { width: 100%; max-width: 100%; max-height: 92vh; border-radius: 14px 14px 0 0; }
}

@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 276px;
        max-width: 84vw;
        transform: translateX(-100%);
        transition: transform 240ms var(--ease);
        box-shadow: none;
        z-index: 95; /* above the drawer scrim (90); panels (100) stay above the drawer */
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-drawer); }
    /* Drawer scrim — tap to dismiss (shown via :has, closed by app.js) */
    body:has(.sidebar.open) .drawer-scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: var(--scrim);
        z-index: 90;
        animation: fadeIn var(--t-panel) var(--ease);
    }
    .mobile-toggle { display: grid; }
    .topbar-credit { display: none; }
    .topbar-tags .tag:nth-child(n+3) { display: none; }
    .messages { padding: 22px 16px 14px; }
    .input-bar { padding: 12px 16px 14px; }
    .msg-bubble { max-width: 100%; }
    .msg-edge-io .msg-bubble { max-width: 100%; }
    .panel-body { padding: 14px 16px; }
    .panel-header { padding: 14px 16px 12px; }
}

@media (max-width: 480px) {
    .topbar { gap: 10px; padding: 0 12px; }
    .topbar-title h2 { font-size: .75rem; }
    .topbar-tags { display: none; }
    .welcome { padding: 24px 0 8px; }
    .welcome h2 { font-size: 16px; }
    .suggestions { grid-template-columns: 1fr; }
    .radio-group { grid-template-columns: 1fr; }
    .msg-bubble { max-width: 90%; }
    .input-hint { display: none; }
    /* panels become bottom sheets */
    .panel, #wf-a-panel, #settings-panel {
        border-radius: 14px 14px 0 0;
        top: auto;
        bottom: 0;
        transform: translate(-50%, 0);
        width: 100%;
        max-width: 100%;
        max-height: 92vh;
        animation-name: sheetIn;
    }
    .toast { left: 12px; right: 12px; max-width: none; }
}
@keyframes sheetIn {
    from { opacity: 0; transform: translate(-50%, 12px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    .sidebar, .input-bar, .topbar-actions, .panel, .banner, .toast { display: none !important; }
    .main { margin: 0; }
    .messages { overflow: visible; max-height: none; }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
    .msg-streaming .msg-content::after { animation: none !important; opacity: 1; }
}
