/*
 * Admin dashboard styling.
 *
 * Deliberately plain CSS with no build step and no external requests, so the
 * dashboard works offline and copies across to a hoster as-is. Colours follow
 * the app's calm "Zen Earth" palette; dark mode follows the operating system.
 */

:root {
  color-scheme: light dark;

  --bg: #f6f4ef;
  --surface: #fffdf9;
  --surface-2: #f1ece3;
  --border: #e3dcd1;
  --border-strong: #d3c9b9;
  --text: #2c2924;
  --muted: #6f675c;
  --accent: #8f6535;
  --accent-text: #fffdf9;
  --accent-soft: #f3ebda;
  --positive: #5b744c;
  --positive-soft: #e4ebdd;
  --danger: #9a4632;
  --danger-soft: #f7e7e2;
  --info: #4e6470;
  --info-soft: #e2e9ec;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(44, 41, 36, .06), 0 10px 28px -18px rgba(44, 41, 36, .35);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --surface: #1c1e23;
    --surface-2: #23262c;
    --border: #31353d;
    --border-strong: #414751;
    --text: #eceae4;
    --muted: #9c968b;
    --accent: #c4a06c;
    --accent-text: #201a12;
    --accent-soft: #33291c;
    --positive: #8fa87c;
    --positive-soft: #262f22;
    --danger: #d38a76;
    --danger-soft: #382520;
    --info: #a2b6c0;
    --info-soft: #263036;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -20px rgba(0, 0, 0, .8);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

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

h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .2rem; }
p { margin: 0 0 .6rem; }
p:last-child { margin-bottom: 0; }

code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 12px; top: 12px; z-index: 10;
  background: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.uppercase { text-transform: uppercase; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.brand-mark-large { width: 46px; height: 46px; border-radius: 14px; font-size: 1.2rem; }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: var(--muted); font-weight: 500; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }

.mainnav { display: flex; gap: 4px; margin-right: auto; }
.mainnav a {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
}
.mainnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.mainnav a.is-active { background: var(--accent-soft); color: var(--accent); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 56px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.foot {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px 32px;
  color: var(--muted);
  font-size: .8rem;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.page-head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.eyebrow {
  margin: 0 0 .2rem;
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card.narrow { max-width: 560px; }

.card-head { margin-bottom: 14px; }
.card-head p { margin: 0; }

/* Collapsible card: the summary carries the heading and keeps the browser's
   own disclosure marker, so a section needs no JavaScript to open or close. */
.card.panel { padding: 0; }
.card.panel > summary { padding: 16px 18px; cursor: pointer; }
.card.panel > summary > h2 { display: inline; }
.card.panel > summary > span { display: block; }
.card.panel[open] > summary { border-bottom: 1px solid var(--border); }
.card.panel > .panel-body { padding: 18px; }
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 18px;
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

/* ── Period switcher ─────────────────────────────────────────────────────── */

.periods {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
}
.periods a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 500;
}
.periods a:hover { color: var(--text); text-decoration: none; }
.periods a.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ── KPI tiles ───────────────────────────────────────────────────────────── */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.kpi-label {
  margin: 0 0 .35rem;
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.kpi-value { margin: 0; font-size: 1.55rem; font-weight: 600; letter-spacing: -.02em; }
.kpi-of { color: var(--muted); font-size: 1rem; font-weight: 500; }
.kpi-meta { margin: .2rem 0 0; color: var(--muted); font-size: .82rem; }

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table thead th {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; }
.table .empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.table td .muted.small { display: block; }
.table .strong { display: block; }

/* ── Badges, chips ───────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge-paid { background: var(--positive-soft); color: var(--positive); }
.badge-open { background: var(--info-soft); color: var(--info); }
.badge-failed, .badge-expired, .badge-canceled, .badge-charged_back { background: var(--danger-soft); color: var(--danger); }
.badge-pending, .badge-authorised, .badge-refunded { background: var(--accent-soft); color: var(--accent); }

.chip {
  display: inline-block;
  margin: 0 4px 2px 0;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: .76rem;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  vertical-align: -2px;
  margin-right: 4px;
}

/* ── Facts list ──────────────────────────────────────────────────────────── */

.facts { margin: 0; font-size: .9rem; }
.facts dt {
  margin-top: 12px;
  color: var(--muted);
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.facts dt:first-child { margin-top: 0; }
.facts dd { margin: 2px 0 0; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--surface-2); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */

.alert {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: .9rem;
  border: 1px solid transparent;
}
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-success { background: var(--positive-soft); color: var(--positive); border-color: color-mix(in srgb, var(--positive) 25%, transparent); }

/* ── Charts ──────────────────────────────────────────────────────────────── */

.chart { margin: 0; }
.chart-svg { width: 100%; height: auto; display: block; color: var(--accent); }
.chart-area-fill { fill: currentColor; opacity: .14; }
.chart-area-line { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--surface); stroke: currentColor; stroke-width: 2; }
.chart-grid line { stroke: var(--border); stroke-width: 1; }
.chart-grid-label, .chart-x text {
  fill: var(--muted);
  font-family: var(--font);
  font-size: 11px;
}
.chart-grid-label { text-anchor: end; }
.chart-x text { text-anchor: middle; }

.chart-bars { display: flex; flex-direction: column; gap: 10px; }
.chart-row {
  display: grid;
  grid-template-columns: minmax(90px, 34%) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: .88rem;
}
.chart-row-label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-row-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.chart-row-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  min-width: 3px;
}
.chart-row-value { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.chart-columns {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 140px;
}
.chart-column { flex: 1; display: flex; align-items: flex-end; height: 100%; }
.chart-column-bar {
  width: 100%;
  border-radius: 4px 4px 2px 2px;
  background: var(--accent);
  opacity: .75;
}
.chart-empty {
  padding: 32px 12px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* ── Login ───────────────────────────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 15% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}
.login-card h1 { font-size: 1.2rem; margin: .8rem 0 .1rem; }
.login-lead {
  color: var(--muted);
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 20px;
}
.login-card form { text-align: left; }
.login-hint {
  margin-top: 16px;
  color: var(--muted);
  font-size: .78rem;
  text-align: left;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */

.stack { display: flex; flex-direction: column; gap: 14px; }

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.field { display: block; }
.field-wide { grid-column: 1 / -1; }

.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: .85rem;
  font-weight: 500;
}
.field .hint { color: var(--muted); font-weight: 400; font-size: .78rem; }
.field .req {
  color: var(--accent);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  /* 16px keeps iOS from zooming when the field is focused. */
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; min-height: 76px; font-family: var(--mono); font-size: 14px; }
input.is-invalid, textarea.is-invalid { border-color: var(--danger); background: var(--danger-soft); }

.color-input { display: flex; align-items: center; gap: 8px; }
.color-input input { font-family: var(--mono); font-size: 15px; }
.color-input .swatch { width: 22px; height: 22px; flex: 0 0 auto; margin: 0; }

.toggles { display: flex; flex-direction: column; gap: 10px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

.advanced {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.advanced summary { cursor: pointer; font-size: .88rem; color: var(--muted); }
.advanced[open] summary { margin-bottom: 12px; }

/* ── Wizard ──────────────────────────────────────────────────────────────── */

.wizard { display: flex; flex-direction: column; gap: 16px; }

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.step-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 14px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.step-dot .step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: .8rem;
  font-weight: 600;
}
.step-dot[aria-current="step"] {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--text);
  background: var(--accent-soft);
}
.step-dot[aria-current="step"] .step-number { background: var(--accent); color: var(--accent-text); }
.step-dot.is-done .step-number { background: var(--positive-soft); color: var(--positive); }

.wizard .step { border: 1px solid var(--border); margin: 0; }
.wizard .step legend { padding: 0; }

/* With JavaScript only the active step is shown; without it every step is
   visible and the browser handles the single submit. */
html.js .wizard .step { display: none; }
html.js .wizard .step.is-active { display: block; }
html:not(.js) .step-nav,
html:not(.js) .steps { display: none; }
html:not(.js) .noscript-note { display: block; }
html.js .noscript-note { display: none; }

.wizard-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  padding: 12px 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.wizard-progress { margin-left: auto; color: var(--muted); font-size: .85rem; }
html.js .wizard-progress { order: 2; }
.wizard-footer .btn[type="submit"] { order: 3; }
html:not(.js) .wizard-footer .btn[type="submit"] { order: 1; }

@media (max-width: 640px) {
  .steps { display: none; }
  .wizard-footer .btn { flex: 1; }
}
