/* ============ Design tokens ============ */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --surface-3: #f1f3f8;
  --border: #e6e8ef;
  --border-strong: #d7dbe5;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8a94a8;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --primary-soft: #eef0ff;
  --success: #059669;
  --success-soft: #e8f8f1;
  --danger: #dc2626;
  --danger-soft: #fdeeee;
  --warn: #d97706;
  --warn-soft: #fff6e6;
  --info: #0284c7;
  --info-soft: #e8f4fb;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 2px 8px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .10), 0 2px 6px rgba(15, 23, 42, .05);
  --sidebar: 248px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.up { color: var(--success); }
.down { color: var(--danger); }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.bold { font-weight: 600; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ============ Shell ============ */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex: none;
  position: fixed;
  inset: 0 auto 0 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform .3s var(--ease);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: grid; place-items: center; color: #fff; box-shadow: 0 6px 16px rgba(79, 70, 229, .3);
}
.brand-name { font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }
.nav-group { margin-top: 14px; }
.nav-label { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px; color: var(--text-2);
  font-weight: 500; font-size: 13.5px; position: relative;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a.active::before {
  content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary);
  animation: growY .3s var(--ease);
}
.nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav .badge-count { margin-left: auto; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }

.main { flex: 1; margin-left: var(--sidebar); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 28px;
  background: rgba(245, 246, 250, .82);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s, background .2s;
}
.topbar.scrolled { border-bottom-color: var(--border); background: rgba(255, 255, 255, .86); }
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: -.015em; font-weight: 650; }
.crumbs { font-size: 12px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.menu-btn { display: none; }
.content { padding: 22px 28px 48px; max-width: 1480px; width: 100%; }

/* ============ Primitives ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-h h3 { margin: 0; font-size: 14px; font-weight: 620; letter-spacing: -.005em; }
.card-h .sub { font-size: 12px; color: var(--muted); }
.card-h .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-b { padding: 16px 18px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }
.mt-s { margin-top: 8px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin: 22px 0 10px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 13px; cursor: pointer;
  transition: transform .12s var(--ease), box-shadow .15s, background .15s, border-color .15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-2); border-color: #c9cede; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79, 70, 229, .25); }
.btn.primary:hover { background: #4338ca; }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge.sm { height: 19px; font-size: 10.5px; padding: 0 7px; }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); }
.badge-count { min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 10.5px; display: inline-grid; place-items: center; font-weight: 700; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; }
.dot.working { background: var(--success); box-shadow: 0 0 0 0 rgba(5, 150, 105, .5); animation: pulse 1.6s infinite; }
.dot.error { background: var(--danger); }
.dot.idle { background: #c3c9d6; }
.dot.live { background: var(--success); animation: pulse 2s infinite; }
.dot.off { background: var(--warn); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 8px; font-size: 12px;
  background: var(--surface-3); color: var(--text-2); border: 1px solid transparent;
}
.chip.scope { font-family: var(--mono); font-size: 11px; }
.chip.scope.restricted { background: var(--danger-soft); color: #b42318; }
.chip.scope.internal { background: var(--info-soft); color: #075985; }
.chip.scope.public { background: var(--success-soft); color: #05603a; }

.input, select.input {
  height: 34px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface);
  padding: 0 11px; font: inherit; font-size: 13px; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
.search { position: relative; }
.search .input { padding-left: 32px; width: 240px; }
.search svg { position: absolute; left: 10px; top: 9px; width: 15px; height: 15px; color: var(--muted); }

.tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-3); border-radius: 10px; border: 1px solid var(--border); flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 550; font-size: 12.5px; color: var(--text-2); cursor: pointer; transition: background .15s, color .15s, box-shadow .15s; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ============ KPI ============ */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 15px 16px; position: relative; overflow: hidden; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 550; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 22px; font-weight: 680; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; margin-top: 2px; font-weight: 550; }
.kpi .icon { position: absolute; right: 14px; top: 14px; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; }
.kpi .icon svg { width: 16px; height: 16px; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.t th {
  text-align: left; font-weight: 600; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap;
}
.t td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr { transition: background .12s; }
.t tbody tr:hover { background: var(--surface-2); }
.t tr.clickable { cursor: pointer; }
.t td.num, .t th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ============ Lists / feed ============ */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 11px; padding: 10px 18px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.feed li:last-child { border-bottom: 0; }
.feed .ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; flex: none; margin-top: 1px; }
.feed .ico svg { width: 14px; height: 14px; }
.feed .msg { font-size: 13px; color: var(--text); word-break: break-word; }
.feed .meta { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.feed li.new { animation: flashIn .9s var(--ease); }
.scroll-y { overflow-y: auto; }

.lvl-success .ico { background: var(--success-soft); color: var(--success); }
.lvl-error .ico { background: var(--danger-soft); color: var(--danger); }
.lvl-warn .ico { background: var(--warn-soft); color: var(--warn); }
.lvl-info .ico, .lvl-debug .ico { background: var(--primary-soft); color: var(--primary); }

/* ============ Avatar ============ */
.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; letter-spacing: .02em;
}
.avatar.sm { width: 26px; height: 26px; border-radius: 8px; font-size: 10px; }
.avatar.lg { width: 52px; height: 52px; border-radius: 14px; font-size: 17px; }
.agent-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 550; }
.agent-link:hover { text-decoration: none; color: var(--primary); }

/* ============ Stage stepper ============ */
.stepper { list-style: none; margin: 0; padding: 0; }
.stepper li { display: flex; gap: 12px; align-items: flex-start; position: relative; padding: 0 0 14px; }
.stepper li:last-child { padding-bottom: 0; }
.stepper li::before { content: ""; position: absolute; left: 11px; top: 24px; bottom: 0; width: 2px; background: var(--border); }
.stepper li:last-child::before { display: none; }
.stepper li.done::before { background: linear-gradient(var(--success), var(--border)); }
.step-ico { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface); display: grid; place-items: center; flex: none; z-index: 1; transition: all .3s var(--ease); }
.step-ico svg { width: 12px; height: 12px; }
li.done .step-ico { background: var(--success); border-color: var(--success); color: #fff; }
li.running .step-ico { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
li.running .step-ico::after { content: ""; position: absolute; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--primary); border-top-color: transparent; animation: spin 0.9s linear infinite; }
li.failed .step-ico { background: var(--danger); border-color: var(--danger); color: #fff; }
li.skipped .step-ico { background: var(--surface-3); border-style: dashed; color: var(--muted); }
.step-name { font-weight: 600; font-size: 13px; }
.step-sum { font-size: 12px; color: var(--text-2); margin-top: 1px; }
li.pending .step-name, li.skipped .step-name { color: var(--muted); }

.progress { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width .8s var(--ease); }
.progress.success > span { background: var(--success); }
.progress.warn > span { background: var(--warn); }
.progress.danger > span { background: var(--danger); }
.progress.indeterminate > span { width: 40% !important; animation: indet 1.4s var(--ease) infinite; }

/* ============ Status pill ============ */
.pill { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; font-weight: 550; box-shadow: var(--shadow-sm); }
.pill .sep { width: 1px; height: 14px; background: var(--border); }

/* ============ Drawer / modal / toast ============ */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .28); backdrop-filter: blur(2px); z-index: 60; animation: fade .2s ease; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); z-index: 61;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slideIn .32s var(--ease);
}
.drawer.wide { width: min(880px, 100vw); }
.drawer-h { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-h h3 { margin: 0; font-size: 15px; }
.drawer-b { padding: 18px 20px; overflow-y: auto; flex: 1; }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast {
  min-width: 280px; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 12px 14px; display: flex; gap: 10px; animation: toastIn .4s var(--ease); font-size: 13px;
}
.toast.out { animation: toastOut .3s var(--ease) forwards; }
.toast .ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.toast .t-title { font-weight: 620; }
.toast .t-body { color: var(--text-2); font-size: 12.5px; }

/* ============ Code / markdown ============ */
pre.code {
  background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 10px; overflow: auto; font-family: var(--mono);
  font-size: 12px; line-height: 1.55; margin: 0; max-height: 520px;
}
pre.code.light { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.md { font-size: 13.5px; line-height: 1.65; color: var(--text); word-wrap: break-word; }
.md h1 { font-size: 20px; margin: 0 0 12px; letter-spacing: -.015em; }
.md h2 { font-size: 15.5px; margin: 20px 0 8px; }
.md h3 { font-size: 14px; margin: 16px 0 6px; }
.md p { margin: 8px 0; }
.md ul { padding-left: 20px; margin: 8px 0; }
.md code { font-family: var(--mono); font-size: 12px; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
.md pre { margin: 10px 0; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 12.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface-2); }
.md blockquote { margin: 8px 0; padding: 4px 14px; border-left: 3px solid var(--primary-2); color: var(--text-2); background: var(--primary-soft); border-radius: 0 8px 8px 0; }

/* ============ Empty / skeleton ============ */
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 36px; height: 36px; opacity: .5; margin-bottom: 8px; }
.empty .e-title { font-weight: 600; color: var(--text-2); font-size: 14px; }
.skeleton { background: linear-gradient(90deg, var(--surface-3) 0%, #eceff5 40%, var(--surface-3) 80%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }

/* ============ Org tree ============ */
.tree-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.tree-viewport { position: relative; overflow: auto; height: calc(100vh - 230px); min-height: 520px; background:
  radial-gradient(circle, #dfe3ec 1px, transparent 1.2px) 0 0 / 22px 22px, var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); cursor: grab; }
.tree-viewport.dragging { cursor: grabbing; }
.tree-canvas { position: relative; transform-origin: 0 0; transition: transform .25s var(--ease); }
.tree-links { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.tree-links path { fill: none; stroke: #c7cdda; stroke-width: 1.6; stroke-dasharray: 1000; stroke-dashoffset: 1000; animation: draw 1.1s var(--ease) forwards; transition: stroke .2s, opacity .2s; }
.tree-links path.hl { stroke: var(--primary-2); stroke-width: 2.2; }
.tree-links path.dim { opacity: .25; }
.node {
  position: absolute; width: 228px; height: 62px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; padding: 0 10px 0 12px; cursor: pointer;
  transition: box-shadow .2s, transform .2s var(--ease), opacity .25s, border-color .2s, top .35s var(--ease), left .35s var(--ease);
  animation: nodeIn .5s var(--ease) both; animation-delay: calc(var(--d, 0) * 70ms);
}
.node::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--c, var(--primary)); }
.node:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); border-color: #cdd3e0; }
.node.sel { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(99, 102, 241, .18), var(--shadow-lg); }
.node.dim { opacity: .3; }
.node.match { border-color: var(--warn); box-shadow: 0 0 0 3px rgba(217, 119, 6, .18); }
.node .n-body { min-width: 0; flex: 1; }
.node .n-name { font-weight: 620; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .n-title { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .n-tags { display: flex; gap: 4px; margin-top: 3px; }
.node .n-state { position: absolute; top: 8px; right: 9px; }
.node .toggle {
  position: absolute; right: -11px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--surface); display: grid; place-items: center; font-size: 11px; font-weight: 700;
  color: var(--text-2); cursor: pointer; box-shadow: var(--shadow-sm); z-index: 2; transition: background .15s;
}
.node .toggle:hover { background: var(--primary-soft); color: var(--primary); }
.node.working { border-color: rgba(5, 150, 105, .45); }
.node.working::after { content: ""; position: absolute; inset: -1px; border-radius: 12px; border: 1px solid var(--success); animation: ring 1.6s infinite; pointer-events: none; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ============ Flow (decision pipeline) ============ */
.flow { display: flex; flex-direction: column; gap: 0; max-width: 980px; margin: 0 auto; }
.flow-step { display: grid; grid-template-columns: 54px 1fr; gap: 14px; position: relative; padding-bottom: 18px; animation: fadeUp .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 55ms); }
.flow-step::before { content: ""; position: absolute; left: 26px; top: 46px; bottom: 0; width: 2px; background: linear-gradient(var(--border-strong), var(--border)); }
.flow-step:last-child::before { display: none; }
.flow-num { width: 54px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 15px; box-shadow: var(--shadow); }
.flow-card { padding: 12px 16px; }
.flow-card .f-title { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.flow-card .f-desc { font-size: 12.5px; color: var(--text-2); margin: 3px 0 9px; }

/* ============ Debate ============ */
.debate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bubble { border-radius: 14px; padding: 14px 16px; border: 1px solid var(--border); background: var(--surface); position: relative; animation: fadeUp .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 80ms); }
.bubble.bull { border-color: #bfe8d6; background: linear-gradient(180deg, #f3fcf8, #fff 60%); }
.bubble.bear { border-color: #f6caca; background: linear-gradient(180deg, #fff5f5, #fff 60%); }
.bubble.evidence { border-color: #c7d7fe; background: linear-gradient(180deg, #f3f6ff, #fff 60%); grid-column: 1 / -1; }
.bubble .b-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; color: var(--text-2); }
.bubble p { margin: 0; font-size: 13.5px; line-height: 1.6; }
.bubble ul { margin: 8px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--text-2); }
.round-label { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin-top: 6px; }
.round-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.scorebar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-3); }
.scorebar .b { background: var(--success); transition: width 1s var(--ease); }
.scorebar .r { background: var(--danger); transition: width 1s var(--ease); }

/* ============ Approval chain ============ */
.chain { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.chain .link { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 8px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); animation: popIn .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); }
.chain .link.approve, .chain .link.pass { border-color: #bfe8d6; background: var(--success-soft); color: #05603a; }
.chain .link.modify { border-color: #fde3b0; background: var(--warn-soft); color: #93370d; }
.chain .link.reject, .chain .link.fail { border-color: #f6caca; background: var(--danger-soft); color: #b42318; }
.chain .link.pending { color: var(--muted); border-style: dashed; }
.chain .arrow { color: var(--muted); font-size: 12px; }

/* ============ Evidence browser ============ */
.ev-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; }
.ev-list { list-style: none; margin: 0; padding: 6px; max-height: calc(100vh - 260px); overflow-y: auto; }
.ev-list li { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; transition: background .12s; }
.ev-list li:hover { background: var(--surface-3); }
.ev-list li.sel { background: var(--primary-soft); color: var(--primary); }
.ev-list li svg { width: 15px; height: 15px; flex: none; color: var(--muted); }
.ev-list li .cnt { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.path-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 12.5px; }
.path-bar a { color: var(--text-2); padding: 2px 6px; border-radius: 6px; }
.path-bar a:hover { background: var(--surface-3); text-decoration: none; }

/* ============ Access matrix ============ */
.matrix { border-collapse: separate; border-spacing: 0; font-size: 12px; }
.matrix th { position: sticky; top: 0; background: var(--surface-2); z-index: 1; font-weight: 600; color: var(--text-2); padding: 6px; border-bottom: 1px solid var(--border); }
.matrix th.rot { height: 170px; white-space: nowrap; vertical-align: bottom; padding: 0 0 8px; }
.matrix th.rot > div { transform: rotate(-55deg); transform-origin: 14px 0; width: 26px; font-family: var(--mono); font-size: 10.5px; }
.matrix td { border-bottom: 1px solid var(--border); padding: 0; text-align: center; height: 30px; }
.matrix td.name { text-align: left; padding: 0 12px; white-space: nowrap; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.matrix .cell { width: 26px; height: 20px; margin: 0 auto; border-radius: 5px; transition: transform .15s; }
.matrix .cell.yes { background: #c7f0de; }
.matrix .cell.yes.restricted { background: #fcd2d2; }
.matrix .cell.yes.internal { background: #cfe6fb; }
.matrix tr:hover td { background: var(--surface-2); }
.matrix .cell:hover { transform: scale(1.2); }

/* ============ Misc components ============ */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
.list-plain { margin: 0; padding-left: 18px; }
.list-plain li { margin: 3px 0; }
.dept-card { padding: 16px 18px; cursor: pointer; transition: transform .2s var(--ease), box-shadow .2s; position: relative; overflow: hidden; }
.dept-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.dept-card .stripe { position: absolute; left: 0; right: 0; top: 0; height: 3px; }
.agent-card { padding: 14px 16px; cursor: pointer; transition: transform .2s var(--ease), box-shadow .2s; }
.agent-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.stat-mini { display: flex; flex-direction: column; }
.stat-mini .v { font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums; }
.stat-mini .l { font-size: 11.5px; color: var(--muted); }
.memo { padding: 12px 18px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: auto 1fr; gap: 12px; }
.memo:last-child { border-bottom: 0; }
.memo .m-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.memo .m-subj { font-weight: 620; font-size: 13px; margin-top: 2px; }
.memo .m-body { font-size: 13px; color: var(--text-2); margin-top: 2px; white-space: pre-wrap; }
.gauge { position: relative; width: 120px; height: 66px; }
.range { position: relative; height: 8px; border-radius: 99px; background: linear-gradient(90deg, #fecaca, #f1f5f9 45%, #f1f5f9 55%, #bbf7d0); }
.range .mark { position: absolute; top: -4px; width: 4px; height: 16px; border-radius: 2px; background: var(--text); transform: translateX(-2px); transition: left .6s var(--ease); }
.chart { width: 100%; display: block; }
.chart .area { animation: fade 1.2s ease; }
.chart .line { stroke-dasharray: 3000; stroke-dashoffset: 3000; animation: draw 1.6s var(--ease) forwards; }
.chart-tip { position: absolute; pointer-events: none; background: #0f172a; color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 8px; transform: translate(-50%, -120%); white-space: nowrap; opacity: 0; transition: opacity .12s; }
.chart-wrap { position: relative; }
.checks { list-style: none; padding: 0; margin: 0; font-size: 12.5px; }
.checks li { display: flex; gap: 8px; padding: 4px 0; align-items: flex-start; }
.checks .r { font-weight: 700; font-size: 10.5px; padding: 1px 6px; border-radius: 5px; flex: none; margin-top: 2px; }
.checks .r.pass { background: var(--success-soft); color: var(--success); }
.checks .r.fail { background: var(--danger-soft); color: var(--danger); }
.checks .r.adjusted, .checks .r.warn { background: var(--warn-soft); color: var(--warn); }

/* ============ Page animations ============ */
.page { animation: pageIn .45s var(--ease); }
.page.no-anim, .page.no-anim * { animation: none !important; }
.anim > * { animation: fadeUp .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); }
.anim > *:nth-child(1) { --i: 0; } .anim > *:nth-child(2) { --i: 1; } .anim > *:nth-child(3) { --i: 2; }
.anim > *:nth-child(4) { --i: 3; } .anim > *:nth-child(5) { --i: 4; } .anim > *:nth-child(6) { --i: 5; }
.anim > *:nth-child(7) { --i: 6; } .anim > *:nth-child(8) { --i: 7; } .anim > *:nth-child(n+9) { --i: 8; }
.flash { animation: flash 1.2s ease; }

@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastIn { from { transform: translateY(16px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateX(30px); opacity: 0; } }
@keyframes popIn { from { transform: scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes nodeIn { from { opacity: 0; transform: translateX(-12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(5, 150, 105, .45); } 70% { box-shadow: 0 0 0 7px rgba(5, 150, 105, 0); } 100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); } }
@keyframes ring { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.06); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes indet { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
@keyframes flashIn { 0% { background: var(--primary-soft); } 100% { background: transparent; } }
@keyframes flash { 0% { background: #fff7d6; } 100% { background: transparent; } }
@keyframes growY { from { transform: scaleY(0); } to { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ============ Responsive ============ */
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .g-2-1, .g-1-2 { grid-template-columns: minmax(0, 1fr); }
  .ev-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px 16px 40px; }
  .topbar { padding: 10px 16px; }
  .g2, .g4, .debate-grid { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search .input { width: 100%; }
  .topbar-right .pill.hide-sm { display: none; }
}

/* ---------- live P&L (livepnl.js) ---------- */
.live-pnl { margin-bottom: 18px; animation: fadeUp .5s var(--ease) both; }
.live-pnl .card-h .actions { gap: 12px; }
.lp-status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.lp-top { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 30px; }
.lp-main { margin-right: 8px; }
.lp-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-bottom: 3px; }
.lp-big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; border-radius: 8px; padding: 0 4px; margin-left: -4px; }
.lp-stat b { font-size: 15px; font-weight: 650; }
.lp-chart { position: relative; height: 230px; margin-top: 14px; color: var(--primary); }
.lp-chart.up { color: var(--success); }
.lp-chart.down { color: var(--danger); }
.lp-chart svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.lp-chart path { transition: d .5s var(--ease); }
.lp-overlay { position: absolute; inset: 0; cursor: crosshair; }
.lp-y { position: absolute; right: 0; transform: translateY(-50%); font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lp-x { position: absolute; bottom: 0; font-size: 10.5px; color: var(--muted); transform: translateX(-50%); white-space: nowrap; }
.lp-x.start { transform: none; }
.lp-x.end { transform: translateX(-100%); }
.lp-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: currentColor; border: 2px solid var(--surface); animation: lp-pulse 1.8s ease-out infinite; transition: left .5s var(--ease), top .5s var(--ease); }
.lp-hover-x { position: absolute; top: 20px; bottom: 26px; width: 1px; background: var(--border-strong); opacity: 0; pointer-events: none; }
.lp-tip { position: absolute; pointer-events: none; background: #0f172a; color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 8px; transform: translate(-50%, calc(-100% - 12px)); white-space: nowrap; opacity: 0; transition: opacity .12s; z-index: 2; }
.lp-tip .lp-tip-ch { opacity: .75; }
.lp-empty { position: absolute; inset: 0; display: grid; place-items: center; }
.lp-float { position: absolute; z-index: 3; transform: translate(-50%, -50%); font-weight: 700; font-size: 13px; padding: 2px 9px; border-radius: 99px; white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums; box-shadow: var(--shadow-sm); animation: lp-rise 2.6s cubic-bezier(.2, .7, .2, 1) forwards; }
.lp-float.up { color: var(--success); background: var(--success-soft); }
.lp-float.down { color: var(--danger); background: var(--danger-soft); animation-name: lp-sink; }
.lp-float.sm { font-size: 11px; padding: 1px 7px; }
.lp-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.lp-chip { position: relative; display: inline-flex; gap: 8px; align-items: baseline; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-size: 12.5px; }
.lp-side { font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 5px; background: var(--surface-3); }
.flash-up { animation: lp-flash-up 1.4s ease; }
.flash-down { animation: lp-flash-down 1.4s ease; }
@keyframes lp-rise {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.75); }
  12% { opacity: 1; transform: translate(-50%, -110%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -330%); }
}
@keyframes lp-sink {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.75); }
  12% { opacity: 1; transform: translate(-50%, 10%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, 230%); }
}
@keyframes lp-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 45%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}
@keyframes lp-flash-up { 0% { background: var(--success-soft); } 100% { background: transparent; } }
@keyframes lp-flash-down { 0% { background: var(--danger-soft); } 100% { background: transparent; } }
.lp-chip.flash-up { animation-name: lp-chip-up; }
.lp-chip.flash-down { animation-name: lp-chip-down; }
@keyframes lp-chip-up { 0% { background: var(--success-soft); border-color: var(--success); } 100% { background: var(--surface-2); border-color: var(--border); } }
@keyframes lp-chip-down { 0% { background: var(--danger-soft); border-color: var(--danger); } 100% { background: var(--surface-2); border-color: var(--border); } }
@media (max-width: 860px) {
  .live-pnl .card-h { flex-wrap: wrap; }
  .lp-big { font-size: 28px; }
  .lp-chart { height: 190px; }
}
@media (prefers-reduced-motion: reduce) {
  .lp-float { animation-duration: .01s; }
  .lp-dot { animation: none; }
}

/* ---------- sign-in (login.js) ---------- */
[hidden] { display: none !important; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); padding: 36px 32px 28px; text-align: center; animation: fadeUp .5s var(--ease) both; }
.login-mark { width: 48px; height: 48px; margin: 0 auto 16px; border-radius: 14px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--primary), #7c3aed); box-shadow: 0 8px 20px rgba(79, 70, 229, .3); }
.login-mark svg { width: 24px; height: 24px; }
.login-card h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.login-card > p { margin: 6px 0 24px; font-size: 13.5px; }
.btn.google { width: 100%; height: 46px; justify-content: center; gap: 12px; font-size: 14.5px; font-weight: 600; background: var(--surface);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-sm); text-decoration: none; color: var(--text); }
.btn.google:hover { background: var(--surface-2); border-color: #b8bfd0; }
.btn.google svg { width: 20px; height: 20px; }
.btn.google.busy { opacity: .6; pointer-events: none; }
.login-error { margin: 0 0 14px; padding: 9px 12px; border-radius: 10px; font-size: 13px; color: var(--danger); background: var(--danger-soft); text-align: left; }
.login-link { margin-top: 18px; padding: 4px; border: 0; background: none; color: var(--text-2); font: inherit; font-size: 12.5px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.login-link:hover { color: var(--text); }
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; text-align: left; }
.login-form .input { width: 100%; box-sizing: border-box; height: 42px; }
.login-form .input.code { font-size: 22px; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }
.login-form .btn { justify-content: center; height: 42px; }
.login-form .login-link { margin-top: 0; align-self: center; }
.login-note { margin-top: 22px; }

/* ---------- paged lists (ui.js pager) ---------- */
.load-more { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; }
