/* Design decisions live in DESIGN.md. Light is the default (office staff, daytime); dark is complete, not an afterthought. */

:root,
:root[data-theme="light"] {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-2: #F2F4F7;
  --line: #E6E8EC;
  --field: #858D9B;
  --ink: #101828;
  --muted: #5D6675;
  --accent: #0A7F73;
  --accent-ink: #08695F;
  --on-accent: #FFFFFF;
  --accent-soft: rgb(10 127 115 / 0.09);
  --warn: #9A5B00;
  --warn-soft: rgb(154 91 0 / 0.10);
  --danger: #B42318;
  --danger-soft: rgb(180 35 24 / 0.08);
  --ok: #1F7A4C;
  --ok-soft: rgb(31 122 76 / 0.10);
  --shadow: 0 20px 48px rgb(16 24 40 / 0.14);
  --scrim: rgb(16 24 40 / 0.32);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0E1114;
  --surface: #15191D;
  --surface-2: #1B2025;
  --line: #262C32;
  --field: #5F6B75;
  --ink: #E7ECEF;
  --muted: #919CA5;
  --accent: #2FC2B0;
  --accent-ink: #5CD4C5;
  --on-accent: #06201C;
  --accent-soft: rgb(47 194 176 / 0.12);
  --warn: #E8A23A;
  --warn-soft: rgb(232 162 58 / 0.14);
  --danger: #F2695C;
  --danger-soft: rgb(242 105 92 / 0.13);
  --ok: #45C486;
  --ok-soft: rgb(69 196 134 / 0.13);
  --shadow: 0 20px 48px rgb(0 0 0 / 0.45);
  --scrim: rgb(4 6 8 / 0.62);
  color-scheme: dark;
}

:root {
  /* Satoshi: geometric like the reference, firm at large figure sizes and calm in small table text */
  --font: "Satoshi", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --r-control: 10px;
  --r-panel: 16px;
  --side-w: 248px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 14.5px/1.55 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
h2 { font-size: 1.0625rem; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 0.9375rem; font-weight: 700; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }

a[href], button, summary, select, label[for], input[type="checkbox"], input[type="radio"], [role="button"] { cursor: pointer; }
button:disabled, select:disabled, input:disabled, textarea:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip { position: absolute; left: -9999px; top: 8px; z-index: 80; background: var(--surface); padding: 8px 12px; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.code { font-family: var(--mono); font-size: 0.85em; letter-spacing: 0; overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.wordmark { font-weight: 800; font-size: 1.1875rem; letter-spacing: -0.02em; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 0.875rem; white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--field); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 0.8125rem; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface); color: var(--ink);
}
.icon-btn:hover { background: var(--surface-2); }

label { font-weight: 600; font-size: 0.8125rem; color: var(--muted); }
input[type="text"], input[type="number"], input[type="search"], input[type="password"], input[type="date"], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--field); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink);
}
textarea { resize: vertical; }
.field { display: grid; gap: 6px; }
.stack { display: grid; gap: 14px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }

/* ---------- status pill (real states only) ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.wait { background: var(--warn-soft); color: var(--warn); }
.pill.block { background: var(--danger-soft); color: var(--danger); }
/* "Langsung" marks that the page refreshes itself while agents work: a real state, so a steady dot, no pulse */
.pill.live { background: var(--ok-soft); color: var(--ok); vertical-align: 4px; margin-left: 10px; }

/* ---------- shell ---------- */
.mobilebar { display: none; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 30;
  display: flex; flex-direction: column; gap: 20px;
  padding: 22px 16px 16px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
}
.side-brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand-mark { display: grid; place-items: center; flex: none; width: 40px; height: 40px; color: var(--ink); border-radius: 10px; }
.brand-mark .logo { width: 38px; height: auto; }
.mobile-brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; }
.mobile-brand .logo { width: 30px; height: auto; }
.side-brand-text { display: grid; min-width: 0; }
.company { color: var(--muted); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-nav { display: grid; gap: 2px; }
.nav-label { padding: 14px 10px 6px; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.side-nav a {
  display: flex; align-items: center; gap: 12px;
  min-height: 42px; padding: 0 12px; border-radius: var(--r-control);
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.9rem;
}
.side-nav a svg { flex: none; color: var(--muted); }
.side-nav a > span:first-of-type { flex: 1; }
.side-nav a:hover { background: var(--surface-2); }
.side-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
.side-nav a[aria-current="page"] svg { color: var(--accent-ink); }
.count:empty { display: none; }
.count {
  min-width: 24px; padding: 1px 8px; border-radius: 999px; text-align: center;
  background: var(--warn-soft); color: var(--warn); font-size: 0.75rem; font-weight: 700;
}
.sim-card { margin-top: auto; display: grid; gap: 8px; padding: 14px; border-radius: var(--r-panel); background: var(--surface-2); }
.sim-title { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.sim-clock { font-weight: 700; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: var(--r-panel); }
.side-user-text { display: grid; min-width: 0; flex: 1; }
.side-user-name { font-weight: 700; font-size: 0.875rem; }
.side-user-role { font-size: 0.75rem; color: var(--muted); }
.side-actions { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-top: -8px; }

/* Theme switch: sun on the left (light), moon on the right (dark). The knob covers the active mode and
   carries its symbol; position and symbol follow data-theme, so it is right from the first paint. */
.theme-switch {
  display: grid; place-items: center; min-height: 44px; padding: 0 2px;
  border: 0; border-radius: 999px; background: none; color: var(--muted); cursor: pointer;
}
.theme-track {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  width: 60px; height: 32px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  transition: border-color 0.2s ease;
}
.theme-switch:hover .theme-track { border-color: var(--field); }
.theme-switch:focus-visible { outline: none; }
.theme-switch:focus-visible .theme-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-track svg { width: 16px; height: 16px; }
.theme-knob {
  position: absolute; left: 3px; top: 3px; display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 999px;
  background: var(--ink); color: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
:root[data-theme="dark"] .theme-knob { transform: translateX(28px); }
.theme-knob svg { grid-area: 1 / 1; transition: transform 0.45s ease, opacity 0.3s ease; }
.theme-moon, :root[data-theme="dark"] .theme-sun { opacity: 0; transform: rotate(-90deg) scale(0.5); }
:root[data-theme="dark"] .theme-moon { opacity: 1; transform: none; }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 0.8125rem;
}
.avatar.lg { width: 40px; height: 40px; }

.content { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; min-width: 0; padding: 30px 32px 40px; }
main:focus { outline: none; }
.foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 32px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.8125rem;
}
body.signed-out .sidebar, body.signed-out .mobilebar { display: none; }
body.signed-out .content { margin-left: 0; }

/* ---------- page head ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-meta { color: var(--muted); font-size: 0.875rem; margin-top: 6px; }
.page-head .lede { color: var(--muted); margin-top: 6px; max-width: 72ch; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); }
/* a wide table scrolls inside its own panel instead of pushing the page sideways */
.panel:has(> .table) { overflow-x: auto; }
.panel-pad { padding: 20px 22px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 .count { margin-left: 8px; vertical-align: 2px; }
.panel-sub { color: var(--muted); font-size: 0.8125rem; margin-top: 2px; }
.state-msg { color: var(--muted); padding: 20px; }
.state-msg.error { color: var(--danger); }
.empty { padding: 34px 22px; display: grid; gap: 8px; justify-items: start; }
.empty h3 { font-size: 1rem; }

/* KPI cards: three real figures, each with the breakdown behind it */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.kpi { display: grid; gap: 10px; align-content: start; padding: 20px 22px; }
.fig-label { font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.fig { font-size: 2.25rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.fig small { font-size: 0.875rem; font-weight: 600; letter-spacing: 0; color: var(--muted); margin-left: 6px; }
.segbar { display: flex; gap: 4px; height: 8px; }
.segbar span { flex: 1; border-radius: 4px; background: var(--surface-2); }
.segbar span.ok { background: var(--ok); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.75rem; color: var(--muted); }
.legend span { padding: 2px 9px; border-radius: 999px; background: var(--surface-2); }
.legend b { color: var(--ink); font-weight: 700; }
.kpi-foot { font-size: 0.75rem; color: var(--muted); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.row-link { cursor: pointer; }
.table tr.row-link:hover td { background: var(--surface-2); }
.table .right { text-align: right; }
.table td a { display: inline-flex; align-items: center; min-height: 32px; }
.cell-main { font-weight: 500; }
.table td.nowrap { white-space: nowrap; }
.row-btn {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0; border: 0; background: none;
  color: var(--ink); font-weight: 600; text-align: left;
}
.row-btn:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }
.row-btn.code { font-weight: 500; }
.section-label .row-btn { min-height: 24px; font-size: 0.8125rem; color: var(--accent-ink); }
.cell-sub { font-size: 0.8125rem; color: var(--muted); }
.truncate { max-width: min(34ch, 28vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conf { font-size: 0.75rem; color: var(--muted); }
.conf.low { color: var(--warn); font-weight: 600; }

/* ---------- meja kerja ---------- */
.desk { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.desk-main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; min-width: 0; }
/* the queue description wraps to two lines instead of forcing one long line, so the table fits beside the rail */
.desk .table .truncate {
  max-width: 46ch; white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
@media (min-width: 1281px) and (max-width: 1599px) {
  .desk { grid-template-columns: minmax(0, 1fr) 320px; }
  .desk .feed-tabs { padding-inline: 12px; gap: 0; }
  .desk .feed-tab { padding: 0 8px; }
}

/* agent activity rail: real agent runs grouped by day, newest first */
.activity { position: sticky; top: 20px; display: flex; flex-direction: column; max-height: calc(100dvh - 40px); }
.activity-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 22px 0; }
.activity-head h2 { display: flex; align-items: center; }
.feed-stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 16px 22px 0;
  padding: 14px 6px; border-radius: 14px; background: var(--surface-2); text-align: center;
}
.feed-stat { display: grid; justify-items: center; align-content: start; gap: 2px; }
.feed-stat .ico { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--surface); color: var(--accent-ink); margin-bottom: 4px; }
.feed-stat b { font-size: 1.125rem; font-weight: 800; }
.feed-stat span { font-size: 0.72rem; color: var(--muted); line-height: 1.3; }
.feed-tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 14px 18px 4px; }
.feed-tab {
  display: inline-flex; align-items: center; gap: 5px; min-height: 32px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 999px; background: transparent; color: var(--muted); font-size: 0.8125rem; font-weight: 600;
}
.feed-tab:hover { color: var(--ink); background: var(--surface-2); }
.feed-tab[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.feed-tab small { font-size: 0.72rem; color: var(--muted); }
.feed-scroll { overflow-y: auto; padding: 4px 22px 18px; min-height: 0; }
.feed-day { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.feed-day::after { content: ""; flex: 1; height: 1px; background: var(--line); order: 1; }
.feed-day .n { order: 2; padding: 0 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.feed-list { list-style: none; margin: 0; padding: 0; }
.feed-list > li { position: relative; display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; }
.feed-list > li::before { content: ""; position: absolute; left: 16px; top: 42px; bottom: 0; width: 2px; background: var(--line); }
.feed-list > li:last-child::before { display: none; }
.feed-node { position: relative; z-index: 1; display: grid; place-items: center; width: 34px; height: 38px; margin-top: 4px; background: var(--surface); }
.feed-node.bad { outline: 2px solid var(--danger); outline-offset: 1px; border-radius: 50%; }
.mascot { display: block; flex: none; }
.feed-item {
  display: grid; gap: 3px; width: 100%; padding: 9px 10px; margin: 2px 0 6px; text-align: left;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink);
}
.feed-item:hover { background: var(--surface-2); }
.feed-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.feed-title { font-weight: 700; font-size: 0.9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-time { flex: none; font-size: 0.72rem; color: var(--muted); }
.feed-text { font-size: 0.8125rem; color: var(--muted); line-height: 1.45; }
.feed-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 0.75rem; color: var(--muted); }
.agent-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.feed-more { display: inline-flex; align-items: center; gap: 6px; margin: 2px 0 4px 44px; min-height: 32px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--accent-ink); font-size: 0.8125rem; font-weight: 600; }
.feed-more:hover { background: var(--accent-soft); }

/* ---------- side sheet ---------- */
.sheet {
  margin: 0 0 0 auto; padding: 0; border: 0; border-left: 1px solid var(--line);
  width: min(600px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh;
  background: var(--surface); color: var(--ink);
}
.sheet::backdrop, .modal::backdrop { background: var(--scrim); }
.sheet-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.sheet-crumb { color: var(--muted); font-size: 0.875rem; }
.sheet-crumb .code { color: var(--ink); }
.sheet[open] { display: flex; flex-direction: column; }
.sheet-body { flex: 1; display: flex; flex-direction: column; }
.sheet-body > .sheet-actions { margin-top: auto; }
.sheet-section { padding: 18px 22px; border-bottom: 1px solid var(--line); display: grid; gap: 12px; }
.sheet-section:last-child { border-bottom: 0; }
.section-label { display: flex; justify-content: space-between; gap: 12px; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.hero { display: grid; gap: 6px; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hero-title { font-size: 1.125rem; font-weight: 600; }
.hero-agent { display: flex; align-items: center; gap: 12px; }
.hero-sub { color: var(--muted); font-size: 0.8125rem; }
.hero-amount { font-size: 1.875rem; font-weight: 600; letter-spacing: -0.01em; }
.hero-amount small { font-size: 0.8125rem; color: var(--muted); font-weight: 500; margin-left: 8px; }
.alert {
  display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 10px;
  padding: 12px 14px; border-radius: var(--r-control); border: 1px solid;
}
.alert.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.alert.block { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.alert.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.alert svg { margin-top: 2px; }
.alert.warn svg { color: var(--warn); }
.alert.block svg { color: var(--danger); }
.alert.info svg { color: var(--accent-ink); }
.alert-title { font-weight: 600; }
.alert-text { color: var(--muted); font-size: 0.875rem; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 8px 16px; font-size: 0.875rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.checks li { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; align-items: start; font-size: 0.875rem; }
.checks .ok { color: var(--ok); }
.checks .bad { color: var(--danger); }
.checks .wait { color: var(--warn); }
.checks .note { color: var(--muted); font-size: 0.8125rem; }
.sheet-actions {
  position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  padding: 14px 22px; background: var(--surface); border-top: 1px solid var(--line);
}

/* ---------- flow rail: the Niagara motif ---------- */
.rail { list-style: none; margin: 0; padding: 0; display: grid; }
.rail > li { position: relative; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; padding-bottom: 16px; }
.rail > li:last-child { padding-bottom: 0; }
.rail > li::before { content: ""; position: absolute; left: 13px; top: 32px; bottom: 0; width: 2px; background: var(--line); }
.rail-mascot { position: relative; z-index: 1; display: grid; place-items: center; width: 28px; height: 32px; background: var(--surface); }
.rail-mascot.bad { outline: 2px solid var(--danger); outline-offset: 1px; border-radius: 50%; }
.rail > li:last-child::before { display: none; }
.rail-node {
  position: relative; z-index: 1; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface); border: 2px solid var(--accent);
}
.rail-node::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.rail-node.wait { border-color: var(--warn); }
.rail-node.wait::after { background: var(--warn); }
.rail-node.bad { border-color: var(--danger); }
.rail-node.bad::after { background: var(--danger); }
.rail-node.quiet { border-color: var(--field); }
.rail-node.quiet::after { background: var(--field); }
.rail-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.rail-title { font-weight: 600; font-size: 0.9375rem; }
.rail-meta { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.rail-text { font-size: 0.875rem; color: var(--muted); margin-top: 2px; }
.rail details { margin-top: 6px; }
.rail summary { font-size: 0.8125rem; color: var(--accent-ink); min-height: 28px; display: inline-flex; align-items: center; }
.steps { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.step { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px; font-size: 0.8125rem; }
.step-kind { font-weight: 600; color: var(--muted); }
.step-kind.policy, .step-kind.decision { color: var(--accent-ink); }
.step-kind.error { color: var(--danger); }
.step-title { color: var(--ink); }
.step-fail .step-title { color: var(--danger); }
.step-detail { margin-top: 3px; color: var(--muted); display: grid; gap: 2px; }
.step-detail .k { color: var(--ink); }
.step-detail .kvline { overflow-wrap: anywhere; }

/* ---------- percakapan: simulator styled after WhatsApp Desktop (labelled as a simulator in the UI) ---------- */
.chat-app {
  --wa-bg: #111B21; --wa-panel: #202C33; --wa-input: #2A3942; --wa-hover: #202C33; --wa-active: #2A3942;
  --wa-line: #222D34; --wa-ink: #E9EDEF; --wa-muted: #9AA8B1; --wa-green: #00A884; --wa-green-ink: #00A884;
  --wa-wall: #0B141A; --wa-in: #202C33; --wa-out: #005C4B; --wa-out-meta: rgb(255 255 255 / 0.68);
  --wa-note-bg: #182229; --wa-note-ink: #FFD279; --wa-day: #182229; --wa-av-bg: #6A7175; --wa-av-fg: #CFD4D6; --wa-chip-on: #0A332C; --wa-chip-on-ink: #00A884; --wa-tick: #53BDEB;
  /* shared components inside the simulator pick up the WhatsApp-like palette */
  --surface: var(--wa-bg); --surface-2: var(--wa-panel); --line: var(--wa-line); --ink: var(--wa-ink); --muted: var(--wa-muted);
  display: grid; grid-template-columns: clamp(280px, 28vw, 420px) minmax(0, 1fr);
  height: calc(100dvh - 160px); min-height: 580px; overflow: hidden;
  border: 1px solid var(--wa-line); border-radius: var(--r-panel);
  background: var(--wa-bg); color: var(--wa-ink);
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
:root[data-theme="light"] .chat-app {
  --wa-bg: #FFFFFF; --wa-panel: #F0F2F5; --wa-input: #FFFFFF; --wa-hover: #F5F6F6; --wa-active: #F0F2F5;
  --wa-line: #E9EDEF; --wa-ink: #111B21; --wa-muted: #56656E; --wa-green-ink: #008069;
  --wa-wall: #EFEAE2; --wa-in: #FFFFFF; --wa-out: #D9FDD3; --wa-out-meta: #56656E;
  --wa-note-bg: #FFEECD; --wa-note-ink: #54656F; --wa-day: #FFFFFF; --wa-av-bg: #DFE5E7; --wa-av-fg: #FFFFFF; --wa-chip-on: #E7FCE3; --wa-chip-on-ink: #008069; --wa-tick: #027EB5;
}
.chat-app, .chat-app * { scrollbar-width: thin; scrollbar-color: rgb(134 150 160 / 0.45) transparent; }
.chat-app .icon-btn { border: 0; color: var(--wa-muted); border-radius: 50%; }
.chat-app .icon-btn:hover { background: rgb(134 150 160 / 0.15); color: var(--wa-ink); }

.chat-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--wa-line); background: var(--wa-bg); }
.chat-list-head { display: grid; gap: 8px; padding: 10px 12px 8px; }
.chat-list-head .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 4px 4px 12px; }
.chat-list-head h2 { font-size: 1.375rem; font-weight: 700; }
.sim-tag { display: block; font-size: 0.75rem; font-weight: 400; color: var(--wa-muted); }
.wa-search { position: relative; }
.wa-search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--wa-muted); }
.chat-app .wa-search input {
  min-height: 35px; padding: 6px 12px 6px 52px; border: 0; border-radius: 8px;
  background: var(--wa-panel); color: var(--wa-ink); font-size: 0.875rem;
}
.chat-app .wa-search input::placeholder { color: var(--wa-muted); }
.wa-filters { display: flex; gap: 8px; padding: 0 0 4px; flex-wrap: wrap; }
.wa-filter {
  min-height: 32px; padding: 0 12px; border: 0; border-radius: 999px;
  background: var(--wa-panel); color: var(--wa-muted); font-size: 0.9375rem;
}
.wa-filter[aria-pressed="true"] { background: var(--wa-chip-on); color: var(--wa-chip-on-ink); }
.wa-filter:hover { color: var(--wa-ink); }
.contacts { overflow-y: auto; flex: 1; padding: 0 12px 8px; }
.contact {
  display: grid; grid-template-columns: 49px minmax(0, 1fr); gap: 15px; align-items: center;
  width: 100%; min-height: 72px; padding: 0 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--wa-ink); text-align: left;
}
.contact:hover { background: var(--wa-hover); }
.contact[aria-current="true"] { background: var(--wa-active); }
.wa-avatar { display: block; flex: none; width: 49px; height: 49px; border-radius: 50%; object-fit: cover; background: var(--wa-av-bg); }
.wa-avatar-bg { fill: var(--wa-av-bg); }
.wa-avatar-fg { fill: var(--wa-av-fg); }
.contact-body { display: grid; gap: 2px; min-width: 0; align-self: stretch; align-content: center; border-bottom: 1px solid var(--wa-line); }
.contact:last-child .contact-body { border-bottom: 0; }
.contact-top, .contact-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; }
.contact-name { font-size: 1.0625rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-last { display: flex; align-items: center; gap: 3px; min-width: 0; font-size: 0.875rem; color: var(--wa-muted); }
.contact-last span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-time { flex: none; font-size: 0.75rem; color: var(--wa-muted); }
.contact-flag { flex: none; padding: 0 7px; border-radius: 999px; background: var(--wa-green); color: #111B21; font-size: 0.75rem; font-weight: 600; line-height: 20px; }
.contacts-empty { padding: 24px 12px; color: var(--wa-muted); font-size: 0.875rem; }

.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--wa-wall); }
.chat-head { display: flex; align-items: center; gap: 13px; min-height: 59px; padding: 8px 16px; background: var(--wa-panel); }
.chat-head .wa-avatar { width: 40px; height: 40px; }
.chat-head-text { flex: 1; min-width: 0; }
.chat-head-name { font-size: 1rem; font-weight: 400; color: var(--wa-ink); }
.chat-head-sub { font-size: 0.8125rem; color: var(--wa-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-app.show-info { grid-template-columns: clamp(280px, 26vw, 420px) minmax(0, 1fr) 360px; }
.back-btn { display: none; }
.thread { flex: 1; overflow-y: auto; padding: 16px max(16px, 7%) 12px; display: flex; flex-direction: column; background: var(--wa-wall); }
.wa-note {
  align-self: center; max-width: 560px; margin: 4px 0 12px; padding: 6px 12px 8px; border-radius: 7.5px;
  background: var(--wa-note-bg); color: var(--wa-note-ink); font-size: 0.78rem; line-height: 1.4; text-align: center;
  box-shadow: 0 1px 0.5px rgb(11 20 26 / 0.13);
}
.day-sep {
  align-self: center; margin: 12px 0 10px; padding: 5px 12px 6px; border-radius: 7.5px;
  background: var(--wa-day); color: var(--wa-muted); font-size: 0.78rem;
  box-shadow: 0 1px 0.5px rgb(11 20 26 / 0.13);
}
.bubble {
  position: relative; max-width: min(65%, 620px); margin-top: 2px; padding: 6px 7px 8px 9px; border-radius: 7.5px;
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.9rem; line-height: 1.36; color: var(--wa-ink);
  box-shadow: 0 1px 0.5px rgb(11 20 26 / 0.13);
}
.bubble.in { align-self: flex-start; background: var(--wa-in); }
.bubble.out { align-self: flex-end; background: var(--wa-out); }
.bubble.tail { margin-top: 12px; }
.bubble.tail.in { border-top-left-radius: 0; }
.bubble.tail.out { border-top-right-radius: 0; }
.bubble.tail::before { content: ""; position: absolute; top: 0; width: 8px; height: 13px; }
.bubble.tail.in::before { left: -8px; background: var(--wa-in); clip-path: polygon(0 0, 100% 0, 100% 100%); }
.bubble.tail.out::before { right: -8px; background: var(--wa-out); clip-path: polygon(0 0, 100% 0, 0 100%); }
.bubble img { display: block; border-radius: 6px; margin: -3px -4px 6px -6px; max-height: 300px; width: auto; }
.bubble audio { display: block; margin-bottom: 4px; max-width: 100%; }
.meta-spacer { display: inline-block; width: var(--meta-w, 58px); height: 1px; }
.bubble-meta {
  position: absolute; right: 7px; bottom: 4px; display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.6875rem; line-height: 15px; color: var(--wa-muted); white-space: nowrap;
}
.bubble.out .bubble-meta { color: var(--wa-out-meta); }
.bubble-meta .ticks { display: inline-flex; color: var(--wa-tick); }
/* agent work between bubbles: a Niagara overlay, visibly not part of the chat app */
.agent-work {
  align-self: center; width: min(560px, 92%); margin: 10px 0 6px; padding: 8px; border-radius: 12px;
  background: var(--wa-bg); border: 1px dashed var(--wa-muted); display: grid; gap: 2px;
}
.agent-work-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 2px 8px 6px; font-size: 0.75rem; font-weight: 700; color: var(--wa-ink); font-family: var(--font); }
.agent-work-head span { font-weight: 400; color: var(--wa-muted); }
.agent-step {
  display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%;
  padding: 6px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--wa-ink); text-align: left;
  font-family: var(--font); font-size: 0.8125rem; line-height: 1.4;
}
.agent-step:hover { background: var(--wa-panel); }
.agent-step-text { color: var(--wa-muted); min-width: 0; }
.agent-step-text b { color: var(--wa-ink); font-weight: 700; }
.agent-step-time { font-size: 0.72rem; color: var(--wa-muted); }
.work-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 12px 0 8px; border-radius: 999px;
  border: 1px solid var(--wa-line); background: transparent; color: var(--wa-ink); font-size: 0.8125rem; white-space: nowrap;
}
.work-toggle:hover { background: rgb(134 150 160 / 0.15); }
.work-toggle[aria-pressed="false"] { color: var(--wa-muted); }
.intent { display: block; width: fit-content; margin-top: 4px; font-size: 0.72rem; font-weight: 600; color: var(--wa-green-ink); white-space: normal; }

.composer { display: grid; gap: 0; background: var(--wa-panel); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px 0; scrollbar-width: thin; }
.chip {
  flex: none; min-height: 30px; padding: 0 12px; border: 0; border-radius: 999px;
  background: var(--wa-input); color: var(--wa-muted); font-size: 0.8125rem;
}
.chip:hover { color: var(--wa-ink); }
.compose-row { position: relative; display: flex; gap: 8px; align-items: flex-end; padding: 8px 16px 10px; }
.chat-app .compose-row textarea {
  min-height: 42px; max-height: 140px; padding: 10px 12px; border: 0; border-radius: 8px;
  background: var(--wa-input); color: var(--wa-ink); font-size: 0.9375rem; line-height: 1.4; resize: none; overflow-y: hidden;
}
.chat-app .compose-row textarea::placeholder { color: var(--wa-muted); }
.compose-row .icon-btn { width: 42px; height: 42px; flex: none; }
.send-btn { width: 42px; height: 42px; flex: none; border: 0; border-radius: 50%; background: transparent; color: var(--wa-muted); display: grid; place-items: center; }
.send-btn:hover { color: var(--wa-ink); background: rgb(134 150 160 / 0.15); }
.attach-menu {
  position: absolute; left: 16px; bottom: 58px; z-index: 5; min-width: 260px; padding: 8px 0; border-radius: 12px;
  background: var(--wa-panel); box-shadow: 0 6px 24px rgb(11 20 26 / 0.35);
}
:root[data-theme="light"] .attach-menu { background: #FFFFFF; }
.attach-menu button, .attach-menu label {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 18px; border: 0;
  background: transparent; color: var(--wa-ink); font-size: 0.9375rem; font-weight: 400; text-align: left;
}
.attach-menu button:hover, .attach-menu label:hover { background: var(--wa-hover); }
.attach-menu button:disabled { color: var(--wa-muted); }
.compose-hint { padding: 0 16px 8px; font-size: 0.75rem; color: var(--wa-muted); }

.chat-info { border-left: 1px solid var(--wa-line); overflow-y: auto; background: var(--wa-wall); }
.chat-info-head { display: flex; align-items: center; gap: 14px; min-height: 59px; padding: 0 12px; background: var(--wa-panel); font-size: 1rem; }
.chat-info-hero { display: grid; justify-items: center; gap: 4px; padding: 22px 16px 18px; background: var(--wa-bg); margin-bottom: 8px; text-align: center; }
.chat-info-hero .wa-avatar { width: 160px; height: 160px; margin-bottom: 10px; }
.chat-info-hero .name { font-size: 1.25rem; }
.chat-info-hero .sub { font-size: 0.875rem; color: var(--wa-muted); }
.chat-info .sheet-section { padding: 14px 20px; background: var(--wa-bg); border-bottom: 0; margin-bottom: 8px; }
.chat-info .section-label { color: var(--wa-muted); font-weight: 400; font-size: 0.875rem; }
.chat-info .btn { background: transparent; border-color: var(--wa-line); color: var(--wa-green-ink); }
.basket { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 0.8125rem; }
.mini-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.8125rem; }
.mini-lines li { display: flex; justify-content: space-between; gap: 10px; }

/* ---------- other pages ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.aging { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; }
.aging span { display: block; height: 100%; min-width: 2px; }
.aging-legend { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.aging-legend div { display: grid; gap: 2px; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }
.brief-lead { font-size: 1.0625rem; line-height: 1.65; }
.brief-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 0.875rem; }

/* ---------- login ---------- */
.login { max-width: 400px; margin: 9vh auto 0; display: grid; gap: 16px; padding: 28px; }
.login .state-msg { padding: 0; }
.login .state-msg:empty { display: none; }

/* ---------- dialogs & toast ---------- */
.modal {
  border: 1px solid var(--line); border-radius: var(--r-panel); padding: 22px;
  width: min(460px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.modal h2 { margin-bottom: 10px; }
.modal p { color: var(--muted); margin-bottom: 18px; }
.toast {
  position: fixed; left: 50%; bottom: 22px; z-index: 90; transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 11px 16px; border-radius: var(--r-control); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-size: 0.875rem;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: sheet-in 180ms ease-out; }
  .toast { transition: opacity 160ms ease, transform 160ms ease; }
}
@keyframes sheet-in { from { transform: translateX(28px); opacity: 0.6; } to { transform: none; opacity: 1; } }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .chat-info { display: none; }
  .chat-app.show-info { grid-template-columns: clamp(280px, 28vw, 420px) minmax(0, 1fr); }
  .desk { grid-template-columns: minmax(0, 1fr); }
  .activity { position: static; max-height: none; }
}

/* the decision queue has five columns; below this width it reads better as stacked cards */
@media (max-width: 1180px) {
  .desk .table.cards thead { display: none; }
  .desk .table.cards, .desk .table.cards tbody, .desk .table.cards tr, .desk .table.cards td { display: block; width: 100%; }
  .desk .table.cards tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .desk .table.cards tbody tr:last-child { border-bottom: 0; }
  .desk .table.cards td { border: 0; padding: 3px 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  .desk .table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 0.75rem; text-align: left; flex: none; }
  .desk .table.cards td.stack-cell { display: grid; gap: 4px; text-align: left; }
  .desk .table.cards td.stack-cell::before { display: none; }
  .desk .truncate { max-width: 100%; }
}

@media (max-width: 960px) {
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .mobilebar {
    display: flex; position: sticky; top: 0; z-index: 40; justify-content: space-between; align-items: center;
    padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .sidebar { transform: translateX(-100%); width: min(300px, 86vw); box-shadow: var(--shadow); visibility: hidden; }
  .sidebar.open { transform: none; visibility: visible; }
  .content { margin-left: 0; }
  main { padding: 18px 16px 28px; }
  .foot { padding: 12px 16px; }
  h1 { font-size: 1.375rem; }

  .chat-page .page-head { margin-bottom: 12px; }
  .chat-page .page-head .lede { display: none; }
  .chat-app { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 150px); min-height: 480px; }
  .contacts { padding: 0 4px 8px; }
  .thread { padding: 12px 14px; }
  .chat-app.has-chat .chat-list { display: none; }
  .chat-app:not(.has-chat) .chat-pane { display: none; }
  .back-btn { display: inline-grid; }
  .bubble { max-width: 85%; }

  .table.cards thead { display: none; }
  .table.cards, .table.cards tbody, .table.cards tr, .table.cards td { display: block; width: 100%; }
  .table.cards tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table.cards tbody tr:last-child { border-bottom: 0; }
  .table.cards td { border: 0; padding: 3px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  .table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 0.75rem; text-align: left; flex: none; }
  .table.cards td.stack-cell { display: grid; gap: 4px; text-align: left; }
  .table.cards td.stack-cell::before { display: none; }
  .truncate { max-width: 60vw; }
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
  .aging-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compose-hint { display: none; }
  .work-toggle { padding: 0 8px; font-size: 0; gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .btn:active { transform: none; }
}
