/* ═══════════════════════════════════════════════════════════
   KWN Admin — house style v2, iteration 1 (sandbox)
   Direction: same identity, sharper craft, calmer/premium.
   Orange is scarce: logo, keel, primary actions, focus, eyebrows.
   All components consume the tokens below — nothing hardcoded.
   Fonts self-hosted (CSP: default-src 'self').
   ═══════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'DM Sans';
  src: url('/fonts/dm-sans-var.woff2') format('woff2-variations');
  font-weight: 100 1000;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'DM Mono';
  src: url('/fonts/dm-mono-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'DM Mono';
  src: url('/fonts/dm-mono-500.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

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

:root {
  /* ── palette (identity hues — do not multiply) ── */
  --orange:      #F4600C;
  --orange-deep: #D9530A;
  --black:       #111111;

  /* ── color roles ── */
  --bg:            #E8E6E1;   /* page */
  --surface:       #FAFAF8;   /* panels, tables */
  --surface-raised:#FFFFFF;   /* cards, modals, inputs */
  --ink-strong:    #111111;   /* headings */
  --ink:           #211E1A;   /* body text (warm, softer than pure black) */
  --ink-muted:     #625E57;   /* secondary text */
  --ink-faint:     #999690;   /* labels, placeholders */
  --line:          #D8D5CF;   /* hairline borders */
  --line-soft:     #ECEAE5;   /* row separators */
  --accent:        var(--orange);
  --danger:        #B3372B;
  --success:       #2D6A4F;
  --amber:         #E3A008;

  /* ── type scale ── */
  --sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --fs-xs:   11px;   /* eyebrows, table headers */
  --fs-sm:   12.5px; /* labels, meta */
  --fs-base: 14px;   /* body, controls */
  --fs-md:   16px;   /* emphasized body */
  --fs-lg:   20px;   /* card titles */
  --fs-xl:   26px;   /* page titles */

  /* ── spacing (4px base) ── */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 40px; --sp-8: 48px;

  /* ── radii ── */
  --r-sm: 5px; --r-md: 8px; --r-lg: 12px;

  /* ── elevation ── */
  --shadow-1: 0 1px 2px rgba(30,26,20,0.04), 0 2px 10px rgba(30,26,20,0.05);
  --shadow-2: 0 4px 14px rgba(30,26,20,0.08), 0 14px 40px rgba(30,26,20,0.10);
  --ring: 0 0 0 3px rgba(244,96,12,0.18);
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: var(--fs-base);
  /* 450: variable-font half-step — sturdier than 400 without reading as bold.
     No -webkit-font-smoothing:antialiased — it thins glyphs on macOS. */
  font-weight: 450;
  line-height: 1.55;
}

h1 { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.4px; color: var(--ink-strong); line-height: 1.2; }
strong { font-weight: 600; color: var(--ink-strong); }

/* ── Header / nav — black bar + orange keel (the identity signature) ── */
nav {
  background: var(--black);
  border-bottom: 3px solid var(--accent);
  padding: 15px 32px;
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  flex-wrap: wrap;
}

.logo {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.5px;
  color: var(--accent);
  text-decoration: none;
  margin-right: var(--sp-3);
}
.logo span { color: #FAFAF8; }

nav a:not(.logo) {
  font-size: 13px;
  font-weight: 600;
  color: rgba(250,250,248,0.6);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s;
}
nav a:not(.logo):hover { color: #FAFAF8; }

nav form { margin-left: auto; }
nav button {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  color: rgba(250,250,248,0.6);
  background: none;
  border: 1px solid #3A3A3A;
  padding: 7px 16px;
  border-radius: var(--r-sm);
  cursor: pointer;
  width: auto;
  margin: 0;
  transition: color 0.15s, border-color 0.15s;
}
nav button:hover { color: #FAFAF8; border-color: #6A6A6A; background: none; }

/* ── Layout ── */
main { padding: var(--sp-7) var(--sp-6) 72px; max-width: 1120px; margin: 0 auto; }
main.narrow { max-width: 600px; margin: 0; }
main > p { color: var(--ink-muted); max-width: 620px; margin-bottom: var(--sp-5); }

/* Page head: eyebrow + title (+ optional action on the right) */
.eyebrow {
  font-family: var(--mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  margin-bottom: var(--sp-2);
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.page-head h1 { margin-bottom: 0; }
main h1 { margin-bottom: var(--sp-2); }
.page-head + p { margin-top: calc(-1 * var(--sp-3)); }

/* ── Auth screens ── */
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp-5); }

.card {
  background: var(--surface-raised);
  border: 1px solid var(--line-soft);
  border-bottom: 3px solid var(--accent);
  border-radius: var(--r-lg);
  padding: var(--sp-6) var(--sp-6) var(--sp-6);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-2);
}
.card h1 { font-size: var(--fs-lg); margin-bottom: var(--sp-2); }
.card > p { color: var(--ink-muted); font-size: 13px; }

.brand {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.3px;
  color: var(--accent);
  margin-bottom: var(--sp-4);
}
.brand span { color: var(--ink-strong); }

/* ── Forms ── */
label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-muted);
  letter-spacing: 0.2px;
  margin-top: var(--sp-4);
}

input:not([type="checkbox"]), select {
  width: 100%;
  font-family: var(--sans);
  font-size: var(--fs-base);
  font-weight: 450;
  padding: 10px 12px;
  margin-top: var(--sp-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:not([type="checkbox"]):focus, select:focus { border-color: var(--accent); box-shadow: var(--ring); }
input::placeholder { color: var(--ink-faint); }

input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; vertical-align: -3px; }

input[name="code"] {
  font-family: var(--mono);
  font-size: 21px;
  letter-spacing: 7px;
  text-align: center;
}

button {
  width: 100%;
  font-family: var(--sans);
  font-size: var(--fs-base);
  font-weight: 600;
  padding: 11px 18px;
  margin-top: var(--sp-4);
  border: none;
  border-radius: var(--r-md);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background 0.15s;
}
button:hover { background: var(--orange-deep); }
button:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
button:disabled:hover { background: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-secondary { background: var(--surface-raised); color: var(--ink-muted); border: 1px solid var(--line); box-shadow: none; }
.btn-secondary:hover { background: var(--surface-raised); color: var(--ink-strong); border-color: var(--ink-faint); }
.btn-secondary:disabled:hover { color: var(--ink-muted); border-color: var(--line); }

.form-panel {
  background: var(--surface-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-5) var(--sp-6);
  max-width: 480px;
  box-shadow: var(--shadow-1);
}

.error { color: var(--danger); font-size: 13px; font-weight: 600; margin-top: var(--sp-3); }

/* ── Links & actions ── */
.link-accent {
  color: var(--ink-strong);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s;
}
.link-accent:hover { text-decoration-color: var(--ink-strong); }

.btn-new {
  display: inline-block;
  background: var(--black);
  color: #FAFAF8;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: var(--r-md);
  text-decoration: none;
  box-shadow: var(--shadow-1);
  transition: background 0.15s;
}
.btn-new:hover { background: #2E2B27; }

/* ── Tables — quiet headers (v2's biggest departure from v1) ── */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
th {
  font-family: var(--mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--ink-faint);
  text-align: left;
  padding: 13px 16px 11px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px;
}
th:first-child { border-top-left-radius: 11px; }
th:last-child { border-top-right-radius: 11px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:last-child td:first-child { border-bottom-left-radius: 11px; }
tbody tr:last-child td:last-child { border-bottom-right-radius: 11px; }
tbody tr:hover td { background: #F4F2ED; }

/* ── Badges — dot + text, no filled pills ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-muted);
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.badge-yes { color: var(--ink); }
.badge-yes::before { background: var(--success); }
.badge-no { color: var(--ink-faint); }
.badge-no::before { background: var(--line); }
.badge-alert { color: var(--danger); }
.badge-alert::before { background: var(--danger); }

/* ── Audit log ── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  margin-bottom: var(--sp-4);
}
.filter-bar input, .filter-bar select { margin-top: 0; width: auto; font-size: 13px; padding: 8px 10px; }
.filter-bar button { margin-top: 0; width: auto; padding: 9px 18px; font-size: 13px; }

td code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  word-break: break-word;
}

/* ── Temp password ── */
.temp-password-box {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 1px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--r-md);
  max-width: 480px;
  margin: var(--sp-4) 0;
  user-select: all;
}

/* ── Page-access matrix — stays dense: 28 rows on a laptop ── */
#matrix { max-width: 920px; }
#matrix th, #matrix td { padding: 7px 12px; }
#matrix thead th { position: sticky; top: 0; z-index: 2; }
#matrix th:nth-child(n+3), #matrix td:nth-child(n+3) { text-align: center; width: 60px; }
#matrix td:first-child {
  font-family: var(--mono);
  color: var(--ink-faint);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  white-space: nowrap;
}
#matrix td:nth-child(2) { font-weight: 600; }
#matrix input[type="checkbox"] { width: 17px; height: 17px; cursor: pointer; }

/* amber = pending, not yet applied (David's ruling 2026-07-11) */
.grant-toggle.pending { outline: 2px solid var(--amber); outline-offset: 2px; }
td:has(.grant-toggle.pending) { background: rgba(227,160,8,0.12); }

.apply-bar {
  display: flex;
  gap: var(--sp-3);
  justify-content: flex-end;
  align-items: center;
  position: sticky;
  bottom: var(--sp-3);
  margin-top: var(--sp-4);
  max-width: 920px;
  background: var(--surface-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-2);
}
.apply-bar button { margin-top: 0; }

/* ── Step-up modal (matrix.js reveals it) ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17,17,17,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: var(--sp-5);
}
.modal-backdrop.hidden { display: none; }
.modal-backdrop .card h1 { font-size: 18px; }

/* ── Utilities (referenced by views/matrix.js — keep) ── */
.hidden { display: none; }
.w-auto { width: auto; }
.inline-block { display: inline-block; }
.mt-16 { margin-top: 16px; }

/* ── Small screens ── */
@media (max-width: 720px) {
  nav { padding: 12px 16px; gap: var(--sp-4); }
  main { padding: var(--sp-5) var(--sp-4) var(--sp-8); }
  th, td { padding: 9px 10px; }
}
