/* =====================================================================
   Proposal Studio — app.css
   One stylesheet for the whole workspace (dashboard, token usage, login).
   Replaces dashboard.css (kept in the repo, unlinked, for rollback).

   Design idea: quiet product chrome in Instrument Sans; the proposal itself
   is the hero, rendered as a sheet of paper on a grey desk in Source Serif 4.
   One accent (VINSINFO blue) for primary actions, selection and focus only.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
    --doc-pad-x: 72px;         /* paper side margins */
    --ink: #0A1A3D;            /* VINSINFO navy: headings, primary text */
    --ink-2: #33415C;          /* body text */
    --muted: #5B6780;          /* secondary text */
    --subtle: #8792A8;         /* tertiary text, placeholders */
    --line: #DFE4EC;           /* borders */
    --line-strong: #C9D1DE;
    --canvas: #F3F5F9;         /* app background */
    --desk: #E7EBF2;           /* behind the paper */
    --surface: #FFFFFF;
    --surface-2: #F8F9FC;      /* hover, inset areas */

    --accent: #0681FE;         /* VINSINFO blue */
    --accent-hover: #0569D6;
    --accent-press: #0459B5;
    --accent-soft: #EAF3FF;
    --accent-ring: rgba(6, 129, 254, 0.28);

    --success: #12805C;  --success-soft: #E7F5EF;
    --warning: #A35F00;  --warning-soft: #FFF4E0;
    --danger:  #C22F2A;  --danger-soft:  #FDECEB;

    --font-ui: 'Instrument Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-doc: 'Source Serif 4', Georgia, 'Times New Roman', serif;

    --r-sm: 6px;   /* inputs, small buttons */
    --r-md: 10px;  /* panels */
    --r-lg: 14px;  /* large containers */

    --shadow-panel: 0 1px 2px rgba(10, 26, 61, 0.05);
    --shadow-paper: 0 1px 3px rgba(10, 26, 61, 0.08), 0 12px 32px -12px rgba(10, 26, 61, 0.18);
    --shadow-pop: 0 18px 48px -16px rgba(10, 26, 61, 0.35);

    --sidebar-w: 264px;
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

    --z-sticky: 10;
    --z-sidebar: 40;
    --z-modal: 60;
    --z-overlay: 70;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink-2);
    background: var(--canvas);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--ink); line-height: 1.25; font-weight: 600; text-wrap: balance; }
p { text-wrap: pretty; }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
.hidden { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.skip-link {
    position: absolute; left: 12px; top: -48px; z-index: 100;
    padding: 8px 12px; background: var(--ink); color: #fff; border-radius: var(--r-sm);
    transition: top 0.15s;
}
.skip-link:focus { top: 12px; }

/* Remnants of the old theme that script.js still creates */
.particle { display: none !important; }

::selection { background: #CFE4FF; }

/* Scrollbars: thin and visible */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }

/* ---------- Buttons ---------- */
.btn, .platform-new-conversion-btn, .platform-convert-btn, .platform-download-btn,
.generate-btn-unified, .download-btn, .token-refresh-btn, .panel-link {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 36px; padding: 0 14px;
    border-radius: var(--r-sm);
    font-size: 13.5px; font-weight: 600; line-height: 1;
    white-space: nowrap;
    transition: background-color 0.15s var(--ease), border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:active, .platform-new-conversion-btn:active, .platform-convert-btn:active,
.platform-download-btn:active, .generate-btn-unified:active, .download-btn:active { transform: translateY(1px); }

/* Primary */
.btn-primary, .platform-convert-btn, .platform-download-btn, .generate-btn-unified, .download-btn {
    background: var(--accent); color: #fff; border: 1px solid var(--accent);
}
.btn-primary:hover, .platform-convert-btn:hover:not(:disabled), .platform-download-btn:hover,
.generate-btn-unified:hover, .download-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* Secondary */
.btn-secondary, .platform-new-conversion-btn, .token-refresh-btn {
    background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong);
}
.btn-secondary:hover, .platform-new-conversion-btn:hover, .token-refresh-btn:hover { background: var(--surface-2); border-color: var(--subtle); }

/* Text link button */
.panel-link { min-height: 28px; padding: 0 8px; color: var(--accent); font-weight: 600; }
.panel-link:hover { background: var(--accent-soft); }

button:disabled, .platform-convert-btn:disabled {
    background: var(--surface-2) !important; color: var(--subtle) !important;
    border-color: var(--line) !important; cursor: not-allowed; transform: none;
}
.btn i, .platform-convert-btn i, .platform-download-btn i, .platform-new-conversion-btn i { font-size: 13px; }

/* ---------- Form controls ---------- */
.field-label, .platform-field-block > label {
    display: block; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 6px;
}
.field-hint { display: block; font-size: 12.5px; color: var(--muted); margin-top: 6px; }

textarea, input[type="text"], input[type="password"], input[type="email"],
select, .model-select-enhanced, .platform-text-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm);
    padding: 9px 11px;
    font-size: 14px; line-height: 1.45; color: var(--ink);
    transition: border-color 0.15s, box-shadow 0.15s;
}
select, .model-select-enhanced {
    appearance: none; -webkit-appearance: none;
    padding-right: 34px; height: 38px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%235B6780' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 11px center;
}
textarea { resize: vertical; min-height: 96px; }
textarea::placeholder, input::placeholder { color: var(--subtle); }
textarea:hover, input:hover, select:hover { border-color: var(--subtle); }
textarea:focus, input:focus, select:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}

/* =====================================================================
   App shell
   ===================================================================== */
.app-shell { display: flex; min-height: 100dvh; }

.app-sidebar {
    position: sticky; top: 0;
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    height: 100dvh;
    display: flex; flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line);
    z-index: var(--z-sidebar);
}

.sidebar-brand {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 18px 14px;
}
.app-brand { display: flex; flex-direction: column; gap: 4px; color: var(--ink); }
.app-brand img { height: 22px; width: auto; display: block; }
.app-brand-name { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.01em; }

.sidebar-close { display: none; width: 32px; height: 32px; border-radius: var(--r-sm); color: var(--muted); }
.sidebar-close:hover { background: var(--surface-2); color: var(--ink); }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }

.tool-nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 36px; padding: 0 10px;
    border-radius: var(--r-sm);
    color: var(--ink-2); font-size: 14px; font-weight: 500; text-align: left;
    transition: background-color 0.12s, color 0.12s;
}
.nav-item i { width: 18px; text-align: center; font-size: 14px; color: var(--subtle); transition: color 0.12s; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item:hover i { color: var(--muted); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-press); font-weight: 600; }
.nav-item.active i { color: var(--accent); }
.nav-divider { height: 1px; background: var(--line); margin: 10px 6px; }

/* Recent list (per tool) */
.sidebar-section { margin-top: 18px; }
.section-title {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 10px 6px; font-size: 12px; font-weight: 600; color: var(--muted);
}
.chat-list { list-style: none; display: flex; flex-direction: column; gap: 1px; }
.chat-item { position: relative; display: flex; align-items: center; border-radius: var(--r-sm); }
.chat-item:hover { background: var(--surface-2); }
.chat-link {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; justify-content: center;
    min-height: 32px; padding: 6px 10px;
    color: var(--ink-2); font-size: 13.5px; text-align: left;
}
.chat-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.is-current { background: var(--surface-2); }
.chat-item.is-current .chat-link { color: var(--ink); font-weight: 600; }
.chat-item.is-current::before {
    content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 2px; border-radius: 2px; background: var(--accent);
}
.platform-history-date { font-size: 11.5px; color: var(--subtle); margin-top: 1px; }
.platform-history-empty .chat-link { color: var(--subtle); cursor: default; }
.platform-history-empty:hover { background: transparent; }

.action-buttons { display: flex; gap: 2px; padding-right: 4px; opacity: 0; transition: opacity 0.12s; }
.chat-item:hover .action-buttons, .chat-item:focus-within .action-buttons { opacity: 1; }
.action-buttons button {
    width: 26px; height: 26px; border-radius: 5px; color: var(--subtle); font-size: 12px;
    display: inline-flex; align-items: center; justify-content: center;
}
.action-buttons button:hover { background: var(--line); color: var(--ink); }
.action-buttons .delete-btn:hover { background: var(--danger-soft); color: var(--danger); }
.rename-input { width: 100%; height: 30px; padding: 4px 8px; font-size: 13.5px; margin: 2px 4px; }

/* User block */
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; border-top: 1px solid var(--line);
}
.user-avatar {
    flex: 0 0 32px; width: 32px; height: 32px; border-radius: 8px;
    display: grid; place-items: center;
    background: var(--ink); color: #fff; font-weight: 600; font-size: 13px;
}
.user-meta { flex: 1; min-width: 0; line-height: 1.3; }
.user-meta strong { display: block; color: var(--ink); font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signout-btn {
    width: 32px; height: 32px; border-radius: var(--r-sm); color: var(--muted);
    display: inline-flex; align-items: center; justify-content: center;
}
.signout-btn:hover { background: var(--surface-2); color: var(--ink); }

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

.mobile-bar {
    display: none; position: sticky; top: 0; z-index: var(--z-sticky);
    align-items: center; gap: 10px; height: 56px; padding: 0 14px;
    background: var(--surface); border-bottom: 1px solid var(--line);
}
.mobile-bar img { height: 20px; }
.menu-btn { width: 36px; height: 36px; border-radius: var(--r-sm); color: var(--ink); font-size: 16px; }
.menu-btn:hover { background: var(--surface-2); }

.sidebar-scrim { display: none; }

.main-content { flex: 1; padding: 28px 32px 48px; width: 100%; max-width: 1560px; margin: 0 auto; }

/* Page header shared by every tool */
.page-header, .platform-tool-header, .dashboard-overview-header {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
    margin-bottom: 22px;
}
.page-header h1, .page-header h2, .platform-tool-header h2, .dashboard-overview-header h2 {
    font-size: 24px; font-weight: 600; letter-spacing: -0.015em; color: var(--ink);
}
.page-header p, .platform-tool-header p, .dashboard-overview-header p {
    margin-top: 4px; color: var(--muted); font-size: 14px; max-width: 62ch;
}

/* ---------- Panels ---------- */
.panel, .dashboard-panel, .platform-conversion-form, .proposal-input-panel .form-section, .token-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-panel);
}
.panel-header, .dashboard-panel-header, .token-panel-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 52px; padding: 10px 18px; border-bottom: 1px solid var(--line);
}
.panel-header h3, .dashboard-panel-header h3, .token-panel-header h2 { font-size: 14.5px; font-weight: 600; }
.panel-header span, .token-panel-header span { font-size: 12.5px; color: var(--muted); }

/* =====================================================================
   Overview
   ===================================================================== */
.dashboard-metrics-grid {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
    box-shadow: var(--shadow-panel); margin-bottom: 20px; overflow: hidden;
}
.dashboard-metric-card { padding: 18px 20px; border-right: 1px solid var(--line); min-width: 0; }
.dashboard-metric-card:last-child { border-right: 0; }
.dashboard-metric-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.dashboard-metric-card strong {
    display: block; margin-top: 6px;
    font-size: 26px; font-weight: 600; letter-spacing: -0.02em; color: var(--ink);
    font-variant-numeric: tabular-nums; line-height: 1.15;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dashboard-metric-card small { display: block; margin-top: 4px; font-size: 12.5px; color: var(--subtle); }
.dashboard-token-card.is-alert strong { color: var(--danger); }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.overview-stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* Start new work: rows, not a card trio */
.dashboard-quick-actions-grid { display: flex; flex-direction: column; padding: 6px; }
.dashboard-quick-action-card {
    display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 14px;
    width: 100%; padding: 12px; border-radius: var(--r-sm); text-align: left;
    transition: background-color 0.12s;
}
.dashboard-quick-action-card + .dashboard-quick-action-card { border-top: 1px solid var(--line); border-radius: 0 0 var(--r-sm) var(--r-sm); }
.dashboard-quick-action-card:hover { background: var(--surface-2); }
.dashboard-tool-icon {
    width: 40px; height: 40px; border-radius: 9px; display: grid; place-items: center;
    background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); font-size: 16px;
}
.dashboard-quick-action-card:first-child .dashboard-tool-icon { background: var(--accent); border-color: var(--accent); color: #fff; }
.dashboard-tool-copy strong { display: block; color: var(--ink); font-size: 14.5px; font-weight: 600; }
.dashboard-tool-copy small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.dashboard-tool-action { color: var(--subtle); font-size: 13px; transition: transform 0.15s var(--ease), color 0.15s; }
.dashboard-quick-action-card:hover .dashboard-tool-action { color: var(--accent); transform: translateX(2px); }

.dashboard-activity-list { display: flex; flex-direction: column; padding: 6px; }
.dashboard-activity-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-sm); color: var(--ink-2);
}
.dashboard-activity-item:hover { background: var(--surface-2); }
.dashboard-activity-icon {
    flex: 0 0 30px; height: 30px; border-radius: 7px; display: grid; place-items: center;
    background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 12.5px;
}
.dashboard-activity-item strong { display: block; color: var(--ink); font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-activity-item small { display: block; color: var(--subtle); font-size: 12px; }
.dashboard-activity-item > span:last-child { min-width: 0; }

.dashboard-empty-line, .token-empty { padding: 18px; color: var(--muted); font-size: 13.5px; }

.dashboard-token-summary { padding: 6px 18px 12px; }
.dashboard-token-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 0; border-bottom: 1px solid var(--line);
}
.dashboard-token-row:last-child { border-bottom: 0; }
.dashboard-token-row strong { display: block; color: var(--ink); font-weight: 600; font-size: 13.5px; }
.dashboard-token-row small { display: block; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.dashboard-token-row b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.usage-bar { display: block; height: 4px; border-radius: 4px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.usage-bar > i { display: block; height: 100%; background: var(--ink); border-radius: 4px; }

/* =====================================================================
   Two-column tool layout (all three tools)
   ===================================================================== */
.proposal-generation-grid, .platform-conversion-grid {
    display: grid; grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); gap: 24px; align-items: start;
}

.proposal-has-result .proposal-generation-grid { grid-template-columns: minmax(300px, 340px) minmax(0, 1fr); }
.proposal-has-result .field-row { grid-template-columns: 1fr; }
.proposal-has-result .field-row > .field + .field { margin-top: 14px; }

/* ---------- Proposal form ---------- */
.proposal-input-panel { order: 1; min-width: 0; position: sticky; top: 20px; }
.proposal-result-panel { order: 2; min-width: 0; }

/* ---------- Resizable split: form | handle | preview ---------- */
.proposal-generation-grid { grid-template-columns: var(--form-w, minmax(340px, 400px)) 8px minmax(0, 1fr); column-gap: 8px; }
.proposal-has-result .proposal-generation-grid { grid-template-columns: var(--form-w, minmax(300px, 340px)) 8px minmax(0, 1fr); }
.panel-resizer { order: 2; align-self: stretch; position: relative; cursor: col-resize; touch-action: none; }
.panel-resizer::before {
    content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; transform: translateX(-50%);
    background: var(--line); border-radius: 2px; transition: background 0.15s, width 0.15s;
}
.panel-resizer:hover::before, .panel-resizer:focus-visible::before, .panel-resizer.is-dragging::before { width: 3px; background: var(--accent); }
.panel-resizer:focus-visible { outline: none; }
body.is-resizing-panels { cursor: col-resize; user-select: none; }

/* ---------- Settings panel collapse toggle (proposal toolbar, only once a proposal is shown) ---------- */
.action-icon.settings-toggle-btn { display: none; }
.proposal-has-result .action-icon.settings-toggle-btn { display: inline-flex; border-color: var(--line-strong); background: var(--surface); }
.proposal-has-result .proposal-generation-grid.is-form-collapsed { grid-template-columns: minmax(0, 1fr); }
.proposal-has-result .proposal-generation-grid.is-form-collapsed .proposal-input-panel,
.proposal-has-result .proposal-generation-grid.is-form-collapsed .panel-resizer { display: none; }

@media (max-width: 1100px) {
    .proposal-generation-grid, .proposal-has-result .proposal-generation-grid { grid-template-columns: minmax(0, 1fr); }
    .panel-resizer { display: none; }
    /* Panels are stacked here, so the toggle is not needed and the form always shows */
    .proposal-has-result .action-icon.settings-toggle-btn { display: none; }
    .proposal-has-result .proposal-generation-grid.is-form-collapsed .proposal-input-panel { display: block; }
}

.proposal-input-panel .form-section {
    max-height: calc(100dvh - 124px); overflow-y: auto;
}
.proposal-input-panel form { display: flex; flex-direction: column; }

.form-block { padding: 18px; border-bottom: 1px solid var(--line); }
.form-block-title { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 12px; display: flex; align-items: baseline; justify-content: space-between; }
.form-block-title small { font-weight: 500; color: var(--subtle); font-size: 12px; }

#projectBrief { min-height: 168px; font-size: 14px; line-height: 1.55; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field + .field, .field-row + .field, .field + .field-row { margin-top: 14px; }
.field-row > .field { margin-top: 0; }
.field > label, .field > .field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; display: block; }

/* Segmented control (drives hidden #versionToggle) */
.segmented {
    display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
    padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
}
.segmented button {
    display: flex; align-items: center; justify-content: center; gap: 7px;
    height: 32px; border-radius: 6px; font-size: 13.5px; font-weight: 500; color: var(--muted);
    transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.segmented button i { font-size: 12.5px; }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] {
    background: var(--surface); color: var(--ink); font-weight: 600;
    box-shadow: 0 1px 2px rgba(10, 26, 61, 0.12), 0 0 0 1px var(--line);
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Option rows with a switch */
.option-block { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); transition: border-color 0.15s, background-color 0.15s; }
.option-block + .option-block { margin-top: 8px; }
.option-block:has(input:checked) { border-color: #B9D6FB; background: #FAFCFF; }

.switch-row { display: flex; align-items: center; gap: 12px; padding: 11px 12px; cursor: pointer; }
.switch-copy { flex: 1; min-width: 0; }
.switch-copy strong { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.switch-copy small { display: block; font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.switch { position: relative; flex: 0 0 34px; width: 34px; height: 20px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch-track {
    position: absolute; inset: 0; border-radius: 20px; background: var(--line-strong);
    transition: background-color 0.18s var(--ease);
}
.switch-track::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(10, 26, 61, 0.3);
    transition: transform 0.18s var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-ring); }

/* Upload panels revealed by the switches (JS sets display:flex) */
.requirement-upload-panel, .template-upload-panel, .understanding-upload-panel {
    flex-direction: column; gap: 8px; padding: 0 12px 12px;
}
.requirement-upload-btn, .template-upload-btn, .understanding-upload-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; min-height: 40px; padding: 8px 12px;
    border: 1px dashed var(--line-strong); border-radius: var(--r-sm);
    background: var(--surface); color: var(--ink); font-size: 13.5px; font-weight: 500;
    transition: border-color 0.15s, background-color 0.15s;
}
.requirement-upload-btn:hover, .template-upload-btn:hover, .understanding-upload-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.requirement-upload-hint, .template-upload-hint, .understanding-upload-hint { font-size: 12px; color: var(--muted); }
.requirement-file-name, .template-file-name, .understanding-file-name, .platform-file-name {
    font-size: 12.5px; color: var(--success); font-weight: 500;
    display: none; padding: 7px 10px; border-radius: var(--r-sm); background: var(--success-soft);
    word-break: break-word;
}
.requirement-file-name:not(:empty), .platform-file-name:not(:empty) { display: block; }

.form-actions { padding: 16px 18px 18px; position: sticky; bottom: 0; background: var(--surface); border-radius: 0 0 var(--r-md) var(--r-md); }
.generate-btn-unified { width: 100%; min-height: 42px; font-size: 14px; }
.btn-content { display: inline-flex; align-items: center; gap: 9px; }
.btn-shine { display: none; }
.form-footnote { font-size: 12px; color: var(--subtle); text-align: center; margin-top: 8px; }

/* Inline status (after the form) */
.status {
    display: flex; align-items: center; gap: 10px;
    margin: 0 18px 16px; padding: 10px 12px;
    border-radius: var(--r-sm); font-size: 13px; font-weight: 500;
    background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.status.streaming, .status.connecting, .status.creating-doc { background: var(--accent-soft); color: var(--accent-press); border-color: #CFE3FB; }
.status.success, .status.complete { background: var(--success-soft); color: var(--success); border-color: #C6E7D9; }
.status.error { background: var(--danger-soft); color: var(--danger); border-color: #F5C9C6; }
.doc-loader {
    flex: 0 0 16px; width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite;
}
#progressContainer { margin: 0 18px 16px; }
.progress-bar { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width 0.4s var(--ease); }
#progressText { font-size: 12.5px; color: var(--muted); }

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

/* =====================================================================
   The desk + paper (proposal output)
   ===================================================================== */
.chat-output-panel {
    background: var(--desk);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    min-height: calc(100dvh - 160px);
    padding: 28px;
}
.chat-messages-area { display: flex; flex-direction: column; gap: 24px; }
#out { display: none; }

/* Empty state: a blank page that invites a brief */
.platform-result-empty.proposal-empty-state {
    display: block; border: 0;
    max-width: 640px; margin: 0 auto; width: 100%;
    background: var(--surface); border-radius: 4px; box-shadow: var(--shadow-paper);
    padding: 56px 56px 64px; position: relative;
}
.empty-sheet-lines { display: flex; flex-direction: column; gap: 12px; margin-bottom: 36px; }
.empty-sheet-lines span { height: 9px; border-radius: 9px; background: var(--surface-2); }
.empty-sheet-lines span:nth-child(1) { width: 46%; height: 16px; background: var(--line); margin-bottom: 8px; }
.empty-sheet-lines span:nth-child(2) { width: 92%; }
.empty-sheet-lines span:nth-child(3) { width: 84%; }
.empty-sheet-lines span:nth-child(4) { width: 61%; }
.proposal-empty-state h3 { font-family: var(--font-doc); font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.proposal-empty-state p { margin-top: 8px; color: var(--muted); font-size: 14.5px; max-width: 46ch; }
.empty-steps { list-style: none; counter-reset: s; margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.empty-steps li { counter-increment: s; display: flex; gap: 12px; align-items: baseline; color: var(--ink-2); font-size: 14px; }
.empty-steps li::before {
    content: counter(s); flex: 0 0 22px; height: 22px; border-radius: 50%;
    display: inline-grid; place-items: center; font-size: 12px; font-weight: 600;
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}

.selected-chat-section { display: flex; flex-direction: column; gap: 28px; }

.proposal-viewer-card {
    /* No fixed max-width: the paper fills the desk so the grey margin stays the
       panel padding at every browser zoom level */
    width: 100%; margin: 0 auto;
    background: var(--surface); border-radius: 4px; box-shadow: var(--shadow-paper);
}

/* Document column: side margins grow on wide paper so title, brief and body share
   one centred column of at most 1100px (100% = the paper width where it is used) */
.project-summary-container { --doc-side: max(var(--doc-pad-x), calc((100% - 1100px) / 2)); }

/* Toolbar pinned to the top of the paper */
.icons-version-row {
    position: sticky; top: 0; z-index: var(--z-sticky);
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 10px 14px; background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line); border-radius: 4px 4px 0 0;
}
.proposal-action-icons { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.action-icon {
    display: inline-flex; align-items: center;
    height: 32px; padding: 0 11px; border-radius: var(--r-sm);
    font-size: 13px; font-weight: 600; color: var(--ink-2);
    border: 1px solid transparent; transition: background-color 0.12s, border-color 0.12s, color 0.12s;
    vertical-align: middle; line-height: 30px;
}
.action-icon i { font-size: 12.5px; }
.action-icon i + .label-text { margin-left: 7px; }
.action-icon:hover { background: var(--surface-2); color: var(--ink); }
.action-icon.save-btn { background: var(--accent); color: #fff !important; }
.action-icon.refine-btn { color: var(--accent-press) !important; }
.action-icon.edit-btn[style*="pointer-events: none"] { opacity: 0.45; }
.action-icon.save-btn:hover { background: var(--accent-hover); }
.action-icon.refine-btn { color: var(--accent-press); border-color: #CFE3FB; background: var(--accent-soft); }
.action-icon.download-btn { border-color: var(--line-strong); color: var(--ink); background: var(--surface); }
.action-icon.download-btn:hover { border-color: var(--subtle); }
.toolbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

.version-selector-inline { display: flex; align-items: center; gap: 8px; }
.version-label { font-size: 12.5px; color: var(--muted); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.version-select { height: 32px; width: auto; min-width: 190px; font-size: 13px; padding: 0 30px 0 10px; font-variant-numeric: tabular-nums; }

/* Document title block */
.proposal-title-area { padding: 52px var(--doc-side) 0; }
.proposal-main-title {
    font-family: var(--font-doc); font-size: 34px; font-weight: 600; line-height: 1.15; letter-spacing: -0.015em; color: var(--ink);
}
.proposal-description { margin-top: 12px; font-family: var(--font-doc); font-size: 17px; line-height: 1.55; color: var(--muted); max-width: 60ch; }

.proposal-brief-strip { margin: 22px var(--doc-side) 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.proposal-brief-strip summary {
    list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
    padding: 10px 0; font-size: 12.5px; font-weight: 600; color: var(--muted);
}
.proposal-brief-strip summary::-webkit-details-marker { display: none; }
.proposal-brief-strip summary::after { content: "Show"; margin-left: auto; font-weight: 500; color: var(--accent); }
.proposal-brief-strip[open] summary::after { content: "Hide"; }
.proposal-brief-strip summary:hover { color: var(--ink); }
.proposal-brief-strip p { padding: 0 0 14px; font-size: 13.5px; color: var(--ink-2); white-space: pre-wrap; max-width: 72ch; }

/* Document body */
.project-summary, #out {
    font-family: var(--font-doc);
    font-size: 16.5px; line-height: 1.7; color: #1F2A44;
}
.project-summary {
    /* !important: script.js writes inline border/padding when entering edit mode */
    padding: 28px var(--doc-side) 72px !important; border: 0 !important; outline: none;
}
.project-summary > *:first-child { margin-top: 0 !important; }
.project-summary h1, .project-summary .main-heading {
    font-family: var(--font-doc); font-size: 26px; font-weight: 600; letter-spacing: -0.01em;
    color: var(--ink); margin: 40px 0 12px; line-height: 1.25;
}
.project-summary h2, .project-summary .main-sub-heading {
    font-family: var(--font-doc); font-size: 21px; font-weight: 600; color: var(--ink); margin: 32px 0 10px; line-height: 1.3;
}
.project-summary h3, .project-summary h4, .project-summary .subheading {
    font-family: var(--font-ui); font-size: 15px; font-weight: 600; color: var(--ink); margin: 24px 0 8px;
}
.project-summary p { margin: 0 0 14px; }
.project-summary ul, .project-summary ol { margin: 0 0 16px; padding-left: 1.35em; }
.project-summary li { margin: 0 0 6px; padding-left: 2px; }
.project-summary li::marker { color: var(--subtle); }
.project-summary strong { color: var(--ink); font-weight: 600; }
.project-summary a { text-decoration: underline; text-underline-offset: 2px; }
.project-summary blockquote { margin: 0 0 16px; padding: 4px 0 4px 16px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.project-summary hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
.project-summary code { font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; font-size: 0.86em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.project-summary table {
    width: 100%; border-collapse: collapse; margin: 6px 0 22px;
    font-family: var(--font-ui); font-size: 13.5px; line-height: 1.45;
    display: block; overflow-x: auto;
}
.project-summary th, .project-summary td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.project-summary thead th { color: var(--ink); font-weight: 600; border-bottom: 1.5px solid var(--ink); white-space: nowrap; }
.project-summary tbody tr:hover td { background: var(--surface-2); }
.project-summary img { display: block; max-width: 100%; height: auto; border-radius: 4px; margin: 8px 0 18px; }

/* Edit mode */
.edit-highlight { box-shadow: inset 0 0 0 2px var(--accent-ring); border-radius: 4px; }
.edit-highlight .project-summary.editable { background: #FBFDFF; }
.project-summary.editable { cursor: text; }
.project-summary.editable:focus { box-shadow: inset 3px 0 0 var(--accent); }

/* Images inside the proposal (edit / download controls from script.js) */
.image-container { position: relative; display: block; margin: 8px 0 18px; border: 1.5px dashed transparent; border-radius: 6px; padding: 4px; transition: border-color 0.15s, background-color 0.15s; }
.image-container img { margin: 0; cursor: default; }
.image-container.edit-mode { border-color: var(--line-strong); }
.image-container.edit-mode:hover { border-color: var(--accent); background: var(--accent-soft); }
.image-container.edit-mode img { cursor: pointer; }
.image-container.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.image-container::after {
    content: "Drop an image to replace"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    padding: 7px 12px; border-radius: var(--r-sm); background: var(--ink); color: #fff;
    font: 600 12.5px var(--font-ui); opacity: 0; pointer-events: none; transition: opacity 0.15s; white-space: nowrap;
}
.image-container.edit-mode:hover::after { opacity: 1; }
.edit-image-btn {
    display: none; align-items: center; gap: 7px; margin-top: 8px; height: 32px; padding: 0 12px;
    border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line-strong);
    font: 600 13px var(--font-ui); color: var(--ink);
}
.edit-image-btn:hover { border-color: var(--accent); color: var(--accent-press); }
.image-download-btn {
    position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border-radius: var(--r-sm);
    background: rgba(10, 26, 61, 0.78); color: #fff; font-size: 13px; opacity: 0; transition: opacity 0.15s;
}
div:hover > .image-download-btn, .image-download-btn:focus-visible { opacity: 1; }

/* "Request a change" box (legacy, hidden by default) */
.user-request-ui { margin: 0 var(--doc-side) 24px !important; padding: 12px !important; border: 1px solid var(--line) !important; border-radius: var(--r-md) !important; background: var(--surface-2) !important; font-family: var(--font-ui); }
.user-request-input { border: 1px solid var(--line-strong) !important; border-radius: var(--r-sm) !important; padding: 9px 11px !important; }
.user-request-submit { background: var(--accent) !important; border-radius: var(--r-sm) !important; font-weight: 600; }

/* Success block shown briefly before redirect */
.download-section {
    max-width: 640px; margin: 0 auto; width: 100%;
    display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
    padding: 20px 22px; background: var(--surface); border: 1px solid #C6E7D9; border-radius: var(--r-md);
}
.download-section h3 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.download-section h3 i { color: var(--success); }
.download-section p { color: var(--muted); margin-bottom: 8px; }

/* =====================================================================
   Understanding + platform forms and results
   ===================================================================== */
.platform-conversion-form { display: flex; flex-direction: column; gap: 0; padding: 0; position: sticky; top: 20px; }
.platform-field-block { padding: 14px 18px 0; }
.platform-field-block textarea { min-height: 92px; }
.platform-conversion-form > .platform-convert-btn { margin: 18px; min-height: 42px; }
.platform-field-block .platform-file-name { margin-top: 8px; }

.platform-upload-btn {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 12px 14px; border: 1px dashed var(--line-strong); border-radius: 8px;
    background: var(--surface); color: var(--ink); text-align: left; font-size: 13.5px; font-weight: 500;
    transition: border-color 0.15s, background-color 0.15s;
}
.platform-upload-btn > i {
    flex: 0 0 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
    background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 14px;
}
.platform-upload-btn strong { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.platform-upload-btn small { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.platform-upload-btn:hover, .platform-upload-btn.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.platform-upload-btn:hover > i, .platform-upload-btn.drag-over > i { color: var(--accent); border-color: #CFE3FB; background: #fff; }

.platform-conversion-result { min-width: 0; }

.platform-result-empty {
    display: flex; flex-direction: column; align-items: flex-start;
    padding: 40px; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--r-md);
}
.platform-result-empty > i {
    width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center;
    background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 18px; margin-bottom: 16px;
}
.platform-result-empty h3 { font-size: 17px; }
.platform-result-empty p { margin-top: 6px; color: var(--muted); max-width: 52ch; }
.platform-result-empty .fa-spin { color: var(--accent); }
.platform-result-error { border-style: solid; border-color: #F5C9C6; background: #FFFBFB; }
.platform-result-error > i { background: var(--danger-soft); border-color: #F5C9C6; color: var(--danger); }

.platform-result-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-panel);
    overflow: hidden;
}
.platform-result-status { display: flex; align-items: flex-start; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.platform-result-status > i {
    flex: 0 0 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-size: 16px;
    background: var(--success-soft); color: var(--success);
}
.platform-result-status-info > i { background: var(--accent-soft); color: var(--accent); }
.platform-result-status h3 { font-size: 16px; }
.platform-result-status p { color: var(--muted); margin-top: 2px; }

.platform-summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); border-bottom: 1px solid var(--line); }
.platform-summary-grid > div { padding: 14px 20px; border-right: 1px solid var(--line); min-width: 0; }
.platform-summary-grid > div:last-child { border-right: 0; }
.platform-summary-grid span { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.platform-summary-grid strong { display: block; margin-top: 3px; color: var(--ink); font-weight: 600; word-break: break-word; font-variant-numeric: tabular-nums; }

.platform-result-list { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.platform-result-list h4 { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 8px; }
.platform-result-list ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.platform-result-list li { position: relative; padding-left: 16px; color: var(--ink-2); font-size: 13.5px; }
.platform-result-list li::before { content: ""; position: absolute; left: 3px; top: 0.62em; width: 5px; height: 5px; border-radius: 50%; background: var(--line-strong); }
.platform-result-card > .platform-download-btn { margin: 16px 20px 18px; min-height: 40px; }

/* =====================================================================
   Overlays: generation progress + document preview modal
   ===================================================================== */
#loadingOverlay {
    display: none; position: fixed; inset: 0; z-index: var(--z-overlay);
    align-items: center; justify-content: center; padding: 20px;
    background: rgba(231, 235, 242, 0.78);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.loader-box {
    width: min(420px, 100%); padding: 28px 28px 24px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
}
.loader-sheet {
    width: 84px; height: 108px; margin-bottom: 22px; padding: 14px 12px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 3px; box-shadow: var(--shadow-paper);
    display: flex; flex-direction: column; gap: 7px; overflow: hidden;
}
.loader-sheet span { height: 5px; border-radius: 5px; background: var(--line); transform-origin: left; animation: write 2.4s var(--ease) infinite; }
.loader-sheet span:nth-child(1) { width: 60%; height: 7px; background: var(--ink); animation-delay: 0s; }
.loader-sheet span:nth-child(2) { width: 100%; animation-delay: 0.25s; }
.loader-sheet span:nth-child(3) { width: 92%; animation-delay: 0.5s; }
.loader-sheet span:nth-child(4) { width: 70%; animation-delay: 0.75s; }
.loader-sheet span:nth-child(5) { width: 96%; animation-delay: 1s; }
.loader-sheet span:nth-child(6) { width: 54%; animation-delay: 1.25s; }
@keyframes write { 0% { transform: scaleX(0); } 40%, 85% { transform: scaleX(1); } 100% { transform: scaleX(1); opacity: 0.35; } }
.loader-title { font-size: 17px; font-weight: 600; color: var(--ink); }
.loader-detail { margin-top: 4px; color: var(--muted); font-size: 13.5px; min-height: 20px; }
.loader-meta { display: flex; justify-content: space-between; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--subtle); font-variant-numeric: tabular-nums; }
.loader-box .spinner { display: none; }

.modal {
    display: none; position: fixed; inset: 0; z-index: var(--z-modal);
    background: rgba(10, 26, 61, 0.45); padding: 3vh 3vw;
}
.modal-content {
    width: 100%; max-width: 1100px; height: 100%; margin: 0 auto;
    display: flex; flex-direction: column;
    background: var(--surface); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-pop);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 12px 20px; border-bottom: 1px solid var(--line); }
.modal-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; color: var(--ink); }
.modal-title i { color: var(--muted); }
.modal-close { width: 34px; height: 34px; border-radius: var(--r-sm); color: var(--muted); }
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-body { flex: 1; overflow: auto; padding: 24px; background: var(--desk); }
.loading-state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 64px 0; color: var(--muted); }
.loading-state h3 { font-size: 15px; }
.loading-spinner { width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
.docx-wrapper { background: transparent !important; padding: 0 !important; }
.docx-wrapper > section.docx { box-shadow: var(--shadow-paper) !important; margin-bottom: 24px !important; }

/* SweetAlert2 theme */
.swal2-container { font-family: var(--font-ui) !important; }
.swal2-popup { border-radius: var(--r-lg) !important; padding: 24px 24px 20px !important; box-shadow: var(--shadow-pop) !important; width: 26em !important; }
.swal2-title { font-size: 18px !important; font-weight: 600 !important; color: var(--ink) !important; padding: 0 !important; margin-top: 4px !important; }
.swal2-html-container { font-size: 14px !important; color: var(--muted) !important; margin: 8px 0 0 !important; line-height: 1.55 !important; }
.swal2-icon { transform: scale(0.72); margin: 0 auto -6px !important; }
.swal2-actions { margin-top: 20px !important; gap: 8px; }
.swal2-styled { margin: 0 !important; border-radius: var(--r-sm) !important; font-size: 14px !important; font-weight: 600 !important; padding: 9px 18px !important; box-shadow: none !important; }
.swal2-styled.swal2-confirm { background: var(--accent) !important; }
.swal2-styled.swal2-confirm:hover { background: var(--accent-hover) !important; }
.swal2-styled.swal2-cancel, .swal2-styled.swal2-deny { background: var(--surface) !important; color: var(--ink) !important; border: 1px solid var(--line-strong) !important; }
.swal2-input, .swal2-textarea { font-size: 14px !important; border-radius: var(--r-sm) !important; border-color: var(--line-strong) !important; box-shadow: none !important; }
.swal2-timer-progress-bar { background: var(--accent) !important; }

/* =====================================================================
   Token usage page
   ===================================================================== */
.token-metrics-grid { margin-bottom: 20px; }
.token-panel + .token-panel { margin-top: 20px; }
.token-table-wrap { overflow-x: auto; }
.token-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.token-table th {
    text-align: left; padding: 10px 18px; font-size: 12px; font-weight: 600; color: var(--muted);
    background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.token-table td { padding: 11px 18px; border-bottom: 1px solid var(--line); color: var(--ink-2); vertical-align: middle; }
.token-table tbody tr:last-child td { border-bottom: 0; }
.token-table tbody tr:hover td { background: #FAFBFD; }
.token-number { font-variant-numeric: tabular-nums; white-space: nowrap; }
.token-table th:nth-child(n+2), .token-table td.token-number { text-align: right; }
#tokenUsageTable th:nth-child(-n+4) { text-align: left; }
#tokenUsageTable td:first-child { text-align: left; color: var(--muted); }
.token-model-pill {
    display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border-radius: 5px;
    background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; color: var(--ink); white-space: nowrap;
}
.token-context { color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.token-refresh-btn.is-spinning i { animation: spin 0.8s linear infinite; }

/* =====================================================================
   Login
   ===================================================================== */
.auth-page { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); background: var(--surface); }
.auth-form-side { display: flex; flex-direction: column; padding: 32px 48px; }
.auth-form-side .brand-row img { height: 24px; }
.auth-form-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; width: 100%; max-width: 380px; margin: 0 auto; padding: 40px 0; }
.auth-form-wrap h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.auth-form-wrap > p { margin-top: 8px; color: var(--muted); font-size: 15px; }
.auth-form { margin-top: 28px; display: flex; flex-direction: column; gap: 16px; }
.auth-form input { height: 42px; }
.password-field { position: relative; }
.password-field input { padding-right: 64px; }
.password-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); height: 30px; padding: 0 10px; border-radius: 5px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.password-toggle:hover { background: var(--surface-2); color: var(--ink); }
.auth-form .btn-primary { height: 44px; font-size: 14.5px; margin-top: 4px; }
.auth-error { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger); font-size: 13.5px; font-weight: 500; }
.auth-note { margin-top: 20px; color: var(--subtle); font-size: 13px; }
.auth-footer { color: var(--subtle); font-size: 12.5px; }

.auth-visual-side {
    position: relative; overflow: hidden; background: var(--desk);
    display: flex; align-items: center; justify-content: center; padding: 48px;
}
.auth-visual-side::before {
    content: ""; position: absolute; inset: 0;
    background-image: radial-gradient(rgba(10, 26, 61, 0.07) 1px, transparent 1px);
    background-size: 18px 18px; mask-image: linear-gradient(180deg, #000 30%, transparent 100%);
}
.sample-stack { position: relative; width: min(440px, 100%); }
.sample-page {
    position: relative; background: #fff; border-radius: 3px; box-shadow: var(--shadow-paper);
    padding: 40px 40px 48px; font-family: var(--font-doc);
}
.sample-page.back { position: absolute; inset: 0; transform: rotate(-3.5deg) translate(-18px, 10px); opacity: 0.7; }
.sample-page .doc-kicker { font-family: var(--font-ui); font-size: 11.5px; font-weight: 600; color: var(--muted); }
.sample-page h2 { font-family: var(--font-doc); font-size: 25px; line-height: 1.2; margin-top: 10px; letter-spacing: -0.01em; }
.sample-page p { font-size: 14px; line-height: 1.6; color: #3A4660; margin-top: 12px; }
.sample-page h3 { font-family: var(--font-doc); font-size: 16px; margin-top: 22px; }
.sample-table { width: 100%; margin-top: 10px; border-collapse: collapse; font-family: var(--font-ui); font-size: 12px; }
.sample-table td { padding: 7px 0; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.sample-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.sample-badge {
    position: absolute; right: -14px; bottom: 34px; display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; background: #fff; border-radius: var(--r-md); box-shadow: var(--shadow-pop);
    font-family: var(--font-ui); font-size: 13px; color: var(--ink); font-weight: 600;
}
.sample-badge i { color: var(--success); }
.sample-badge small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1280px) {
    :root { --doc-pad-x: 48px; }
}

@media (max-width: 1100px) {
    .proposal-generation-grid, .platform-conversion-grid { grid-template-columns: minmax(0, 1fr); }
    .proposal-input-panel, .platform-conversion-form { position: static; }
    .proposal-input-panel .form-section { max-height: none; overflow: visible; }
    .overview-grid { grid-template-columns: minmax(0, 1fr); }
    .chat-output-panel { min-height: 0; padding: 20px; }
    /* When a proposal is open, show the document first on narrow screens */
    .proposal-has-result .proposal-result-panel { order: 1; }
    .proposal-has-result .proposal-input-panel { order: 2; }
}

@media (max-width: 960px) {
    .app-sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%);
        transition: transform 0.22s var(--ease); box-shadow: none;
    }
    body.sidebar-open .app-sidebar { transform: none; box-shadow: var(--shadow-pop); }
    body.sidebar-open .sidebar-scrim { display: block; position: fixed; inset: 0; background: rgba(10, 26, 61, 0.35); z-index: calc(var(--z-sidebar) - 1); }
    .sidebar-close { display: inline-flex; align-items: center; justify-content: center; }
    .mobile-bar { display: flex; }
    .main-content { padding: 20px 16px 40px; }
    .dashboard-metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-metric-card:nth-child(2) { border-right: 0; }
    .dashboard-metric-card:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
    .auth-page { grid-template-columns: 1fr; }
    .auth-visual-side { display: none; }
    .icons-version-row { top: 56px; }
}

@media (max-width: 640px) {
    .page-header, .platform-tool-header, .dashboard-overview-header { flex-direction: column; align-items: stretch; }
    .field-row { grid-template-columns: 1fr; }
    .chat-output-panel { padding: 10px; border-radius: var(--r-md); }
    :root { --doc-pad-x: 22px; }
    .proposal-title-area { padding-top: 28px; }
    .proposal-main-title { font-size: 26px; }
    .project-summary { font-size: 16px; }
    .proposal-empty-state { padding: 32px 24px 36px; }
    .version-selector-inline { width: 100%; }
    .version-select { flex: 1; min-width: 0; }
    .action-icon .label-text { display: none; }
    .auth-form-side { padding: 24px; }
    .action-buttons { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media print {
    .app-sidebar, .mobile-bar, .proposal-input-panel, .icons-version-row, .platform-tool-header { display: none !important; }
    .chat-output-panel { background: none; border: 0; padding: 0; }
    .proposal-viewer-card { box-shadow: none; }
}
