/* EMI Locker - the look.
   A shop's ledger and a TV's front light: calm paper, a deep teal-ink frame, and three status lights that mean what
   the light on a TV means - green on, red locked, amber waiting. Phone: bottom tabs and sheets. Desktop: a side
   rail, a dashboard and tables. One stylesheet, no build step. */

:root {
  --ink: #0d2b2e;          /* the frame: side rail, code screens */
  --ink-2: #143a3e;
  --paper: #f2f5f3;
  --surface: #ffffff;
  --line: #dbe4e0;
  --line-2: #eaf0ed;
  --text: #12211f;
  --muted: #5d706b;
  --faint: #8a9b96;
  --go: #0e7c6b;           /* actions; "on" */
  --go-ink: #095a4e;
  --go-soft: #e1f3ee;
  --lock: #cf3f3f;
  --lock-soft: #fbe9e8;
  --wait: #c98511;
  --wait-light: #f2a93b;
  --wait-soft: #fdf1dc;
  --r: 14px;
  --r-s: 10px;
  --shadow: 0 1px 2px rgba(13, 43, 46, .06), 0 8px 24px -12px rgba(13, 43, 46, .18);
  --display: "Bricolage Grotesque", "Hanken Grotesk", system-ui, sans-serif;
  --body: "Hanken Grotesk", system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --rail: 248px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--text); font: 15.5px/1.5 var(--body); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.015em; }
h1 { font-size: clamp(24px, 3.2vw, 32px); font-weight: 700; line-height: 1.12; }
h2 { font-size: 17px; font-weight: 600; }
p { margin: 0; }
svg { display: block; flex: none; }
:focus-visible { outline: 2.5px solid var(--go); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.mono { font-family: var(--mono); letter-spacing: .02em; }
.nowrap { white-space: nowrap; }

/* ---------- frame ---------- */

.shell { min-height: 100dvh; }
.rail { display: none; }
.main { padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 1240px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 18px var(--display); letter-spacing: -.01em; }
.brand .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--go); display: grid; place-items: center; color: #fff; }
.topbar .who { margin-left: auto; font-size: 13.5px; opacity: .75; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
.tabs a { display: grid; justify-items: center; gap: 2px; padding: 7px 2px; border-radius: 10px; font-size: 11.5px; font-weight: 600; color: var(--faint); }
.tabs a.on { color: var(--go-ink); }
.tabs a.plus span.ic { background: var(--go); color: #fff; width: 44px; height: 30px; border-radius: 12px; display: grid; place-items: center; }
.tabs a.plus { color: var(--go-ink); }

.head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin: 6px 0 18px; }
.head .grow { flex: 1 1 240px; min-width: 0; }
.head p { color: var(--muted); margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.back:hover { color: var(--text); }

@media (min-width: 960px) {
  .shell { display: grid; grid-template-columns: var(--rail) 1fr; }
  .topbar, .tabs { display: none; }
  .rail { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100dvh; padding: 22px 14px 16px; background: var(--ink); color: #cfe0dc; }
  .rail .brand { color: #fff; padding: 2px 10px 22px; }
  .rail a.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 15px; color: #b9cdc8; }
  .rail a.nav:hover { background: rgba(255, 255, 255, .06); color: #fff; }
  .rail a.nav.on { background: var(--ink-2); color: #fff; box-shadow: inset 3px 0 0 var(--wait-light); }
  .rail .cta { margin: 14px 4px 10px; }
  .rail .me { margin-top: auto; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, .05); }
  .rail .me b { display: block; color: #fff; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rail .me span { font-size: 12.5px; color: #8fb0a9; }
  .main { padding: 30px 36px 48px; margin: 0; width: 100%; }
}

/* ---------- pieces ---------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.pad { padding: 18px; }
.card > h2 { padding: 16px 18px 0; }
.card.pad > h2 { padding: 0; }
.stack { display: grid; gap: 14px; }
.cols { display: grid; gap: 16px; }
@media (min-width: 960px) { .cols { grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); align-items: start; } .cols.even { grid-template-columns: 1fr 1fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: var(--r-s);
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 600 15px var(--body); cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--line-2); }
.btn:active { transform: translateY(1px); }
.btn.go { background: var(--go); border-color: var(--go); color: #fff; }
.btn.go:hover { background: var(--go-ink); border-color: var(--go-ink); }
.btn.lock { background: var(--lock); border-color: var(--lock); color: #fff; }
.btn.lock:hover { background: #b53232; border-color: #b53232; }
.btn.quiet-lock { color: var(--lock); border-color: #efc9c7; }
.btn.quiet-lock:hover { background: var(--lock-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--line-2); color: var(--text); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; pointer-events: none; }
.btn .spin { width: 16px; height: 16px; border-width: 2px; }

label.f { display: grid; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
label.f small { font-weight: 400; color: var(--faint); }
input, textarea, select { width: 100%; min-height: 46px; padding: 11px 13px; border-radius: var(--r-s); border: 1px solid var(--line); background: #fbfcfb; color: var(--text); font: 500 15.5px var(--body); }
textarea { min-height: 92px; resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--go); box-shadow: 0 0 0 3px rgba(14, 124, 107, .16); background: #fff; }
input.code-in { font: 700 22px var(--mono); letter-spacing: .28em; text-transform: uppercase; text-align: center; }
.grid2 { display: grid; gap: 12px; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.form { display: grid; gap: 14px; }
.err { color: var(--lock); font-size: 14px; font-weight: 600; }

.spin { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid rgba(14, 124, 107, .2); border-top-color: var(--go); animation: spin .7s linear infinite; display: inline-block; }
.btn.go .spin, .btn.lock .spin { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { min-height: 100dvh; display: grid; place-items: center; }
.loading { padding: 48px; display: grid; place-items: center; }

/* The status light: what the light on a TV's front says. */
.led { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.led.ok { background: var(--go); box-shadow: 0 0 0 3px rgba(14, 124, 107, .16); }
.led.bad { background: var(--lock); box-shadow: 0 0 0 3px rgba(207, 63, 63, .16); }
.led.wait { background: var(--wait-light); box-shadow: 0 0 0 3px rgba(242, 169, 59, .22); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.status { display: inline-flex; align-items: center; gap: 8px; padding: 5px 11px 5px 9px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--line-2); color: var(--muted); white-space: nowrap; }
.status.ok { background: var(--go-soft); color: var(--go-ink); }
.status.bad { background: var(--lock-soft); color: #a52e2e; }
.status.wait { background: var(--wait-soft); color: #8a5a06; }

/* ---------- dashboard ---------- */

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); gap: 14px; } }
.stat { text-align: left; padding: 14px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); cursor: pointer; font: inherit; color: inherit; box-shadow: var(--shadow); display: grid; gap: 6px; }
.stat:hover { border-color: #c4d2cd; }
.stat.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink), var(--shadow); }
.stat .k { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.stat .v { font: 700 30px/1 var(--display); letter-spacing: -.02em; }

.tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 260px; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { padding-left: 40px; background: var(--surface); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { min-height: 36px; padding: 0 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font: 600 13.5px var(--body); color: var(--muted); cursor: pointer; }
.pill.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.list { overflow: hidden; }
.thead, .tvrow { display: grid; align-items: center; gap: 12px; padding: 13px 18px; }
.thead { display: none; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); border-bottom: 1px solid var(--line); background: #fafcfb; }
.tvrow { grid-template-columns: 1fr auto; grid-template-areas: "who status" "meta meta"; row-gap: 6px; border-top: 1px solid var(--line-2); }
.tvrow:first-of-type, .thead + .tvrow { border-top: 0; }
.tvrow:hover { background: #f8fbfa; }
.tvrow .who { grid-area: who; min-width: 0; }
.tvrow .who b { display: block; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tvrow .st { grid-area: status; justify-self: end; }
.tvrow .meta { grid-area: meta; display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.tvrow .c { display: none; }
.due.late { color: var(--lock); font-weight: 700; }
.due.soon { color: var(--wait); font-weight: 700; }
@media (min-width: 960px) {
  .thead { display: grid; }
  .thead, .tvrow { grid-template-columns: minmax(180px, 1.6fr) 120px minmax(200px, 1.3fr) 150px 150px var(--extra, 0px); grid-template-areas: none; }
  .tvrow .who, .tvrow .st, .tvrow .meta, .tvrow .c { grid-area: auto; }
  .tvrow .meta { display: none; }
  .tvrow .c { display: block; font-size: 14.5px; }
  .tvrow .st { justify-self: start; }
  .admin .thead, .admin .tvrow { --extra: 160px; }
}
.empty { padding: 44px 20px; text-align: center; display: grid; gap: 12px; justify-items: center; color: var(--muted); }
.empty h2 { color: var(--text); }

/* ---------- one TV ---------- */

.hero { display: grid; gap: 18px; padding: 20px; }
@media (min-width: 560px) { .hero { grid-template-columns: 150px 1fr; align-items: center; } }
/* A small TV: its screen says what the real one shows, its light what the real one's light shows. */
.tvset { width: 150px; justify-self: center; }
.tvset .screen { height: 92px; border-radius: 10px; background: linear-gradient(140deg, #1b4a4f, var(--ink)); border: 5px solid #0a1f21; display: grid; place-items: center; color: #d6ece7; position: relative; overflow: hidden; }
.tvset.bad .screen { background: linear-gradient(140deg, #3a1f22, #170d0e); color: #ffb9b3; }
.tvset.wait .screen { color: var(--wait-light); }
.tvset.off .screen { background: #1a2224; color: #5b6b68; }
.tvset .foot { height: 6px; width: 54px; margin: 5px auto 0; border-radius: 0 0 6px 6px; background: #0a1f21; }
.tvset .screen .led { position: absolute; right: 8px; bottom: 7px; width: 6px; height: 6px; box-shadow: none; }
.hero h1 { font-size: clamp(22px, 2.6vw, 28px); }
.hero .line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.hero .note { margin-top: 8px; color: var(--muted); font-size: 14px; }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 20px 20px; }
.acts .full { grid-column: 1 / -1; }
@media (min-width: 560px) { .acts { grid-template-columns: repeat(3, 1fr); } .acts .full { grid-column: auto; } }

.kv { display: grid; }
.kv > div { display: grid; grid-template-columns: 124px 1fr; gap: 10px; padding: 11px 18px; border-top: 1px solid var(--line-2); font-size: 14.5px; }
.kv > div:first-child { border-top: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
dl { margin: 0; }
.bar { height: 8px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--go); border-radius: 99px; }
.rows > div { display: flex; gap: 12px; align-items: baseline; padding: 11px 18px; border-top: 1px solid var(--line-2); font-size: 14.5px; }
.rows > div:first-child { border-top: 0; }
.rows .t { color: var(--muted); font-size: 13px; flex: none; width: 108px; }
.rows .g { flex: 1; min-width: 0; }
.rows .r { color: var(--muted); font-size: 13px; text-align: right; }

/* The code screen: the same thing the dealer sees on the TV beside them. */
.codescreen { background: var(--ink); color: #fff; border-radius: var(--r); padding: 20px 18px 16px; text-align: center; border: 6px solid #081c1e; position: relative; }
.codescreen .cap { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #8fb0a9; }
.codescreen .digits { font: 700 clamp(40px, 11vw, 58px)/1.15 var(--mono); letter-spacing: .1em; margin: 8px 0 12px; }
.codescreen .meter { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.codescreen .meter i { display: block; height: 100%; background: var(--wait-light); transition: width 1s linear; }
.codescreen .sub { margin-top: 10px; font-size: 13px; color: #a9c4be; }

.steps { display: grid; gap: 12px; counter-reset: s; }
.step { display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start; }
.step::before { counter-increment: s; content: counter(s); width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: #fff; font: 700 14px var(--display); display: grid; place-items: center; }
.step b { display: block; font-size: 15.5px; }
.keys { display: inline-flex; gap: 4px; margin: 6px 0 2px; flex-wrap: wrap; }
.keys kbd { font: 700 12.5px var(--mono); padding: 4px 8px; border-radius: 7px; background: var(--line-2); border: 1px solid var(--line); border-bottom-width: 2px; }
@media (min-width: 960px) { .sticky { position: sticky; top: 24px; } }

/* ---------- sign in ---------- */

.auth { min-height: 100dvh; display: grid; }
.auth .side { display: none; }
.auth .box { display: grid; align-content: center; gap: 22px; padding: 28px 22px; max-width: 440px; width: 100%; margin: 0 auto; }
.auth .box .brand { color: var(--ink); font-size: 20px; }
.auth h1 { font-size: 30px; }
@media (min-width: 960px) {
  .auth { grid-template-columns: minmax(380px, 1fr) 1.1fr; }
  .auth .side { display: grid; align-content: space-between; padding: 44px; background: var(--ink); color: #cfe0dc;
    background-image: radial-gradient(circle at 85% 12%, rgba(242, 169, 59, .16), transparent 42%), radial-gradient(circle at 10% 90%, rgba(14, 124, 107, .5), transparent 46%); }
  .auth .side .brand { color: #fff; }
  .auth .side h2 { font-size: clamp(30px, 3.4vw, 44px); line-height: 1.08; color: #fff; font-weight: 700; max-width: 12ch; }
  .auth .side ul { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 14px; max-width: 38ch; }
  .auth .side li { display: flex; gap: 12px; align-items: flex-start; }
  .auth .side li .led { margin-top: 7px; }
  .auth .box .brand { display: none; }
}

/* ---------- dialogs and toasts ---------- */

.veil { position: fixed; inset: 0; z-index: 50; background: rgba(9, 28, 30, .5); display: grid; align-items: end; animation: fade .15s ease-out; }
.sheet { background: var(--surface); border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 92dvh; overflow: auto; display: grid; gap: 16px; animation: up .2s ease-out; }
.sheet h2 { font-size: 20px; }
.sheet .foot { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; }
@media (min-width: 640px) {
  .veil { align-items: center; justify-items: center; padding: 24px; }
  .sheet { width: min(480px, 100%); border-radius: 18px; padding: 24px; box-shadow: 0 24px 60px -20px rgba(9, 28, 30, .5); }
  .sheet .foot { justify-content: end; grid-auto-columns: auto; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(18px); opacity: 0; } }
#toasts { position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(86px + env(safe-area-inset-bottom)); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 14.5px; box-shadow: var(--shadow); max-width: 520px; animation: up .2s ease-out; }
.toast.bad { background: #8f2626; }
@media (min-width: 960px) { #toasts { left: auto; right: 28px; bottom: 28px; justify-items: end; } }

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

/* Phone: one column in the order a dealer needs it - the TV, its plan, then the rest. */
@media (max-width: 959px) {
  .cols.flat > .stack { display: contents; }
  .acts > :first-child { grid-column: 1 / -1; }
}
@media (max-width: 559px) { .rows .t { width: 86px; } .rows .r { display: none; } }
/* People: one person per row, their state and what can be done with them on the right (under, on a phone). */
.prow { display: grid; gap: 12px; padding: 14px 18px; border-top: 1px solid var(--line-2); }
.prow:first-child { border-top: 0; }
.prow .who { display: grid; gap: 2px; min-width: 0; }
.prow .who b { font-size: 16px; overflow-wrap: anywhere; }
.pacts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (min-width: 760px) { .prow { grid-template-columns: 1fr auto; align-items: center; } .pacts { justify-content: flex-end; } }
/* The keys table (desktop): key, status, used on, customer and TV, [dealer], action. */
@media (min-width: 960px) {
  .list.keys .thead, .list.keys .tvrow { grid-template-columns: 190px 130px 160px minmax(180px, 1fr) var(--extra, 0px) 100px; }
  .list.keys.admin .thead, .list.keys.admin .tvrow { --extra: 170px; }
}
select { appearance: auto; }

/* Password fields: Show / Hide inside the field; a quiet warning under it. */
.pw { position: relative; display: block; }
.pw input { padding-right: 76px; }
.pw .eye { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); min-height: 34px; color: var(--go-ink); }
.caps { color: var(--wait) !important; font-weight: 600 !important; }

/* History: one box per person, the latest doer first. */
.boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.box { text-align: left; display: grid; gap: 10px; align-content: space-between; min-height: 132px; padding: 14px 16px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; font: inherit; color: inherit; }
.box:hover { border-color: #c4d2cd; }
.box.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink), var(--shadow); }
.box .who { display: grid; gap: 2px; }
.box .who b { font: 600 16px var(--display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box .role { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); }
.box .what { font-size: 14.5px; font-weight: 600; }
.box .when { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.box .when i { font-style: normal; color: var(--go-ink); font-weight: 700; }
@media (max-width: 559px) { .boxes { grid-template-columns: 1fr 1fr; } .box { min-height: 120px; padding: 12px; } }
