:root {
  /* Brand palette */
  --navy: #154360;          /* deep desert-night blue */
  --mustard: #FFDB58;       /* saffron / Vegas-marquee gold */
  --navy-deep: #0d2c41;
  --navy-soft: #2a6187;

  --bg: #f7f4ec;            /* warm sand, not cool slate */
  --panel: #ffffff;
  --ink: #12283a;
  --muted: #6b7c8a;
  --line: #e4ddcf;
  --brand: var(--navy); --brand-ink: #ffffff;
  --accent: var(--mustard); --accent-ink: var(--navy);
  --ok: #17784b; --warn: #b8730f; --bad: #c0392b;
  --radius: 10px;
}
* { box-sizing: border-box; }

/* The `hidden` attribute is only display:none in the UA stylesheet, so ANY
   author `display` rule silently beats it. `.modal { display: grid }` therefore
   left the "hidden" overlay covering the viewport and swallowing every click,
   and `.login-wrap { display: grid }` kept the login screen up after sign-in.
   Author-level and !important so hidden always means hidden. */
[hidden] { display: none !important; }

body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin-top: .5rem; min-height: 1.2em; }
.ok { color: var(--ok); }

/* ---- login: dusk over the Mojave, with the Strip glowing behind the mesas ----
   Layered top-to-bottom: near mesas, far mesas, city glow, sun, stars, sky.
   All inline SVG + gradients, so there are no image files to load or cache. */
.login-wrap {
  display: grid; place-items: center; min-height: 100vh; padding: 1rem;
  position: relative; overflow: hidden;
  background:
    /* near mesa ridge */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 240' preserveAspectRatio='none'%3E%3Cpath fill='%230a2335' d='M0,150 L90,120 L150,132 L260,86 L300,84 L360,124 L470,104 L560,140 L660,112 L780,146 L900,118 L1010,150 L1120,120 L1240,152 L1340,128 L1440,156 L1440,240 L0,240 Z'/%3E%3C/svg%3E")
      bottom center / 100% 30vh no-repeat,
    /* far mesa ridge */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 200' preserveAspectRatio='none'%3E%3Cpath fill='%23123a55' d='M0,140 L140,96 L230,112 L340,60 L420,62 L520,110 L640,78 L760,118 L880,84 L1000,122 L1130,90 L1260,124 L1360,100 L1440,126 L1440,200 L0,200 Z'/%3E%3C/svg%3E")
      bottom center / 100% 40vh no-repeat,
    /* the Strip, glowing just past the ridgeline */
    radial-gradient(60% 18% at 50% 72%, rgba(255,219,88,.30), rgba(255,219,88,0) 70%),
    /* low sun */
    radial-gradient(circle at 50% 70%, #FFDB58 0 5.2vh, rgba(255,219,88,.55) 5.2vh, rgba(255,219,88,0) 24vh),
    /* desert sky */
    linear-gradient(180deg,
      #071b2b 0%, #0d2c41 26%, #154360 48%,
      #2a6187 63%, #8a6a5c 74%, #d99a4e 83%, #FFDB58 100%);
  background-color: var(--navy-deep);
}
/* a scatter of stars, kept up in the dark half only */
.login-wrap::before {
  content: ''; position: absolute; inset: 0 0 45% 0; pointer-events: none;
  background-image:
    radial-gradient(1.6px 1.6px at 12% 22%, rgba(255,255,255,.85), transparent),
    radial-gradient(1.3px 1.3px at 78% 14%, rgba(255,255,255,.7), transparent),
    radial-gradient(1.5px 1.5px at 34% 9%, rgba(255,219,88,.8), transparent),
    radial-gradient(1.2px 1.2px at 62% 31%, rgba(255,255,255,.6), transparent),
    radial-gradient(1.4px 1.4px at 89% 38%, rgba(255,255,255,.55), transparent),
    radial-gradient(1.2px 1.2px at 22% 41%, rgba(255,255,255,.5), transparent),
    radial-gradient(1.5px 1.5px at 51% 18%, rgba(255,255,255,.75), transparent);
}
.login-card {
  position: relative; z-index: 1;
  background: rgba(10, 32, 49, .72);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  backdrop-filter: blur(14px) saturate(120%);
  border: 1px solid rgba(255, 219, 88, .28);
  color: #eaf1f6;
  padding: 2rem; border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.05) inset;
  width: min(380px, 100%);
}
.login-card h1 {
  color: var(--mustard); letter-spacing: -.02em;
  text-shadow: 0 0 22px rgba(255,219,88,.35);
}
.login-card .muted { color: #a9bdcc; }
.login-card label { display: block; margin: 1rem 0 0; font-weight: 600; font-size: .85rem; color: #d7e4ec; }
.login-card input {
  margin-top: .35rem; background: rgba(255,255,255,.07);
  border-color: rgba(255,255,255,.18); color: #f2f7fa;
}
.login-card input::placeholder { color: #8aa2b4; }
.login-card input:focus {
  border-color: var(--mustard);
  outline: 2px solid rgba(255,219,88,.35);
  background: rgba(255,255,255,.12);
}
/* `button.primary` is declared later with equal specificity, so it would win
   and render this navy-on-navy. Match on .primary too so gold stays gold. */
.login-card button,
.login-card button.primary {
  margin-top: 1.25rem; width: 100%;
  background: var(--mustard); color: var(--navy); border-color: var(--mustard);
  font-weight: 700; letter-spacing: .01em;
}
.login-card button:hover,
.login-card button.primary:hover { filter: brightness(1.06); background: var(--mustard); }
.login-card .error { color: #ffb4a8; }

@media (prefers-reduced-motion: no-preference) {
  .login-card { animation: rise .45s ease-out both; }
  @keyframes rise { from { opacity: 0; transform: translateY(10px); } }
}

/* ---- chrome ---- */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--navy);
  border-bottom: 3px solid var(--mustard);
  padding: .6rem 1rem; position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 14px rgba(13,44,65,.25);
}
.brand {
  font-weight: 800; letter-spacing: -.01em; color: var(--mustard);
  text-shadow: 0 0 16px rgba(255,219,88,.3);
}
#tabs { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
#tabs button {
  background: none; border: 0; padding: .45rem .75rem; border-radius: 7px;
  cursor: pointer; color: #b9cfdd; font-weight: 600; font-size: .88rem;
}
#tabs button:hover { background: rgba(255,255,255,.1); color: #fff; }
#tabs button.active { background: var(--mustard); color: var(--accent-ink); }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.topbar-right .muted { color: #b9cfdd; }
.topbar #logout { color: #b9cfdd; }
.topbar #logout:hover { background: rgba(255,255,255,.1); color: #fff; }
main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }

/* ---- controls ---- */
input, select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; color: inherit; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea { min-height: 120px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
button {
  padding: .5rem .85rem; border-radius: 7px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font: inherit; font-weight: 600;
}
button:hover { background: var(--bg); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.primary:hover { filter: brightness(1.08); }
button.ghost { border-color: transparent; color: var(--muted); font-weight: 500; }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small { padding: .28rem .55rem; font-size: .8rem; }
label.field { display: block; margin-bottom: .75rem; font-weight: 600; font-size: .82rem; }
label.field > input, label.field > select, label.field > textarea { margin-top: .3rem; font-weight: 400; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; }
label.inline input { width: auto; }

/* ---- layout ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.split { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; gap: 1rem; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.stat { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--mustard); border-radius: var(--radius); padding: 1rem; }
.stat .n { font-size: 1.9rem; font-weight: 800; line-height: 1; color: var(--navy); }
.stat .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; margin-top: .35rem; }

/* ---- tables ---- */
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); font-size: .87rem; }
table.data th { color: var(--navy); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; background: var(--panel); }
table.data tbody tr:hover { background: var(--bg); }
.scroll { max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }

/* ---- bits ---- */
.tag { display: inline-block; padding: .1rem .45rem; border-radius: 999px; font-size: .72rem; font-weight: 700; color: #fff; }
.pill { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--bg); color: var(--muted); }
.pill.ok { background: #dcfce7; color: #166534; }
.pill.bad { background: #fee2e2; color: #991b1b; }
.pill.warn { background: #fdf0c8; color: #7a5300; }
.pill.gold { background: var(--mustard); color: var(--navy); }
.rule { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: .4rem; margin-bottom: .4rem; align-items: center; }
@media (max-width: 700px) { .rule { grid-template-columns: 1fr 1fr; } }
.tagpick { display: flex; flex-wrap: wrap; gap: .4rem; }
.tagpick label { cursor: pointer; }
.preview-frame { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; width: 100%; height: 480px; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .65rem 1.1rem; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(15,23,42,.25); z-index: 100; font-weight: 600; font-size: .88rem;
}
.toast.bad { background: var(--bad); }
.toast.good { background: var(--ok); }

.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 90; padding: 1rem; }
.modal-card { background: var(--panel); border-radius: var(--radius); padding: 1.25rem; width: min(640px, 100%); max-height: 88vh; overflow: auto; }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
code.tok { background: var(--bg); padding: .08rem .3rem; border-radius: 4px; font-size: .8rem; cursor: pointer; }
