/* ─────────────────────────────────────────────────────────────────────────────
   maps67 admin console — THE stylesheet.

   One file, because `conventions.md` thumb rule #3 is centralize: every colour, radius, space
   and type step is a token declared once at the top and referenced everywhere below. Changing
   the console's density or palette is an edit to the token block, not a hunt through rules.

   UI rules honoured here (conventions.md §UI/UX):
     #1  native look, no emoji — icons come from src/admin/icons.ts, never inline in a view
     #3  fluid, compact-native typography that adapts to viewport
     #7  icon buttons carry tooltips (title attributes) on destructive actions
     #8  spacing from a single scale, so gutters line up at every breakpoint
     #11 colour-theme switching is always present — light/dark, following the OS by default
     #12 data views are modern: sortable-looking tables with filters, not orthodox dumps
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Tokens ───────────────────────────────────────────────────────────────── */
:root {
  color-scheme: light dark;

  /* Space scale — one geometric run; nothing in this file uses a raw pixel margin. */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  /* Fluid type: compact on a laptop, comfortable on a wide desktop, never jumping at a
     breakpoint. The clamp middle term is viewport-relative, which is what makes it fluid. */
  --text-xs: clamp(11px, 0.68rem + 0.1vw, 12px);
  --text-sm: clamp(12px, 0.75rem + 0.12vw, 13.5px);
  --text-md: clamp(13px, 0.82rem + 0.14vw, 15px);
  --text-lg: clamp(16px, 0.95rem + 0.35vw, 20px);
  --text-xl: clamp(20px, 1.15rem + 0.7vw, 28px);

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

  /* Light palette */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #16191d;
  --text-dim: #5c6570;
  --accent: #1f6feb;
  --accent-contrast: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #e8f5ec;
  --warn: #9a6700;
  --warn-bg: #fdf5e2;
  --danger: #b42318;
  --danger-bg: #fdeceb;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
}

/* Dark palette. Applied by OS preference, and overridable by the explicit toggle below —
   the explicit choice must win in BOTH directions, hence the two selectors. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2430;
    --border: #2b3440;
    --text: #e6edf3;
    --text-dim: #9aa7b4;
    --accent: #4a90ff;
    --accent-contrast: #06101f;
    --ok: #4ac26b;
    --ok-bg: #10261a;
    --warn: #d9a441;
    --warn-bg: #2a2113;
    --danger: #f28b82;
    --danger-bg: #2c1614;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}
:root[data-theme='dark'] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2430;
  --border: #2b3440;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --accent: #4a90ff;
  --accent-contrast: #06101f;
  --ok: #4ac26b;
  --ok-bg: #10261a;
  --warn: #d9a441;
  --warn-bg: #2a2113;
  --danger: #f28b82;
  --danger-bg: #2c1614;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
h1 {
  font-size: var(--text-xl);
  margin: 0 0 var(--s-2);
  letter-spacing: -0.01em;
}
h2 {
  font-size: var(--text-lg);
  margin: 0 0 var(--s-3);
  letter-spacing: -0.005em;
}
.muted {
  color: var(--text-dim);
}
.mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.icon {
  flex: none;
  vertical-align: -0.15em;
}

/* ── Shell ────────────────────────────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 650;
  font-size: var(--text-lg);
}
.brand small {
  display: block;
  font-weight: 400;
  font-size: var(--text-xs);
  color: var(--text-dim);
}
.nav {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.nav a {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--text-sm);
}
.nav a:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.nav a[aria-current='page'] {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--accent);
}
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.main {
  padding: var(--s-6) var(--s-6) var(--s-7);
  max-width: 1400px;
}
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-5);
  flex-wrap: wrap;
}

/* ── Cards & metrics ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s-5);
  margin-bottom: var(--s-5);
}
.card-tight {
  padding: var(--s-4);
}
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-4);
  box-shadow: var(--shadow);
}
.metric .label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.metric .value {
  font-size: var(--text-xl);
  font-weight: 650;
  margin-top: var(--s-1);
  font-variant-numeric: tabular-nums;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
th,
td {
  text-align: left;
  padding: var(--s-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
  white-space: nowrap;
}
tbody tr:hover {
  background: var(--surface-2);
}
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.empty {
  padding: var(--s-6);
  text-align: center;
  color: var(--text-dim);
}

/* ── Pills ────────────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px var(--s-2);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.pill-warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.pill-danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.pill-neutral {
  background: var(--surface-2);
  color: var(--text-dim);
  border-color: var(--border);
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  margin-bottom: var(--s-4);
}
label {
  font-size: var(--text-sm);
  font-weight: 550;
}
.hint {
  font-size: var(--text-xs);
  color: var(--text-dim);
}
input,
select,
textarea {
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-4);
}

button,
.btn {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover,
.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}
.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}
.btn-danger:hover {
  background: var(--danger-bg);
}
/* Icon-only buttons carry a title, so the desktop tooltip IS the label (UI rule #7). */
.btn-icon {
  padding: var(--s-2);
}
.actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  align-items: center;
}
form.inline {
  display: inline;
}

/* ── Notices ──────────────────────────────────────────────────────────────── */
.notice {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-4);
  border-radius: var(--radius);
  margin-bottom: var(--s-5);
  border: 1px solid;
  align-items: flex-start;
}
.notice-ok {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
}
.notice-warn {
  background: var(--warn-bg);
  border-color: var(--warn);
  color: var(--warn);
}
.notice-danger {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}
.notice code {
  display: block;
  margin-top: var(--s-2);
  padding: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  word-break: break-all;
}

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s-5);
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--s-6);
}
.login-card .brand {
  justify-content: center;
  margin-bottom: var(--s-5);
}
/* Motion (UI rule #10): a single, tasteful entrance — and none at all for anyone who has asked
   their OS not to animate. */
.login-card {
  animation: rise 260ms cubic-bezier(0.2, 0.7, 0.3, 1);
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .login-card {
    animation: none;
  }
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: var(--s-4);
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .nav {
    flex-direction: row;
  }
  .sidebar-foot {
    margin-top: 0;
    flex-direction: row;
  }
  .main {
    padding: var(--s-4);
  }
}
