/* TSD Admin. Plain, dense, readable. One accent colour, no gradients. */
:root {
  --bg: #f5f5f2; --panel: #ffffff; --ink: #1b1d21; --ink-2: #4a4f57; --ink-3: #7a8089;
  --line: #e1e1dc; --line-2: #ececE8; --side: #15171b; --side-ink: #c9ccd2; --side-hi: #ffffff;
  --accent: #2458a6; --accent-bg: #e9f0fa;
  --ok: #1f7a4d; --ok-bg: #e7f4ec; --warn: #a3590b; --warn-bg: #fdf1e2; --bad: #b42318; --bad-bg: #fdecea;
  --muted-bg: #f0f0ec; --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.hidden { display: none !important; }

/* ---------- example-data strip ---------- */
.example-strip { background: #fff4d6; color: #6b4a00; border-bottom: 1px solid #f0dc9e; font-size: 13px; padding: 7px 20px; }
.example-strip b { font-weight: 600; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); }
.side-inner { display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; border-bottom: 1px solid #2a2d33; margin-bottom: 12px; }
.side .brand img { height: 52px; width: auto; }
.side .brand span { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: #8d929b; }
.nav a { display: flex; align-items: center; justify-content: space-between; color: var(--side-ink); padding: 8px 10px; border-radius: 5px; font-size: 14px; }
.nav a:hover { background: #22252b; text-decoration: none; color: var(--side-hi); }
.nav a.active { background: #262a31; color: var(--side-hi); box-shadow: inset 2px 0 0 #5b8fd9; }
.side .foot { margin-top: auto; font-size: 12px; color: #8d929b; padding: 12px 8px 0; border-top: 1px solid #2a2d33; }
.side .foot .who { color: var(--side-ink); word-break: break-all; }
.side .foot button { margin-top: 8px; background: none; border: 1px solid #3a3e46; color: var(--side-ink); border-radius: 5px; padding: 5px 10px; cursor: pointer; }
.side .foot button:hover { border-color: #5b616b; color: #fff; }

.main { min-width: 0; padding: 22px 28px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }

/* ---------- panels and stats ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.panel-head h2 { font-size: 14px; font-weight: 650; margin: 0; display: flex; align-items: center; gap: 9px; }
.panel-head h2 img { width: 24px; height: 24px; object-fit: contain; }
.panel-body { padding: 14px 16px; }

.totals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.totals > div { padding: 14px 16px; border-left: 1px solid var(--line-2); }
.totals > div:first-child { border-left: 0; }
.stat-label { font-size: 12px; color: var(--ink-3); }
.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-note { font-size: 12px; color: var(--ink-3); }

.app-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.app-grid .panel + .panel { margin-top: 0; }
.kv { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 10px; }
.kv .stat-value { font-size: 19px; }
.attn { list-style: none; margin: 14px 0 0; padding: 12px 0 0; border-top: 1px solid var(--line-2); font-size: 13px; }
.attn li { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; color: var(--ink-2); }
.attn li::before { content: ""; flex: 0 0 7px; height: 7px; border-radius: 50%; background: var(--ink-3); transform: translateY(-1px); }
.attn li.warn::before { background: var(--warn); }
.attn .none { color: var(--ink-3); }
.attn .none::before { display: none; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; padding: 2px 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--ink-3); background: var(--muted-bg); }
.tag.example { color: #6b4a00; background: #fff4d6; border-color: #f0dc9e; }
.tag.live { color: var(--ok); background: var(--ok-bg); border-color: #bfe3cd; }
.tag.error { color: var(--bad); background: var(--bad-bg); border-color: #f5c2bd; }

.later { display: flex; flex-wrap: wrap; gap: 8px 24px; font-size: 13px; color: var(--ink-2); }
.later b { font-weight: 600; color: var(--ink); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; color: var(--ink-2); border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.toolbar input[type=search], .toolbar select { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 6px 10px; min-width: 0; }
.toolbar input[type=search] { width: 260px; }
.toolbar .count { margin-left: auto; color: var(--ink-3); font-size: 13px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--ink-3); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafaf8; position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; } th.sortable:hover { color: var(--ink); }
th .arrow { font-size: 10px; margin-left: 3px; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
td .sub { color: var(--ink-3); font-size: 12px; }
.app-chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--ink-2); }
.app-chip img { width: 18px; height: 18px; object-fit: contain; }

.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12.5px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.status.paying::before { background: var(--ok); }
.status.trialing::before { background: var(--accent); }
.status.pastDue { color: var(--bad); font-weight: 600; } .status.pastDue::before { background: var(--bad); }
.status.comped::before { background: #8a6fbf; }
.status.canceled { color: var(--ink-3); } .status.canceled::before { background: #c4c7cc; }
.status.setup::before { background: var(--warn); }
.status.off { color: var(--ink-3); } .status.off::before { background: #c4c7cc; }
.status.none { color: var(--ink-3); } .status.none::before { background: transparent; border: 1px solid #c4c7cc; }

.empty, .loading, .err { padding: 28px 16px; text-align: center; color: var(--ink-3); }
.err { color: var(--bad); }

/* ---------- usage chart ---------- */
.chart { width: 100%; height: 170px; display: block; }
.chart .bar { fill: #9db8e0; } .chart .bar.we { fill: #c3d3ea; }
.chart .line { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.chart .axis { stroke: var(--line); }
.chart text { font-size: 10px; fill: var(--ink-3); font-family: var(--font); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-3); margin: 8px 0 0; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; background: #9db8e0; }
.legend i.ln { height: 2px; background: var(--ink); vertical-align: 3px; }
.usage-cols { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.toplist { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.toplist li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line-2); }
.toplist li:last-child { border-bottom: 0; }
.toplist span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chain { font-size: 13px; }
.chain.ok { color: var(--ok); } .chain.bad { color: var(--bad); font-weight: 600; }
.result-denied { color: var(--bad); font-weight: 600; }
.result-partial { color: var(--warn); }
.mono { font-family: var(--mono); font-size: 12px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--side); }
.login { width: 100%; max-width: 380px; background: var(--panel); border-radius: 8px; padding: 28px 28px 24px; }
.login .logo { display: block; height: 64px; width: auto; margin: 0 auto 6px; }
.login .logo-bg { background: var(--side); border-radius: 6px; padding: 14px 0; margin: -6px -6px 18px; }
.login h1 { font-size: 17px; margin: 0 0 4px; font-weight: 650; }
.login p { margin: 0 0 16px; color: var(--ink-3); font-size: 13px; }
.login label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 12px 0 5px; }
.login input { width: 100%; border: 1px solid #cfd0cb; border-radius: var(--radius); padding: 9px 11px; background: #fff; }
.login input:focus, .toolbar input:focus, .toolbar select:focus { outline: 2px solid #9db8e0; outline-offset: 0; border-color: var(--accent); }
.login input.code { font-family: var(--mono); font-size: 20px; letter-spacing: .3em; text-align: center; }
.login button.primary { width: 100%; margin-top: 18px; background: var(--ink); color: #fff; border: 0; border-radius: var(--radius); padding: 10px; font-weight: 600; cursor: pointer; }
.login button.primary:disabled { opacity: .6; cursor: default; }
.login .msg { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 18px; }
.login .note { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-2); font-size: 12px; color: var(--ink-3); }
.login .demo { background: #fff4d6; color: #6b4a00; border: 1px solid #f0dc9e; border-radius: 5px; padding: 8px 10px; font-size: 12px; margin-bottom: 14px; }
.login code { font-family: var(--mono); font-size: 11.5px; }

/* ---------- phone ---------- */
.topbar { display: none; }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar { display: block; background: var(--side); position: sticky; top: 0; z-index: 5; }
  .topbar .row { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 6px; }
  .topbar img { height: 30px; }
  .topbar button { background: none; border: 1px solid #3a3e46; color: var(--side-ink); border-radius: 5px; padding: 4px 9px; font-size: 12px; }
  .topbar .tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 8px 8px; scrollbar-width: none; }
  .topbar .tabs a { color: var(--side-ink); padding: 6px 10px; border-radius: 5px; white-space: nowrap; font-size: 13px; }
  .topbar .tabs a.active { background: #262a31; color: #fff; }
  .main { padding: 16px 14px 40px; }
  .example-strip { padding: 7px 14px; }
  .totals { grid-template-columns: 1fr 1fr; }
  .totals > div:nth-child(3) { border-left: 0; }
  .totals > div:nth-child(n+3) { border-top: 1px solid var(--line-2); }
  .app-grid, .usage-cols { grid-template-columns: 1fr; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar input[type=search] { width: 100%; order: -1; }
  .toolbar .count { margin-left: 0; width: 100%; }
  /* tables become stacked rows */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { border: 0; padding: 2px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--ink-3); font-size: 12px; text-align: left; flex: 0 0 auto; }
  table.stack td.lead { display: block; text-align: left; font-weight: 600; font-size: 14px; padding-bottom: 4px; }
  table.stack td.lead::before { display: none; }
  table.stack td.lead .sub { font-weight: 400; }
  table.stack td.r { text-align: right; }
}
.login a.primary-link { display: block; text-align: center; margin-top: 18px; background: var(--ink); color: #fff; border-radius: var(--radius); padding: 10px; font-weight: 600; }
.login a.primary-link:hover { text-decoration: none; background: #000; }
.app-grid + .panel { margin-top: 16px; }
.panel.err { margin-bottom: 12px; }
table.stack td > .v .sub { display: block; }
