/* Gateway panels (admin and merchant portal): one stylesheet, no scripts,
   no external fonts or assets (the Content-Security-Policy allows only
   this origin). Light and dark follow the system. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #eef0f3;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eef2ff;
  --accent-soft-ink: #3730a3;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --info: #1d4ed8;
  --info-soft: #eff6ff;
  --side: #0f172a;
  --side-ink: #cbd5e1;
  --side-muted: #64748b;
  --side-hover: #1e293b;
  --side-on: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .10);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --surface: #121826;
    --surface-2: #161d2d;
    --ink: #e5e7eb;
    --ink-2: #cbd5e1;
    --muted: #94a3b8;
    --line: #243044;
    --line-2: #1c2536;
    --accent: #818cf8;
    --accent-ink: #0b0f17;
    --accent-soft: #1e1b4b;
    --accent-soft-ink: #c7d2fe;
    --ok: #34d399;
    --ok-soft: #052e22;
    --warn: #fbbf24;
    --warn-soft: #2d2205;
    --danger: #f87171;
    --danger-soft: #2f0e0e;
    --info: #93c5fd;
    --info-soft: #0c1d3a;
    --side: #080b12;
    --side-hover: #141b2a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.55 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Shell ---------- */

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

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px 12px;
  background: var(--side); color: var(--side-ink);
  overflow-y: auto;
}
.brand, .bare-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 14px; font-weight: 650; font-size: 15px; color: #fff;
}
.brand:hover { text-decoration: none; }
.brand small, .bare-brand small { display: block; font-weight: 500; font-size: 12px; color: var(--side-muted); }
.logo {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-weight: 700;
  font-size: 13px; letter-spacing: -0.02em;
}
.menu { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.menu a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--side-ink); font-weight: 500;
}
.menu a:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.menu a.on { background: var(--side-hover); color: var(--side-on); box-shadow: inset 3px 0 0 #818cf8; }
.menu-label {
  margin: 14px 10px 4px; font-size: 11px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--side-muted);
}
.ico { width: 18px; height: 18px; flex: none; opacity: .9; }

.me {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 6px 0; border-top: 1px solid #1e293b;
}
.me form { margin: 0; }
.me-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px; border-radius: var(--radius-sm); color: var(--side-ink); }
.me-link:hover, .me-link.on { background: var(--side-hover); text-decoration: none; }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: #334155; color: #fff; font-weight: 600; font-size: 13px;
}
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-text strong { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { color: var(--side-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .ghost { color: var(--side-ink); border-color: #334155; }
.me .ghost:hover { background: var(--side-hover); color: #fff; }

.content { padding: 28px 36px 64px; max-width: 1240px; width: 100%; min-width: 0; }
.pagehead { margin-bottom: 20px; }
h1 { font-size: 22px; line-height: 1.3; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 15px; font-weight: 620; margin: 0 0 12px; }

/* Login, signup, setup: a centered card. */
body.bare { min-height: 100vh; display: grid; place-items: start center; padding: 8vh 16px 40px; }
body.bare .content { max-width: 460px; padding: 0; }
body.bare .bare-brand { color: var(--ink); justify-content: center; padding-bottom: 18px; }
body.bare .bare-brand small { color: var(--muted); }
body.bare .pagehead { text-align: center; }
body.bare .card, body.bare .narrow { max-width: none; }
body.bare form > button[type="submit"]:last-of-type { width: 100%; }

/* ---------- Surfaces ---------- */

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin: 0 0 16px; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > p:first-child { margin-top: 0; }
.narrow { max-width: 520px; }
section.card + table, .card table { box-shadow: none; }
.decide { border-color: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.secret { border-color: var(--warn); background: var(--warn-soft); }

.counters { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
.counter {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); color: var(--muted);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
a.counter:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.counter .sub { display: block; margin-top: 4px; font-size: 12px; }
.counter.alarm { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.counter.alarm strong { color: var(--danger); }
.counter strong { display: block; font-size: 26px; font-weight: 680; color: var(--ink); letter-spacing: -.02em; margin-bottom: 2px; }

dl.grid { display: grid; grid-template-columns: minmax(160px, 220px) 1fr; gap: 10px 20px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; color: var(--ink); }

.hint { color: var(--muted); font-size: 13px; }
pre {
  white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line);
  padding: 12px 14px; border-radius: var(--radius-sm); font: 13px/1.5 var(--mono); margin: 0 0 12px;
}
code {
  font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line-2);
  padding: 1px 6px; border-radius: 6px; word-break: break-all;
}
.codes { columns: 2; padding-left: 18px; }

/* ---------- Tables ---------- */

table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin: 0 0 16px; box-shadow: var(--shadow); overflow: hidden;
}
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
th {
  background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Badges and alerts ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin: 0 0 16px; border: 1px solid; }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert.info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }

/* ---------- Forms ---------- */

label { display: block; margin: 0 0 14px; color: var(--ink-2); font-size: 13px; font-weight: 550; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 9px 12px;
  font: inherit; font-weight: 400; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
input.short { width: 96px; display: inline-block; }
input[type="checkbox"] { width: auto; display: inline-block; margin: 0; accent-color: var(--accent); }
input[type="file"] { padding: 7px; }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; color: var(--ink); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 0 0 14px; padding: 10px 14px 4px; }
legend { color: var(--muted); font-size: 12px; font-weight: 600; padding: 0 6px; }

button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600;
  cursor: pointer; transition: filter .15s, background .15s, transform .05s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.ok { background: var(--ok); color: #fff; }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
button.ghost:hover { background: var(--surface-2); filter: none; }
button.small { padding: 5px 10px; font-size: 12px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 500; }
button.link.danger-link, .danger-link { color: var(--danger); }
@media (prefers-color-scheme: dark) {
  button.ok, button.danger { color: #0b0f17; }
}

form.inline { display: inline; }
form.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
form.row label { margin: 0; display: flex; align-items: center; gap: 8px; }
form.row select, form.row input { width: auto; margin: 0; }
form.row input[type="search"] { flex: 1; min-width: 220px; }
form.stack { display: flex; flex-direction: column; gap: 6px; min-width: 170px; }
form.stack input { margin: 0; }
.card form:last-child, form.card > :last-child { margin-bottom: 0; }
.decide button, .card button + button { margin-left: 6px; }

/* ---------- Small screens: the menu becomes a top bar ---------- */

@media (max-width: 900px) {
  body.app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; }
  .brand { padding: 0 8px 0 0; }
  .brand small { display: none; }
  .menu { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; order: 3; }
  .menu-label { display: none; }
  .menu a { padding: 6px 10px; }
  .menu a.on { box-shadow: inset 0 -2px 0 #818cf8; }
  .me { border-top: 0; padding: 0; margin-left: auto; }
  .me-text { display: none; }
  .content { padding: 20px 16px 48px; }
  dl.grid { grid-template-columns: 1fr; gap: 2px 0; }
  dd { margin-bottom: 8px; }
  table { display: block; overflow-x: auto; }
}
