/* zora admin panel (backend spec §11.5).
 *
 * Token values are copied from ui/src/app.css (the backend's Docker build
 * context doesn't include ui/), and the email layout in
 * src/mail/templates.rs holds the same copy. Keep the three in step.
 * --danger, --warning and --success are darker than the app's in light mode
 * so small status text meets WCAG AA on white. Status dots aren't text, so
 * --success-dot is a brighter green that still reads as green on white. */

:root {
  color-scheme: light;
  --canvas: #fafafa;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --ink: #171717;
  --body: #4d4d4d;
  --muted: #737373;
  --hairline: #ebebeb;
  --fill-hover: rgba(0, 0, 0, 0.04);
  --fill-selected: rgba(0, 0, 0, 0.07);
  --primary: #171717;
  --primary-hover: #383838;
  --on-primary: #ffffff;
  --accent: #0070f3;
  --link: var(--accent);
  --danger: #d00000;
  --warning: #9a6700;
  --success: #1a7f37;
  --success-dot: #22b55a;
  --shadow-2: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 2px 2px rgba(0, 0, 0, 0.04), 0 8px 16px -4px rgba(0, 0, 0, 0.08);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, monospace;
  --text: 13px;
  --text-meta: 12px;
  --text-header: 15px;
  --text-title: 20px;
  --radius-sm: 6px;
  --radius-md: 12px;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --canvas: #0a0a0a;
    --surface: #171717;
    --surface-raised: #1f1f1f;
    --ink: #ededed;
    --body: #a1a1a1;
    --muted: #8a8a8a;
    --hairline: #2e2e2e;
    --fill-hover: rgba(255, 255, 255, 0.06);
    --fill-selected: rgba(255, 255, 255, 0.1);
    --primary: #ededed;
    --primary-hover: #ffffff;
    --on-primary: #171717;
    --link: color-mix(in srgb, var(--accent) 60%, #fff);
    --danger: #ff6b6b;
    --warning: #f2c230;
    --success: #3ecf6e;
    --success-dot: #3ecf6e;
    --shadow-2: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 2px 2px rgba(0, 0, 0, 0.3), 0 8px 20px -4px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0a0a0a;
  --surface: #171717;
  --surface-raised: #1f1f1f;
  --ink: #ededed;
  --body: #a1a1a1;
  --muted: #8a8a8a;
  --hairline: #2e2e2e;
  --fill-hover: rgba(255, 255, 255, 0.06);
  --fill-selected: rgba(255, 255, 255, 0.1);
  --primary: #ededed;
  --primary-hover: #ffffff;
  --on-primary: #171717;
  --link: color-mix(in srgb, var(--accent) 60%, #fff);
  --danger: #ff6b6b;
  --warning: #f2c230;
  --success: #3ecf6e;
  --success-dot: #3ecf6e;
  --shadow-2: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 2px 2px rgba(0, 0, 0, 0.3), 0 8px 20px -4px rgba(0, 0, 0, 0.5);
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  font-size: var(--text);
  line-height: 1.45;
  color: var(--body);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3 { color: var(--ink); margin: 0; font-weight: 600; }
h1 { font-size: var(--text-title); letter-spacing: -0.01em; }
h2 { font-size: var(--text-header); }
h3 { font-size: var(--text); }

.mono, code, kbd { font-family: var(--font-mono); font-size: 12px; }
.muted { color: var(--muted); }
.ink { color: var(--ink); }
.small { font-size: var(--text-meta); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- layout */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  border-right: 1px solid var(--hairline);
  background: var(--canvas);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px 16px; color: var(--ink); font-weight: 600; font-size: var(--text-header); }
.brand img { width: 22px; height: 22px; border-radius: 6px; }
.badge-dev {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--warning); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px;
}

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: var(--radius-sm);
  color: var(--body); text-decoration: none;
}
.nav svg { flex: none; opacity: 0.8; }
.nav a[aria-current="page"] svg { opacity: 1; }
.nav a:hover { background: var(--fill-hover); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--fill-selected); color: var(--ink); font-weight: 500; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px; }

.main { flex: 1; min-width: 0; padding: 24px 32px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; align-items: center; }
.section { margin-top: 28px; }
.section > h2 { margin-bottom: 10px; }

/* ------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 28px; padding: 0 12px; border-radius: var(--radius-sm);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
  border: 1px solid var(--hairline); background: var(--surface); color: var(--ink);
  transition: background 120ms var(--ease-out);
}
.btn:hover { background: var(--fill-hover); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--body); }
.btn-ghost:hover { color: var(--ink); }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger); filter: brightness(0.92); }
.btn-sm { height: 24px; padding: 0 8px; font-size: var(--text-meta); }
/* One width for a page's actions, fitting the longest label. */
.btn-wide { min-width: 168px; }
/* Page actions and pager buttons share a width, fitting the longest label,
   "Simulate purchase". */
.btn-even { min-width: 164px; }
.inline { display: inline; margin: 0; }
/* Lines a heading's action up with buttons in a table's last cell; after
   .inline, which resets margins. */
.inset { margin-right: 10px; }

/* -------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; border-top: 1px solid var(--hairline); }
table.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left; font-weight: 500; font-size: var(--text-meta); color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--hairline); white-space: nowrap;
}
.list td { padding: 8px 10px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.list tbody tr:hover { background: var(--fill-hover); }
.list td.ink, .list td .ink { color: var(--ink); }
.list th.num, .list th.right { text-align: right; }
.list td.clip { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .empty { color: var(--muted); padding: 24px 10px; text-align: center; }
/* Fixed layout so stacked tables (one per service) line their columns up. */
table.list.aligned { table-layout: fixed; }
.list.aligned col.status { width: 180px; }

.pager { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.pager-top { margin: 0 0 12px; }

/* -------------------------------------------------------------- status */

.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.status-active::before, .status-sent::before, .status-converted::before { background: var(--success-dot); }
.status-deactivated::before, .status-failed::before { background: var(--danger); }
.status-queued::before { background: var(--warning); }
.status-expired::before, .status-released::before { background: var(--muted); }
.status-ok::before { background: var(--success-dot); }
.status-degraded::before { background: var(--warning); }
.status-down::before { background: var(--danger); }

/* --------------------------------------------------------------- forms */

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
/* Filters on the left, the top pager on the right, wrapping when narrow. */
.toolbar { display: flex; gap: 8px 16px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .filters, .toolbar .pager { margin: 0; }
.toolbar .pager { margin-left: auto; }
input[type="text"], input[type="search"], input[type="email"], input[type="number"], input[type="password"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  height: 28px; padding: 0 8px;
}
/* Own arrow with room on the right: the native one sits flush against the
   border. Gradients, as the CSP blocks data: images. */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 28px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
textarea { height: auto; padding: 6px 8px; min-height: 64px; resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 0; border-color: var(--accent); }

.form { display: grid; gap: 14px; max-width: 440px; }
.field { display: grid; gap: 4px; }
.field label { color: var(--ink); font-weight: 500; }
.field .hint { color: var(--muted); font-size: var(--text-meta); }
.field input[type="text"], .field input[type="email"], .field input[type="number"], .field select { width: 100%; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

.notice { padding: 10px 12px; border: 1px solid var(--hairline); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); margin-bottom: 16px; }
.notice-error { border-color: color-mix(in srgb, var(--danger) 40%, var(--hairline)); color: var(--danger); }

/* ---------------------------------------------------------- dashboard */

.periods { display: inline-flex; border: 1px solid var(--hairline); border-radius: var(--radius-sm); overflow: hidden; }
.periods a { padding: 4px 10px; color: var(--body); text-decoration: none; border-left: 1px solid var(--hairline); }
.periods a:first-child { border-left: 0; }
.periods a:hover { background: var(--fill-hover); }
.periods a[aria-current="true"] { background: var(--fill-selected); color: var(--ink); font-weight: 500; }

/* 12 tiles: column counts that divide 12, so every row is full. */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border-top: 1px solid var(--hairline); border-left: 1px solid var(--hairline); }
@media (max-width: 1400px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { padding: 12px 14px; border-right: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); background: var(--surface); }
.stat .label { color: var(--muted); font-size: var(--text-meta); }
.stat .value { color: var(--ink); font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .sub { color: var(--muted); font-size: var(--text-meta); }

/* 6 charts: column counts that divide 6, so every row is full. */
.charts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .charts { grid-template-columns: minmax(0, 1fr); } }
.chart { margin: 0; border: 1px solid var(--hairline); border-radius: var(--radius-md); background: var(--surface); padding: 12px 14px; }
.chart h3 { display: flex; justify-content: space-between; margin-bottom: 8px; }
.chart svg { display: block; width: 100%; height: 120px; color: var(--ink); }
.chart .bar { fill: currentColor; opacity: 0.85; }
.chart .bar:hover { opacity: 1; }
.chart .axis { stroke: var(--hairline); }
.chart-axis { display: flex; justify-content: space-between; margin-top: 4px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- detail */

.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; color: var(--ink); min-width: 0; overflow-wrap: anywhere; }

.key { display: inline-flex; gap: 8px; align-items: center; }
.key details { display: inline; }
.key summary { cursor: pointer; list-style: none; color: var(--ink); }
.key summary::-webkit-details-marker { display: none; }
.key details[open] summary { display: none; }
.notes summary { cursor: pointer; color: var(--muted); width: max-content; }
.notes summary:hover { color: var(--ink); }
.notes[open] summary { margin-bottom: 6px; }
.notes-text h4 { margin: 10px 0 4px; font-size: inherit; font-weight: 600; }
.notes-text h4:first-child { margin-top: 0; }
.notes-text ul { margin: 0; padding-left: 18px; }
.notes-text p { margin: 0 0 4px; }
.key .full { font-family: var(--font-mono); color: var(--ink); letter-spacing: 0.04em; user-select: all; -webkit-user-select: all; }

.columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; }

.preview { width: 100%; height: 640px; border: 1px solid var(--hairline); border-radius: var(--radius-md); background: var(--surface); }
pre.text { white-space: pre-wrap; font-family: var(--font-mono); font-size: 12px; color: var(--ink); background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-md); padding: 16px; margin: 0; }

/* --------------------------------------------------------------- login */

.login { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 16px; padding: 24px; }
.login .theme { width: 120px; }
.login .card { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-md); padding: 28px; display: grid; gap: 16px; }
.login .brand { padding: 0; }
.login .status-card { max-width: 460px; }
.login .site-link { color: var(--muted); }
.login .site-link:hover { color: var(--link); }
.status-card h1 .status::before { width: 10px; height: 10px; }
.status-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--hairline); }
.status-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--hairline); }
.login input[type="password"] { width: 100%; height: 32px; }
.login .btn { width: 100%; height: 32px; }

/* --------------------------------------------------------------- theme */

.theme { display: flex; border: 1px solid var(--hairline); border-radius: var(--radius-sm); overflow: hidden; }
.theme button { flex: 1; border: 0; border-left: 1px solid var(--hairline); background: transparent; color: var(--body); font: inherit; font-size: var(--text-meta); padding: 4px 0; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.theme button svg { display: block; }
.theme button:first-child { border-left: 0; }
.theme button:hover { background: var(--fill-hover); }
.theme button[aria-pressed="true"] { background: var(--fill-selected); color: var(--ink); font-weight: 500; }

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--hairline); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 16px; }
  .columns { grid-template-columns: 1fr; }
}

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

/* ------------------------------------------------------------- api docs */

.doc { max-width: 860px; }
.doc p, .doc ul { margin: 8px 0; }
.doc ul { padding-left: 20px; }
.doc code { font-family: var(--font-mono); font-size: 0.92em; color: var(--ink); }
.doc pre { font-family: var(--font-mono); font-size: var(--text-meta); line-height: 1.5; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-sm); padding: 10px 12px; margin: 8px 0; overflow-x: auto; color: var(--ink); }
.copyable-wrap { position: relative; margin: 8px 0; }
.doc .copyable-wrap pre { margin: 0; padding-right: 72px; }
.copyable-wrap .btn { position: absolute; top: 6px; right: 6px; }
td.doc .copyable-wrap { margin: 0; }
.copy-icon { display: inline-flex; }
.copied .copy-icon { color: var(--success); }
.doc .toc { columns: 2; padding-left: 20px; }
.endpoint { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--hairline); }
.endpoint h3 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: var(--text-header); overflow-wrap: anywhere; }
.endpoint h4 { margin: 14px 0 4px; color: var(--ink); font-size: var(--text-meta); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.method { font-family: var(--font-mono); font-size: var(--text-meta); font-weight: 600; border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; }
.method-get { color: var(--success); }
.method-post { color: var(--accent); }
.auth { font-family: var(--font); font-size: var(--text-meta); font-weight: 400; color: var(--muted); }
