:root {
  --ink: #16202c; --muted: #6b7686; --line: #e4e8ee;
  --accent: #0b63e5; --accent-soft: #e8f0fe;
  --ok: #0d9f6e; --ok-soft: #e6f7f1; --warn: #d97706; --warn-soft: #fdf0e0; --err: #d64545; --err-soft: #fde8e8;
  --purple: #7c3aed; --teal: #0e9aa7; --orange: #f59e0b; --grey: #9aa7b8;
  --console-bg: #f7f9fc; --bg: #fff;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 500; font-size: 12px; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 12px; align-items: center; }
.logo { background: var(--ink); color: #fff; font-weight: 700; border-radius: 8px; padding: 8px 10px; letter-spacing: .5px; }
.brand-title { font-weight: 700; font-size: 16px; }
.pi { color: var(--accent); font-style: italic; }
.brand-sub { color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 12px; align-items: center; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 999px; font-size: 12px; padding: 3px 10px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.grey { background: #eef1f5; color: var(--muted); }
select.tiny { font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; max-width: 120px; }

.layout { display: grid; grid-template-columns: 380px 1fr; gap: 18px; padding: 18px 24px; height: calc(100vh - 65px); overflow: hidden; }
.chat-pane { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-height: 0; }
.pane-title { font-weight: 700; margin-bottom: 8px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg .bubble { border-radius: 10px; padding: 9px 12px; white-space: pre-wrap; word-break: break-word; font-size: 13.5px; }
.msg.agent .bubble { background: var(--console-bg); border: 1px solid var(--line); }
.msg.user .bubble { background: var(--accent-soft); }
.msg.user { align-self: flex-end; max-width: 92%; }
.msg .bubble code { background: #eef1f5; padding: 1px 4px; border-radius: 4px; font-size: 12px; }
.msg .bubble .notice { color: var(--warn); font-size: 12px; }
.chat-input { display: flex; gap: 8px; margin-top: 10px; }
.chat-input textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13px; outline: none; }
.chat-input textarea:focus { border-color: var(--accent); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; font-size: 12px; padding: 4px 10px; cursor: pointer; color: var(--muted); }
.chip:hover { border-color: var(--accent); color: var(--accent); }

.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { border: none; color: var(--muted); }
.btn.small { padding: 5px 10px; font-size: 12px; }

.main-pane { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; min-height: 0; padding-bottom: 30px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: #fff; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.cfg-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-top: 8px; }
.cfg-grid label, .adv label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; min-width: 0; }
.cfg-grid select, .cfg-grid input { width: 100%; min-width: 0; }
.cfg-grid input, .cfg-grid select, .adv input[type=number], .adv select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font: 13px inherit; color: var(--ink); outline: none; background: #fff; }
.cfg-grid input:focus, .cfg-grid select:focus { border-color: var(--accent); }
.adv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 14px; }
.adv-col { display: flex; flex-direction: column; gap: 8px; }
.adv-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.toggle-line { display: flex !important; flex-direction: row !important; align-items: center; gap: 7px; font-size: 13px !important; color: var(--ink) !important; font-weight: 500 !important; cursor: pointer; }

/* flow */
.flow-wrap { overflow-x: auto; padding: 6px 0; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -2px; border: 1.5px solid var(--grey); }
.sw.planned { border-style: dashed; background: #fff; }
.sw.running { border-color: var(--accent); background: var(--accent-soft); }
.sw.done { border-color: var(--ok); background: var(--ok-soft); }
.sw.error { border-color: var(--err); background: var(--err-soft); }
.node rect { rx: 9; fill: #fff; stroke: var(--grey); stroke-width: 1.5; cursor: pointer; transition: all .3s; }
.node.planned rect { stroke-dasharray: 4 3; }
.node.planned text { fill: var(--muted); }
.node.running rect { stroke: var(--accent); fill: var(--accent-soft); filter: drop-shadow(0 0 4px rgba(11,99,229,.35)); }
.node.done rect { stroke: var(--ok); fill: #fff; }
.node.error rect { stroke: var(--err); fill: var(--err-soft); }
.node.selected rect { stroke-width: 3; }
.node text { font-size: 11.5px; font-weight: 700; fill: var(--ink); pointer-events: none; }
.node text.sub { font-size: 10px; font-weight: 500; fill: var(--muted); }
.edge { stroke: #c3cad4; stroke-width: 1.5; fill: none; }
.edge.loop { stroke: var(--accent); stroke-dasharray: 5 4; }
.lane-label { font-size: 11px; font-weight: 700; fill: var(--muted); }
.lane-result { font-size: 11px; font-weight: 600; fill: var(--ink); }
.lane-result.ok { fill: var(--ok); }
.lane-result.bad { fill: var(--warn); }
@keyframes pulse { 50% { opacity: .55; } }
.node.running rect { animation: pulse 1.1s infinite; }

/* loop chart & round table */
.axis { stroke: var(--line); }
.axis-text { font-size: 10px; fill: var(--muted); }
.round-table { font-size: 11.5px; margin-top: 6px; display: grid; gap: 3px; }
.round-row { display: grid; grid-template-columns: 52px 1fr; gap: 8px; padding: 3px 6px; border-radius: 6px; background: var(--console-bg); }
.round-row.best { outline: 1.5px solid var(--ok); }
.round-row b { color: var(--accent); }

/* console */
.console { background: var(--console-bg); border: 1px solid var(--line); border-radius: 10px; font: 12px/1.65 "SF Mono", "JetBrains Mono", Consolas, monospace; padding: 10px 12px; height: 220px; overflow-y: auto; margin-top: 6px; }
.console-hint { color: var(--muted); }
.cline { display: flex; gap: 8px; }
.cline .tag { color: var(--accent); font-weight: 700; flex-shrink: 0; min-width: 150px; }
.cline .txt { white-space: pre-wrap; }
.cline.warn .txt { color: var(--warn); }
.cline.ok .txt { color: var(--ok); }
.cline.error .txt { color: var(--err); font-weight: 700; }
.cline.head .txt { font-weight: 700; }
.tag-measured, .txt .m { color: var(--ok); font-weight: 700; }
.tag-modeled, .txt .d { color: var(--purple); font-weight: 700; }

/* report */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin: 8px 0 14px; }
.kpi { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; position: relative; }
.kpi .k-label { font-size: 11px; color: var(--muted); font-weight: 600; }
.kpi .k-value { font-size: 21px; font-weight: 800; margin-top: 2px; }
.kpi .k-value small { font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi .k-delta { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.kpi .k-delta.good { color: var(--ok); }
.kpi .k-delta.bad { color: var(--warn); }
.prov { position: absolute; top: 8px; right: 8px; font-size: 9.5px; font-weight: 700; border-radius: 4px; padding: 1px 5px; text-transform: uppercase; letter-spacing: .3px; }
.prov.measured { background: var(--ok-soft); color: var(--ok); }
.prov.modeled { background: #f1e9ff; color: var(--purple); }
.tee-line .prov { position: static; margin-left: 5px; }
.report-cols { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 14px; }
.chart-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.chart-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.bar-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 12px; }
.bar-row .bl { width: 60px; color: var(--muted); font-weight: 600; flex-shrink: 0; }
.bar-track { flex: 1; background: var(--console-bg); border-radius: 6px; height: 22px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; color: #fff; font-weight: 700; font-size: 11.5px; min-width: 58px; white-space: nowrap; transition: width .8s ease; }
.bar-fill.before { background: var(--grey); } .bar-fill.after { background: var(--accent); } .bar-fill.ok { background: var(--ok); }
.tee-line { display: flex; justify-content: space-between; font-size: 12.5px; padding: 4px 0; border-bottom: 1px dashed var(--line); gap: 8px; }
.tee-line b { font-variant-numeric: tabular-nums; text-align: right; }
.tee-note { font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.handoff { margin-top: 12px; font-size: 12.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 10px; }

@media (max-width: 1200px) {
  .layout { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .two-col, .report-cols { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .cfg-grid { grid-template-columns: repeat(2, 1fr); }
}

.run-divider { text-align: center; color: var(--muted); font-size: 11px; margin: 4px 0; border-top: 1px dashed var(--line); padding-top: 4px; }

/* ---------------------------------------------------------------- auth */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--console-bg); }
.auth-card { width: 420px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.auth-card .brand { margin-bottom: 18px; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab { border: none; background: none; font: inherit; font-weight: 600; font-size: 13px; color: var(--muted); padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.auth-form input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font: 14px inherit; color: var(--ink); outline: none; }
.auth-form input:focus { border-color: var(--accent); }
.auth-form .hint { font-weight: 500; font-size: 11px; color: var(--muted); }
.btn.wide { width: 100%; margin-top: 4px; }
.auth-err { margin-top: 14px; background: var(--err-soft); color: var(--err); border-radius: 8px; padding: 9px 11px; font-size: 12.5px; font-weight: 600; }
.auth-foot { margin-top: 16px; font-size: 11.5px; color: var(--muted); text-align: center; }

/* ---------------------------------------------------------------- queue / jobs */
.user-chip { font-size: 12px; color: var(--muted); font-weight: 600; }
.queue-bar { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; font-size: 12.5px; }
.queue-bar .qitem { display: flex; gap: 6px; align-items: center; }
.qdot { width: 8px; height: 8px; border-radius: 50%; background: var(--grey); }
.qdot.online { background: var(--ok); } .qdot.busy { background: var(--accent); } .qdot.offline { background: var(--err); }
.job-list { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow-y: auto; }
.job-row { display: grid; grid-template-columns: 78px 1fr auto; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 7px; background: var(--console-bg); font-size: 12px; cursor: pointer; border: 1px solid transparent; }
.job-row:hover { border-color: var(--accent); }
.job-row.active { border-color: var(--accent); background: var(--accent-soft); }
.job-row .jstatus { font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: .3px; }
.jstatus.queued { color: var(--warn); } .jstatus.running { color: var(--accent); }
.jstatus.done { color: var(--ok); } .jstatus.failed, .jstatus.cancelled { color: var(--err); }
.job-row .jmodel { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-row .jtime { color: var(--muted); font-size: 11px; }
.waiting-note { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 11px; font-size: 12.5px; font-weight: 600; margin-top: 8px; }
