/*
 * The admin panel's own stylesheet.
 *
 * Separate from the shop's style.css rather than shared. The shop is a dense
 * data table tuned for scanning prices on a phone; this is a control surface
 * with forms and status cards. Sharing one file would have meant every shop
 * tweak risking a control here, and the shared part (the colour tokens) is
 * twenty lines that are cheaper duplicated than coupled.
 *
 * `[hidden]` is restated at author level on purpose. The user-agent rule
 * `[hidden] { display: none }` loses to ANY author rule that sets a display,
 * regardless of specificity, which is how the shop once shipped a permanently
 * visible empty error banner pinned over the viewport.
 */

/*
 * Theming, in three layers, and the order is the whole mechanism.
 *
 *  1. `:root` carries the COMPLETE light palette. Every colour used anywhere
 *     is defined here, so no token can exist only inside a media query.
 *  2. The dark values are redefined under `prefers-color-scheme: dark`, guarded
 *     so an explicit light choice still wins over the device.
 *  3. The dark values are redefined again under `[data-theme="dark"]`, so the
 *     toggle wins in both directions.
 *
 * `data-theme-default` is stamped by the server from `ui.theme` and read by
 * the inline script in index.html, which resolves it against localStorage and
 * writes `data-theme` before first paint. That is why there is no flash: the
 * decision is made before the document has any pixels.
 */

:root {
  --bg: #f6f7f9;
  /* What the browser chrome is painted; /lib/theme.js reads this token. */
  --theme-color: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #eef1f5;
  --line: #d9dee6;
  --ink: #14181f;
  --muted: #5c6673;
  --accent: #1f5fd0;
  /* The second stop of the brand mark gradient. */
  --accent-2: #63c2f0;
  --ok: #197f37;
  --warn: #97650a;
  --bad: #c02c26;
  --log-bg: #ffffff;
  --log-time: #8791a0;
  --log-scope: #1f5fd0;
  --banner-bg: #fdeceb;
  --banner-ink: #7a1f1a;
  --notice-bg: #eaf3ff;
  --notice-ink: #123a75;
  --on-accent: #ffffff;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --theme-color: #0f1115;
    --panel: #161a21;
    --panel-2: #1c212a;
    --line: #262c37;
    --ink: #e6e8ee;
    --muted: #9aa3b2;
    --accent: #4c8dff;
  --accent-2: #7bd1ff;
    --accent-2: #7bd1ff;
    --ok: #3fb950;
    --warn: #d29922;
    --bad: #f85149;
    --log-bg: #0b0d11;
    --log-time: #5a6472;
    --log-scope: #7bd1ff;
    --banner-bg: #40161a;
    --banner-ink: #ffd9d6;
    --notice-bg: #16283f;
    --notice-ink: #cfe3ff;
    --on-accent: #08101f;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --theme-color: #0f1115;
  --panel: #161a21;
  --panel-2: #1c212a;
  --line: #262c37;
  --ink: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #4c8dff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --log-bg: #0b0d11;
  --log-time: #5a6472;
  --log-scope: #7bd1ff;
  --banner-bg: #40161a;
  --banner-ink: #ffd9d6;
  --notice-bg: #16283f;
  --notice-ink: #cfe3ff;
  --on-accent: #08101f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

[hidden] { display: none !important; }

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

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

/* -- navigation ---------------------------------------------------------- */

.nav {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand .mark {
  width: 12px; height: 12px; border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.nav nav { display: flex; flex-direction: column; gap: 2px; }

.nav a.link,
.nav button.link {
  appearance: none;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 8px 10px;
  text-align: left;
  text-decoration: none;
}

.nav a.link:hover { background: var(--panel-2); color: var(--ink); }
.nav a.link.is-active { background: var(--panel-2); color: var(--ink); font-weight: 600; }

.navfoot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.navfoot button {
  appearance: none; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--muted); cursor: pointer; font: inherit; padding: 6px 10px;
}
.navfoot button:hover { color: var(--ink); }

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

.view { padding: 22px 26px 60px; min-width: 0; }

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.lede { color: var(--muted); margin: 0 0 20px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}

.card h2 { color: var(--muted); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.big { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }

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

.scroll { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 7px 10px; text-align: left; }
th { color: var(--muted); font-size: 11px; letter-spacing: .05em; text-transform: uppercase; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--panel-2); }

.mono { font-family: var(--mono); font-size: 12px; }

/* -- controls ------------------------------------------------------------ */

button.btn {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
}
button.btn:hover:not(:disabled) { border-color: var(--accent); }
button.btn:disabled { opacity: .45; cursor: not-allowed; }
button.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.btn.danger { color: var(--bad); }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.spread { justify-content: space-between; }
.gap { height: 18px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { color: var(--muted); font-size: 12px; }
.field .help { color: var(--muted); font-size: 12px; }
.field input[type="text"],
.field input[type="tel"],
.field input[type="number"],
.field input[type="password"],
.field select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  padding: 6px 8px;
  width: 100%;
  max-width: 460px;
}
/* Declared after the width rule above, which is the mechanism: a checkbox
   inheriting `width: 100%` rendered 135px wide in the shop once already. */
.field input[type="checkbox"] { width: auto; }

/* -- state --------------------------------------------------------------- */

.pill {
  border-radius: 999px;
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

.muted { color: var(--muted); }
.right { text-align: right; }

/* -- logs ---------------------------------------------------------------- */

.logs {
  background: var(--log-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  height: 62vh;
  overflow: auto;
  padding: 10px 12px;
}
.logline { display: flex; gap: 10px; padding: 1px 0; align-items: baseline; }
.logline .t { color: var(--log-time); white-space: nowrap; }
.logline .lv { width: 42px; flex: none; text-transform: uppercase; font-size: 10px; }
.logline .sc { color: var(--log-scope); width: 92px; flex: none; overflow: hidden; text-overflow: ellipsis; }
.logline .msg { overflow-wrap: anywhere; }
.logline.debug .lv { color: var(--log-time); }
.logline.info .lv { color: var(--ok); }
.logline.warn .lv { color: var(--warn); }
.logline.error .lv { color: var(--bad); }

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

.gate { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.gate .box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 360px;
  padding: 26px;
  width: 100%;
}
.gate h1 { margin-bottom: 14px; }

/* -- error banner -------------------------------------------------------- */

.banner {
  background: var(--banner-bg);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  bottom: 16px;
  color: var(--banner-ink);
  display: flex;
  gap: 12px;
  align-items: center;
  left: 50%;
  padding: 10px 14px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(680px, calc(100vw - 32px));
}
.banner button {
  appearance: none; background: none; border: 0; color: inherit;
  cursor: pointer; font-size: 18px; line-height: 1; padding: 0;
}

/* A confirmation is not a failure, so it does not wear the failure colours. */
.banner.is-notice {
  background: var(--notice-bg);
  border-color: var(--accent);
  color: var(--notice-ink);
}

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

.themes { display: flex; gap: 4px; }
.themes button {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  flex: 1;
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
}
.themes button.is-active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* -- narrow -------------------------------------------------------------- */

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; }
  .nav nav { flex-direction: row; flex-wrap: wrap; }
  .view { padding: 16px 14px 60px; }
}
