/* ═══════════════════════════════════════════════════════════════
   Workspace Agent — CSS
   Based on system.css by @sakun (v0.1.11)
   Font spec: Chicago (system UI/monospace) + Geneva (body/sans-serif)
   Fallback: -apple-system
   ═══════════════════════════════════════════════════════════════ */

/* ── Variables ────────────────────────────────────────────── */

html {
    zoom: 1.25;
}

:root {
    --border-color: oklch(45% 0 0);          /* softer dark gray for chrome borders */
    --box-shadow: 2px 2px var(--border-color);
    --element-spacing: 8px;
    --grouped-element-spacing: 6px;
    --radio-width: 12px;
    --checkbox-width: 13px;
    --radio-label-spacing: 6px;

    --sys-color-white: #FFFFFF;
    --sys-color-black: #000000;
    --sys-color-grey: #A5A5A5;
    --sys-color-darkgrey: #B6B7B8;

    --primary: var(--sys-color-white);
    --secondary: var(--sys-color-black);
    --tertiary: var(--sys-color-grey);
    --disabled: var(--sys-color-darkgrey);

    /* Font stacks */
    --font-chicago: Chicago, -apple-system, monospace;
    --font-geneva: 'Recursive', monospace;
    --font-monaco: Monaco, monospace;

    /* Accent: blue for links only. Chat message boxes are monochrome. */
    --color-subtle: oklch(50% 0.15 240);        /* blue — links only */
    --color-agent-text: oklch(28% 0.08 240);    /* (unused — kept for reference) */
    --color-user-band: oklch(94% 0.008 240);    /* (unused — kept for reference) */
    --color-result-pane: oklch(97.5% 0 0);      /* very light gray — message boxes */
    --color-result-data: oklch(92% 0.010 240);  /* (unused — kept for reference) */
}

/* ── Fonts ─────────────────────────────────────────────────── */

/* ChiKareGo2 = pixel-accurate Susan Kare Chicago recreation at 12pt */
@font-face {
    font-family: Chicago;
    src: url("/static/fonts/ChiKareGo2.woff2") format("woff2"),
         url("/static/fonts/ChiKareGo2.woff") format("woff");
}

/* Geneva = native macOS system font (/System/Library/Fonts/Geneva.ttf) */
/* No @font-face needed — browser resolves natively */

/* Monaco = native macOS monospace (/System/Library/Fonts/Monaco.ttf) */
/* No @font-face needed — browser resolves natively */

/* ── Reset ─────────────────────────────────────────────────── */

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

/* ── Body ─────────────────────────────────────────────────── */

body {
    font-family: var(--font-geneva);
    font-size: 12px;
    color: var(--secondary);
    background: var(--primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    cursor: default;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Scrollbar (WebKit) ───────────────────────────────────── */

::-webkit-scrollbar {
    width: 18px;
    background-color: var(--primary);
}

::-webkit-scrollbar-track {
    background: linear-gradient(45deg, var(--secondary) 25%, transparent 25%, transparent 75%, var(--secondary) 75%, var(--secondary)),
                linear-gradient(45deg, var(--secondary) 25%, transparent 25%, transparent 75%, var(--secondary) 75%, var(--secondary));
    background-color: var(--primary);
    background-size: 4px 4px;
    background-position: 0 0, 2px 2px;
    width: 10px;
    border-left: 2px solid var(--border-color);
}

::-webkit-scrollbar-thumb {
    width: 16px;
    box-sizing: content-box;
    background-color: var(--primary);
    border: 2px solid var(--border-color);
    border-right: none;
}

::-webkit-scrollbar-button {
    display: none;
}

/* ── Desktop ───────────────────────────────────────────────── */

#desktop {
    position: fixed;
    top: 34px;
    left: 0;
    right: 0;
    bottom: 0;
    /* 50% checkerboard — authentic Mac desktop */
    background-image: url("data:image/svg+xml,%3Csvg width='2' height='2' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,0h1v1h-1zM1,1h1v1h-1z' fill='%23000'/%3E%3C/svg%3E");
    background-repeat: repeat;
    image-rendering: pixelated;
    /* Backup — grid pattern:
    background: linear-gradient(90deg, var(--primary) 21px, transparent 1%) center,
                linear-gradient(var(--primary) 21px, transparent 1%) center,
                var(--secondary);
    background-size: 22px 22px;
    background-attachment: fixed;
    */
}

/* ── Selection Marquee ─────────────────────────────────────── */

#selection-marquee {
    position: fixed;
    border: 1px solid var(--border-color);
    background: transparent;
    pointer-events: none;
    display: none;
    z-index: 9999;
}

/* ── Menu Bar — Chicago 12px ─────────────────────────────── */

ul[role="menu-bar"] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 34px;
    display: flex;
    align-items: center;
    background: var(--primary);
    border-bottom: 2px solid var(--border-color);
    z-index: 10000;
    list-style: none;
    user-select: none;
    font-family: var(--font-chicago);
    font-size: 16px;
    font-weight: bold;
    padding: 0;
    padding-left: 18px;
    margin: 0;
}

#menu-bar-logo {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    height: 14px;
    width: auto;
    pointer-events: none;
}

ul[role="menu-bar"] > [role="menu-item"] {
    position: relative;
    padding: 3px 8px;
    cursor: default;
    line-height: 18px;
}

ul[role="menu-bar"] > [role="menu-item"]:hover,
ul[role="menu-bar"] > [role="menu-item"].open {
    background: var(--secondary);
    color: var(--primary);
    outline: none;
}

.apple-logo {
    background: url("/static/icon/apple.svg") no-repeat center;
    display: inline-block;
    width: 12px;
    height: 15px;
    vertical-align: middle;
}

ul[role="menu-bar"] > [role="menu-item"]:hover .apple-logo,
ul[role="menu-bar"] > [role="menu-item"].open .apple-logo {
    filter: invert(1);
}

/* ── Dropdown Menu — Geneva 12px ─────────────────────────── */

ul[role="menu"] {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    min-width: 180px;
    background: var(--primary);
    color: var(--secondary);
    border: 1px solid var(--border-color);
    box-shadow: var(--box-shadow);
    z-index: 10001;
    list-style: none;
    padding: 2px 0;
    margin: 0;
}

[role="menu-item"].open > ul[role="menu"] {
    display: block;
}

ul[role="menu"] > [role="menu-item"] {
    position: relative;
}

ul[role="menu"] > [role="menu-item"] > a,
ul[role="menu"] > [role="menu-item"] > button,
ul[role="menu"] > [role="menu-item"] > span {
    all: unset;
    position: relative;
    padding: 3px 18px;
    display: block;
    width: 100%;
    box-sizing: border-box;
    cursor: default;
    font-family: var(--font-geneva);
    font-size: 12px;
    white-space: nowrap;
}

ul[role="menu"] > [role="menu-item"] > a:hover,
ul[role="menu"] > [role="menu-item"] > button:hover,
ul[role="menu"] > [role="menu-item"] > span:hover {
    background: var(--secondary);
    color: var(--primary);
}

ul[role="menu"] > [role="menu-item"].divider::after {
    content: "";
    pointer-events: none;
    display: block;
    padding: 0;
    border-top: 1.5px dotted var(--border-color);
}

ul[role="menu"] > [role="menu-item"].disabled > span {
    color: var(--disabled);
    pointer-events: none;
}

/* ── Submenu (right-expanding) ─────────────────────────────── */

.has-submenu {
    position: relative;
}

.has-submenu > span::after {
    content: '▶';
    float: right;
    margin-left: 12px;
    font-size: 8px;
    line-height: 18px;
}

.has-submenu > .submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: -2px;
    min-width: 140px;
    background: var(--primary);
    border: 2px solid var(--border-color);
    box-shadow: var(--box-shadow);
    padding: 2px 0;
    z-index: 1001;
}

.has-submenu:hover > .submenu {
    display: block;
}

.submenu > [role="menu-item"] > span {
    display: block;
    padding: 2px 16px;
    font-family: var(--font-geneva);
    font-size: 12px;
    white-space: nowrap;
}

.submenu > [role="menu-item"] > span:hover {
    background: var(--secondary);
    color: var(--primary);
}

.submenu > [role="menu-item"].divider::after {
    content: "";
    pointer-events: none;
    display: block;
    padding: 0;
    border-top: 1.5px dotted var(--border-color);
}

/* ── Window ────────────────────────────────────────────────── */

.window {
    position: absolute;
    display: flex;
    flex-direction: column;
    min-width: 240px;
    min-height: 100px;
    overflow: hidden;
    background-color: var(--primary);
    border: 2px solid var(--border-color);
    box-shadow: var(--box-shadow);
    font-family: var(--font-geneva);
}

/* ── Title Bar — Chicago 12px bold ───────────────────────── */

.title-bar {
    flex: none;
    position: relative;
    height: 32px;
    margin: 0;
    padding: 0 8px;
    user-select: none;
    cursor: grab;
    flex-shrink: 0;
    padding-left: 28px;
}

/* 4 horizontal lines via box-shadow — wider gaps, lighter feel */
.title-bar::before {
    content: '';
    position: absolute;
    left: 28px;
    right: 8px;
    top: 8px;
    height: 1px;
    background: oklch(78% 0 0);
    box-shadow:
        0 5px 0 oklch(78% 0 0),
        0 10px 0 oklch(78% 0 0),
        0 15px 0 oklch(78% 0 0);
}

.title-bar .title {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    padding: 0 8px;
    font-size: 16px;
    font-weight: bold;
    line-height: 32px;
    text-align: center;
    background: var(--primary);
    cursor: default;
    font-family: var(--font-chicago);
    white-space: nowrap;
    overflow: hidden;
    z-index: 1;
}

/* Unfocused: keep lines, dim title text */
.window:not(.focused) .title-bar .title {
    color: var(--tertiary);
}

/* Close button — square, top-right, X always visible */
.title-bar button {
    position: absolute;
    right: 8px;
    top: 8px;
    width: 16px;
    height: 16px;
    box-sizing: border-box;
    border: 1px solid var(--border-color);
    background-color: var(--primary);
    cursor: pointer;
    padding: 0;
    z-index: 1;
}

.title-bar button.close::before {
    content: '\00D7';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--secondary);
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
}

.title-bar button.close:hover {
    background-color: var(--secondary);
}

.title-bar button.close:hover::before {
    color: var(--primary);
}

/* ── Details Bar (status bar) — Geneva 11px ──────────────── */

.details-bar {
    flex: none;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    padding: 3px 8px;
    border: 1px solid var(--border-color);
    border-width: 1px 0;
    font-size: 10px;
    font-family: var(--font-geneva);
}

/* ── Window Pane — Geneva 12px ───────────────────────────── */

.window-pane {
    overflow-y: auto;
    flex: 1;
    min-height: 0; /* flex shrink: allow below content height; overflow-y handles the rest */
    padding: 6px 10px;
    font-size: 12px;
    font-family: var(--font-geneva);
    line-height: 1.5;
    /* Grid layout for folder icons inside project/trash windows */
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
}

/* When pane only contains the empty-state, switch to center alignment */
.window-pane:has(> .window-empty),
.trash-items:has(> .window-empty) {
    display: flex;
    justify-content: center;
    align-items: center;
    align-content: center;
}

/* Empty-state message centered in the pane */
.window-pane .window-empty,
.trash-items .window-empty {
    flex: 0 0 auto;
    text-align: center;
    color: #A5A5A5;
    font-family: Geneva_9, Geneva, sans-serif;
    font-size: 11px;
    padding: 16px;
}

/* Chat messages stack vertically, not grid */
#chat-messages {
    flex-direction: column;
    flex-wrap: nowrap;
    position: relative;
}

/* ── Separator ────────────────────────────────────────────── */

.separator {
    flex: none;
    border-top: 1px solid var(--border-color);
}

/* ── Resize Handle ─────────────────────────────────────────── */

#chat-input-area .resize-handle {
    position: relative;
    width: 18px;
    flex-shrink: 0;
    cursor: nwse-resize;
    background: var(--primary);
    border-left: 2px solid var(--border-color);
}

#chat-input-area .resize-handle::after {
    content: '';
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--border-color);
    border-bottom: 2px solid var(--border-color);
}

/* Generic resize handle for other windows */
.resize-handle:not(#chat-input-area .resize-handle) {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    z-index: 10;
    background: var(--primary);
    border-left: 2px solid var(--border-color);
    border-top: 2px solid var(--border-color);
}

.resize-handle:not(#chat-input-area .resize-handle)::after {
    content: '';
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--border-color);
    border-bottom: 2px solid var(--border-color);
}

/* ── Button — Chicago 12px ────────────────────────────────── */

.btn {
    min-height: 20px;
    min-width: 54px;
    padding: 2px 14px;
    text-align: center;
    background: var(--primary);
    border-style: solid;
    border-width: 5.5px;
    border-image: url("/static/icon/button.svg") 30 stretch;
    color: var(--secondary);
    text-decoration: none;
    font-size: 12px;
    font-family: var(--font-chicago);
    cursor: pointer;
    font-weight: bold;
}

.btn:active {
    background: var(--secondary);
    border-radius: 6px;
    color: var(--primary);
}

.btn:disabled {
    color: var(--disabled);
}

.btn-default {
    border-image: url("/static/icon/button-default.svg") 60 stretch;
    border-width: 0.5em;
}

.btn-default:active {
    border-radius: 12px;
}

/* Auth dialog sign-in link — guarantee white text regardless of skin or browser a:link default */
#auth-dialog a.btn {
    color: #ffffff !important;
    text-decoration: none;
}

/* ── Input — Geneva 12px ──────────────────────────────────── */

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
    border: 1.5px solid var(--border-color);
    font-family: var(--font-geneva);
    font-size: 12px;
    padding: 2px 5px;
    outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus {
    background: var(--secondary);
    color: var(--primary);
}

/* ── Dialog — Chicago 12px bold title, Geneva 12px body ───── */

.modal-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30000;
    width: auto;
    padding: 13px;
    background: var(--primary);
}

.outer-border {
    border: 2px solid var(--border-color);
    padding: 3px;
}

.inner-border {
    border-color: var(--border-color);
    border-top: 3.5px solid;
    border-bottom: 3.5px solid;
    border-left: 5px solid;
    border-right: 5px solid;
}

.modal-contents {
    padding: 10px 14px;
    font-family: var(--font-geneva);
    font-size: 12px;
    line-height: 1.5;
}

.modal-contents p {
    margin-bottom: 8px;
}

.modal-contents label {
    display: block;
    margin-bottom: 5px;
    font-family: var(--font-chicago);
    font-size: 12px;
    font-weight: bold;
}

.modal-contents input[type="text"] {
    width: 100%;
    margin-bottom: 8px;
    background: var(--primary);
    color: var(--secondary);
}

.field-row {
    display: flex;
    align-items: center;
    font-family: var(--font-geneva);
    font-size: 12px;
}

.field-row + .field-row {
    margin-top: var(--grouped-element-spacing);
}

.field-row > * + * {
    margin-left: var(--grouped-element-spacing);
}

/* ── Overlay ───────────────────────────────────────────────── */

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 29000;
}

.overlay.visible {
    display: block;
}

/* ── Context Menu — Geneva 12px (dropdown items) ──────────── */

#context-menu {
    display: none;
    position: fixed;
    background: var(--primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--box-shadow);
    z-index: 20000;
    padding: 2px 0;
    min-width: 180px;
    list-style: none;
    font-family: var(--font-geneva);
    font-size: 12px;
}

#context-menu > [role="menu-item"] > span {
    all: unset;
    padding: 3px 8px;
    display: flex;
    align-items: center;
    cursor: default;
    white-space: nowrap;
}

#context-menu > [role="menu-item"] > span svg {
    flex-shrink: 0;
    vertical-align: middle;
    margin-right: 5px;
}

#context-menu > [role="menu-item"] > span:hover {
    background: var(--secondary);
    color: var(--primary);
}

#context-menu > [role="menu-item"].divider::after {
    content: "";
    display: block;
    border-top: 1.5px dotted var(--border-color);
}

/* ── Folder Drop Target — full inversion (matches trash hover) */

.folder-icon.folder-drop-target .folder-label {
    background: var(--secondary);
    color: var(--primary);
}

.folder-icon.folder-drop-target svg rect[stroke],
.folder-icon.folder-drop-target svg line {
    stroke: var(--primary);
}

.folder-icon.folder-drop-target svg rect[fill="white"] {
    fill: var(--secondary);
}

/* ── Trash Can — fixed bottom-right ────────────────────────── */

.trash-icon {
    position: fixed;
    bottom: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 90px;
    cursor: pointer;
    user-select: none;
    z-index: 5;
}

.trash-icon svg {
    image-rendering: pixelated;
    width: 48px;
    height: 48px;
    transform: scale(1.2);
}

.trash-icon .folder-label {
    font-family: var(--font-geneva);
    font-size: 11px;
    text-align: center;
    padding: 1px 4px;
    margin-top: 6px;
    color: var(--secondary);
    background: var(--primary);
}

/* Highlight when folder dragged over trash */
.trash-icon.trash-hover .folder-label {
    background: var(--secondary);
    color: var(--primary);
}

.trash-icon.trash-hover svg rect,
.trash-icon.trash-hover svg line {
    stroke: var(--primary);
}

.trash-icon.trash-hover svg rect[fill="white"] {
    fill: var(--secondary);
}

/* ── Folder Icon — Geneva 11px label (mac-1984 spec) ─────── */

.folder-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 90px;
    cursor: pointer;
    user-select: none;
    margin: 4px;
}

.folder-icon svg {
    image-rendering: pixelated;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(1.2);
}

/* Icon does NOT invert on select — only the label does */

.folder-icon .folder-label {
    font-family: var(--font-geneva);
    font-size: 11px;
    text-align: center;
    padding: 1px 4px;
    max-width: 90px;
    word-wrap: break-word;
    line-height: 1.2;
    margin-top: 6px;
    color: var(--secondary);
    background: var(--primary);
}

.folder-icon.selected .folder-label {
    background: var(--secondary);
    color: var(--primary);
}

/* ── Chat Window ──────────────────────────────────────────── */

#chat-window {
    width: clamp(425px, 40vw, 600px);
    height: clamp(400px, 65vh, 800px);
    /* Guarantee chat window sits above desktop icons (z-index: 1) at all times,
       even before focusWindow() promotes it to 100+ on first click. */
    z-index: 10;
}

/* Desktop icons always sit below windows — prevents overlap on load and resize */
#desktop > .folder-icon {
    z-index: 1;
}

/* Chat messages — Geneva 12px body, Chicago 12px bold labels */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
    background: var(--primary);
    font-family: var(--font-geneva);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
}

.chat-msg {
    margin-bottom: 6px;
    padding: 0;
    max-width: 85%;
    min-width: 0; /* prevent flex item overflow */
}

/* AGENT message container — full width, no background */
.chat-msg:not(.user-msg):not(.thinking-msg) {
    max-width: unset;
}

/* AGENT role label — inherits .chat-msg .chat-role styles (no override) */
.chat-msg:not(.user-msg) .chat-role {
    margin-bottom: 3px;
}

/* AGENT message body — pale blue-white box */
.chat-msg:not(.user-msg) .chat-body {
    background: var(--color-result-pane);
    padding: 5px 8px 7px 10px;
    overflow-wrap: break-word;
    min-width: 0;
}

/* AGENT intro prose — black on gray box */
.chat-msg:not(.user-msg) .chat-text {
    color: var(--secondary);
    padding: 0;
}

/* AGENT result block — data zone, flows after prose without indent */
.chat-result {
    color: var(--secondary);
    font-size: 11px;
    line-height: 1.5;
    padding: 0;
    margin: 0;
    background: transparent;
    white-space: pre-line;
    word-wrap: break-word;
}

/* Separator only when prose intro precedes the result block */
.chat-text + .chat-result {
    border-top: 1px dotted var(--border-color);
    padding-top: 6px;
    margin-top: 6px;
}

/* ── Sources drawer (appears below agent body when gather_project_context ran) ── */
.chat-sources {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dotted var(--border-color);
    font-family: Menlo, monospace;
    font-size: 10px;
    line-height: 1.4;
}
.chat-sources > summary {
    cursor: pointer;
    color: var(--secondary);
    list-style: none;
    padding: 2px 0 4px;
    user-select: none;
    outline: none;
}
.chat-sources > summary::-webkit-details-marker { display: none; }
.chat-sources > summary::marker { content: ''; }
.chat-sources > summary::before {
    content: '\25B8'; /* ▸ */
    display: inline-block;
    margin-right: 4px;
    transition: transform 0.1s ease;
}
.chat-sources[open] > summary::before {
    transform: rotate(90deg);
}
.chat-sources-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-top: 2px;
}
.src-row {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr) auto;
    gap: 6px;
    align-items: baseline;
    padding: 2px 4px;
    text-decoration: none;
    color: var(--secondary);
    border-radius: 1px;
}
.src-row:hover {
    background: var(--color-result-pane);
    color: var(--secondary);
    text-decoration: none;
}
.src-glyph {
    text-align: center;
    font-size: 10px;
    opacity: 0.7;
}
.src-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.src-meta {
    font-size: 9px;
    opacity: 0.6;
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.src-golden .src-title { font-weight: bold; }

/* ── Source match-provenance lane badge ───────────────────────
   Shows which Drive search lane surfaced this source (filename > phrase > content).
   Tooltip on hover shows the underlying Drive query. Trust scaled via opacity. */
.src-lane {
    display: inline-block;
    font-family: var(--font-menlo, "Menlo", monospace);
    font-size: 9px;
    line-height: 1.3;
    padding: 0 4px;
    border: 1px solid currentColor;
    border-radius: 2px;
    opacity: 0.55;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 4px;
    vertical-align: baseline;
}
.src-lane-filename { opacity: 0.85; }
.src-lane-phrase   { opacity: 0.70; }
.src-lane-content  { opacity: 0.50; }

/* ── Citation chips ───────────────────────────────────────────── */
a.citation-chip {
    display: inline-block;
    font-family: var(--font-geneva);
    font-size: 10px;
    line-height: 1;
    padding: 1px 4px;
    border: 1px solid var(--border-color);
    border-radius: 2px;
    background: var(--color-result-pane);
    color: var(--color-subtle);
    text-decoration: none;
    vertical-align: super;
    cursor: pointer;
}
a.citation-chip:hover {
    background: var(--secondary);
    color: var(--primary);
    border-color: var(--secondary);
}

/* ── Action cards ─────────────────────────────────────────────── */
.action-card {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 7px 10px;
    border: 2px solid var(--border-color);
    box-shadow: var(--box-shadow);
    background: var(--color-result-pane);
    font-family: var(--font-geneva);
    font-size: 11px;
}
.action-card-icon {
    font-size: 16px;
    flex-shrink: 0;
    line-height: 1;
}
.action-card-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.action-card-title {
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.action-card-meta {
    font-size: 10px;
    color: oklch(45% 0 0);
}
a.action-card-open {
    flex-shrink: 0;
    font-family: var(--font-chicago);
    font-size: 11px;
    padding: 3px 8px;
    border: 2px solid var(--border-color);
    box-shadow: var(--box-shadow);
    background: var(--primary);
    color: var(--secondary);
    text-decoration: none;
    cursor: pointer;
}
a.action-card-open:hover {
    background: var(--secondary);
    color: var(--primary);
}

/* ── Re-auth banner ───────────────────────────────────────────── */
.reauth-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    background: oklch(97% 0.04 60);
    border-bottom: 1px solid oklch(80% 0.08 60);
    font-family: var(--font-geneva);
    font-size: 11px;
}
.reauth-banner a {
    color: var(--color-subtle);
    font-weight: bold;
}
.reauth-banner a:hover { text-decoration: underline; }
button.reauth-dismiss {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    line-height: 1;
    color: oklch(45% 0 0);
}
button.reauth-dismiss:hover { color: var(--secondary); }

/* YOU messages — flex column, align-items:flex-end shrinks children to
   intrinsic width and parks them at the right edge */
.chat-msg.user-msg {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: unset;
}

.chat-msg.user-msg .chat-text {
    max-width: min(68%, 360px);
    background: var(--color-result-pane);
    padding: 6px 8px 7px 8px;
    text-align: left;
}

.chat-msg .chat-role {
    font-family: var(--font-geneva);
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--tertiary);
    margin-bottom: 2px;
}

.chat-msg .chat-text {
    margin-top: 2px;
    white-space: pre-line;
    word-wrap: break-word;
    font-size: 11px;
    line-height: 1.5;
}

.chat-msg .chat-text a,
.chat-result a {
    color: var(--color-subtle);
    text-decoration: underline;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: inline-block;
    vertical-align: bottom;
}



.chat-msg .chat-text a:hover,
.chat-result a:hover {
    background: var(--secondary);
    color: var(--primary);
}

/* Image links — suppress the black-inversion hover; use opacity instead */
.chat-msg .chat-text a:has(> .chat-img):hover,
.chat-result a:has(> .chat-img):hover {
    background: transparent;
    color: inherit;
}

.chat-img {
    max-width: 280px;
    max-height: 180px;
    display: block;
    margin: 6px 0 2px;
    border: none;
    outline: none;
    image-rendering: auto;
    cursor: zoom-in;
    transition: opacity 0.12s;
}

.chat-img:hover {
    opacity: 0.82;
}

.tool-call {
    color: var(--secondary);
    font-size: 11px;
    padding: 2px 0 2px 10px;
    font-family: var(--font-geneva);
    font-style: italic;
    margin: 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Thinking / Status Indicator ──────────────────────────── */

.thinking-msg {
    font-family: var(--font-geneva);
    font-size: 11px;
    color: var(--secondary);
    padding: 4px 0;
    margin-bottom: 4px;
}

.thinking-spinner {
    display: inline;
    font-size: 13px;
}

.thinking-label {
    font-style: italic;
}

.thinking-tool {
    display: inline;
    font-style: italic;
    color: var(--tertiary);
}

.tool-chip {
    display: inline;
}
.tool-chip::before {
    content: ' · ';
}

.thinking-work {
    margin-top: 6px;
    font-size: 10px;
    color: var(--tertiary);
    white-space: pre-wrap;
    line-height: 1.5;
    max-height: 120px;
    overflow-y: auto;
}

/* ── Chat Markdown Rendering ─────────────────────────────── */

.chat-text .md-h {
    font-weight: bold;
    margin: 8px 0 2px;
    line-height: 1.2;
}

h2.md-h {
    font-family: var(--font-chicago);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

h3.md-h {
    font-family: var(--font-geneva);
    font-size: 12px;
}

h4.md-h {
    font-family: var(--font-geneva);
    font-size: 11px;
    font-style: italic;
}

/* Bold-headed paragraph (e.g. "**Label:** body text") — reset browser <p> margins */
.chat-text .md-p,
.chat-result .md-p {
    margin: 4px 0;
    padding: 0;
}

.chat-text .md-blockquote,
.chat-result .md-blockquote {
    font-style: italic;
    padding: 0 0 0 12px;
    margin: 4px 0;
    color: var(--secondary);
    border-left: 1px solid var(--border-color);
}

.chat-text .md-list,
.chat-result .md-list {
    list-style: none;
    padding-left: 14px;
    margin: 2px 0 8px;
}

/* Section header (md-p) immediately before a list — tighten the gap */
.chat-text .md-p + .md-list,
.chat-result .md-p + .md-list {
    margin-top: 1px;
}

.chat-text .md-list li,
.chat-result .md-list li {
    position: relative;
    padding-left: 10px;
    margin: 2px 0;
    line-height: 1.4;
}

.chat-text .md-list li::before,
.chat-result .md-list li::before {
    content: '▸';
    position: absolute;
    left: 0;
    top: 0;
    font-size: 8px;
    line-height: 1.85;
    color: var(--secondary);
}

.chat-text .md-code {
    font-family: var(--font-monaco);
    font-size: 11px;
    background: var(--sys-color-darkgrey);
    padding: 1px 3px;
    border: 1px solid var(--border-color);
}

.chat-text .md-hr {
    border: none;
    border-top: 1px dotted var(--border-color);
    margin: 6px 0;
}

/* Bold-headed paragraph blocks (wrapped by renderMarkdown) */
.chat-text .md-p,
.chat-result .md-p {
    display: block;
    margin: 6px 0 2px;
}
.chat-text .md-p:first-child,
.chat-result .md-p:first-child {
    margin-top: 2px;
}

.chat-text strong {
    font-family: var(--font-geneva);
    font-weight: bold;
}

/* Section headers: a bare <strong> following a list or rule is rendered as a
   bold mini-header (e.g. "VO / Talent:" between two bullet lists). Without
   extra top margin it sticks to the previous list. Inline-block + margin-top
   works because pure margin on inline <strong> would be ignored. */
/* Section headers inside lists: Gemini emits sections as `- **Header:**`, so
   they end up as <li><strong>Header:</strong></li> — bold-only list items
   sharing a single <ul> with their content items. Give them extra top space
   and hide their bullet glyph so they read as headers, not list items. */
.chat-text .md-list li:has(> strong:only-child),
.chat-result .md-list li:has(> strong:only-child) {
    margin-top: 14px;
    margin-bottom: 2px;
    padding-left: 0;
}
.chat-text .md-list li:has(> strong:only-child):first-child,
.chat-result .md-list li:has(> strong:only-child):first-child {
    margin-top: 0;
}
.chat-text .md-list li:has(> strong:only-child)::before,
.chat-result .md-list li:has(> strong:only-child)::before,
.chat-text .md-list li:has(> strong:first-child)::before,
.chat-result .md-list li:has(> strong:first-child)::before {
    content: none;
}

/* Bold-headed list items (e.g. **Label:** — text) get no left indent,
   matching the paragraph-style blocks that render alongside them. */
.chat-text .md-list li:has(> strong:first-child),
.chat-result .md-list li:has(> strong:first-child) {
    padding-left: 0;
}

.chat-text em {
    font-family: var(--font-geneva);
    font-style: italic;
}

/* ── Chat Buttons (interactive options) — Chicago 12px ────── */

.chat-buttons {
    display: flex;
    gap: 5px;
    margin: 3px 0;
    flex-wrap: wrap;
}

.chat-buttons .btn {
    min-height: 18px;
    min-width: auto;
    padding: 1px 8px;
    font-size: 12px;
}

/* ── Chat Welcome ─────────────────────────────────────────── */

/* .chat-welcome is a marker class only — removed when first real message arrives.
   No layout styles needed; the element renders as a normal agent .chat-msg. */

/* ── Chat History ─────────────────────────────────────────── */

.chat-history-item {
    padding: 4px 8px;
    cursor: default;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px dotted var(--tertiary);
    overflow: hidden;
}

.chat-history-item:hover {
    background: var(--secondary);
    color: var(--primary);
}

.chat-history-preview {
    font-family: var(--font-geneva);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    margin-right: 8px;
}

.chat-history-meta {
    font-family: var(--font-geneva);
    font-size: 9px;
    color: var(--tertiary);
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-history-item:hover .chat-history-meta {
    color: var(--primary);
}

.chat-history-delete {
    background: none;
    border: none;
    cursor: default;
    font-family: var(--font-chicago);
    font-size: 9px;
    color: var(--tertiary);
    padding: 0 0 0 6px;
    flex-shrink: 0;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
}

.chat-history-item:hover .chat-history-delete,
.chat-history-item.selected .chat-history-delete {
    opacity: 1;
    pointer-events: auto;
}

.chat-history-item.selected {
    background: var(--secondary);
    color: var(--primary);
}

.chat-history-item.selected .chat-history-meta {
    color: var(--primary);
}

/* ── Chat Input Area ──────────────────────────────────────── */

/* ── Chat Attachments ─────────────────────────────────────── */

#chat-attachments {
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 6px;
    border-top: 1px solid var(--tertiary);
    background: var(--primary);
    flex-shrink: 0;
}

#chat-attachments:not(:empty) {
    display: flex;
}

.attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 6px;
    border: 1px solid var(--border-color);
    font-family: var(--font-geneva);
    font-size: 10px;
    background: var(--primary);
    max-width: 180px;
    cursor: default;
}

.attach-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attach-chip-x {
    cursor: pointer;
    font-family: var(--font-chicago);
    font-size: 9px;
    font-weight: bold;
    padding: 0 2px;
}

.attach-chip-x:hover {
    background: var(--secondary);
    color: var(--primary);
}

/* Drop zone highlight */
.chat-drop-active .window-pane {
    outline: 2px dashed var(--secondary);
    outline-offset: -4px;
}

#chat-attach {
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-right: 1px solid var(--tertiary);
    background: var(--primary);
    font-family: var(--font-chicago);
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    color: var(--secondary);
    flex-shrink: 0;
}

#chat-attach:hover {
    background: var(--secondary);
    color: var(--primary);
}

#chat-input-area {
    display: flex;
    border-top: 2px solid var(--border-color);
    background: var(--primary);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    border: none;
    padding: 3px 6px;
    font-family: var(--font-geneva);
    font-size: 11px;
    outline: none;
    background: var(--primary);
    /* Textarea auto-grow setup: no manual drag-resize, hidden scrollbar until
       content exceeds the max height set by JS; matches single-line input look. */
    resize: none;
    overflow-y: hidden;
    line-height: 15px;
    min-height: 17px;
    vertical-align: middle;
}

#chat-input:focus {
    background: var(--primary);
    color: var(--secondary);
}

#chat-send {
    padding: 3px 12px;
    border: none;
    border-left: 2px solid var(--border-color);
    background: var(--primary);
    font-family: var(--font-chicago);
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    color: var(--secondary);
}

#chat-send:active {
    background: var(--secondary);
    color: var(--primary);
}

/* ── About Dialog ────────────────────────────────────────── */

.about-body {
    font-size: 14px;
    line-height: 1.6;
}

/* ── About Dialog Title Bar — Chicago 12px bold ──────────── */

.dialog-title-bar {
    display: flex;
    align-items: center;
    height: 22px;
    margin: 2px 0;
    padding: 3px 2px;
    background: linear-gradient(var(--secondary) 50%, transparent 50%);
    background-size: 100% 2px;
    background-clip: content-box;
}

.dialog-title-bar .title {
    padding: 2px 0.5em;
    margin: 0 auto;
    font-size: 12px;
    font-weight: bold;
    background: var(--primary);
    font-family: var(--font-chicago);
    line-height: 1;
}

/* ── Mobile Hamburger (hidden on desktop) ───────────────────── */

#mobile-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: transparent;
    border: none;
    color: var(--secondary);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    margin-right: 4px;
}

/* Mobile Drawer (hidden on desktop) */
#mobile-drawer {
    display: none;
}

#mobile-drawer-overlay {
    display: none;
}

/* ═══ Mobile Layout ≤768px ════════════════════════════════════ */

@media (max-width: 768px) {

    /* Kill the 1.25x zoom — it destroys mobile layout */
    html { zoom: 1; }

    /* Show the hamburger button */
    #mobile-hamburger {
        display: flex;
    }

    /* Collapse File/View menu items — navigated via drawer instead */
    ul[role="menu-bar"] > [role="menu-item"] {
        display: none;
    }

    /* Menu bar: flush left, no extra padding */
    ul[role="menu-bar"] {
        padding-left: 0;
    }

    /* Desktop: clean background, no checkerboard on mobile */
    #desktop {
        background-image: none;
        background-color: var(--primary);
    }

    /* Hide all desktop icons and trash on mobile */
    #desktop > .folder-icon,
    #desktop > .trash-icon {
        display: none !important;
    }

    /* Chat window: fills full viewport below menu bar.
       Use calc(100dvh - 34px) so mobile browser toolbar is included in
       the height budget — avoids the input area hiding behind the address bar. */
    #chat-window {
        position: fixed !important;
        top: 34px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: calc(100dvh - 34px) !important;
        min-width: 0 !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        z-index: 100 !important;
    }

    /* Hide the window title bar — redundant on mobile full-screen layout */
    #chat-window .title-bar,
    #chat-window .separator {
        display: none !important;
    }

    /* Hide edge resize handles and resize corner on mobile */
    #chat-window .win-edge,
    #chat-window .resize-handle {
        display: none !important;
    }

    /* Mobile drawer overlay */
    #mobile-drawer-overlay {
        display: none;
        position: fixed;
        inset: 0;
        top: 34px;
        background: rgba(0, 0, 0, 0.35);
        z-index: 14000;
    }

    #mobile-drawer-overlay.visible {
        display: block;
    }

    /* Mobile drawer panel */
    #mobile-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 34px;
        left: -280px;
        width: 280px;
        bottom: 0;
        background: var(--primary);
        border-right: 2px solid var(--border-color);
        z-index: 15000;
        transition: left 0.22s cubic-bezier(0.22, 1, 0.36, 1);
        overflow-y: auto;
    }

    #mobile-drawer.open {
        left: 0;
    }

    #mobile-drawer-nav {
        list-style: none;
        padding: 8px 0;
        margin: 0;
    }

    #mobile-drawer-nav li > span {
        display: block;
        padding: 11px 20px;
        font-family: var(--font-geneva);
        font-size: 14px;
        cursor: pointer;
        user-select: none;
    }

    #mobile-drawer-nav li > span:hover,
    #mobile-drawer-nav li > span:active {
        background: var(--secondary);
        color: var(--primary);
    }

    #mobile-drawer-nav li.divider {
        border-top: 1px dotted var(--border-color);
        margin-top: 4px;
        padding-top: 4px;
    }

    /* Action cards: stack full-width on mobile */
    .action-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    /* Auth dialog: full-width on small screens */
    .modal-dialog {
        width: calc(100vw - 32px) !important;
        max-width: 400px;
    }
}

/* ── Gather card (source approval before doc creation) ────────────── */

.gather-card {
    background: var(--sys-color-white);
    border: 2px solid var(--sys-color-black);
    border-radius: 3px;
    margin: 8px 0 4px;
    overflow: hidden;
    font-size: 11px;
}

.gather-card-header {
    font-family: ChicagoFLF, -apple-system, monospace;
    font-weight: bold;
    font-size: 11px;
    padding: 6px 10px;
    background: #e8e8e8;
    border-bottom: 1px solid var(--sys-color-black);
}

.gather-source-row {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    padding: 4px 10px;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
}

.gather-source-row:last-of-type {
    border-bottom: none;
}

.gather-source-row input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
    cursor: pointer;
}

.gather-source-link {
    flex: 1;
    min-width: 0;
}

.gather-source-title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--sys-color-black);
    text-decoration: none;
    font-family: Geneva, -apple-system, sans-serif;
    font-size: 11px;
}

.gather-source-title:hover {
    text-decoration: underline;
}

.gather-source-meta {
    font-size: 10px;
    color: #666;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gather-cta {
    background: var(--sys-color-black);
    padding: 9px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.gather-cta-primary {
    background: var(--sys-color-white);
    color: var(--sys-color-black);
    font-family: ChicagoFLF, -apple-system, monospace;
    font-weight: bold;
    font-size: 12px;
    border: 2px solid var(--sys-color-white);
    padding: 5px 14px;
    cursor: pointer;
    border-radius: 2px;
    white-space: nowrap;
}

.gather-cta-primary:hover:not(:disabled) {
    background: #e8e8e8;
    border-color: #e8e8e8;
}

.gather-cta-primary:disabled {
    opacity: 0.5;
    cursor: default;
}

.gather-cta-status {
    font-family: ChicagoFLF, -apple-system, monospace;
    font-size: 11px;
    color: var(--sys-color-white);
    opacity: 0.85;
}

.gather-cta-status-error {
    color: #ff6b6b;
    opacity: 1;
}

.gather-cta-link {
    background: var(--sys-color-white);
    color: var(--sys-color-black);
    font-family: ChicagoFLF, -apple-system, monospace;
    font-weight: bold;
    font-size: 12px;
    border: 2px solid var(--sys-color-white);
    padding: 5px 14px;
    text-decoration: none;
}

.gather-cta-link:hover {
    background: #e8e8e8;
    border-color: #e8e8e8;
}

/* ── Budget Cards (base / System 1 theme) ────────────────────── */

.budget-card {
    margin-top: 10px;
    padding: 12px 14px;
    border: 1px solid #bdbdbd;
    background: #f7f7f7;
    box-shadow: 2px 2px var(--border-color);
}

.budget-card-title  { font-weight: bold; margin-bottom: 4px; }
.budget-card-subtitle { margin-top: 4px; font-size: 11px; }
.budget-card-meta   { margin-top: 2px; font-size: 10px; color: #666; }
.budget-section-block { margin-top: 10px; }
.budget-section-hdr { font-weight: bold; margin-bottom: 4px; }

.budget-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.budget-th {
    text-align: left;
    padding: 4px 8px;
    font-weight: bold;
    border-bottom: 1px solid var(--border-color);
}
.budget-th-r { text-align: right; }

.budget-td { padding: 6px 8px; border-top: 1px solid #ddd; vertical-align: middle; }
.budget-td-r { text-align: right; }

.budget-source-quote { font-size: 11px; color: #666; margin-top: 3px; }

.budget-qty-input,
.budget-rate-input {
    width: 88px;
    border: 1px solid var(--border-color);
    background: var(--primary);
    padding: 3px 5px;
    font-family: var(--font-geneva);
    font-size: 12px;
}
.budget-rate-input { width: 72px; text-align: right; }
.budget-input-zero { color: #999; }

.budget-section-total td { border-top: 1px solid var(--border-color); }
.budget-section-total-label { text-align: right; font-weight: bold; padding: 6px 8px; }
.budget-section-total-value { text-align: right; font-weight: bold; padding: 6px 8px; }

.budget-footer {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid #ddd;
}
.budget-footer-end { justify-content: flex-end; }
.budget-footer-total { font-weight: bold; }

.budget-confirmed-bar {
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--primary);
    border: 1px solid #ddd;
    font-size: 12px;
}

.budget-stat-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.budget-stat-box {
    padding: 8px 10px;
    background: var(--primary);
    border: 1px solid #ddd;
    font-size: 12px;
    flex: 1;
    min-width: 100px;
}
.budget-stat-box-alert { color: #c00; }

.shave-card { border-color: #b54b4b; background: #fff6f6; }
