:root {
  --graphite: #1f1f1f; --bone: #f8f7f2; --yellow: #f4b000; --warm-gray: #a7a096;
  --ink: var(--graphite); --accent: var(--yellow); --surface: #fffefa; --subtle: #efede6;
  --muted: #635f57; --line: #dcd8ce; --error: #8b3029; --error-surface: #fff3ee;
  --radius: 6px; --space-1: .4rem; --space-2: .8rem; --space-3: 1.25rem; --space-4: 2rem;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink); background: var(--bone); line-height: 1.6;
}
* { box-sizing: border-box; }
body { margin: 0; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
button, input, textarea, select, summary { font: inherit; }
h1, h2, h3, button, summary, .tabs, .app-header { font-family: "Inter Tight", Inter, system-ui, sans-serif; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.8rem, 3vw, 2.6rem); line-height: 1.15; letter-spacing: -.045em; margin-bottom: .75rem; }
h2 { font-size: 1.2rem; line-height: 1.3; letter-spacing: -.02em; margin-bottom: .7rem; }
h3 { font-size: 1rem; line-height: 1.4; margin-bottom: .7rem; }
a { color: var(--ink); text-underline-offset: 4px; }
button { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: .65rem 1rem; min-height: 44px; cursor: pointer; font-weight: 600; }
button:hover { background: var(--subtle); border-color: var(--warm-gray); }
button:disabled { color: var(--muted); opacity: .65; cursor: default; }
button.secondary { background: var(--surface); color: var(--ink); }
button.quiet { background: transparent; color: inherit; border-color: transparent; }
button.quiet:hover { background: var(--subtle); }
#new-machine, #question-form button[type=submit], #login-form button[type=submit], #machine-form button[type=submit], #upload-form button[type=submit], #transcript .empty-state button {
  background: var(--yellow); border-color: var(--yellow); color: var(--graphite);
}
#new-machine:hover, #question-form button[type=submit]:hover, #login-form button[type=submit]:hover { background: #e5a600; }
button.danger { color: var(--error); background: var(--surface); border-color: #d6b4ab; }
button.danger:hover { background: var(--error-surface); }
:where(button,a,input,textarea,select,summary):focus-visible { outline: 3px solid var(--graphite); outline-offset: 3px; }
.app-header { min-height: 84px; background: var(--bone); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: var(--space-3); padding: .5rem clamp(.8rem, 3vw, 2.5rem); flex-shrink: 0; }
.brand { padding: 0; background: transparent; border-color: transparent; display: inline-flex; align-items: center; flex-shrink: 0; }
.brand:hover { background: transparent; border-color: transparent; }
.brand img { display: block; width: 180px; height: auto; }
.workspace-context { font-size: .8rem; color: var(--muted); max-width: 24ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-context:empty { display: none; }
.edition { font-size: .8rem; color: var(--muted); flex: 1; }
.language-control { margin: 0; flex-shrink: 0; }
.language-control select { width: auto; padding: .5rem .65rem; background: transparent; border-color: transparent; }
#account-open, #advanced-open, #toggle-sidebar { font-size: .82rem; }
#toggle-sidebar { border-color: var(--line); }
#notice { flex-shrink: 0; padding: .65rem 1.5rem; background: var(--subtle); border-bottom: 1px solid var(--line); overflow-wrap: anywhere; font-size: .9rem; }
#notice:empty { display: none; }
#notice.error, #profile-message:not(:empty) { color: var(--error); background: var(--error-surface); border-left: 3px solid var(--error); }
#dashboard { flex: 1; min-height: 0; overflow-y: auto; padding: clamp(1.25rem, 4vw, 3.5rem); }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 1.5rem; margin-bottom: 2.5rem; max-width: 1250px; margin-inline: auto; }
.page-heading p { color: var(--muted); margin-bottom: 0; max-width: 62ch; }
.eyebrow { font-size: .72rem; text-transform: uppercase; letter-spacing: .13em; font-weight: 650; color: var(--muted); margin-bottom: .6rem; }
.machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 1.25rem; max-width: 1250px; margin: auto; }
.machine-card { color: var(--ink); background: var(--surface); border: 1px solid var(--line); text-align: left; padding: 1.5rem; min-height: 255px; display: flex; flex-direction: column; gap: .5rem; overflow-wrap: anywhere; }
.machine-card:hover { border-color: var(--graphite); background: var(--surface); }
.machine-card strong { font-size: 1.35rem; font-weight: 650; letter-spacing: -.025em; }
.machine-icon { display: grid; place-items: center; width: 42px; height: 42px; background: var(--subtle); border: 1px solid var(--line); border-radius: var(--radius); font-size: 1.3rem; margin-bottom: .4rem; }
.machine-card small { color: var(--muted); font-size: .82rem; font-weight: 400; }
.machine-cta { margin-top: auto; border-top: 1px solid var(--line); padding-top: .9rem; font-size: .9rem; font-weight: 650; }
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); flex: 1; min-height: 0; }
#sidebar { min-width: 0; overflow-y: auto; border-right: 1px solid var(--line); padding: 1.25rem; background: var(--bone); }
.back-link { width: 100%; text-align: left; padding-left: 0; margin-bottom: .9rem; }
.machine-switch { border-bottom: 1px solid var(--line); padding-bottom: .8rem; margin-bottom: 1.5rem; }
.section-heading { display: flex; flex-direction: column; gap: .6rem; margin-bottom: .9rem; }
.section-heading h2 { margin: 0; }
nav button { display: block; width: 100%; text-align: left; margin: .4rem 0; background: transparent; border-color: transparent; color: var(--ink); font-size: .87rem; overflow-wrap: anywhere; }
nav button[aria-current="true"] { background: var(--surface); border-color: var(--line); border-left: 3px solid var(--yellow); }
nav small { display: block; font-size: .73rem; font-weight: 400; color: var(--muted); }
.archive-toggle { display: flex; align-items: center; gap: .6rem; font-size: .8rem; font-weight: 400; min-height: 44px; }
.archive-toggle input { width: 18px; height: 18px; }
.sidebar-note { font-size: .75rem; color: var(--muted); margin-top: 1.5rem; }
.machine-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.workspace-header { padding: 1.5rem 2rem 1rem; display: flex; justify-content: space-between; align-items: start; gap: 1.25rem; }
.workspace-header h1 { font-size: 1.7rem; overflow-wrap: anywhere; }
.workspace-header p:last-child { margin: 0; color: var(--muted); font-size: .88rem; }
.tabs { display: flex; gap: 1.7rem; padding: 0 2rem; border-bottom: 1px solid var(--line); }
.tabs button { background: transparent; color: var(--muted); border-color: transparent; border-radius: 0; border-bottom: 3px solid transparent; padding-inline: .2rem; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--yellow); color: var(--graphite); }
#workspace { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-toolbar { display: flex; justify-content: space-between; align-items: start; gap: .8rem; padding: 1rem 2rem .5rem; }
#chat-heading { margin: .45rem 0; font-size: .95rem; overflow-wrap: anywhere; }
#chat-actions { max-width: 290px; flex-shrink: 0; font-size: .82rem; }
#chat-actions[open] { background: var(--bone); padding: .8rem; border: 1px solid var(--line); border-radius: var(--radius); }
.context-note { margin: 0; padding: .5rem 2rem; color: var(--ink); background: #fff4d8; border-bottom: 1px solid var(--line); font-size: .86rem; }
.context-note:empty { display: none; }
#transcript { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem max(1.5rem, calc((100% - 850px) / 2)); }
.empty-state { padding: 2.5rem 1.5rem; text-align: center; color: var(--muted); margin: auto; max-width: 620px; }
.empty-state h2 { color: var(--ink); }
.empty-state p { margin-bottom: 1rem; }
.empty-state button { margin-top: .4rem; }
.message { margin: .8rem 0 2rem; overflow-wrap: anywhere; }
.message.user { background: var(--subtle); padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); margin-left: 8%; white-space: pre-wrap; }
.message.user > small { display: block; color: var(--muted); font-size: .73rem; margin-top: .5rem; }
.message.assistant { border-top: 2px solid var(--graphite); padding: 1.1rem 0 .5rem; }
.message.assistant[data-status="INSUFFICIENT_EVIDENCE"], .message.assistant[data-status="CLARIFICATION_REQUIRED"] { border-top-color: var(--yellow); }
.message.assistant[data-status="FAILED"], .message.assistant[data-status="LIMIT_ABORT"] { border-top-color: var(--error); }
.message-label { display: block; font-size: .82rem; font-weight: 650; color: var(--ink); margin-bottom: .75rem; }
.rich-text p { white-space: pre-wrap; margin: .7rem 0; }
.rich-text h3 { margin-top: 1.2rem; }
.rich-text pre { overflow-x: auto; white-space: pre; padding: 1rem; background: var(--subtle); border-radius: var(--radius); max-width: 100%; }
code { font-family: ui-monospace, monospace; background: var(--subtle); font-size: .9em; }
.rich-text li { margin: .4rem 0; }
.evidence-note { border-left: 3px solid var(--yellow); background: var(--bone); padding: .9rem 1rem; font-size: .9rem; }
.attachments { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .9rem; }
.attachment { display: block; border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; font-size: .83rem; max-width: 100%; overflow-wrap: anywhere; text-decoration: none; min-height: 44px; background: var(--surface); }
.attachment:hover { border-color: var(--graphite); }
.attachment span { display: block; margin-top: .25rem; }
.attachment img { max-width: 100%; max-height: 260px; display: block; border-radius: 3px; }
.sources-heading { margin: 1.4rem 0 .4rem; font-size: .82rem; font-weight: 700; }
.source-list { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,240px),1fr)); }
.source-card { border-left: 3px solid var(--yellow); padding: 1rem; }
.source-card img { max-height: 220px; object-fit: contain; margin: auto auto .8rem; }
.source-card strong { display: block; font-size: .92rem; }
.source-card span { color: var(--muted); }
.feedback { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1.25rem; font-size: .8rem; }
.feedback > span:first-child { width: 100%; font-weight: 600; }
.feedback button { font-size: .8rem; padding: .5rem .75rem; }
.feedback button[aria-pressed="true"] { border-color: var(--graphite); box-shadow: inset 0 -3px 0 var(--yellow); }
.feedback label { width: 100%; margin: .25rem 0; font-weight: 400; }
.feedback input { margin-top: .4rem; }
.feedback [role="status"] { color: var(--muted); }
.composer { border-top: 1px solid var(--line); padding: .8rem 1.5rem max(.7rem, env(safe-area-inset-bottom)); background: var(--bone); flex-shrink: 0; }
.composer-heading { max-width: 960px; margin: 0 auto .6rem; font-size: .8rem; font-weight: 650; }
#question-form { display: flex; align-items: flex-end; gap: .6rem; max-width: 960px; margin: auto; }
.question-label { flex: 1; min-width: 0; margin: 0; }
.composer small { display: block; text-align: center; font-size: .73rem; color: var(--muted); margin-top: .5rem; }
#new-question { margin-bottom: .5rem; font-size: .82rem; }
#chat-attachments { max-height: 140px; overflow-y: auto; margin: 0 0 .6rem; }
#chat-attachments:empty { display: none; }
.draft-attachment { display: flex; align-items: center; gap: .4rem; }
.draft-attachment img { max-height: 65px; }
.content-panel { flex: 1; min-height: 0; overflow-y: auto; padding: 1.8rem 2rem; background: var(--bone); }
.compact { margin-bottom: 1.4rem; }
.manual-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 1rem; }
.document { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; min-width: 0; overflow-wrap: anywhere; }
.document h3 { margin-top: .8rem; font-size: 1.1rem; }
.document p { font-size: .88rem; color: var(--muted); margin-bottom: .8rem; }
.badge { display: inline-block; padding: .25rem .65rem; border-radius: 4px; font-size: .75rem; font-weight: 650; background: var(--subtle); color: var(--ink); border: 1px solid var(--line); }
.badge.processing { color: var(--ink); background: #fff4d8; }
.badge.error { color: var(--error); background: var(--error-surface); border-color: #d6b4ab; }
.document details { margin-top: .8rem; }
.document summary { font-size: .85rem; }
.document > button { margin: .4rem .4rem .2rem 0; }
.advanced-panel { margin-top: 1.5rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.advanced-panel form { max-width: 720px; }
summary { cursor: pointer; font-weight: 600; min-height: 44px; padding: .6rem 0; }
label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: .8rem; }
input, textarea, select { width: 100%; display: block; padding: .7rem .8rem; border: 1px solid #b5afa2; border-radius: var(--radius); background: var(--surface); color: inherit; min-height: 44px; }
input:focus, textarea:focus { border-color: var(--graphite); }
input[type="checkbox"] { accent-color: var(--graphite); }
textarea { resize: vertical; max-height: 160px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem; margin-top: 1rem; }
dialog { width: min(680px, calc(100% - 2rem)); max-height: 85dvh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; color: var(--ink); background: var(--surface); box-shadow: 0 12px 40px #1f1f1f12; }
dialog::backdrop { background: #1f1f1f80; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-heading h2 { margin: 0; }
dialog > p { color: var(--muted); font-size: .88rem; margin-top: .8rem; }
.machine-menu { position: relative; font-size: .83rem; max-width: 260px; }
.machine-menu button { display: block; width: 100%; margin-top: .4rem; }
#delete-error { color: var(--error); }
#account-dialog section { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1rem; }
#usage-details { overflow-wrap: anywhere; }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 1rem; }
.login-page { background: var(--bone); overflow-y: auto; }
.login-panel { width: min(100%, 34rem); margin: 5vh auto; padding: 1.5rem 2rem 2rem; }
.login-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 3.5rem; }
.login-panel h1 { font-size: clamp(2rem, 7vw, 3.5rem); max-width: 12ch; }
.login-panel > p { color: var(--muted); }
.login-panel form { display: grid; gap: .8rem; border-top: 1px solid var(--line); margin: 1.5rem 0; padding-top: 1.5rem; }
#login-error:not(:empty) { color: var(--error); border-left: 3px solid var(--error); padding-left: .8rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.skip-link { position: absolute; left: 1rem; top: -100px; background: var(--yellow); color: var(--graphite); padding: .7rem 1rem; z-index: 10; }
.skip-link:focus { top: 1rem; }
[hidden] { display: none !important; }
@media (min-width: 901px) { #toggle-sidebar { display: none; } }
@media (max-width: 1100px) { .edition { display: none; } .brand { margin-right: auto; } }
@media (max-width: 900px) {
  .layout, .layout.sidebar-closed { grid-template-columns: minmax(0, 1fr); }
  .layout.sidebar-closed #sidebar { display: none; }
  .layout:not(.sidebar-closed) .machine-main { display: none; }
  #sidebar { border-right: 0; }
  .workspace-header { padding: 1.1rem; }
  .tabs { padding-inline: 1.1rem; }
  .chat-toolbar { padding: .7rem 1.1rem; }
  .context-note { padding-inline: 1.1rem; }
  #transcript { padding: 1rem 1.1rem; }
  .content-panel { padding: 1.2rem; }
}
@media (max-width: 600px) {
  .app-header { gap: .4rem; padding: .4rem .7rem; flex-wrap: wrap; }
  .app-header .brand img { width: 138px; }
  #account-open, #advanced-open, #toggle-sidebar { font-size: .78rem; padding: .5rem .65rem; }
  .app-header .language-control { margin-left: auto; }
  .workspace-context { order: 5; width: 100%; max-width: none; padding: .2rem .3rem; }
  .page-heading { align-items: stretch; flex-direction: column; gap: 1rem; }
  .workspace-header { flex-wrap: wrap; gap: .5rem; }
  .workspace-header h1 { font-size: 1.4rem; }
  .workspace-header p:last-child { font-size: .8rem; }
  .workspace-header .eyebrow { display: none; }
  .machine-menu { max-width: 100%; }
  .tabs { gap: 1.4rem; }
  .chat-toolbar { flex-wrap: wrap; }
  #chat-actions { max-width: 100%; }
  .composer { padding: .6rem .7rem max(.6rem, env(safe-area-inset-bottom)); }
  #question-form { display: grid; grid-template-columns: 1fr auto; }
  .question-label { grid-row: 1; grid-column: 1 / -1; }
  #attach { justify-self: start; }
  .message.user { margin-left: 0; }
  .attachment { width: 100%; }
  .fields { grid-template-columns: 1fr; }
  #notice { padding: .5rem .8rem; font-size: .85rem; }
  .login-panel { padding: 1.25rem; }
  .login-top .brand img { width: 155px; }
  .login-top { margin-bottom: 2.5rem; }
  .composer small { text-align: left; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
