/* Layout: a left rail with five screens, and one list or one draft per screen. */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --sunken: #eaeef5;
  --ink: #14233b;
  --ink-2: #3d4c63;
  --ink-3: #64718a;
  --line: #dce2ec;
  --line-2: #e9edf4;
  --accent: #1f4fbf;
  --accent-ink: #ffffff;
  --accent-soft: #e7eefc;
  --accent-text: #1b47ad;
  --agent: #6a3fc4;
  --agent-soft: #efe9fb;
  --ok: #17794a;
  --ok-soft: #e4f4ea;
  --warn: #8f5a00;
  --warn-soft: #fdf1d7;
  --scrim: rgba(12, 22, 40, .46);
  --shadow: 0 14px 44px rgba(16, 30, 54, .18);
  --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --r: 7px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1420; --surface: #151d2c; --surface-2: #1a2436; --sunken: #212c40;
    --ink: #e8edf5; --ink-2: #b9c3d3; --ink-3: #8a97ab;
    --line: #2a364b; --line-2: #212c3f;
    --accent: #7ea3f6; --accent-ink: #0b1424; --accent-soft: #1a2a4d; --accent-text: #9bb8fa;
    --agent: #b9a3f7; --agent-soft: #2a2148;
    --ok: #5fc493; --ok-soft: #14301f;
    --warn: #e6b455; --warn-soft: #382a0e;
    --scrim: rgba(2, 6, 14, .62);
    --shadow: 0 14px 44px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1420; --surface: #151d2c; --surface-2: #1a2436; --sunken: #212c40;
  --ink: #e8edf5; --ink-2: #b9c3d3; --ink-3: #8a97ab;
  --line: #2a364b; --line-2: #212c3f;
  --accent: #7ea3f6; --accent-ink: #0b1424; --accent-soft: #1a2a4d; --accent-text: #9bb8fa;
  --agent: #b9a3f7; --agent-soft: #2a2148;
  --ok: #5fc493; --ok-soft: #14301f;
  --warn: #e6b455; --warn-soft: #382a0e;
  --scrim: rgba(2, 6, 14, .62);
  --shadow: 0 14px 44px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font-ui); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
ul, ol { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-3); }
.fine { font-size: 13px; color: var(--ink-3); }
.grow { flex: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* shell */
.app { display: grid; grid-template-columns: 208px minmax(0, 1fr); height: 100%; }
.rail { display: flex; flex-direction: column; gap: 20px; padding: 20px 12px; border-right: 1px solid var(--line); background: var(--surface); overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font-weight: 700; font-size: 16px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand i { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--ink); color: var(--surface); font-style: normal; font-size: 14px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: var(--r); color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.nav .n { margin-left: auto; min-width: 22px; text-align: center; font: 700 12px var(--font-mono); padding: 1px 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.rail .foot { margin-top: auto; padding: 0 8px; font-size: 12.5px; color: var(--ink-3); }
.view { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.bar { display: flex; align-items: center; gap: 10px 14px; padding: 16px 28px; border-bottom: 1px solid var(--line); background: var(--surface); flex: none; flex-wrap: wrap; }
.bar-t { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-width: 0; flex: 1 1 auto; }
.bar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.bar .sub { color: var(--ink-3); }
.body { flex: 1; min-height: 0; overflow: auto; padding-block: 24px 96px; padding-inline: 28px; }
.wrap { max-width: 800px; display: flex; flex-direction: column; gap: 22px; }
.wrap.wide { max-width: 1040px; }
.tabs { display: none; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.1); background: var(--accent); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.link { border: 0; background: none; padding: 0; color: var(--accent-text); cursor: pointer; font-weight: 600; }
.link:hover { text-decoration: underline; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--sunken); color: var(--ink-2); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.agent { background: var(--agent-soft); color: var(--agent); }
.tag { font: 600 12px var(--font-mono); padding: 1px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink-2); background: var(--surface); white-space: nowrap; }
.tags { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 13px; font-size: 14px; font-weight: 600; color: var(--ink-3); cursor: pointer; border-right: 1px solid var(--line); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
.in, .ta, .sel { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); }
.ta { min-height: 110px; resize: vertical; line-height: 1.5; }
.sel { width: auto; min-width: 180px; }
.in:focus-visible, .ta:focus-visible, .sel:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* blocks */
.sec { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sec > h2 { font-size: 16px; font-weight: 700; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel h3 { font-size: 16px; }
.callout { padding: 11px 13px; border-radius: var(--r); background: var(--warn-soft); color: var(--warn); display: flex; gap: 10px; align-items: flex-start; }
.callout .ic { margin-top: 2px; }
.callout.ok { background: var(--ok-soft); color: var(--ok); }
.callout .acts { margin-top: 8px; }
.empty { padding: 36px 16px; text-align: center; color: var(--ink-3); display: flex; flex-direction: column; gap: 6px; align-items: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.run { background: var(--agent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; color: var(--ink-2); }

/* lists */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-top: 1px solid var(--line-2); color: inherit; min-width: 0; }
.list > .item:first-child { border-top: 0; }
a.item:hover { background: var(--surface-2); text-decoration: none; }
.item .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item .t { font-weight: 700; font-size: 16px; }
.item .d { color: var(--ink-3); }
.item > .ic { color: var(--ink-3); }
.iicon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--sunken); color: var(--ink-2); flex: none; }
.problem { border-color: var(--warn); }
.ptitle { display: flex; gap: 10px; align-items: center; color: var(--warn); }
.ptitle h3 { color: var(--ink); }
.tbl-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; min-width: 720px; }
th, td { padding: 11px 14px; text-align: left; border-top: 1px solid var(--line-2); vertical-align: top; }
thead th { border-top: 0; font-size: 13px; color: var(--ink-3); font-weight: 700; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td .t { font-weight: 700; color: var(--ink); }
td .d { color: var(--ink-3); font-size: 14px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .in { flex: 1 1 220px; width: auto; }
.addline { display: flex; gap: 8px; flex-wrap: wrap; }
.addline .in { flex: 1 1 260px; width: auto; }

/* draft */
.draft { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; align-items: start; max-width: 1080px; }
.dmain { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.dhead { display: flex; flex-direction: column; gap: 6px; }
.dhead h2 { font-size: 24px; letter-spacing: -.01em; }
.plain { display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }
.plain li { padding-left: 16px; position: relative; }
.plain li::before { content: ""; position: absolute; left: 3px; top: .62em; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); }
.warnline { display: flex; gap: 8px; align-items: flex-start; color: var(--warn); }
.warnline .ic { margin-top: 3px; }
.field { display: flex; flex-direction: column; gap: 6px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.field:first-child { padding-top: 0; border-top: 0; }
.field label, .field .lbl { font-weight: 700; }
.field.need .in { border-color: var(--warn); }
.chatcol { position: sticky; top: 0; }
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 380px; overflow: auto; }
.msg { max-width: 94%; padding: 9px 12px; border-radius: 10px; }
.msg.agent { background: var(--agent-soft); align-self: flex-start; }
.msg.you { background: var(--accent); color: var(--accent-ink); align-self: flex-end; }
.msg.wait { color: var(--ink-3); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.quick button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 11px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.quick button:hover { border-color: var(--ink-3); }
.ask { display: flex; gap: 8px; }
.ask .in { flex: 1; min-width: 0; }
.steps { display: flex; flex-direction: column; gap: 8px; }
.steps li { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 10px; color: var(--ink-3); }
.steps li.done { color: var(--ink-2); }
.steps li.done .ic { color: var(--ok); }
.steps li.now { color: var(--ink); font-weight: 600; }
.spin { width: 14px; height: 14px; margin: 4px 2px; border: 2px solid var(--agent-soft); border-top-color: var(--agent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* memory, settings */
.mem { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-top: 1px solid var(--line-2); }
.list > .mem:first-child { border-top: 0; }
.mem .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.srow { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 13px 0; border-top: 1px solid var(--line-2); }
.srow:first-child { border-top: 0; padding-top: 0; }
.srow:last-child { padding-bottom: 0; }
.srow .main { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.srow .t { font-weight: 700; }
.pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; }
.pick button { text-align: left; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.pick button:hover { border-color: var(--ink-3); }
.pick button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.pick b { font-weight: 700; }
.pick span { font-size: 13px; color: var(--ink-3); }
.form { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px 14px; align-items: center; }
.form label { font-weight: 600; }
.runs { display: flex; flex-direction: column; gap: 8px; }
.runs li { display: grid; grid-template-columns: 124px minmax(0, 1fr); gap: 12px; color: var(--ink-2); }
.runs time { color: var(--ink-3); font: 400 13px var(--font-mono); padding-top: 2px; }

/* layer */
.scrim { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { width: min(560px, 100%); max-height: min(88%, 760px); overflow: auto; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); display: flex; flex-direction: column; }
.modal > header { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal > header h2 { font-size: 18px; }
.mbody { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal > footer { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); }
.sheet { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 9px; }
.sheet i { display: block; height: 7px; border-radius: 3px; background: var(--sunken); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; width: max-content; max-width: min(640px, calc(100% - 32px)); padding: 11px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); }
.toast .btn { background: transparent; color: inherit; border-color: currentColor; height: 28px; padding: 0 10px; font-size: 13px; }
.toast .btn:hover { background: transparent; opacity: .8; }

@media (max-width: 1000px) {
  .draft { grid-template-columns: minmax(0, 1fr); }
  .chatcol { position: static; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); height: calc(100% - 60px - env(safe-area-inset-bottom, 0px)); }
  .rail { display: none; }
  .tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; height: calc(60px + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--surface); border-top: 1px solid var(--line); z-index: 10; }
  .tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; color: var(--ink-3); position: relative; min-width: 0; }
  .tabs a:hover { text-decoration: none; }
  .tabs a[aria-current="page"] { color: var(--accent-text); font-weight: 700; }
  .tabs .n { position: absolute; top: 6px; left: calc(50% + 6px); font: 700 10px var(--font-mono); background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 5px; }
  .bar { padding: 12px 16px; }
  .bar h1 { font-size: 19px; }
  .bar .sub { flex-basis: 100%; }
  .body { padding-inline: 16px; }
  .item { flex-wrap: wrap; }
  .item .main { flex-basis: calc(100% - 60px); }
  .item > .chip { margin-left: 50px; }
  .item > .ic { display: none; }
  .form { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .form label { margin-top: 8px; }
  .runs li { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toast { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* hosted app additions */
.signin { max-width: 420px; margin: 12vh auto 0; }
.error { color: var(--warn); }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.tabs { grid-template-columns: repeat(var(--tabs, 5), minmax(0, 1fr)); }
td.nw { white-space: nowrap; }
td .narrow { display: none; }
@media (max-width: 760px) {
  /* On a phone the roles table keeps the role and its status; the rest moves under the title. */
  table.roles { min-width: 0; }
  table.roles th:nth-child(n+2):nth-child(-n+5), table.roles td:nth-child(n+2):nth-child(-n+5) { display: none; }
  td .narrow { display: block; }
}
.dot.off { background: var(--warn); }
.srow .form.wide { flex-basis: 100%; }
.in.w-s, .sel.w-s { width: 130px; min-width: 0; }
.in.w-m { width: 220px; max-width: 100%; }
.in.w-l { width: 260px; max-width: 100%; }
