:root {
  --bg: #f4f6fa; --panel: #ffffff; --ink: #1b2433; --muted: #667085; --line: #e3e8ef;
  --brand: #1d4ed8; --brand-ink: #ffffff; --ok: #15803d; --warn: #b45309; --bad: #be123c;
  --user: #1d4ed8; --agent: #f1f4f9; --chat-w: 460px;
  font-family: "Noto Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 14px; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.danger { background: #fff1f2; border-color: #fecdd3; color: var(--bad); font-weight: 600; }
button.ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #e8eefc; }
button.ghost:hover { background: rgba(255,255,255,.1); }
button.ghost.off { border-color: #fbbf24; color: #fde68a; }
button.wide { width: 100%; padding: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg,#f97316,#16a34a); color: #fff; font-weight: 800; font-size: 13px; }

/* ---- login ---- */
.login-page { display: grid; place-items: center; min-height: 100%; background: linear-gradient(160deg,#0f1b3d,#1d4ed8); }
.login-card { width: min(400px, 92vw); background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.login-brand h1 { font-size: 18px; margin: 0; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 14px; }
.login-card input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; }
.login-card input:focus { outline: 2px solid #93c5fd; border-color: var(--brand); }
.login-error { background: #fff1f2; color: var(--bad); border: 1px solid #fecdd3; padding: 8px 12px; border-radius: 8px; font-size: 13px; }

/* ---- app shell ---- */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.bar { display: flex; align-items: center; gap: 16px; padding: 8px 14px; background: #0f1b3d; color: #fff; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.agent-state { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #c7d2fe; margin-left: 8px; }
.agent-state .dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; }
.agent-state[data-state=working] .dot { background: #fbbf24; animation: pulse 1s infinite; }
.agent-state[data-state=waiting] .dot { background: #f43f5e; animation: pulse 1s infinite; }
.agent-state[data-state=waiting] { color: #fecdd3; font-weight: 600; }
@keyframes pulse { 50% { opacity: .35; } }
.bar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.bar-actions form { margin: 0; }
.bar-actions button { padding: 5px 11px; font-size: 13px; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr 6px var(--chat-w); min-height: 0; }
.screen-pane { position: relative; background: #111827; min-width: 0; }
.screen { position: absolute; inset: 0; }
.screen > div { background: #111827 !important; }
.screen-overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #cbd5e1; background: rgba(17,24,39,.85); font-size: 15px; pointer-events: none; }
.screen-overlay[hidden] { display: none; }
.splitter { cursor: col-resize; background: var(--line); }
.splitter:hover { background: #c7d2fe; }

.chat-pane { position: relative; display: flex; flex-direction: column; background: var(--panel); min-width: 0; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.drop-hint { display: none; position: absolute; inset: 0; background: rgba(29,78,216,.08); border: 3px dashed var(--brand); color: var(--brand); font-weight: 700; place-items: center; z-index: 5; pointer-events: none; }
.chat-pane.drag .drop-hint { display: grid; }

.welcome { background: linear-gradient(160deg,#eef2ff,#f8fafc); border: 1px solid #e0e7ff; border-radius: 14px; padding: 16px 18px; font-size: 14px; }
.welcome h2 { margin: 0 0 8px; font-size: 17px; }
.welcome ol { margin: 0 0 8px; padding-left: 20px; line-height: 1.55; }

.msg { display: flex; flex-direction: column; max-width: 92%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.agent { align-self: flex-start; }
.bubble { padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); color: #fff; border-bottom-right-radius: 4px; }
.msg.agent .bubble { background: var(--agent); border-bottom-left-radius: 4px; }
.meta { font-size: 11px; color: var(--muted); margin-top: 3px; }

.md p { margin: 0 0 6px; } .md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0 6px; padding-left: 20px; }
.md h3, .md h4, .md h5, .md h6 { margin: 8px 0 4px; font-size: 14px; }
.md code { background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 4px; font-size: 12.5px; }
.md pre, .step pre { background: #0f172a; color: #e2e8f0; padding: 8px 10px; border-radius: 8px; overflow: auto; font-size: 12px; max-height: 320px; white-space: pre-wrap; word-break: break-word; }
.tbl { overflow-x: auto; margin: 6px 0; }
.md table, table.fields { border-collapse: collapse; font-size: 12.5px; width: 100%; background: #fff; }
.md th, .md td, table.fields th, table.fields td { border: 1px solid var(--line); padding: 4px 7px; text-align: left; vertical-align: top; }
.md th, table.fields th { background: #f8fafc; }

.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; justify-content: flex-end; }
.file { font-size: 12px; background: #eef2ff; color: var(--ink); border-radius: 8px; padding: 5px 8px; text-decoration: none; }
.file.img { padding: 0; overflow: hidden; }
.file.img img { display: block; max-width: 160px; max-height: 120px; }

.steps { border: 1px solid var(--line); border-radius: 10px; background: #fbfcfe; font-size: 13px; }
.steps > summary { padding: 6px 10px; cursor: pointer; color: var(--muted); font-weight: 600; list-style: none; }
.steps > summary::before { content: '▸ '; } .steps[open] > summary::before { content: '▾ '; }
.steps-body { padding: 0 6px 6px; display: flex; flex-direction: column; gap: 2px; }
.step > summary { display: flex; gap: 8px; align-items: baseline; padding: 4px 6px; border-radius: 6px; cursor: pointer; list-style: none; }
.step > summary:hover { background: #eef2ff; }
.step .ico { flex: none; width: 18px; text-align: center; }
.step .txt { flex: 1; overflow-wrap: anywhere; }
.step .ms { flex: none; color: var(--muted); font-size: 11px; }
.step.err .txt { color: var(--warn); }
.step-body { padding: 4px 6px 8px 32px; }
.kv b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 0 3px; }
.thinking { font-size: 12.5px; color: #475569; background: #f8fafc; border-left: 3px solid #c7d2fe; padding: 4px 8px; border-radius: 4px; }
.thinking summary { cursor: pointer; color: var(--muted); }
img.shot { display: block; max-width: 100%; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; cursor: zoom-in; }

.card { border-radius: 12px; padding: 12px 14px; font-size: 14px; border: 1px solid var(--line); background: #fff; }
.card-head { font-weight: 700; margin-bottom: 6px; }
.card-foot { font-size: 12px; margin-top: 8px; }
.card.question { border-color: #fcd34d; background: #fffbeb; }
.card.approval { border-color: #fda4af; background: #fff5f6; }
.card.live { box-shadow: 0 0 0 3px rgba(244,63,94,.18); }
.card.question.live { box-shadow: 0 0 0 3px rgba(251,191,36,.3); }
.card.done { opacity: .85; box-shadow: none; }
.card.done .choices, .card.done textarea.comment { display: none; }
.card.ok { border-color: #86efac; background: #f0fdf4; }
.card .action { font-weight: 600; background: #fff; border: 1px dashed #fda4af; border-radius: 8px; padding: 6px 9px; margin-bottom: 8px; font-size: 13px; }
.card .purpose { margin-bottom: 6px; }
.fields-wrap { margin: 8px 0; } .fields-wrap summary { cursor: pointer; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.choice { background: #fff; border-color: #fcd34d; }
.choice:hover:not(:disabled) { background: #fef3c7; }
textarea.comment { width: 100%; margin-top: 8px; font: inherit; font-size: 13px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.verdict { font-weight: 600; margin-top: 6px; } .verdict:empty { display: none; }

.turn { align-self: center; font-size: 11.5px; color: var(--muted); background: #f1f5f9; border-radius: 999px; padding: 3px 10px; }
.note { font-size: 13px; border-radius: 10px; padding: 8px 12px; }
.note.error { background: #fff1f2; border: 1px solid #fecdd3; color: #9f1239; }
.note.system { align-self: center; color: var(--muted); font-style: italic; padding: 2px; }
.working { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 2px 4px; }
.spinner { width: 14px; height: 14px; border: 2px solid #c7d2fe; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.composer { border-top: 1px solid var(--line); padding: 10px 12px 12px; background: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; } .chips:empty { display: none; }
.chip { display: flex; align-items: center; gap: 6px; background: #eef2ff; border-radius: 8px; padding: 4px 6px; font-size: 12px; max-width: 100%; }
.chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.chip .x { border: 0; background: transparent; padding: 0 4px; font-size: 16px; line-height: 1; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea#input { flex: 1; resize: none; font: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; min-height: 42px; max-height: 220px; }
.composer textarea#input:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
.attach { display: grid; place-items: center; width: 40px; height: 42px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; color: var(--muted); flex: none; }
.attach:hover { background: #f1f5f9; color: var(--ink); }
.composer-row button { height: 42px; flex: none; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: grid; place-items: center; z-index: 50; cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 96vw; max-height: 94vh; border-radius: 6px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 45vh 0 1fr; }
  .splitter { display: none; }
  .agent-state { display: none; }
}
