/*
 * OpsImprove control plane: sign-up, account and the admin dashboard.
 * Black and white, pill buttons and Opsi the bear, like the app: docs/DESIGN.md and web/src/styles/tokens.css.
 */
:root {
  color-scheme: light;
  --brand-blue: #0A0A0A;
  --brand-navy: #0A0A0A;
  --brand-ice: #F3F3F3;
  --bg-chrome: #F3F3F3;
  --bg-sidebar: #F3F3F3;
  --bg-pane: #FFFFFF;
  --bg-hover: #0A0A0A0F;
  --bg-subtle: #0A0A0A08;
  --text-1: #0A0A0A;
  --text-2: #525252;
  --text-3: #636363;
  --border-1: #858585;
  --border-2: #E3E3E3;
  --border-3: #EDEDED;
  --primary: #0A0A0A;
  --primary-hover: #2E2E2E;
  --on-primary: #FFFFFF;
  --primary-soft: #0A0A0A0F;
  --primary-text: #0A0A0A;
  --disabled-bg: #0A0A0A1A;
  --focus-ring: 0 0 0 3px #0A0A0A33;
  --success: #1E9E62; --success-bg: #1E9E621F; --success-text: #0F6B3A;
  --warn: #C77A0A; --warn-bg: #E0920F24; --warn-text: #8A5200;
  --danger: #D12F3B; --danger-hover: #B3212D; --danger-bg: #D12F3B14; --danger-text: #B3212D;
  --track: #0A0A0A14;
  --shadow-card: none;
  --shadow-modal: #0A0A0A33 0px 30px 60px -20px, #0A0A0A14 0px 8px 16px -8px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  --display: "Inter Tight", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --tap: 44px;
}
@media (min-width: 760px) { :root { --tap: 40px; } }
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --brand-blue: #FAFAFA; --brand-navy: #161616; --brand-ice: #161616;
    --bg-chrome: #0A0A0A; --bg-sidebar: #161616; --bg-pane: #161616;
    --bg-hover: #FAFAFA14; --bg-subtle: #FAFAFA0A;
    --text-1: #FAFAFA; --text-2: #B3B3B3; --text-3: #9E9E9E;
    --border-1: #7A7A7A; --border-2: #FAFAFA24; --border-3: #FAFAFA14;
    --primary: #FAFAFA; --primary-hover: #D6D6D6; --on-primary: #0A0A0A;
    --primary-soft: #FAFAFA1F; --primary-text: #FAFAFA; --disabled-bg: #FAFAFA1F;
    --focus-ring: 0 0 0 3px #FAFAFA40;
    --success: #2DB877; --success-bg: #2DB87724; --success-text: #6FE0A8;
    --warn: #E0920F; --warn-bg: #E0920F24; --warn-text: #F2B95E;
    --danger: #EF5661; --danger-hover: #F37780; --danger-bg: #EF566124; --danger-text: #FF9299;
    --track: #FAFAFA1F;
    --shadow-card: none;
    --shadow-modal: #000000B8 0 24px 48px -12px, #FAFAFA24 0 0 0 1px;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg-chrome); color: var(--text-1);
  font: 400 14px/20px var(--font); -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-family: var(--display); font-size: 28px; line-height: 32px; font-weight: 800; letter-spacing: -0.035em; text-wrap: balance; }
h2 { font-size: 17px; line-height: 24px; font-weight: 600; }
h3 { font-size: 14px; line-height: 20px; font-weight: 600; }
a { color: var(--primary-text); text-underline-offset: 2px; }
.muted { color: var(--text-2); }
.hint { color: var(--text-3); font-size: 13px; line-height: 18px; }
.mono { font-family: var(--mono); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- brand ---------- */
.lockup { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.wordmark { font-family: var(--display); font-weight: 800; font-size: 20px; letter-spacing: -0.03em; line-height: 1; color: var(--text-1); }
.wordmark--on-brand { color: #FFFFFF; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 16px;
  border: 1px solid transparent; border-radius: 9999px; background: var(--primary); color: var(--on-primary);
  font: 600 14px/20px var(--font); cursor: pointer; text-decoration: none; transition: background 120ms; white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); }
.btn[disabled], .btn[aria-disabled="true"] { background: var(--disabled-bg); color: var(--text-3); cursor: not-allowed; }
.btn--secondary { background: var(--bg-pane); color: var(--text-1); border-color: var(--border-1); }
.btn--secondary:hover { background: var(--bg-hover); }
.btn--quiet { background: transparent; color: var(--primary-text); padding: 0 10px; }
.btn--quiet:hover { background: var(--primary-soft); }
.btn--danger { background: var(--bg-pane); color: var(--danger-text); border-color: var(--danger); }
.btn--danger:hover { background: var(--danger-bg); }
.btn--danger-solid { background: #D12F3B; color: #FFFFFF; }
.btn--danger-solid:hover { background: #B3212D; }
.btn--block { width: 100%; }
.btn--small { min-height: 32px; padding: 0 12px; font-size: 13px; }

.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 600; font-size: 14px; }
.input, select.input {
  width: 100%; min-height: var(--tap); padding: 0 12px; border: 1px solid var(--border-1); border-radius: 8px;
  background: var(--bg-pane); color: var(--text-1); font: 400 16px/22px var(--font);
}
@media (min-width: 760px) { .input, select.input { font-size: 14px; } }
.input:focus { outline: 2px solid var(--primary); outline-offset: 0; box-shadow: var(--focus-ring); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.addr { display: flex; align-items: stretch; border: 1px solid var(--border-1); border-radius: 8px; background: var(--bg-pane); overflow: hidden; }
.addr:focus-within { outline: 2px solid var(--primary); box-shadow: var(--focus-ring); }
.addr .input { border: 0; border-radius: 0; min-width: 0; flex: 1; }
.addr .input:focus { outline: none; box-shadow: none; }
.addr__suffix { display: flex; align-items: center; padding: 0 12px; background: var(--bg-sidebar); color: var(--text-2); border-left: 1px solid var(--border-2); font-size: 14px; white-space: nowrap; }
.status-line { display: flex; align-items: center; gap: 6px; min-height: 20px; font-size: 13px; color: var(--text-3); }
.status-line[data-state="ok"] { color: var(--success-text); }
.status-line[data-state="bad"] { color: var(--danger-text); }
.status-line svg { flex: none; }

.card { background: var(--bg-pane); border-radius: 16px; box-shadow: var(--shadow-card); padding: 16px; }
@media (min-width: 760px) { .card { padding: 20px; } }
.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; line-height: 18px; }
.notice--danger { background: var(--danger-bg); color: var(--danger-text); }
.notice--info { background: var(--primary-soft); color: var(--text-1); }
.stack { display: grid; gap: 16px; align-content: start; }
.stack-sm { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- sign-in ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-columns: 1fr; }
.auth__brand { display: none; }
.auth__main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 20px; }
.auth__box { width: 100%; max-width: 380px; display: grid; gap: 20px; }
.auth__box h1 { font-size: 26px; line-height: 32px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border-2); }
@media (min-width: 960px) {
  .auth { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
  .auth__brand {
    display: flex; flex-direction: column; justify-content: space-between; padding: 40px 48px;
    background: #0A0A0A; color: #FAFAFA;
  }
  .auth__brand h2 { font-family: var(--display); font-size: 40px; line-height: 42px; font-weight: 800; letter-spacing: -0.04em; max-width: 12em; color: #FFFFFF; }
  .auth__brand ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; max-width: 26em; }
  .auth__brand li { display: grid; grid-template-columns: 24px 1fr; gap: 12px; color: #B3B3B3; font-size: 15px; line-height: 22px; }
  .auth__brand li strong { color: #FFFFFF; font-weight: 600; display: block; }
  .auth__brand li svg { margin-top: 2px; color: #FFFFFF; }
  .auth__brand small { color: #9E9E9E; font-size: 13px; }
  .auth__main .lockup--mobile { display: none; }
}

/* ---------- page shell ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; height: 60px; background: var(--bg-pane); border-bottom: 1px solid var(--border-3); position: sticky; top: 0; z-index: 5; }
.topbar nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.topbar__who { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
@media (max-width: 520px) { .topbar__who { display: none; } }
.page { width: 100%; max-width: 560px; margin: 0 auto; padding: 24px 16px 48px; display: grid; gap: 20px; }
.page--wide { max-width: 1240px; }
.page--mid { max-width: 860px; }
@media (min-width: 760px) { .page { padding: 32px 24px 64px; } }

/* ---------- sign-up wizard ---------- */
.steps { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.steps li { flex: 1; height: 4px; border-radius: 4px; background: var(--track); }
.steps li[data-done="true"] { background: var(--primary); }
.step-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.wizard__actions { display: flex; gap: 12px; flex-direction: column-reverse; }
@media (min-width: 520px) { .wizard__actions { flex-direction: row; justify-content: space-between; } .wizard__actions .btn { min-width: 132px; } }
.plans { display: grid; gap: 12px; border: 0; margin: 0; padding: 0; min-width: 0; }
.plans legend { padding: 0; margin-bottom: 8px; font-weight: 600; }
.plan { position: relative; display: block; cursor: pointer; }
.plan input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.plan__body { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px; border: 1px solid var(--border-1); border-radius: 12px; background: var(--bg-pane); }
.plan input:checked + .plan__body { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); background: var(--primary-soft); }
.plan input:focus-visible + .plan__body { outline: 2px solid var(--primary); outline-offset: 2px; }
.plan__name { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.plan__price { font-weight: 700; font-size: 18px; text-align: right; }
.plan__price small { font-weight: 400; font-size: 13px; color: var(--text-2); }
.plan__facts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--text-2); font-size: 13px; list-style: none; margin: 4px 0 0; padding: 0; }
.plan__tag { grid-column: 1 / -1; color: var(--text-2); font-size: 13px; }
.review { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; margin: 0; }
.review dt { color: var(--text-2); }
.review dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- provisioning ---------- */
.center { text-align: center; justify-items: center; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.94); opacity: 0.75; } }
.progress { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; text-align: left; width: 100%; }
.progress li { display: grid; grid-template-columns: 24px 1fr; gap: 12px; align-items: start; color: var(--text-3); }
.progress li[data-state="done"] { color: var(--text-1); }
.progress li[data-state="now"] { color: var(--text-1); font-weight: 600; }
.progress .dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border-2); display: grid; place-items: center; }
.progress li[data-state="done"] .dot { background: var(--success); border-color: var(--success); color: #fff; }
.progress li[data-state="now"] .dot { border-color: var(--primary); border-top-color: transparent; animation: spin 0.9s linear infinite; }
.progress li[data-state="failed"] .dot { background: var(--danger); border-color: var(--danger); color: #fff; }
.progress li[data-state="failed"] { color: var(--danger-text); font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- pills, meters ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 9999px; font-size: 12px; line-height: 16px; font-weight: 600; background: var(--bg-hover); color: var(--text-2); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill--plain::before { display: none; }
.pill--ok { background: var(--success-bg); color: var(--success-text); }
.pill--warn { background: var(--warn-bg); color: var(--warn-text); }
.pill--bad { background: var(--danger-bg); color: var(--danger-text); }
.pill--info { background: var(--primary-soft); color: var(--primary-text); }
.pills { display: flex; flex-wrap: wrap; gap: 4px; }
.meter { display: grid; gap: 4px; min-width: 110px; }
.meter__bar { height: 6px; border-radius: 6px; background: var(--track); overflow: hidden; }
.meter__fill { display: block; height: 100%; border-radius: 6px; background: var(--primary); min-width: 2px; }
.meter[data-level="near"] .meter__fill { background: var(--warn); }
.meter[data-level="over"] .meter__fill { background: var(--danger); }
.meter__text { font-size: 12px; line-height: 16px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.delta { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-3); white-space: nowrap; }
.delta[data-dir="down"] { color: var(--danger-text); }
.delta[data-dir="up"] { color: var(--success-text); }

/* ---------- admin ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.tile { background: var(--bg-pane); border-radius: 16px; box-shadow: var(--shadow-card); padding: 14px 16px; display: grid; gap: 2px; align-content: start; text-decoration: none; color: inherit; }
a.tile:hover { background: var(--bg-hover); }
.tile[aria-current="true"] { box-shadow: inset 0 0 0 2px var(--primary), var(--shadow-card); }
.tile__label { font-size: 13px; line-height: 18px; color: var(--text-2); }
.tile__value { font-size: 24px; line-height: 30px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tile__sub { font-size: 12px; line-height: 16px; color: var(--text-3); }
.tile__sub[data-tone="bad"] { color: var(--danger-text); }
.tile__sub[data-tone="warn"] { color: var(--warn-text); }
.tile__sub[data-tone="ok"] { color: var(--success-text); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 9999px; border: 1px solid var(--border-2); background: var(--bg-pane); color: var(--text-1); font-size: 13px; font-weight: 600; text-decoration: none; }
.chip:hover { background: var(--bg-hover); }
.chip[aria-current="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.chip .count { font-weight: 400; opacity: 0.8; font-variant-numeric: tabular-nums; }

.table-wrap { background: var(--bg-pane); border-radius: 16px; box-shadow: var(--shadow-card); overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; font-size: 12px; line-height: 16px; font-weight: 600; color: var(--text-2); padding: 12px 12px; border-bottom: 1px solid var(--border-2); white-space: nowrap; background: var(--bg-pane); }
table.grid td { padding: 12px 12px; border-bottom: 1px solid var(--border-3); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.r, table.grid th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid tbody tr:hover { background: var(--bg-subtle); }
.client-cell { display: grid; gap: 2px; min-width: 150px; }
.client-cell .mono { white-space: nowrap; }
.client-cell a { font-weight: 600; color: var(--text-1); text-decoration: none; }
.client-cell a:hover { text-decoration: underline; }
.neg { color: var(--danger-text); }
.empty { padding: 40px 16px; text-align: center; color: var(--text-2); }

/* phones: each client becomes a card */
@media (max-width: 759px) {
  .table-wrap { background: transparent; box-shadow: none; overflow: visible; }
  table.grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr { background: var(--bg-pane); border-radius: 16px; box-shadow: var(--shadow-card); padding: 12px 16px; margin-bottom: 12px; }
  table.grid td { border: 0; padding: 6px 0; display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; text-align: left !important; }
  table.grid td::before { content: attr(data-label); font-size: 12px; color: var(--text-2); font-weight: 600; }
  table.grid td > .pill { justify-self: start; }
  table.grid td.client { grid-template-columns: 1fr; padding-bottom: 10px; border-bottom: 1px solid var(--border-3); margin-bottom: 4px; }
  table.grid td.client::before { display: none; }
  table.grid td:empty, table.grid td[data-empty="true"] { display: none; }
}

.detail-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .detail-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .detail-grid .span { grid-column: 1 / -1; } }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 0; margin: 0; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; padding-left: 16px; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kv .total { font-weight: 700; border-top: 1px solid var(--border-2); padding-top: 8px; color: var(--text-1); }
.signal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.signal-list li { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; font-size: 14px; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; font-size: 13px; }
.log li { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--border-3); }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--text-3); font-size: 12px; }
.log .detail { color: var(--text-2); overflow-wrap: anywhere; }
.crumbs { font-size: 13px; color: var(--text-2); }
.crumbs a { color: var(--text-2); }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(92vw, 440px); background: var(--bg-pane); color: var(--text-1); box-shadow: var(--shadow-modal); }
dialog::backdrop { background: #0A0A0A80; }
dialog form { padding: 20px; display: grid; gap: 16px; }
dialog .row { justify-content: flex-end; }
