:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --text: #16191f;
  --muted: #5d6675;
  --border: #e2e6ec;
  --accent: #1f5eff;
  --accent-text: #ffffff;
  --ok: #157f3b;
  --ok-bg: #e5f5ea;
  --bad: #c22a2a;
  --bad-bg: #fde8e8;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --unk: #6b3fb8;
  --unk-bg: #efe8fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --chart-success: #2f9e5b;
  --chart-failed: #d9534f;
  --chart-pending: #e0a100;
  --chart-unknown: #8a63d2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --panel-2: #1e232b;
    --text: #e7eaf0;
    --muted: #9aa3b2;
    --border: #2a303a;
    --accent: #5b8cff;
    --accent-text: #0b0d10;
    --ok: #5fd08a;
    --ok-bg: #16301f;
    --bad: #ff7b7b;
    --bad-bg: #3a1919;
    --warn: #f2c25b;
    --warn-bg: #352a10;
    --unk: #b99bf5;
    --unk-bg: #2a2140;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.boot { padding: 40px; color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand { font-weight: 650; padding: 4px 10px 14px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--panel-2); font-weight: 600; }
.nav .count {
  float: right;
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 12px;
  font-weight: 600;
}
.side .who { margin-top: auto; padding: 10px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border); }
.side .who button { margin-top: 8px; width: 100%; }
.main { padding: 24px 28px 60px; min-width: 0; }
.env-banner {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 16px;
  font-size: 13px;
}

@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { min-width: 0; }
  .nav { min-width: 0; max-width: 100%; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .brand { padding: 0 8px 0 0; }
  .nav { display: flex; overflow-x: auto; gap: 2px; width: 100%; order: 3; }
  .nav a { white-space: nowrap; }
  .nav .count { float: none; margin-left: 6px; }
  .side .who { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; gap: 8px; align-items: center; }
  .side .who button { margin: 0; width: auto; }
  .main { padding: 16px; }
}

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat.alert .value { color: var(--bad); }
a.stat { color: inherit; display: block; }
a.stat:hover { text-decoration: none; border-color: var(--accent); }

.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head-row h1 { margin: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
tbody tr:hover { background: var(--panel-2); }
tr.clickable { cursor: pointer; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* Badges */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.b-SUCCESS { background: var(--ok-bg); color: var(--ok); }
.b-FAILED { background: var(--bad-bg); color: var(--bad); }
.b-PENDING { background: var(--warn-bg); color: var(--warn); }
.b-UNKNOWN { background: var(--unk-bg); color: var(--unk); }
.b-review { background: var(--bad-bg); color: var(--bad); }
.b-neutral { background: var(--panel-2); color: var(--muted); }

/* Forms */
form.inline, .filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
textarea { min-height: 80px; resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit;
  font-weight: 550;
  border-radius: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover { background: var(--panel-2); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.5; cursor: default; }
.error-box { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.ok-box { background: var(--ok-bg); color: var(--ok); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.note-box { background: var(--panel-2); color: var(--muted); border-radius: 8px; padding: 10px 12px; font-size: 13px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login input { width: 100%; }

/* Detail */
dl.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { dl.kv { grid-template-columns: 1fr; } dl.kv dd { margin-bottom: 6px; } }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.timeline li.change::before { background: var(--accent); }
.timeline .when { color: var(--muted); font-size: 12px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.raw pre { background: var(--panel-2); padding: 8px; border-radius: 6px; overflow-x: auto; font-size: 12px; margin: 6px 0 0; }

/* Chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.chart .seg { width: 100%; }
.chart .seg.SUCCESS { background: var(--chart-success); }
.chart .seg.FAILED { background: var(--chart-failed); }
.chart .seg.PENDING { background: var(--chart-pending); }
.chart .seg.UNKNOWN { background: var(--chart-unknown); }
.chart .col .seg:first-child { border-radius: 3px 3px 0 0; }
.chart-x { display: flex; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.chart-x span { flex: 1; text-align: center; min-width: 0; overflow: hidden; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend i.SUCCESS { background: var(--chart-success); }
.legend i.FAILED { background: var(--chart-failed); }
.legend i.PENDING { background: var(--chart-pending); }
.legend i.UNKNOWN { background: var(--chart-unknown); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 520px; border: 1px solid var(--border); }
.secret { font-family: var(--mono); background: var(--panel-2); padding: 10px; border-radius: 8px; overflow-wrap: anywhere; margin: 10px 0; user-select: all; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 16px; right: 16px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; z-index: 20; }

/* Refund statuses */
.b-REQUESTED { background: var(--warn-bg); color: var(--warn); }
.b-APPROVED { background: var(--panel-2); color: var(--accent); }
.b-REJECTED { background: var(--panel-2); color: var(--muted); }
.b-SUCCEEDED { background: var(--ok-bg); color: var(--ok); }

/* Data delivery statuses */
.b-QUEUED { background: var(--panel-2); color: var(--muted); }
.b-DIALING { background: var(--warn-bg); color: var(--warn); }
.b-NEEDS_REVIEW { background: var(--bad-bg); color: var(--bad); }
.b-active { background: var(--ok-bg); color: var(--ok); }
.b-suspended, .b-expired { background: var(--bad-bg); color: var(--bad); }
