/* DeNovo Works — The Works Platform
   Brand system: warm near-black, gold accent, semantic domain colors.
   Fonts: JetBrains Mono (structural), Atkinson Hyperlegible Next (reading). */

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

:root {
    /* Backgrounds — warm near-black */
    --bg-base: #0C0C0A;
    --bg-surface: #14140F;
    --bg-overlay: #1B1B16;
    --bg-inset: #070706;

    /* Borders */
    --border: #2C2924;
    --border-muted: #3A3732;
    --border-accent: rgba(212,168,83,0.4);

    /* Text */
    --text-primary: #E5E1D8;
    --text-secondary: #9A958C;
    --text-tertiary: #5D5950;
    --text-link: #D4A853;

    /* Accent: gold */
    --accent: #D4A853;
    --accent-muted: rgba(212,168,83,0.12);
    --accent-fg: #D4A853;
    --accent-emphasis: #B8922E;

    /* Status colors */
    --green: #5DCAA5;
    --green-muted: rgba(93,202,165,0.12);
    --red: #E87070;
    --red-muted: rgba(232,112,112,0.12);
    --amber: #E0A030;
    --amber-muted: rgba(224,160,48,0.12);
    --purple: #AFA9EC;
    --purple-muted: rgba(175,169,236,0.12);

    /* Domain colors — semantic, not decorative */
    --domain-amber-bg: #1A150E;
    --domain-amber-bd: #6B4D1A;
    --domain-amber-text: #FAC775;
    --domain-amber-sub: #BA7517;

    --domain-teal-bg: #0E1A16;
    --domain-teal-bd: #0F6E56;
    --domain-teal-text: #5DCAA5;
    --domain-teal-sub: #1D9E75;

    --domain-blue-bg: #0F161A;
    --domain-blue-bd: #1B4965;
    --domain-blue-text: #85B7EB;
    --domain-blue-sub: #378ADD;

    --domain-purple-bg: #13111E;
    --domain-purple-bd: #3C3489;
    --domain-purple-text: #AFA9EC;
    --domain-purple-sub: #7F77DD;

    --domain-coral-text: #F0997B;
    --domain-green-text: #97C459;

    /* Geometry */
    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);

    /* Fonts */
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
    --font-sans: 'Atkinson Hyperlegible Next', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    overflow: hidden;
    height: 100vh;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
}

.mono {
    font-family: var(--font-mono);
    font-size: 13px;
}

/* ═══════════════════════════════════════════
   TOP BAR — GitHub-inspired nav
   ═══════════════════════════════════════════ */
.topbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}
.topbar-inner {
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    cursor: pointer;
    user-select: none;
    text-decoration: none;
}
.brand-icon {
    color: var(--accent);
    font-size: 18px;
}
.brand-name {
    font-weight: 600;
    color: var(--text-primary);
}
.brand-page {
    font-weight: 500;
    color: var(--text-secondary);
}
.brand:hover .brand-name,
.brand:hover .brand-page {
    color: var(--accent);
}
.brand-sep {
    color: var(--text-tertiary);
}
.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-dim {
    background: var(--border-muted);
    color: var(--text-tertiary);
}
.badge-active {
    background: var(--accent-muted);
    color: var(--accent);
}

/* ═══════════════════════════════════════════
   PHASE STEPPER — horizontal progress bar
   ═══════════════════════════════════════════ */
/* ─── Second Bar: Sessions + Stepper ──── */
.second-bar {
    display: flex;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 90;
    height: 44px;
}
.second-bar-sidebar {
    width: 260px;
    min-width: 260px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-right: 1px solid var(--border);
}
.second-bar-sidebar h3 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}
.second-bar-stepper {
    flex: 1;
}
.stepper-inner {
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 44px;
    gap: 0;
}
.step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
    position: relative;
}
.step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    transition: all 0.3s;
}
.step.active .step-dot {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-muted);
}
.step.done .step-dot {
    background: var(--green);
}
.step-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    transition: color 0.3s;
}
.step.active .step-label {
    color: var(--text-primary);
}
.step.done .step-label {
    color: var(--text-secondary);
}
.step.clickable {
    cursor: pointer;
}
.step.clickable:hover .step-label {
    color: var(--accent);
}
.step.clickable:hover .step-dot {
    box-shadow: 0 0 6px var(--green);
}
.step.viewing .step-dot {
    box-shadow: 0 0 8px var(--amber);
    background: var(--amber);
}
.step.viewing .step-label {
    color: var(--amber);
}
.step-line {
    flex: 1;
    height: 1px;
    background: var(--border-muted);
    margin: 0 12px;
}

/* ═══════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════ */

.app-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ─── Session Sidebar ─────────────────────── */
.session-sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
/* sidebar-header moved to .second-bar-sidebar */
.sidebar-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.sidebar-session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}
.sidebar-session-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
    position: relative;
}
.sidebar-session-item:hover {
    background: var(--bg-overlay);
}
.sidebar-session-item.active {
    background: var(--bg-overlay);
    border-left-color: var(--accent);
}
.sidebar-phase-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
}
.sidebar-phase-dot.phase-setup { background: var(--accent); }
.sidebar-phase-dot.phase-discovery { background: var(--purple); }
.sidebar-phase-dot.phase-planning { background: var(--amber); }
.sidebar-phase-dot.phase-executing { background: var(--amber); }
.sidebar-phase-dot.phase-review { background: var(--green); }
.sidebar-phase-dot.phase-complete {
    background: none;
    position: relative;
}
.sidebar-phase-dot.phase-complete::after {
    content: '\2713';
    position: absolute;
    top: -3px;
    left: -1px;
    font-size: 10px;
    color: var(--green);
    font-weight: bold;
}
.sidebar-session-info {
    flex: 1;
    min-width: 0;
}
.sidebar-session-goal {
    font-size: 12px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}
.sidebar-session-meta {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 2px;
}
.sidebar-session-delete {
    position: absolute;
    right: 8px;
    top: 8px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 2px 4px;
}
.sidebar-session-item:hover .sidebar-session-delete {
    opacity: 1;
}
.sidebar-session-delete:hover {
    color: var(--red);
}

/* ─── Main Content Area ───────────────────── */
.main-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

main {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.phase { display: none; }
.phase.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.phase-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 32px 24px 16px;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.action-bar {
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}

/* ─── Setup Action Bar (full-width pinned footer) ─── */
.setup-action-bar {
    flex-direction: column;
    gap: 10px;
}
.action-bar-objective {
    width: 100%;
}
.action-bar-objective textarea {
    width: 100%;
    display: block;
}
.action-bar-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    margin-bottom: 6px;
}
.action-bar-buttons {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
}

/* ─── Welcome State ──────────────────────── */
#phase-welcome.phase.active,
#phase-complete.phase.active,
#phase-admin.phase.active {
    overflow-y: auto;
    padding: 32px 24px;
}
.welcome-card {
    text-align: center;
    padding: 100px 20px;
}
.welcome-icon {
    font-size: 48px;
    color: var(--accent);
    margin-bottom: 16px;
}
.welcome-card h1 {
    font-size: 24px;
    margin-bottom: 8px;
}
.welcome-card p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
    }
    .session-sidebar {
        display: none;
    }
}

.page-title {
    margin-bottom: 16px;
}
.page-title h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.page-title p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════
   SETUP — Two-column grid
   ═══════════════════════════════════════════ */
.setup-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
    align-items: start;
}
@media (max-width: 768px) {
    .setup-grid { grid-template-columns: 1fr; }
}

.panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-muted);
    background: var(--bg-overlay);
}
.panel-icon {
    font-size: 16px;
}
.panel-header h2 {
    font-size: 14px;
    font-weight: 600;
    flex: 1;
}
.required-tag {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    background: var(--accent-muted);
    padding: 2px 7px;
    border-radius: 3px;
}
.optional-tag {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    background: var(--border-muted);
    padding: 2px 7px;
    border-radius: 3px;
}
.panel-body {
    padding: 14px 16px;
}
.panel-hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* ═══════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    min-height: 34px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    box-sizing: border-box;
}
.btn:disabled {
    display: none;
}
.btn-primary {
    background: var(--accent-emphasis);
    color: #fff;
    border-color: var(--accent-emphasis);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-fg);
    border-color: var(--accent-fg);
}
.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-outline:hover:not(:disabled) {
    color: var(--text-primary);
    border-color: var(--text-tertiary);
    background: var(--bg-overlay);
}
.btn-accent {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}
.btn-accent:hover:not(:disabled) {
    background: #2ea043;
}
.btn-danger {
    background: var(--red-muted);
    color: var(--red);
    border-color: rgba(248,81,73,0.3);
}
.btn-danger:hover:not(:disabled) {
    background: rgba(248,81,73,0.2);
}
.btn-lg {
    padding: 12px 28px;
    font-size: 14px;
    border-radius: var(--radius-lg);
}

.action-bar-split {
    justify-content: space-between;
}

/* ═══════════════════════════════════════════
   INPUTS
   ═══════════════════════════════════════════ */
.input-group {
    display: flex;
    gap: 8px;
}
input[type="text"], textarea {
    flex: 1;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}
input[type="text"]:focus, textarea:focus {
    border-color: var(--accent-fg);
    box-shadow: 0 0 0 3px var(--accent-muted);
}
textarea {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    resize: vertical;
    min-height: 48px;
}

/* ─── Folder picker ─── */
/* ─── Global Loading Overlay ───────────────── */
.global-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.15s;
}
.global-overlay.hidden { opacity: 0; pointer-events: none; }
.global-overlay-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--text-secondary);
    font-size: 14px;
}
.global-spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skill-spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

/* ─── Source Rows (scratch / folder / github) ── */
.source-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.source-row.disabled { opacity: 0.35; pointer-events: none; }
.source-browse { flex-shrink: 0; }
.source-path {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--text-tertiary);
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-height: 38px;
    line-height: 22px;
}
.source-path.has-value { color: var(--text-primary); }
.source-name-input {
    width: 140px;
    padding: 8px 12px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
}
.source-name-input::placeholder { color: var(--text-tertiary); }
.source-name-input:focus { border-color: var(--accent-fg); outline: none; }
.source-action { flex-shrink: 0; min-width: 80px; }
.source-select, .source-select-sm {
    padding: 8px 12px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    appearance: auto;
}
.source-select:focus, .source-select-sm:focus { border-color: var(--accent); outline: none; }
.source-select { flex: 1; min-width: 0; }
.source-select-sm { width: 140px; flex-shrink: 0; }

/* ─── Scan results ─── */
.scan-stats {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 14px;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
}
.scan-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--accent);
}
.scan-stat-icon {
    font-size: 14px;
}
.scan-files {
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border-muted);
    border-radius: var(--radius);
    background: var(--bg-inset);
}
.scan-file {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    font-size: 12px;
    border-bottom: 1px solid var(--border-muted);
}
.scan-file:last-child { border-bottom: none; }
.scan-file-name {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
}
.scan-file-meta {
    color: var(--text-tertiary);
    font-size: 11px;
}

/* ═══════════════════════════════════════════
   DROP ZONE (file upload)
   ═══════════════════════════════════════════ */
.drop-zone {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg-inset);
}
.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-muted);
}
.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--text-tertiary);
    font-size: 13px;
}
.drop-icon {
    font-size: 20px;
    color: var(--accent);
    font-weight: 700;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent-muted);
}

/* ─── File chips ─── */
.file-chips {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-top: 10px;
    max-height: 160px;
    overflow-y: auto;
    border: 1px solid var(--border-muted);
    border-radius: var(--radius);
    background: var(--bg-inset);
}
.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-overlay);
    border: 1px solid var(--border-muted);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
}
.file-chip-icon {
    color: var(--accent);
}
.file-chip-row {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    border-bottom: 1px solid var(--border-muted);
}
.file-chip-row:last-child { border-bottom: none; }
.file-desc-input {
    width: 100%;
    background: var(--bg-inset);
    border: 1px solid var(--border-muted);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text-secondary);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.file-desc-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-muted);
}
.file-desc-input.has-value {
    color: var(--text-primary);
    border-color: var(--green);
}

/* ═══════════════════════════════════════════
   DISCOVERY — Chat + Sidebar
   ═══════════════════════════════════════════ */
.discovery-layout {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 20px;
    flex: 1;
    min-height: 0;
    padding: 16px 24px;
}
@media (max-width: 768px) {
    .discovery-layout { grid-template-columns: 1fr; }
    .context-sidebar { display: none; }
}

.chat-pane {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.chat-pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-muted);
    background: var(--bg-overlay);
}
.chat-pane-header h2 {
    font-size: 14px;
    font-weight: 600;
}
.counter-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--border-muted);
    color: var(--text-tertiary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-msg {
    flex: 1;
    min-width: 0;
    position: relative;
}
.msg-body {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
}
.chat-msg.user .msg-body {
    background: var(--purple-muted);
    color: var(--text-primary);
    border-bottom-right-radius: 4px;
    border-right: 3px solid var(--text-tertiary);
    padding-right: 14px;
}
.chat-msg.assistant .msg-body {
    background: none;
    border: none;
    color: var(--text-primary);
    border-radius: 0;
    padding: 6px 0;
}

.chat-compose {
    border-top: 1px solid var(--border-muted);
    padding: 0 18px 12px;
    background: var(--bg-overlay);
}
.chat-compose textarea {
    width: 100%;
    display: block;
    min-height: 60px;
    max-height: 180px;
    overflow-y: auto;
    resize: none; /* auto-grow handles it */
}
.compose-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}
.compose-hint {
    font-size: 11px;
    color: var(--text-tertiary);
}
.compose-actions {
    display: flex;
    gap: 8px;
}

/* ─── Context Sidebar ─── */
.context-sidebar {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}
.sidebar-section {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 14px 16px;
}
.sidebar-section:first-child {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.sidebar-section:last-child {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.sidebar-section + .sidebar-section {
    border-top: none;
}
.sidebar-section h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    margin-bottom: 6px;
}
.sidebar-value {
    font-size: 13px;
    color: var(--text-secondary);
    overflow-wrap: break-word;
}
.sidebar-source {
    display: block;
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 2px;
}
.sidebar-name {
    display: block;
    font-size: 11.5px;
    color: var(--text-primary);
    font-weight: 500;
}

/* ═══════════════════════════════════════════
   EXECUTION — Progress
   ═══════════════════════════════════════════ */
.exec-container {
    max-width: 700px;
}
.exec-progress {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
}
.exec-bar {
    height: 4px;
    background: var(--border-muted);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 14px;
}
.exec-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-emphasis), var(--accent));
    border-radius: 2px;
    width: 0%;
    transition: width 0.5s ease;
}
.exec-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.exec-status-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
}
.exec-turns-counter {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}
.exec-turns-counter strong {
    color: var(--accent);
}
.exec-model-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 3px;
    background: var(--purple-muted);
    color: var(--purple);
    margin-left: 8px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ─── Live execution log ─── */
.exec-log {
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    max-height: 300px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.8;
}
.log-entry {
    color: var(--text-secondary);
    padding: 2px 0;
    border-bottom: 1px solid var(--border-muted);
}
.log-entry:last-child { border-bottom: none; }
.log-entry.log-error {
    color: var(--red);
}
.log-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 8px;
    vertical-align: middle;
    animation: pulse 1.5s ease-in-out infinite;
}
.log-dot.error {
    background: var(--red);
    animation: none;
}
@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}
.log-time {
    color: var(--text-tertiary);
    margin-right: 10px;
}

.exec-turns {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.turn-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
}
.turn-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.turn-card-body {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: pre-wrap;
    max-height: 60px;
    overflow: hidden;
}

/* ═══════════════════════════════════════════
   REVIEW — Tabs + Panels
   ═══════════════════════════════════════════ */

/* ─── Review Header (pinned at top) ─── */
.review-header {
    flex-shrink: 0;
    padding: 16px 24px 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}
.review-header .page-title {
    margin-bottom: 12px;
}
.review-header .tab-bar {
    margin-bottom: 0;
    border-bottom: none;
}

.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.tab {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.tab:hover {
    color: var(--text-primary);
}
.tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

.review-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.prose {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.prose p { margin: 8px 0; }
.prose h1 { margin-top: 20px; font-size: 18px; }
.prose h2 { margin-top: 18px; font-size: 16px; }
.prose h3, .prose h4 { margin-top: 14px; font-size: 14px; }
.prose ul, .prose ol { margin: 8px 0; padding-left: 24px; }
.prose li { margin: 4px 0; }

/* ─── File changes ─── */
.file-change-list {}
.change-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-muted);
    font-size: 13px;
}
.change-row:last-child { border-bottom: none; }
.change-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 3px;
    min-width: 52px;
    text-align: center;
}
.change-badge.added   { background: var(--green-muted);  color: var(--green); }
.change-badge.modified { background: var(--amber-muted); color: var(--amber); }
.change-badge.deleted  { background: var(--red-muted);   color: var(--red); }
.change-path {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-primary);
}

/* ─── Diff viewer ─── */
.diff-viewer {
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.5;
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
    white-space: pre;
    color: var(--text-secondary);
}
.diff-add { color: var(--green); }
.diff-del { color: var(--red); }
.diff-hunk { color: var(--purple); font-weight: 600; }

/* ─── Turn details ─── */
.turn-details {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.td-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
}
.td-header {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.td-preview {
    font-size: 13px;
    color: var(--text-tertiary);
    max-height: 150px;
    overflow-y: auto;
    line-height: 1.5;
}

/* ─── Alert ─── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-error {
    background: var(--red-muted);
    border: 1px solid rgba(248,81,73,0.3);
    color: var(--red);
}

/* ─── Review actions bar ─── */
.review-actions-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}
.review-actions-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ═══════════════════════════════════════════
   COMPLETE
   ═══════════════════════════════════════════ */
.complete-card {
    text-align: center;
    padding: 60px 20px;
}
.complete-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--green-muted);
    color: var(--green);
    font-size: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}
.complete-card h1 {
    font-size: 24px;
    margin-bottom: 8px;
}
.complete-card p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ═══════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════ */
.hidden { display: none !important; }

.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
}

/* ═══════════════════════════════════════════
   MODAL — Git choice overlay
   ═══════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(1,4,9,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}
.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    max-width: 480px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    position: relative;
}
.modal-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.modal-close:hover {
    color: var(--text-primary);
}
.modal-card h2 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 10px;
}
.modal-card p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
}
.modal-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.modal-option-btn {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 18px;
    text-align: left;
    width: 100%;
    border-radius: var(--radius);
    justify-content: flex-start;
}
.modal-option-icon {
    font-size: 20px;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
    line-height: 1.4;
}
.modal-option-btn strong {
    display: block;
    font-size: 13px;
    margin-bottom: 2px;
}
.modal-option-btn small {
    display: block;
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 400;
}

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


/* ─── Plan Container ────────────────────────────── */
.plan-generating-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 13px;
    color: var(--text-secondary);
}
.plan-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-y: auto;
    padding: 24px;
    margin-top: 12px;
}
.plan-content {
    min-height: 0;
}


/* ─── Topbar Buttons ────────────────────────────── */
.topbar-btn {
    font-size: 12px;
    padding: 4px 12px;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}


/* ─── Discovery Status (live feedback) ──────────── */
.discovery-status {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    height: 28px;
    padding: 0 16px;
    font-size: 12px;
    line-height: 1;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-muted);
    box-sizing: border-box;
}
.discovery-status.idle .discovery-status-dot {
    display: none;
}

.discovery-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse-dot 1.4s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}


/* ─── Image Thumbnails & Modal ──────────────────── */
.file-thumb {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: border-color 0.2s;
    flex-shrink: 0;
}
.file-thumb:hover {
    border-color: var(--accent);
}

.file-chip-image {
    cursor: pointer;
    color: var(--text-link);
}
.file-chip-image:hover {
    text-decoration: underline;
}

.image-modal-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}
.image-modal-card img {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}


/* ─── Chat Image Preview ────────────────────────── */
.chat-image-preview {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    flex-wrap: wrap;
    border-top: 1px solid var(--border-muted);
}
.chat-image-thumb {
    position: relative;
    display: inline-block;
}
.chat-image-preview img {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: border-color 0.15s;
}
.chat-image-preview img:hover {
    border-color: var(--accent);
}
.chat-image-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--red);
    color: white;
    border: none;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    cursor: pointer;
    padding: 0;
}


/* ─── Review Notice ─────────────────────────────── */
.review-notice {
    background: var(--accent-muted);
    color: var(--accent);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 12px;
    margin-bottom: 16px;
}


/* ─── Small Button ──────────────────────────────── */
.btn-sm {
    font-size: 12px;
    padding: 4px 10px;
    min-height: unset;
}


/* ─── Read-Only Mode (viewing past phases) ──────── */
main.read-only {
    position: relative;
}
main.read-only::before {
    content: 'Viewing past phase (read-only)';
    position: sticky;
    top: 0;
    display: block;
    background: var(--amber-muted);
    color: var(--amber);
    text-align: center;
    padding: 6px 16px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    z-index: 10;
}
main.read-only .phase.active {
    opacity: 0.75;
}
main.read-only .btn,
main.read-only textarea,
main.read-only input,
main.read-only .drop-zone,
main.read-only button {
    pointer-events: none !important;
    opacity: 0.4 !important;
}
/* Allow scrolling and tabs in read-only mode */
main.read-only .phase-scroll,
main.read-only .chat-messages,
main.read-only .tab,
main.read-only .tab-content,
main.read-only .td-card,
main.read-only .change-row {
    pointer-events: auto !important;
    opacity: 1 !important;
}
/* Hide action bar in read-only review */
main.read-only .review-actions-bar {
    display: none;
}


/* ─── Admin Panel ───────────────────────────────── */
.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
@media (max-width: 768px) {
    .admin-grid { grid-template-columns: 1fr; }
}
.admin-input {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}
.admin-input:focus {
    outline: none;
    border-color: var(--accent);
}
select.admin-input {
    appearance: auto;
}
.admin-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-muted);
    font-size: 13px;
}
.admin-item:last-child {
    border-bottom: none;
}
.admin-link {
    color: var(--accent);
    font-size: 11px;
    word-break: break-all;
}
.admin-item-col {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}
.admin-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.admin-link-row {
    overflow: hidden;
}
.admin-item-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}


/* ─── Turn Detail Badges ──────────────────────────── */
.td-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--accent-muted);
    color: var(--accent);
    margin-left: 6px;
    vertical-align: middle;
}
.td-badge-fail {
    background: var(--red-muted);
    color: var(--red);
}
.td-badge-fix {
    background: var(--amber-muted);
    color: var(--amber);
}

/* ─── Preview Tab ───────────────────────────────── */
#preview-pane {
    padding: 16px;
}
.preview-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 13px;
}
.preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    color: var(--text-secondary);
    padding: 24px;
    text-align: center;
}
.preview-app-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.preview-app-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-surface);
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    color: var(--text-primary);
    transition: border-color 0.15s, background 0.15s;
}
.preview-app-card:hover {
    border-color: var(--accent);
    background: var(--bg-inset);
}
.preview-app-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
}
.preview-app-name {
    flex: 1;
    font-weight: 500;
}
.preview-app-open {
    color: var(--text-tertiary);
    font-size: 12px;
}

/* ─── Attach + Button ──────────────────────────── */
.btn-attach-plus {
    font-size: 20px;
    font-weight: 600;
    line-height: 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    flex-shrink: 0;
}
/* Match height of sibling buttons */
.action-bar .btn-attach-plus {
    width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
}
.compose-actions .btn-attach-plus {
    width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
    font-size: 18px;
}

/* ─── Stop Button ──────────────────────────── */
.btn-stop {
    width: 34px;
    height: 34px;
    background: var(--bg-inset);
    border: 1.5px solid var(--red, #e55);
    cursor: pointer;
    padding: 0;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}
.btn-stop:hover {
    background: var(--bg-hover, rgba(255,255,255,0.08));
}

/* ─── Activity Collapsible (Part B) ──────────────── */
.msg-activity-section {
    margin: 2px 0 6px 0;
    max-width: 90%;
}
.msg-activity-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 6px;
    user-select: none;
    transition: background 0.15s;
}
.msg-activity-toggle:hover {
    background: var(--bg-hover, rgba(255,255,255,0.06));
}
.msg-activity-toggle .arrow {
    display: inline-block;
    font-size: 8px;
    transition: transform 0.2s;
}
.msg-activity-toggle.expanded .arrow {
    transform: rotate(90deg);
}
.msg-activity-list {
    display: none;
    padding: 4px 8px 4px 22px;
}
.msg-activity-list.open {
    display: block;
}
.msg-activity-item {
    font-size: 11px;
    color: var(--text-tertiary);
    padding: 1px 0;
    font-family: var(--font-mono, monospace);
    line-height: 1.5;
}

/* ─── Admin Folder Picker ──────────────────────── */
.admin-folder-picker {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ─── Turn Card Improvements ───────────────────── */
.td-card-secondary {
    background: var(--bg-inset);
    border-color: var(--border-muted);
    opacity: 0.8;
}
.td-substep {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-muted);
    opacity: 0.75;
}

/* ─── Turns Selector ─────────────────────────── */
.turns-selector {
    position: relative;
    display: inline-block;
}
.turns-selector:has(.turns-btn:disabled) {
    display: none;
}
.turns-btn {
    min-width: 72px;
    text-align: center;
}
.turns-dropdown {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    z-index: 100;
    min-width: 100px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.turns-option {
    display: block;
    width: 100%;
    padding: 6px 12px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    border-radius: calc(var(--radius) - 2px);
}
.turns-option:hover {
    background: var(--bg-inset);
}
.turns-option.active {
    color: var(--accent);
    font-weight: 600;
}
.td-meta {
    color: var(--text-tertiary);
    font-size: 11px;
}
.td-badge-verify {
    background: var(--accent-muted);
    color: var(--accent);
}

/* ─── Review Summary Prose ─────────────────────── */
.prose strong { color: var(--text-primary); }
.prose br + br { display: block; margin-top: 4px; }

/* ─── Clone Picker ───────────────────────────── */
.clone-picker { margin-top: 0; }
.clone-input-row { display: flex; gap: 8px; align-items: center; }
.clone-url-input { flex: 1; padding: 8px 12px; background: var(--bg-inset); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 14px; }
.clone-branch-input { width: 100px; padding: 8px 12px; background: var(--bg-inset); border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); font-size: 14px; }
.clone-url-input::placeholder, .clone-branch-input::placeholder { color: var(--text-tertiary); }
.clone-url-input:focus, .clone-branch-input:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px var(--accent-muted); outline: none; }

/* ─── Picker Divider ─────────────────────────── */
.picker-divider { display: flex; align-items: center; gap: 12px; margin: 14px 0; color: var(--text-tertiary); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.picker-divider::before, .picker-divider::after { content: ''; flex: 1; height: 1px; background: var(--border-muted); }

/* ─── Reference Actions ─────────────────────── */
.ref-actions { display: flex; gap: 8px; margin-bottom: 10px; }

/* ─── PR Link (Complete phase) ───────────────── */
.pr-link { display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; background: var(--bg-surface); border: 1px solid var(--accent); border-radius: 8px; color: var(--accent); text-decoration: none; font-weight: 500; }
.pr-link:hover { text-decoration: underline; background: var(--accent-muted); }

/* ─── Code Blocks ──────── */
.msg-body pre, .plan-content pre, .prose pre {
    position: relative;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    padding-top: 32px; /* room for lang label + copy btn */
    overflow-x: auto;
    margin: 10px 0;
    font-size: 13px;
    line-height: 1.5;
}
.msg-body pre code, .plan-content pre code, .prose pre code {
    background: none;
    padding: 0;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: inherit; /* don't apply inline code color to code blocks */
}
.copy-btn {
    position: absolute;
    top: 6px;
    right: 8px;
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    color: var(--text-tertiary);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text-primary); background: var(--bg-surface); }
.code-lang {
    position: absolute;
    top: 6px;
    left: 12px;
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: system-ui;
}

/* ─── Inline Code ──────── */
.msg-body code, .plan-content code, .prose code {
    background: rgba(255,255,255,0.06);
    color: #f0a0a0; /* soft red/pink like Claude Code */
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'JetBrains Mono', monospace;
}
.msg-body pre code, .plan-content pre code, .prose pre code {
    color: inherit;
    background: none;
    padding: 0;
}

/* ─── Tables ──────── */
.msg-body table, .plan-content table, .prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 13px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.msg-body th, .plan-content th, .prose th {
    background: var(--bg-overlay);
    font-weight: 600;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 2px solid var(--border);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
}
.msg-body td, .plan-content td, .prose td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-muted);
}
.msg-body tr:last-child td, .plan-content tr:last-child td { border-bottom: none; }
.msg-body tr:hover td, .plan-content tr:hover td { background: rgba(255,255,255,0.02); }

/* ─── Message Wrapper (copy btn outside bubble) ──────── */
.chat-msg-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    position: relative;
    max-width: 90%;
}
.chat-msg-wrapper.assistant {
    max-width: 100%;
}
.chat-msg-wrapper.user {
    flex-direction: row-reverse;
    align-self: flex-end;
}
.chat-msg-wrapper.pending {
    opacity: 0.5;
}
.chat-msg-wrapper .msg-copy-btn {
    flex-shrink: 0;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}
.chat-msg-wrapper:hover .msg-copy-btn {
    opacity: 0.5;
}
.msg-copy-btn:hover {
    opacity: 1 !important;
}
.msg-copy-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    border-radius: 4px;
    line-height: 1;
}
.msg-copy-btn:hover { background: var(--bg-overlay); }

/* ─── Thinking Indicator (inline) ──────── */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--amber, #e8a044);
    font-size: 13px;
    padding: 4px 0;
}
.thinking-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--amber, #e8a044);
    border-radius: 50%;
    animation: thinking-pulse 1.5s ease-in-out infinite;
}
@keyframes thinking-pulse {
    0%, 100% { opacity: 0.4; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* ─── Blockquotes ──────── */
.msg-body blockquote, .plan-content blockquote, .prose blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 14px;
    margin: 10px 0;
    color: var(--text-secondary);
    background: rgba(255,255,255,0.02);
    border-radius: 0 6px 6px 0;
}

/* ─── Links ──────── */
.msg-body a, .plan-content a, .prose a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s;
}
.msg-body a:hover, .plan-content a:hover, .prose a:hover {
    border-bottom-color: var(--accent);
}

/* assistant messages: plain text, no bubble */

/* ─── Other Markdown Elements ──────── */
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 { margin: 14px 0 6px; }
.msg-body ul, .msg-body ol { padding-left: 20px; margin: 6px 0; }
.msg-body li { margin: 3px 0; }
.msg-body p { margin: 6px 0; }

/* ─── Tooltips (JS-positioned) ─────────────── */
.tooltip-popup {
    position: fixed;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-primary);
    background: var(--bg-overlay, #1a1a2e);
    border: 1px solid var(--border-muted);
    border-radius: 4px;
    text-align: left;
    max-width: 220px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: normal;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s;
    z-index: 10000;
}

/* ═══════════════════════════════════════════
   BRAND MARK — DeNovo_ cursor + erase/retype color cycle
   8 colors, 5s per color, 40s full cycle.
   ═══════════════════════════════════════════ */
.brand-mark {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 17px;
    letter-spacing: -0.5px;
    color: var(--accent);
    animation: logo-color 40s linear infinite;
}
.brand-text {
    display: inline-block;
    animation: logo-clip 5s linear infinite;
}
.brand-cursor {
    display: inline-block;
    width: 8px;
    height: 2.5px;
    background: currentColor;
    border-radius: 1px;
    margin-left: 1px;
    vertical-align: baseline;
    animation: cursor-blink 1.2s ease-in-out infinite, cursor-track 5s linear infinite;
}
@keyframes cursor-blink {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 0.15; }
}
/* Color cycle: gold → teal → amber → purple → coral → blue → ink → green → gold
   Switches at midpoint of each blank phase (when text is invisible). */
@keyframes logo-color {
    0%, 6.24%   { color: #D4A853; }
    6.25%, 18.74%  { color: #5DCAA5; }
    18.75%, 31.24% { color: #FAC775; }
    31.25%, 43.74% { color: #AFA9EC; }
    43.75%, 56.24% { color: #F0997B; }
    56.25%, 68.74% { color: #85B7EB; }
    68.75%, 81.24% { color: #E5E1D8; }
    81.25%, 93.74% { color: #97C459; }
    93.75%, 100%   { color: #D4A853; }
}
/* Clip-path erase/retype on 5s cycle.
   35-48%: erase (right inset grows, text disappears right→left)
   48-52%: blank
   52-65%: retype (right inset shrinks, text appears left→right) */
@keyframes logo-clip {
    0%, 35%   { clip-path: inset(0 0 0 0); }
    48%, 52%  { clip-path: inset(0 100% 0 0); }
    65%, 100% { clip-path: inset(0 0 0 0); }
}
/* Cursor tracks the clip edge during erase/retype */
@keyframes cursor-track {
    0%, 35%   { transform: translateX(0); }
    48%, 52%  { transform: translateX(-6ch); }
    65%, 100% { transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
    .brand-mark { animation: none; color: var(--accent); }
    .brand-text { animation: none; }
    .brand-cursor { animation: cursor-blink 1.2s ease-in-out infinite; background: var(--accent); }
}
.brand-platform {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════
   POPUP OVERLAY — reusable overlay pattern
   Used for: search results, email review, refs upload, etc.
   ═══════════════════════════════════════════ */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(1,4,9,0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
}
.popup-overlay.hidden { display: none; }
.popup-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 10px);
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.popup-title {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}
.popup-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.popup-close:hover { color: var(--text-primary); }
.popup-body {
    overflow-y: auto;
    flex: 1;
    padding: 0;
}
.popup-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════
   AUTH PAGES — Login, Invite
   ═══════════════════════════════════════════ */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: auto;
}
.auth-container {
    width: 100%;
    max-width: 380px;
    padding: 40px 24px;
}
.auth-brand {
    display: flex;
    align-items: baseline;
    gap: 7px;
    margin-bottom: 32px;
    justify-content: center;
}
.auth-form {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
}
.auth-heading {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
    margin-bottom: 20px;
}
.auth-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 6px;
    margin-top: 14px;
}
.auth-label:first-of-type { margin-top: 0; }
.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}
.auth-form input:focus {
    border-color: var(--accent);
}
.auth-form input[readonly] {
    opacity: 0.6;
    cursor: not-allowed;
}
.auth-error {
    background: var(--red-muted);
    color: var(--red);
    font-size: 13px;
    padding: 8px 12px;
    border-radius: var(--radius);
    margin-bottom: 14px;
}
.btn-full {
    width: 100%;
    margin-top: 20px;
}
.auth-alt {
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 16px;
    margin-bottom: 0;
}
.auth-alt a {
    color: var(--accent);
    text-decoration: none;
}
.auth-alt a:hover {
    text-decoration: underline;
}

/* ═══════════════════════════════════════════
   WORKS DASHBOARD — /works landing page
   ═══════════════════════════════════════════ */
.works-page {
    overflow: auto;
    height: 100vh;
}
.works-header {
    background: var(--bg-overlay);
    border-bottom: 1px solid var(--border);
    padding: 8px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.works-nav {
    display: flex;
    gap: 2px;
}
.works-tab {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}
.works-tab:hover { color: var(--text-primary); background: var(--bg-surface); }
.works-tab.active { color: var(--accent); background: var(--accent-muted); }
.works-tab-dot {
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    margin-right: 6px;
}
.works-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.works-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-muted);
    border: 1px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--accent);
}

/* Works main */
.works-main {
    padding: 24px 32px;
    max-width: 1100px;
    margin: 0 auto;
}

/* Workspace chips */
.works-chips {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.works-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    cursor: pointer;
    transition: all 0.15s;
}
.works-chip:hover { border-color: var(--domain-blue-bd); }
.works-chip.active { border-color: var(--domain-blue-text); background: var(--domain-blue-bg); }
.works-chip-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--domain-blue-text);
}
.works-chip-name {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}
.works-chip--create {
    border-style: dashed;
    opacity: 0.7;
    cursor: pointer;
}
.works-chip--create:hover { opacity: 1; }

/* Breadcrumb */
.works-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-tertiary);
    margin-bottom: 16px;
}
.works-breadcrumb a {
    color: var(--domain-blue-text);
    text-decoration: none;
}
.works-breadcrumb a:hover { text-decoration: underline; }

/* Stats row */
.works-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}
.works-stat {
    border-radius: var(--radius);
    padding: 14px 16px;
    border: 1px solid;
}
.works-stat.amber  { background: var(--domain-amber-bg);  border-color: var(--domain-amber-bd); }
.works-stat.teal   { background: var(--domain-teal-bg);   border-color: var(--domain-teal-bd); }
.works-stat.blue   { background: var(--domain-blue-bg);   border-color: var(--domain-blue-bd); }
.works-stat.purple { background: var(--domain-purple-bg);  border-color: var(--domain-purple-bd); }
.works-stat-label {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.works-stat.amber .works-stat-label  { color: var(--domain-amber-sub); }
.works-stat.teal .works-stat-label   { color: var(--domain-teal-sub); }
.works-stat.blue .works-stat-label   { color: var(--domain-blue-sub); }
.works-stat.purple .works-stat-label { color: var(--domain-purple-sub); }
.works-stat-value {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 600;
}
.works-stat.amber .works-stat-value  { color: var(--domain-amber-text); }
.works-stat.teal .works-stat-value   { color: var(--domain-teal-text); }
.works-stat.blue .works-stat-value   { color: var(--domain-blue-text); }
.works-stat.purple .works-stat-value { color: var(--domain-purple-text); }
.works-stat-sub {
    font-family: var(--font-sans);
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* Two-column layout */
.works-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.works-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.works-panel-header {
    background: var(--bg-overlay);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}
.works-panel-title {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-secondary);
}
.works-panel-body { padding: 0; }

/* Task items */
.works-task-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-muted);
}
.works-task-item:last-child { border-bottom: none; }
.works-task-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.works-task-dot.running { background: var(--domain-teal-text); box-shadow: 0 0 6px var(--domain-teal-text); }
.works-task-dot.done { background: var(--text-tertiary); }
.works-task-info { flex: 1; min-width: 0; }
.works-task-name {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.works-task-meta {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* Dossier items */
.works-dossier-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-muted);
}
.works-dossier-item:last-child { border-bottom: none; }
.works-dossier-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    background: var(--domain-amber-bg);
    border: 1px solid var(--domain-amber-bd);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--domain-amber-text);
    flex-shrink: 0;
}
.works-dossier-info { flex: 1; }
.works-dossier-name {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
}
.works-dossier-meta {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-tertiary);
    margin-top: 1px;
}

@media (max-width: 768px) {
    .works-stats { grid-template-columns: repeat(2, 1fr); }
    .works-columns { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════
   MOBILE — phone / tablet overrides
   Professional mobile pattern:
   - Vertical scroll unlocked, horizontal locked
   - 16px minimum font-size on inputs (prevents iOS zoom-on-focus)
   - 44px minimum touch targets (iOS HIG / WCAG)
   - Safe-area padding (notch + home indicator)
   - Multi-column desktop grids collapse to 1 column
   - Long mono strings get their own horizontal overflow
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Root: let the document scroll naturally, kill horizontal overflow,
       respect safe areas, use momentum scrolling on iOS. */
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
        height: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: none;
    }
    body {
        min-height: 100vh;
        min-height: 100dvh;
        font-size: 15px;
        line-height: 1.6;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Belt + suspenders: nothing wider than the viewport */
    body, .app-layout, .main-content, .topbar, .topbar-inner, .second-bar,
    .phase-scroll, .setup-grid, .panel, .page-title, .auth-container,
    .works-columns, .works-stats {
        max-width: 100vw;
        box-sizing: border-box;
    }

    /* ── Topbar: single row, condensed, sticky ── */
    .topbar {
        position: sticky;
        top: 0;
        z-index: 100;
    }
    .topbar-inner {
        padding: 12px 16px;
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        gap: 10px;
        min-height: 52px;
        flex-wrap: nowrap;
    }
    .brand-name { font-size: 16px; }
    .brand-page, .badge-dim, .brand-sep { display: none; }

    /* Second bar: reflow vertically on phone, hide side chrome */
    .second-bar {
        flex-direction: column;
        gap: 8px;
        padding: 10px 16px;
    }
    .second-bar-sidebar { display: none; }
    .second-bar-stepper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .second-bar-stepper::-webkit-scrollbar { display: none; }
    .second-bar-stepper .step-label {
        font-size: 10px;
        max-width: 60px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
    }

    /* ── Layout: single column, full-width ── */
    .app-layout { grid-template-columns: 1fr; }
    .session-sidebar { display: none; }
    .main-content {
        padding: 14px 16px;
        padding-left: max(14px, env(safe-area-inset-left));
        padding-right: max(14px, env(safe-area-inset-right));
    }
    .phase-scroll {
        overflow: visible;
        height: auto;
        max-height: none;
    }

    /* ── Grids collapse ── */
    .setup-grid,
    .works-columns { grid-template-columns: 1fr !important; }
    .works-stats { grid-template-columns: repeat(2, 1fr); }

    /* ── Forms / inputs: 16px prevents iOS zoom on focus, 44px touch ── */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="url"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important;
        min-height: 44px;
        padding: 10px 14px;
    }
    textarea {
        min-height: 88px;
    }
    button,
    .btn,
    a.btn,
    .works-tab,
    .step,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        padding-left: 14px;
        padding-right: 14px;
    }

    /* ── Auth page (login / signup): centered card, full-width form ── */
    .auth-container {
        padding: 32px 20px;
        padding-top: max(32px, env(safe-area-inset-top));
    }
    .auth-form {
        padding: 24px 20px;
    }
    .auth-heading { font-size: 18px; }
    .auth-brand { justify-content: center; }

    /* ── Long strings / tables never cause page overflow ── */
    pre, code, .mono { max-width: 100%; overflow-x: auto; }
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Page titles scale up a touch for readability */
    .page-title h1 { font-size: 22px; }
}

/* Very narrow phones: tighten further */
@media (max-width: 400px) {
    .topbar-inner { padding: 10px 12px; gap: 8px; min-height: 48px; }
    .main-content { padding: 12px; }
    .auth-form { padding: 20px 16px; }
}
