/* =========================================================================================
   Switch Registry admin UI.

   The UVeye internal-tools design language (findmyrancher, pleoralicenses): navy #091f34 text,
   orange #f07828 as the only accent, a light ground edge to edge, surface cards with 14px radius,
   pill inputs and buttons, quiet tables, outlined status pills with a dot.

   Deliberate deviations from findmyrancher's app.css, all for WCAG 2.1 AA:
   - Primary buttons keep the bright orange fill but carry NAVY text (white on #f07828 is 2.8:1).
   - --navy-faint is .64 alpha, not .46 (.46 is 2.9:1 on the surface fill).
   - --warn is #8f5400, not #b26a00 (3.9:1 as small pill text).
   - Inputs use --border-input (3:1 against ground and surface) instead of --border-firm.
   - Focus is a solid navy outline, not only the translucent orange ring.

   Constraints from the CSP (ui/__init__.py): no inline style, and fonts from 'self' only.
   Manrope (display) and Inter Tight (body), the uveye.com typefaces, are vendored under
   vendor/fonts (scripts/vendor_fonts.sh) rather than loaded from Google Fonts like
   findmyrancher does. JetBrains Mono is not vendored: used when installed, else ui-monospace.

   The palette is defined on bare :root, then REDEFINED under prefers-color-scheme and again
   under [data-theme]; a new token must go into ALL THREE blocks.
   ========================================================================================= */

/* Variable fonts: one file per subset covers every weight used here (400-600). */
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("vendor/fonts/manrope-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("vendor/fonts/manrope-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

@font-face {
  font-family: "Inter Tight";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("vendor/fonts/inter-tight-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}

@font-face {
  font-family: "Inter Tight";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("vendor/fonts/inter-tight-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

:root {
  --navy:         #091f34;
  --navy-soft:    rgb(9 31 52 / .72);
  --navy-faint:   rgb(9 31 52 / .64);
  --orange:       #f07828;
  --orange-hi:    #d65f0f;
  --accent-hover: #f68d48;
  --on-accent:    #091f34;
  --ground:       #fbfcfd;
  --surface:      #eff5fa;
  --border:       #d2e3f0;
  --border-firm:  #b9cfe2;
  --border-input: #7590a8;
  --ok:           #1f7a55;
  --warn:         #8f5400;
  --danger:       #b3261e;
  --on-danger:    #ffffff;
  --row-hover:    rgb(9 31 52 / .035);
  --row-selected: rgb(240 120 40 / .10);
  --ring:         rgb(240 120 40 / .28);
  --shadow:       0 1px 2px rgb(9 31 52 / .05), 0 8px 24px -12px rgb(9 31 52 / .18);
  --font-display: Manrope, "Inter Tight", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body:    "Inter Tight", Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme:   light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy:         #eaf1f7;
    --navy-soft:    rgb(234 241 247 / .76);
    --navy-faint:   rgb(234 241 247 / .60);
    --orange:       #ff8c3f;
    --orange-hi:    #ffa463;
    --accent-hover: #ffa463;
    --on-accent:    #020303;
    --ground:       #020303;
    --surface:      #0d1a26;
    --border:       #1c3145;
    --border-firm:  #2a4459;
    --border-input: #557591;
    --ok:           #4cc08c;
    --warn:         #e0a44a;
    --danger:       #f2766b;
    --on-danger:    #020303;
    --row-hover:    rgb(234 241 247 / .04);
    --row-selected: rgb(255 140 63 / .12);
    --ring:         rgb(255 140 63 / .32);
    --shadow:       0 1px 2px rgb(0 0 0 / .4), 0 8px 24px -12px rgb(0 0 0 / .7);
  }
}

:root[data-theme="dark"] {
  --navy:         #eaf1f7;
  --navy-soft:    rgb(234 241 247 / .76);
  --navy-faint:   rgb(234 241 247 / .60);
  --orange:       #ff8c3f;
  --orange-hi:    #ffa463;
  --accent-hover: #ffa463;
  --on-accent:    #020303;
  --ground:       #020303;
  --surface:      #0d1a26;
  --border:       #1c3145;
  --border-firm:  #2a4459;
  --border-input: #557591;
  --ok:           #4cc08c;
  --warn:         #e0a44a;
  --danger:       #f2766b;
  --on-danger:    #020303;
  --row-hover:    rgb(234 241 247 / .04);
  --row-selected: rgb(255 140 63 / .12);
  --ring:         rgb(255 140 63 / .32);
  --shadow:       0 1px 2px rgb(0 0 0 / .4), 0 8px 24px -12px rgb(0 0 0 / .7);
}

/* author display rules (#session, labels, grids) must not defeat the hidden attribute */
[hidden] { display: none !important; }

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

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--navy-soft);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.shell { min-height: 100vh; padding-inline: 20px; }

:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }

/* ---- wordmark ---- */
.mark {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2rem, 6vw, 2.9rem);
  letter-spacing: -0.022em;
  line-height: 1.15;
  color: var(--navy);
  margin: 0;
  text-align: center;
}

.mark .dot { color: var(--orange); font-weight: 500; }
.mark.small { font-size: 1.5rem; text-align: left; white-space: nowrap; }

.tagline {
  margin: 8px 0 0;
  text-align: center;
  color: var(--navy-faint);
  font-size: .9375rem;
}

/* ---- login: centred column, like findmyrancher's stage ---- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  padding-block: clamp(48px, 14vh, 140px) 40px;
}

.login-card { width: 100%; max-width: 26rem; padding: 22px 22px 18px; box-shadow: var(--shadow); }
.stack { display: grid; gap: 14px; }

/* ---- app chrome: one row, wordmark / sections / who, no bar background ---- */
.app { max-width: 82rem; margin: 0 auto; padding-block: 22px 56px; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 28px;
  padding-bottom: 14px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.tabs { display: flex; gap: 4px; flex: 1 1 auto; min-width: 0; }

.tabs button {
  height: auto;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--navy-soft);
  font-size: .9375rem;
  font-weight: 500;
  position: relative;
  white-space: nowrap;
}

.tabs button:hover { color: var(--navy); background: var(--row-hover); border-color: transparent; }

/* Active: navy, semibold (the text cue) plus the orange underline (the accent). */
.tabs button.active { color: var(--navy); font-weight: 600; }
.tabs button.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -15px;
  height: 2px;
  border-radius: 2px;
  background: var(--orange);
}

/* Below this width the who-block can wrap onto a second row: anchor the underline to
   the tab itself so it never floats mid-header. */
@media (max-width: 1260px) {
  .tabs button.active::after { bottom: -1px; }
}

.who {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-left: auto;
  color: var(--navy-faint);
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
}

.who .user { color: var(--navy-soft); overflow-wrap: anywhere; }
.badge.role::before { display: none; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 8px;
}

.card-head h2 { margin: 0; }

h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.3125rem;
  letter-spacing: -0.015em;
  line-height: 1.3;
  color: var(--navy);
  margin: 0 0 14px;
  overflow-wrap: anywhere;
}

/* Section labels inside a card: the uppercase "verdict" style. */
h3 {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--navy-faint);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin: 24px 0 10px;
}

/* ---- notices ---- */
.banner,
.notice {
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: 14px;
  padding: 12px 18px;
  font-size: .875rem;
  color: var(--navy);
  background: var(--surface);
}

#banner { max-width: 40rem; margin: 20px auto 0; }
.app .banner { margin: 0 0 16px; }

.notice.error { margin: 0; border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }

/* ---- forms ---- */
label {
  display: grid;
  gap: 6px;
  font-size: .75rem;
  font-weight: 500;
  color: var(--navy-faint);
  letter-spacing: .04em;
  text-transform: uppercase;
}

label.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: .875rem;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  color: var(--navy);
  cursor: pointer;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px 16px;
  align-items: end;
}

.grid .wide { grid-column: 1 / -1; }
.grid label.check { min-height: 40px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

input, select, button {
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
  color: var(--navy);
}

/* :where() keeps these at element specificity, so state rules (:user-invalid) and
   contextual rules (td select, input.mono) override them without a :not() chain. */
:where(input:not([type="checkbox"], [type="radio"], [type="file"])),
select {
  width: 100%;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border-input);
  border-radius: 999px;
  background: var(--ground);
  font-size: .9375rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}

select { padding-right: 10px; cursor: pointer; }
input::placeholder { color: var(--navy-faint); opacity: 1; }
input.mono { font-family: var(--font-mono); font-size: .8125rem; }

:where(input:not([type="checkbox"], [type="radio"], [type="file"])):focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--orange-hi);
  box-shadow: inset 0 0 0 1px var(--orange-hi), 0 0 0 4px var(--ring);
}

/* After focus on purpose: an invalid value stays red while focused, with a red ring. */
input:user-invalid { border-color: var(--danger); }
input:user-invalid:focus-visible {
  border-color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger), 0 0 0 4px color-mix(in srgb, var(--danger) 22%, transparent);
}

input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--orange-hi); cursor: pointer; }

input[type="file"] {
  width: 100%;
  min-height: 40px;
  padding: 3px 3px 3px 3px;
  border: 1px dashed var(--border-input);
  border-radius: 999px;
  background: var(--ground);
  font-size: .8125rem;
  color: var(--navy-soft);
}

input[type="file"]::file-selector-button {
  height: 32px;
  margin-right: 12px;
  padding: 0 14px;
  border: 1px solid var(--border-input);
  border-radius: 999px;
  background: var(--surface);
  color: var(--navy);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

input[type="file"]:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }

/* ---- buttons: secondary pill by default; submit / .primary is the orange pill ---- */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border-input);
  border-radius: 999px;
  background: var(--ground);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

button:hover { border-color: var(--orange-hi); }

button[type="submit"],
button.primary {
  height: 40px;
  padding: 0 24px;
  border: 0;
  background: var(--orange);
  color: var(--on-accent);
  font-weight: 600;
  letter-spacing: .01em;
}

button[type="submit"]:hover,
button.primary:hover { background: var(--accent-hover); }

button.block { width: 100%; height: 44px; font-size: 1rem; }

button.danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

button.danger:hover { background: color-mix(in srgb, var(--danger) 9%, transparent); border-color: var(--danger); }

button.link {
  height: auto;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--navy-soft);
  font-size: .8125rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

button.link:hover { color: var(--navy); }

button:disabled { opacity: .5; cursor: not-allowed; }
button:disabled:hover { border-color: var(--border-input); }
button[type="submit"]:disabled,
button.primary:disabled { background: var(--orange); }
button.danger:disabled:hover { background: transparent; }

/* ---- tables: quiet, no zebra, no header fill ---- */
.table-wrap { width: 100%; overflow-x: auto; margin-bottom: 4px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}

th {
  font-size: .75rem;
  font-weight: 500;
  color: var(--navy-faint);
  letter-spacing: .04em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

td {
  height: 44px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--navy);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; transition: background .12s ease; }
tbody tr.clickable:hover { background: var(--row-hover); }
tbody tr.selected,
tbody tr.selected:hover { background: var(--row-selected); }
tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--orange); }

/* Controls the page renders INSIDE rows (publish, download, unmap, jig factory select). */
td button { height: 30px; padding: 0 12px; font-size: .8125rem; }
td .actions { flex-wrap: nowrap; gap: 8px; }
td button[type="button"].primary { height: 30px; padding: 0 14px; }
td select { width: auto; height: 32px; min-width: 12rem; font-size: .8125rem; }
#records-body td:first-child { white-space: nowrap; }
.grid + .table-wrap { margin-top: 18px; }
td label.check { font-size: .8125rem; color: var(--navy-soft); }

td.mono, code, .mono { font-family: var(--font-mono); font-size: .8125rem; }
code { padding: 1px 5px; border-radius: 6px; background: color-mix(in srgb, var(--navy) 6%, transparent); color: var(--navy); }

/* Empty state: the dashed findmyrancher "miss" card, inside the table. */
td.empty {
  height: auto;
  padding: 22px;
  text-align: center;
  color: var(--navy-faint);
  border: 1px dashed var(--border-firm);
}

td.error { color: var(--danger); font-size: .8125rem; max-width: 22rem; }

/* ---- status pills: outlined, with a dot in the same colour ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .03em;
  line-height: 1.4;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-firm);
  color: var(--navy-soft);
  white-space: nowrap;
  vertical-align: middle;
}

.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.badge.err { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

/* ---- text helpers ---- */
.muted { color: var(--navy-faint); }
.hint { color: var(--navy-faint); font-size: .8125rem; margin: 6px 0; }
.hint.center { text-align: center; margin: 14px 0 0; }
.error { color: var(--danger); }
.inline { display: inline-flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
}

/* ---- toast: JS sets className to exactly "toast" or "toast err" ---- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(480px, calc(100vw - 40px));
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--navy);
  color: var(--ground);
  font-size: .875rem;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast.err { background: var(--danger); color: var(--on-danger); }

/* ---- small screens ---- */
@media (max-width: 720px) {
  .shell { padding-inline: 14px; }
  .app { padding-top: 14px; }
  .top { gap: 10px; padding-bottom: 0; }
  .who { order: 2; margin-left: 0; width: 100%; }
  /* Sections scroll sideways rather than wrapping into a second ragged row. */
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; margin-inline: -4px; padding-bottom: 8px; }
  .tabs button.active::after { bottom: 0; }
  .card { padding: 16px 14px; border-radius: 12px; }
  .grid { grid-template-columns: 1fr; }
  /* One line per cell: the .table-wrap scrolls instead of rows growing four lines tall. */
  td { white-space: nowrap; }
  td.error { white-space: normal; min-width: 14rem; }
  .toast { left: 14px; right: 14px; bottom: 14px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
