:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #eef1f5;
  --line: #e2e6ec;
  --line-strong: #cfd6df;
  --ink: #12161d;
  --ink-2: #59636f;
  --ink-3: #8b95a2;
  --brand: #16645a;
  --brand-soft: #e3f1ee;
  --ok: #16724f;
  --ok-soft: #e2f3ea;
  --warn: #8a5a06;
  --warn-soft: #fbeed3;
  --bad: #b02418;
  --bad-soft: #fbe9e7;
  --info: #1d4f9e;
  --info-soft: #e8f0fb;
  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(15, 25, 40, 0.06);
  --shadow: 0 6px 24px rgba(15, 25, 40, 0.1);
  --shadow-lg: 0 24px 60px rgba(15, 25, 40, 0.18);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 640; letter-spacing: -0.011em; }
h1 { font-size: 19px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.err { color: var(--bad); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #12564e; }
.btn-danger { color: var(--bad); border-color: #eccbc7; }
.btn-danger:hover:not(:disabled) { background: var(--bad-soft); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.btn-sm { padding: 4px 9px; font-size: 12px; }

label.field {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 12px;
}
input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 450;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.hint { font-weight: 450; color: var(--ink-3); font-size: 12px; }

/* ---------- login ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px;
}
.gate-card h1 { margin-bottom: 6px; }
.gate-card .lead { color: var(--ink-2); font-size: 13px; margin-bottom: 20px; }
.gate-card .btn { width: 100%; justify-content: center; margin-top: 4px; }
.gate-card .err { font-size: 13px; margin-bottom: 10px; }

/* ---------- shell ---------- */
#app { max-width: 1420px; margin: 0 auto; padding: 0 20px 56px; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  margin-bottom: 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 660; }
.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}
.topbar-spacer { flex: 1; }
.topbar .stamp { font-size: 12px; color: var(--ink-3); }

/* ---------- attention queue ---------- */
.attention {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  overflow: hidden;
}
.attention-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 620;
  font-size: 13px;
}
.attention-list { display: grid; }
.att {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  font-size: 13px;
}
.attention-list .att:first-child { border-top: 0; }
.att:hover { background: var(--surface-2); }
.att-sev {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
}
.att-sev.bad { background: var(--bad); }
.att-sev.warn { background: #c98a12; }
.att-sev.info { background: var(--info); }
.att-who { font-weight: 600; flex: none; }
.att-what { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-go { margin-left: auto; color: var(--ink-3); font-size: 12px; flex: none; }

/* ---------- kpis ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px 13px;
}
.kpi .k-l {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi .k-n {
  font-size: 25px;
  font-weight: 640;
  letter-spacing: -0.02em;
  margin-top: 4px;
  line-height: 1.1;
}
.kpi .k-n small { font-size: 15px; color: var(--ink-3); font-weight: 550; }
.kpi .k-s { font-size: 12px; color: var(--ink-2); margin-top: 3px; }

.meter { height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.meter.warn > i { background: #c98a12; }
.meter.bad > i { background: var(--bad); }

/* ---------- summary strip ---------- */
.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 12px;
}
.strip-item {
  flex: 1 1 130px;
  background: var(--surface);
  padding: 8px 14px 9px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.strip-item span { font-size: 11.5px; color: var(--ink-3); }
.strip-item b { font-size: 15px; font-weight: 620; letter-spacing: -0.01em; }

/* ---------- split ---------- */
.split { display: grid; grid-template-columns: 320px 1fr; gap: 12px; align-items: start; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.rail { position: sticky; top: 62px; overflow: hidden; }
.rail-head { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.rail-search { display: flex; gap: 6px; align-items: center; }
.rail-search input { margin-top: 0; }
.filters { display: flex; gap: 4px; margin-top: 8px; }
.filter {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 560;
  padding: 4px 9px;
  border-radius: 999px;
}
.filter.on { background: var(--brand-soft); color: var(--brand); }
.filter:hover:not(.on) { background: var(--surface-3); }
.acct-list { max-height: calc(100vh - 220px); overflow-y: auto; padding: 6px; }
.acct {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 9px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: var(--radius);
  padding: 9px 10px;
}
.acct:hover { background: var(--surface-2); }
.acct.on { background: var(--brand-soft); }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: #c98a12; }
.dot.bad { background: var(--bad); }
.dot.idle { background: var(--ink-3); }
.acct-name { font-weight: 620; display: flex; align-items: center; gap: 6px; }
.acct-line { display: block; font-size: 12px; color: var(--ink-2); margin-top: 1px; }
.acct-bar { grid-column: 2; margin-top: 6px; }
.acct-warn { grid-column: 2; font-size: 12px; color: var(--bad); margin-top: 3px; }
.rail-empty { padding: 22px 14px; color: var(--ink-2); font-size: 13px; }

/* ---------- badges ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 640;
  letter-spacing: 0.01em;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--ink-2);
  white-space: nowrap;
}
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.brand { background: var(--brand-soft); color: var(--brand); }

/* ---------- detail ---------- */
.detail { min-height: 520px; }
.detail-empty { display: grid; place-items: center; min-height: 400px; text-align: center; padding: 40px; }
.detail-empty p { color: var(--ink-2); margin-top: 6px; max-width: 340px; }
.d-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.d-title h2 { display: flex; align-items: center; gap: 8px; }
.d-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.d-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.banner {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 12px 16px 0;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid transparent;
}
.banner.bad { background: var(--bad-soft); border-color: #f0cdc9; color: #7d1a11; }
.banner.warn { background: var(--warn-soft); border-color: #ecdcb2; color: #6d4705; }
.banner.info { background: var(--info-soft); border-color: #cddef5; color: #14407f; }

.d-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
  margin-top: 12px;
}
.d-metric { background: var(--surface); padding: 11px 16px 12px; }
.d-metric .m-l { font-size: 11.5px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.d-metric .m-n { font-size: 20px; font-weight: 640; letter-spacing: -0.02em; margin-top: 3px; }
.d-metric .m-n small { font-size: 13px; color: var(--ink-3); font-weight: 550; }
.d-metric .m-s { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; }

.tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); }
.tab {
  border: 0;
  background: transparent;
  padding: 7px 12px 9px;
  font-size: 13px;
  font-weight: 570;
  color: var(--ink-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--brand); border-bottom-color: var(--brand); }
.tab .count { font-size: 11px; color: var(--ink-3); margin-left: 4px; }
.tabs-spacer { flex: 1; }
.tabs-action { align-self: center; margin: 0 0 7px 8px; white-space: nowrap; }
.tab-body { padding: 14px 16px 18px; }
.section-note { font-size: 12.5px; color: var(--ink-2); margin-bottom: 12px; }

/* ---------- templates ---------- */
.phase-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 12.5px;
}
.tmpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.tmpl {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px 11px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.tmpl.pick { cursor: pointer; }
.tmpl.pick:hover { border-color: var(--line-strong); }
.tmpl.sel { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.tmpl.slot-empty { border-style: dashed; background: var(--surface-2); }
.tmpl-head { display: flex; align-items: center; gap: 7px; }
.tmpl-name { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.tmpl-head .tag { margin-left: auto; }
.tmpl-src { font-size: 11.5px; color: var(--ink-3); }
.tmpl-h { font-size: 12.5px; font-weight: 620; }
.tmpl-b {
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: pre-wrap;
  margin: 0;
  font-family: var(--sans);
  max-height: 108px;
  overflow: hidden;
  position: relative;
}
.tmpl-b.long::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 26px;
  background: linear-gradient(transparent, var(--surface));
}
.tmpl-f { font-size: 11.5px; color: var(--ink-3); }
.tmpl-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.tmpl-btns .tag { background: var(--info-soft); color: var(--info); }
.tmpl-act { margin-top: auto; padding-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }

.bulk {
  position: sticky;
  bottom: 12px;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 9px 12px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.bulk .btn { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.22); color: #fff; }
.bulk .btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
.bulk .spacer { flex: 1; }

/* ---------- tables & misc ---------- */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-3); font-weight: 620; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:last-child td { border-bottom: 0; }
td.num { font-family: var(--mono); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.check-list { display: grid; gap: 6px; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.check.no { border-color: #eccbc7; background: var(--bad-soft); }
.check .mark { font-weight: 700; font-size: 12px; }
.check.yes .mark { color: var(--ok); }
.check.no .mark { color: var(--bad); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; align-items: center; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; }

.spark { display: flex; align-items: flex-end; gap: 5px; height: 70px; }
.spark-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.spark-col i { width: 100%; max-width: 26px; background: var(--brand-soft); border: 1px solid #c6e0da; border-radius: 4px 4px 2px 2px; min-height: 3px; display: block; }
.spark-col b { width: 100%; max-width: 26px; background: var(--brand); border-radius: 4px 4px 2px 2px; min-height: 3px; display: block; }
.spark-col span { font-size: 10.5px; color: var(--ink-3); }

.empty { padding: 26px 8px; text-align: center; color: var(--ink-2); font-size: 13px; }

/* ---------- modal ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(16, 22, 30, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}
.sheet {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px 22px 22px;
}
.sheet-sm { width: min(420px, 100%); }
.sheet-wide { width: min(820px, 100%); }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { flex: 1; }
.sheet p.lead { color: var(--ink-2); font-size: 13px; margin-bottom: 16px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.remote-summary { color: var(--ink-2); font-size: 12.5px; margin-bottom: 10px; }
.table-scroll { max-width: 100%; overflow-x: auto; }
.remote-table, .static-table { min-width: 720px; }
.remote-table td { vertical-align: top; }
.remote-name, .remote-id, .remote-reason { display: block; }
.remote-name { font-family: var(--mono); font-weight: 620; white-space: nowrap; }
.remote-id { color: var(--ink-3); font-family: var(--mono); font-size: 10.5px; margin-top: 3px; }
.remote-reason { color: var(--bad); font-size: 11px; margin-top: 5px; max-width: 240px; }

/* ---------- payouts ---------- */
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--info);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.btn.has-badge { color: var(--ink); }
.pay-table td { vertical-align: middle; }
.pay-table .block { display: block; margin-top: 2px; font-size: 11.5px; }
.pay-amt { font-family: var(--mono); font-weight: 700; white-space: nowrap; }
.pay-act { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.pay-ask { font-size: 12px; color: var(--ink-2); }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; justify-items: end; }
.toast {
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: 380px;
  animation: rise 0.16s ease-out;
}
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (max-width: 1080px) {
  .split { grid-template-columns: 1fr; }
  .rail { position: static; }
  .acct-list { max-height: 320px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 620px) {
  #app { padding: 0 12px 40px; }
  .kpis { grid-template-columns: 1fr; }
  .two { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .tabs { overflow-x: auto; }
  .tabs-spacer { min-width: 8px; }
}
