/* ---------------------------------------------------------------------------
   Panel — design tokens and components.

   Hand-written, no build step. Two rules run through the whole file:

   1. The ACCENT marks the primary action. Semantic colour — amber, blue, green,
      violet, red — means ORDER STATE and nothing else. The accent is never used
      to signal "good", because a customer scanning a list of orders reads
      colour before words.

   2. Dark mode exists from the first line. Retrofitting it after the components
      are written means touching every file, so every colour is a token and the
      dark set is defined immediately below the light one.

   Designed at 390px first. Most orders are placed on a phone, one-handed, by
   someone who has done it a hundred times and wants it to take fifteen seconds.
--------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* surfaces — a neutral with a slight bias toward the accent */
  --bg:      #FAFBFC;
  --panel:   #FFFFFF;
  --sunk:    #F1F4F7;
  --line:    #E2E8EE;
  --line-2:  #EDF1F5;

  /* text */
  --ink:   #121721;
  --ink-2: #48525F;
  --ink-3: #78838F;

  /* one accent, used only for primary actions */
  --accent:       #2563A8;
  --accent-hover: #1D4E85;
  --accent-ink:   #FFFFFF;
  --accent-wash:  #E8F0F9;

  /* semantic — reserved for order state, never decoration */
  --pending:    #9A6B10;  --pending-bg:  #FDF3E2;
  --active:     #15607F;  --active-bg:   #E3F0F6;
  --good:       #1B6E45;  --good-bg:     #E3F2EA;
  --partial:    #6A4B93;  --partial-bg:  #EFEAF8;
  --stop:       #A63A31;  --stop-bg:     #FBEAE8;

  /* spacing */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-12: 48px;

  /* radius */
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px; --r-full: 999px;

  /* type */
  --text-xs: 12px; --text-sm: 13px; --text-base: 15px;
  --text-lg: 18px; --text-xl: 24px; --text-2xl: 30px;

  --shadow-sm: 0 1px 2px rgba(18, 23, 33, .06);
  --shadow-md: 0 1px 3px rgba(18, 23, 33, .08), 0 8px 24px -16px rgba(18, 23, 33, .3);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg:     #0E1116;
    --panel:  #161A21;
    --sunk:   #1C222B;
    --line:   #262D38;
    --line-2: #1F2630;

    --ink:   #E7EBF0;
    --ink-2: #AEB8C4;
    --ink-3: #7B8695;

    --accent:       #5B9BE0;
    --accent-hover: #7EB2EA;
    --accent-ink:   #0E1116;
    --accent-wash:  #17293D;

    --pending: #D7A548;  --pending-bg: #2C2413;
    --active:  #63B3D6;  --active-bg:  #122834;
    --good:    #59C08C;  --good-bg:    #11291E;
    --partial: #A98FD4;  --partial-bg: #221C2F;
    --stop:    #E08078;  --stop-bg:    #2F1A18;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, .5), 0 8px 24px -16px rgba(0, 0, 0, .8);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0E1116; --panel: #161A21; --sunk: #1C222B; --line: #262D38; --line-2: #1F2630;
  --ink: #E7EBF0; --ink-2: #AEB8C4; --ink-3: #7B8695;
  --accent: #5B9BE0; --accent-hover: #7EB2EA; --accent-ink: #0E1116; --accent-wash: #17293D;
  --pending: #D7A548; --pending-bg: #2C2413;
  --active: #63B3D6;  --active-bg: #122834;
  --good: #59C08C;    --good-bg: #11291E;
  --partial: #A98FD4; --partial-bg: #221C2F;
  --stop: #E08078;    --stop-bg: #2F1A18;
}

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

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--text-base)/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 var(--sp-3); line-height: 1.25; font-weight: 650; }
h1 { font-size: var(--text-2xl); letter-spacing: -.02em; }
h2 { font-size: var(--text-xl); letter-spacing: -.01em; }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }
p  { margin: 0 0 var(--sp-3); }

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

/* Figures align: balances, prices and quantities all use tabular numerals. */
.num, td.num, .money, input[type="number"], .table td:has(.money) {
  font-variant-numeric: tabular-nums;
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

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

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 var(--sp-4); }
.wrap-narrow { max-width: 720px; }
.wrap-form { max-width: 460px; }

.shell { display: block; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; gap: var(--sp-6); align-items: start; }
}

.main { min-width: 0; padding: var(--sp-5) 0 var(--sp-12); }

.stack > * + * { margin-top: var(--sp-4); }
.row { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; }
.row-between { display: flex; gap: var(--sp-3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }

@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* --- header -------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex; align-items: center; gap: var(--sp-4);
  height: 60px;
}

.brand {
  font-weight: 700; font-size: var(--text-lg); color: var(--ink);
  letter-spacing: -.02em; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand img { height: 30px; width: auto; display: block; }

.topnav { display: none; gap: var(--sp-4); }
@media (min-width: 900px) { .topnav { display: flex; } }
.topnav a { color: var(--ink-2); font-size: var(--text-sm); font-weight: 500; }
.topnav a:hover, .topnav a[aria-current] { color: var(--ink); text-decoration: none; }

.balance-chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  background: var(--accent-wash); color: var(--accent);
  border-radius: var(--r-full);
  padding: 7px var(--sp-3);
  font-weight: 650; font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  min-height: 36px;
}
.balance-chip:hover { text-decoration: none; }

/* --- sidebar ------------------------------------------------------------- */

.side {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-2);
  margin-top: var(--sp-5);
}
@media (min-width: 900px) { .side { position: sticky; top: 76px; } }

.side-group + .side-group { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--line-2); }
.side-heading {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); font-weight: 650;
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
}

.side a {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  min-height: 44px;                     /* touch target */
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--ink-2); font-size: var(--text-sm); font-weight: 500;
}
.side a:hover { background: var(--sunk); color: var(--ink); text-decoration: none; }
.side a[aria-current="page"] { background: var(--accent-wash); color: var(--accent); font-weight: 650; }

.side-badge {
  background: var(--stop); color: #fff;
  border-radius: var(--r-full);
  font-size: 11px; font-weight: 700; line-height: 1;
  padding: 4px 7px; min-width: 20px; text-align: center;
}

/* On phones the customer nav becomes a horizontal scroller under the header. */
.mobile-nav {
  display: flex; gap: var(--sp-2); overflow-x: auto;
  padding: var(--sp-3) var(--sp-4);
  background: var(--panel); border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.mobile-nav::-webkit-scrollbar { display: none; }
.mobile-nav a {
  white-space: nowrap; padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-full); background: var(--sunk);
  color: var(--ink-2); font-size: var(--text-sm); font-weight: 500;
  min-height: 36px; display: inline-flex; align-items: center;
}
.mobile-nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
@media (min-width: 900px) { .mobile-nav { display: none; } }

/* --- cards and panels ---------------------------------------------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}
.card + .card { margin-top: var(--sp-4); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card-head h2, .card-head h3 { margin: 0; }
.card-tight { padding: var(--sp-4); }

.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--sp-4);
}
.stat-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 650; }
.stat-value { font-size: var(--text-xl); font-weight: 700; margin-top: var(--sp-1); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat-note { font-size: var(--text-sm); color: var(--ink-3); margin-top: var(--sp-1); }

.muted { color: var(--ink-3); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.mono { font-family: var(--mono); font-size: .92em; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

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

/* A word alone is not enough — every pill is paired with a progress figure. */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: var(--text-xs); font-weight: 650; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.pill-pending     { background: var(--pending-bg); color: var(--pending); }
.pill-processing,
.pill-in_progress { background: var(--active-bg);  color: var(--active); }
.pill-completed   { background: var(--good-bg);    color: var(--good); }
.pill-partial     { background: var(--partial-bg); color: var(--partial); }
.pill-canceled,
.pill-failed      { background: var(--stop-bg);    color: var(--stop); }
.pill-neutral     { background: var(--sunk);       color: var(--ink-2); }

.progress { height: 4px; background: var(--sunk); border-radius: var(--r-full); overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: var(--active); border-radius: var(--r-full); }
.progress-done > span { background: var(--good); }

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

label, .label {
  display: block; font-size: var(--text-sm); font-weight: 600;
  color: var(--ink-2); margin-bottom: 6px;
}

.field + .field { margin-top: var(--sp-4); }
.hint { font-size: var(--text-sm); color: var(--ink-3); margin-top: 6px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="search"], input[type="date"], input[type="datetime-local"],
input[type="file"], select, textarea {
  width: 100%;
  min-height: 44px;                     /* touch target */
  padding: 10px var(--sp-3);
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font: inherit;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
         linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
         background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
         background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-wash); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--stop); }

.check { display: flex; align-items: flex-start; gap: var(--sp-2); font-weight: 500; color: var(--ink); }
.check input { width: 18px; height: 18px; min-height: 0; margin-top: 2px; flex: 0 0 auto; accent-color: var(--accent); }

.error-text { color: var(--stop); font-size: var(--text-sm); margin-top: 6px; font-weight: 500; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-5);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--sunk); color: var(--ink);
  font: 600 var(--text-base)/1 var(--font);
  cursor: pointer; text-align: center;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; filter: none; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); filter: none; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-danger { background: var(--stop-bg); color: var(--stop); border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 var(--sp-3); font-size: var(--text-sm); }

/* The submit button states the amount, so there is no surprise after the tap. */
.btn-amount { flex-direction: column; gap: 2px; padding-top: 6px; padding-bottom: 6px; min-height: 52px; }
.btn-amount small { font-weight: 500; opacity: .85; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }

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

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--sp-5)); padding: 0 var(--sp-5); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
  text-align: left; font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-3); font-weight: 650;
  padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: var(--sp-3); border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:hover { background: var(--sunk); }
.table tbody tr:last-child td { border-bottom: 0; }

/* Whole rows are tappable, not a small link inside them. */
.table tr[data-href] { cursor: pointer; }

/* --- alerts -------------------------------------------------------------- */

.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--text-sm); font-weight: 500;
  border: 1px solid transparent;
}
.alert + .alert { margin-top: var(--sp-2); }
.alert-success { background: var(--good-bg);    color: var(--good); }
.alert-error   { background: var(--stop-bg);    color: var(--stop); }
.alert-warning { background: var(--pending-bg); color: var(--pending); }
.alert-info    { background: var(--active-bg);  color: var(--active); }

.flash-stack { margin-bottom: var(--sp-4); }

.impersonation-bar {
  background: var(--pending); color: #fff;
  padding: var(--sp-2) var(--sp-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  font-size: var(--text-sm); font-weight: 600; flex-wrap: wrap;
}
.impersonation-bar .btn { background: rgba(255,255,255,.2); color: #fff; min-height: 32px; }

/* --- empty states -------------------------------------------------------- */

.empty { text-align: center; padding: var(--sp-12) var(--sp-4); color: var(--ink-3); }
.empty h3 { color: var(--ink); }
.empty p { max-width: 34ch; margin-left: auto; margin-right: auto; }

/* --- service picker (search-first) -------------------------------------- */

/* Thousands of services cannot go in a <select>. This filters as you type. */
.picker { position: relative; }
.picker-results {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 340px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-md);
}
.picker-results[hidden] { display: none; }
.picker-group {
  padding: var(--sp-2) var(--sp-3); font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3);
  font-weight: 650; background: var(--sunk); position: sticky; top: 0;
}
.picker-option {
  display: block; width: 100%; text-align: left;
  padding: var(--sp-3); border: 0; background: none; cursor: pointer;
  border-bottom: 1px solid var(--line-2); color: var(--ink); font: inherit;
  min-height: 44px;
}
.picker-option:hover, .picker-option[aria-selected="true"] { background: var(--accent-wash); }
.picker-option .po-name { font-weight: 600; font-size: var(--text-sm); }
.picker-option .po-meta { font-size: var(--text-xs); color: var(--ink-3); margin-top: 2px; font-variant-numeric: tabular-nums; }

.selected-service {
  background: var(--sunk); border-radius: var(--r-md);
  padding: var(--sp-3); font-size: var(--text-sm);
}

/* --- pagination ---------------------------------------------------------- */

.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-top: var(--sp-4); flex-wrap: wrap; }
.pager .muted { font-size: var(--text-sm); }

/* --- filters ------------------------------------------------------------- */

.filters { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; min-width: 140px; flex: 1 1 140px; }
.filters .field + .field { margin-top: 0; }

.tabs { display: flex; gap: var(--sp-1); overflow-x: auto; padding-bottom: var(--sp-1); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-full);
  font-size: var(--text-sm); font-weight: 600; color: var(--ink-2);
  background: var(--sunk); white-space: nowrap;
  min-height: 36px; display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { text-decoration: none; color: var(--ink); }
.tab[aria-current] { background: var(--accent); color: var(--accent-ink); }
.tab-count { font-size: 11px; opacity: .8; font-variant-numeric: tabular-nums; }

/* --- public / marketing -------------------------------------------------- */

/* No gradient heroes, no glassmorphism, no emoji as icons.
   This holds people's money; it should look like it. */
.hero { padding: var(--sp-12) 0; }
.hero h1 { font-size: clamp(28px, 6vw, 44px); max-width: 18ch; }
.hero p.lede { font-size: var(--text-lg); color: var(--ink-2); max-width: 52ch; }

.pricing-row { display: flex; align-items: baseline; gap: var(--sp-2); }
.price { font-size: var(--text-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.price-unit { font-size: var(--text-xs); color: var(--ink-3); }

.category-card { display: block; color: inherit; }
.category-card:hover { text-decoration: none; border-color: var(--accent); }

.prose { max-width: 68ch; }
.prose h2 { margin-top: var(--sp-8); }
.prose img { max-width: 100%; height: auto; border-radius: var(--r-md); }
.prose ul, .prose ol { padding-left: 1.25em; }
.prose li + li { margin-top: var(--sp-1); }
.prose code { background: var(--sunk); padding: 2px 5px; border-radius: var(--r-sm); font-family: var(--mono); font-size: .9em; }
.prose pre { background: var(--sunk); padding: var(--sp-4); border-radius: var(--r-md); overflow-x: auto; }
.prose pre code { background: none; padding: 0; }

.footer { border-top: 1px solid var(--line); padding: var(--sp-8) 0; margin-top: var(--sp-12); color: var(--ink-3); font-size: var(--text-sm); }
.footer a { color: var(--ink-2); }

/* --- admin --------------------------------------------------------------- */

.admin-body { background: var(--sunk); }
.admin-topbar { background: var(--panel); border-bottom: 1px solid var(--line); }
.admin-badge { font-size: var(--text-xs); background: var(--pending-bg); color: var(--pending); padding: 3px 8px; border-radius: var(--r-full); font-weight: 650; }

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: var(--sp-2) var(--sp-4); font-size: var(--text-sm); }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 var(--sp-4) var(--sp-5); border-left: 2px solid var(--line); }
.timeline li:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.health-ok   { color: var(--good); font-weight: 650; }
.health-warn { color: var(--pending); font-weight: 650; }
.health-bad  { color: var(--stop); font-weight: 650; }

/* --- misc ---------------------------------------------------------------- */

.copy-row { display: flex; gap: var(--sp-2); align-items: stretch; }
.copy-row input { font-family: var(--mono); font-size: var(--text-sm); }

.banner-promo {
  background: var(--accent-wash); color: var(--accent);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
  font-weight: 600; font-size: var(--text-sm);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
}

hr { border: 0; border-top: 1px solid var(--line); margin: var(--sp-5) 0; }

[hidden] { display: none !important; }

@media print {
  .topbar, .side, .mobile-nav, .footer, .btn, .flash-stack { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}
