:root {
  color-scheme: light dark;
  --bg: #f2f2f5;
  --surface: #ffffff;
  --ink: #0b0b0f;
  --soft: #5e5e66;
  --line: #e6e6eb;
  --sunken: #f2f2f5;
  --select: #fdf0cc;
  --gold: #f2b21b;
  --on-gold: #0b0b0f;
  --danger: #d93a3a;
  --success: #1f9d55;
  --warn-ink: #8a5300;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0f;
    --surface: #16161c;
    --ink: #f4f4f6;
    --soft: #a2a2ad;
    --line: #2a2a33;
    --sunken: #1e1e25;
    --select: #3a2e10;
    --warn-ink: #f5b95a;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

p, dl, dd, h1 { margin: 0; }

a { color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.soft { color: var(--soft); }

.noscript { padding: 16px; text-align: center; }

/* Layout: the sidebar on the left, the page beside it */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 20px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}

.brand { font-size: 18px; font-weight: 700; }

.side-tag {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--select);
  font-size: 12px;
  font-weight: 700;
}

.side-nav { display: grid; gap: 4px; }

.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--soft);
  font-weight: 600;
  text-decoration: none;
  transition: background-color 150ms ease, color 150ms ease;
}

.side-link svg { flex: none; }

.side-link:hover { background: var(--sunken); color: var(--ink); }

.side-link[aria-current="page"] { background: var(--select); color: var(--ink); }

.side-foot {
  display: grid;
  justify-items: start;
  gap: 8px;
  margin-top: auto;
  padding: 16px 12px 0;
  border-top: 1px solid var(--line);
}

.email {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout { margin: 0; }

.content {
  min-width: 0;
  padding: 24px 32px 48px;
  container-type: inline-size;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 24px;
}

.page-title { display: grid; gap: 4px; min-width: 0; }

.page-head, .page-body { max-width: 1200px; }

@media (max-width: 859px) {
  .layout { display: block; }

  .side {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    height: auto;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-brand { margin-right: auto; padding: 0; }

  .side-foot {
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
    border-top: 0;
  }

  .side-foot .email { display: none; }

  .side-nav {
    display: flex;
    order: 1;
    width: 100%;
    overflow-x: auto;
  }

  .side-link { flex: none; }

  .content { padding: 16px 16px 48px; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.btn:disabled { opacity: 0.5; cursor: default; }

.btn-small { padding: 0 14px; }

.btn-gold { background: var(--gold); color: var(--on-gold); }

.btn-quiet { border-color: var(--line); color: var(--ink); }

.btn-danger { border-color: var(--danger); color: var(--danger); }

.tab { border-color: var(--line); background: var(--surface); }

.tab[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
}

/* Sign-in and open error */
.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}

.auth-card {
  display: grid;
  gap: 12px;
  justify-items: center;
  width: 100%;
  max-width: 420px;
  padding: 24px;
  text-align: center;
}

h1 { font-size: 24px; line-height: 1.2; }

/* Customers */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.tile {
  display: grid;
  align-content: space-between;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.tile:hover { border-color: var(--soft); }

.tile[aria-current="true"] { border-color: var(--ink); background: var(--select); }

.tile-label { color: var(--soft); font-size: 14px; font-weight: 600; }

.tile-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow-x: auto;
}

.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--sunken);
  color: var(--soft);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.table tbody tr:last-child td { border-bottom: 0; }

.cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
}

.who { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }

.who strong { font-weight: 600; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--sunken);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.badge-pro { background: var(--ink); color: var(--surface); }

.badge-plus { background: var(--select); }

.badge-sandbox { border: 1px solid var(--line); background: transparent; color: var(--soft); }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }

.status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-active { color: var(--success); }

.status-not_renewing { color: var(--warn-ink); }

.status-billing_issue { color: var(--danger); }

.more { display: flex; justify-content: center; margin-top: 16px; }

.more:empty { display: none; }

/* Rows become cards whenever the page area is too narrow for six columns */
@container (max-width: 839px) {
  .table thead { display: none; }

  .table, .table tbody, .table tr { display: block; }

  .table tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }

  .table tbody tr:last-child { border-bottom: 0; }

  .table td {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 12px;
    padding: 4px 0;
    border-bottom: 0;
  }

  .table td::before {
    content: attr(data-label);
    color: var(--soft);
    font-weight: 600;
  }
}

/* Cards and claims */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.claim {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.claim-body {
  display: grid;
  gap: 16px;
  min-width: 0;
}

@media (min-width: 720px) {
  .claim { grid-template-columns: 260px minmax(0, 1fr); align-items: start; }
}

.proof-link {
  display: block;
  background: var(--sunken);
  border-radius: 12px;
  overflow: hidden;
}

.proof {
  display: block;
  width: 100%;
  height: 260px;
  max-height: 260px;
  object-fit: contain;
}

.facts {
  display: grid;
  grid-template-columns: minmax(96px, max-content) minmax(0, 1fr);
  gap: 8px 16px;
}

.facts dt { color: var(--soft); }

.facts dd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.stack { display: grid; gap: 8px; }

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.decide-group {
  display: grid;
  gap: 12px;
}

.decide {
  display: grid;
  gap: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.decide-group + .decide-group {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

label { font-weight: 600; font-size: 14px; }

.field {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

textarea.field { min-height: 80px; resize: vertical; }

.field-error { color: var(--danger); font-size: 14px; }

.field-error[hidden] { display: none; }

.chip {
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--sunken);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.meta { color: var(--soft); overflow-wrap: anywhere; }

.ok { color: var(--success); font-weight: 600; }

.warn { color: var(--danger); font-weight: 600; }

.state {
  padding: 24px 0;
  color: var(--soft);
  text-align: center;
}

.state.error { color: var(--danger); }

/* Toast */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-width: 420px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  text-align: center;
}

.toast:empty { display: none; }

/* Sign-in notices rendered by the server */
.notice {
  max-width: 420px;
  margin: 15vh auto 0;
  padding: 24px 16px;
  text-align: center;
}
.notice h1 { margin: 0 0 8px; font-size: 22px; }
.notice p { margin: 0 0 24px; color: var(--soft); }
.notice .button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--on-gold);
  font-weight: 600;
  text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
