:root {
  --bg: #f7f6f3; --panel: #ffffff; --panel-2: #f0eee9; --text: #1f1e1c; --muted: #6f6b64;
  --border: #e3e0d9; --accent: #c96442; --accent-soft: #c964421f; --ok: #2f8f5b; --warn: #b7791f; --bad: #c0392b;
  --code: #f2f0eb; --radius: 10px; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111214; --panel: #1a1b1e; --panel-2: #222327; --text: #ecebe8; --muted: #9a968f;
    --border: #2d2e33; --accent: #d97757; --accent-soft: #d977572a; --code: #232428; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.small, .small { font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
h1 { font-size: 20px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 8px; } h3 { font-size: 14px; margin: 16px 0 6px; }
.muted { color: var(--muted); } .error { color: var(--bad); } .hidden { display: none !important; }
code, pre { font-family: var(--mono); font-size: 13px; background: var(--code); border-radius: 6px; }
code { padding: 1px 5px; } pre { padding: 10px 12px; overflow-x: auto; }
pre code { padding: 0; background: none; }

#app { display: flex; height: 100vh; height: 100dvh; }
#nav { width: 190px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; }
#nav .brand { font-weight: 650; padding: 4px 10px 14px; } #nav .brand { color: var(--accent); }
#nav a { color: var(--text); text-decoration: none; padding: 7px 10px; border-radius: 8px; }
#nav a.active, #nav a:hover { background: var(--panel-2); }
#nav .spacer { flex: 1; }
#nav #whoami { padding: 6px 10px; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 12px; margin: 6px 10px; cursor: pointer; text-align: center; }
main { flex: 1; min-width: 0; overflow: auto; }
.page { padding: 22px 26px; max-width: 1100px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
td code { white-space: nowrap; }
.mobile-only { display: none; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); }
.pill.ok { color: var(--ok); border-color: currentColor; } .pill.warn { color: var(--warn); border-color: currentColor; } .pill.bad { color: var(--bad); border-color: currentColor; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }

/* chat */
.chat { display: flex; height: 100%; }
.threads { width: 250px; border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; }
.threads .head { padding: 12px; } .threads ul { list-style: none; margin: 0; padding: 0 6px 12px; overflow: auto; flex: 1; }
.threads li { padding: 8px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.threads li.active, .threads li:hover { background: var(--panel-2); }
.convo { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.convo .bar { padding: 10px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.messages { flex: 1; overflow: auto; padding: 24px 18px; }
.messages .inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg.user { align-self: flex-end; background: var(--panel-2); padding: 10px 14px; border-radius: 14px; max-width: 85%; white-space: pre-wrap; }
.msg.assistant { line-height: 1.6; } .msg.assistant p { margin: 0 0 10px; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg.event { font-size: 13px; color: var(--muted); border-left: 3px solid var(--border); padding-left: 10px; }
.msg.event.err { border-color: var(--bad); color: var(--bad); }
.tool { font-size: 12px; font-family: var(--mono); color: var(--muted); background: var(--code); border-radius: 6px; padding: 4px 8px; margin: 4px 0; }
.approval { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; }
.composer { padding: 12px 18px 18px; }
.composer .box { max-width: 760px; margin: 0 auto; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { border: none; background: transparent; max-height: 220px; min-height: 24px; padding: 4px 6px; outline: none; }
.empty { text-align: center; color: var(--muted); margin-top: 18vh; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

/* graph editor */
.editor { display: flex; height: 100%; }
.canvas-wrap { flex: 1; position: relative; overflow: auto; background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 20px 20px; }
.canvas-wrap svg { display: block; }
.toolbar { position: sticky; top: 0; left: 0; z-index: 2; display: flex; gap: 8px; padding: 10px; flex-wrap: wrap; }
.side { width: 320px; border-left: 1px solid var(--border); background: var(--panel); padding: 16px; overflow: auto; }
.gnode rect { fill: var(--panel); stroke: var(--border); stroke-width: 1.5; }
.gnode.supervisor rect { stroke: var(--accent); }
.gnode.selected rect { stroke: var(--accent); stroke-width: 2.5; fill: var(--accent-soft); }
.gnode.entry rect { stroke-dasharray: none; }
.gnode text { fill: var(--text); font-size: 13px; pointer-events: none; }
.gnode .sub { fill: var(--muted); font-size: 11px; }
.gnode { cursor: grab; }
.gedge { stroke: var(--muted); stroke-width: 1.5; fill: none; cursor: pointer; }
.gedge.selected { stroke: var(--accent); stroke-width: 2.5; }
.gedge-hit { stroke: transparent; stroke-width: 14; fill: none; cursor: pointer; }
.connecting .gnode { cursor: crosshair; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 14px; z-index: 50; }
.modal { position: fixed; inset: 0; background: #0008; display: flex; align-items: center; justify-content: center; z-index: 40; }
.modal .card { width: min(420px, 92vw); display: flex; flex-direction: column; gap: 10px; }

@media (max-width: 760px) {
  #app { flex-direction: column; }
  #nav { width: 100%; flex-direction: row; overflow-x: auto; padding: 8px; border-right: none; border-bottom: 1px solid var(--border); align-items: center; }
  #nav .brand, #nav #whoami, #nav .spacer { display: none; }
  .mobile-only { display: inline-block; }
  .chat { position: relative; }
  .threads { display: none; } .threads.open { display: flex; position: absolute; z-index: 5; height: 100%; }
  .side { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .editor { flex-direction: column; }
  .page { padding: 16px; }
}
