/* Dopamine tracker: shared look for the counter and owner screens. */
:root {
  --bg: #05070d;
  --surface: #0e121b;
  --surface-2: #161c2a;
  --line: #242c3d;
  --text: #eef2fa;
  --muted: #8f9ab0;
  --blue: #2d5bff;
  --blue-soft: #1a2a66;
  --ice: #a0d6f8;
  --green: #2bd576;
  --amber: #ffb020;
  --red: #ff4d4d;
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: rgba(5, 7, 13, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 36px; height: 36px; flex: none; }
.brand b { display: block; font-size: 17px; letter-spacing: 0.02em; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.clock { font-size: 18px; font-weight: 600; margin-right: 4px; }
.pill {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 9px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.pill:hover { border-color: #3a4560; }
.pill.on { border-color: var(--green); color: var(--green); }
.pill.off { border-color: var(--amber); color: var(--amber); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }
.dot.warn { background: var(--amber); }

/* ---------- banners and alert strips ---------- */
.banner { margin: 12px 16px 0; padding: 12px 14px; border-radius: 12px; font-size: 15px; border: 1px solid var(--line); background: var(--surface); }
.banner.warn { border-color: var(--amber); color: var(--amber); }
.banner.info { border-color: var(--blue); background: var(--blue-soft); cursor: pointer; }
#alerts { display: grid; gap: 8px; margin: 12px 16px 0; }
#alerts:empty { display: none; }
.strip {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 12px; border: 2px solid var(--amber); background: rgba(255, 176, 32, 0.12);
}
.strip.over { border-color: var(--red); background: rgba(255, 77, 77, 0.16); }
.strip.over.loud { animation: pulse-red 1s ease-in-out infinite; }
.strip-text { flex: 1 1 220px; min-width: 0; }
.strip-text b { display: block; font-size: 18px; }
.strip-text span { font-size: 14px; color: var(--muted); }
.strip-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* A red frame around the whole screen while an alarm is sounding. */
body.alarm::after {
  content: ""; position: fixed; inset: 0; z-index: 60; pointer-events: none;
  border: 8px solid var(--red); animation: frame 0.9s ease-in-out infinite;
}
@keyframes frame { 0%, 100% { opacity: 1; } 50% { opacity: 0.15; } }
@keyframes pulse-red { 0%, 100% { background: rgba(255, 77, 77, 0.16); } 50% { background: rgba(255, 77, 77, 0.38); } }
@keyframes pulse-amber { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 176, 32, 0.0); } 50% { box-shadow: 0 0 0 6px rgba(255, 176, 32, 0.25); } }

/* ---------- station cards ---------- */
/* One column on a phone, two on a tablet or laptop, four on a very wide screen. */
.grid { display: grid; gap: 16px; padding: 16px; grid-template-columns: minmax(0, 1fr); max-width: 1900px; margin: 0 auto; }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1700px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.card {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 10px; min-height: 300px;
  container-type: inline-size;
}
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head h2 { font-size: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.blue { color: #fff; background: var(--blue); border-color: var(--blue); }
.tv { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.card.free { border-style: dashed; }
.free-box { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; }
.free-word { font-size: 34px; font-weight: 700; color: var(--green); }
.hint { font-size: 14px; color: var(--amber); }

.who { font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { font-weight: 400; color: var(--muted); font-size: 14px; }
.time { font-size: 64px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.time-sub { font-size: 14px; color: var(--muted); }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--blue); border-radius: 999px; transition: width 0.4s linear; }
.money { font-size: 15px; }
.money .due { color: var(--amber); font-weight: 600; }
.money .paid { color: var(--green); }
.note { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: auto; }
/* A wide card has room for bigger numbers and all four buttons in one row. */
@container (min-width: 400px) {
  .actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@container (min-width: 520px) {
  .time { font-size: 92px; }
  .who { font-size: 20px; }
  .free-word { font-size: 44px; }
}

.card.running { border-color: var(--blue); }
.card.warn { border-color: var(--amber); animation: pulse-amber 1.6s ease-in-out infinite; }
.card.warn .time { color: var(--amber); }
.card.warn .bar i { background: var(--amber); }
.card.over { border-color: var(--red); background: #1a0d10; }
.card.over .time { color: var(--red); }
.card.over .bar i { background: var(--red); width: 100% !important; }
.card.over.loud { animation: pulse-red 1s ease-in-out infinite; }
.card.paused { border-color: var(--muted); }
.card.paused .time { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px;
  padding: 12px 14px; font-size: 15px; font-weight: 600; cursor: pointer; min-height: 46px; white-space: nowrap;
}
.btn:hover { border-color: #3a4560; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #1a0505; }
.btn.ghost { background: transparent; }
.btn.big { font-size: 18px; padding: 16px; min-height: 58px; width: 100%; }
.btn.small { padding: 8px 12px; min-height: 38px; font-size: 14px; }
.btn:focus-visible, .pill:focus-visible, .seg button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid var(--ice); outline-offset: 2px;
}

/* ---------- pop-up forms ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text);
  padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-x: hidden;
}
dialog.wide { width: min(980px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.dlg-head h3 { font-size: 19px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-body { padding: 16px 18px; display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
/* The main button stays in reach at the bottom, however long the form is. */
.dlg-foot {
  position: sticky; bottom: 0; z-index: 2; display: flex; gap: 10px;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.dlg-foot .btn { flex: 1; }
.dlg-foot .btn.ghost { flex: 0 0 auto; }
.x { border: 0; background: transparent; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.f { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; font-size: 14px; color: var(--muted); }
.f > .seg button { color: var(--text); }
input[type="text"], input[type="tel"], input[type="number"], input[type="password"], input[type="date"], textarea, select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 17px; color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.f, .row > *, .section > * { min-width: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.seg.multi { grid-auto-flow: row; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); }
.seg button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px 8px; font-size: 16px; font-weight: 600; cursor: pointer; min-height: 50px;
}
.seg button small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.seg button.sel { background: var(--blue); border-color: var(--blue); color: #fff; }
.seg button.sel small { color: #dfe7ff; }
/* "Other": pick any number of whole hours with minus and plus. */
.stepper { display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px; gap: 8px; align-items: stretch; margin-top: 2px; }
.stepper .btn { font-size: 26px; line-height: 1; padding: 0; min-height: 56px; color: var(--text); }
.stepper-value {
  display: flex; align-items: baseline; justify-content: center; gap: 8px;
  border: 1px solid var(--blue); border-radius: 12px; background: var(--bg); padding: 10px; color: var(--text);
}
.stepper-value b { font-size: 30px; line-height: 1.2; }
.stepper-value span { font-size: 16px; color: var(--muted); }
.total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px; border-radius: 12px; background: var(--surface-2); }
.total b { font-size: 30px; }
.link { background: none; border: 0; padding: 0; color: var(--ice); text-decoration: underline; cursor: pointer; font-size: 14px; }
.err { color: var(--red); font-size: 15px; min-height: 1.2em; }
.suggest { display: grid; gap: 6px; }
.suggest button { text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 12px; cursor: pointer; font-size: 15px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 16px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { text-align: right; font-weight: 600; }

/* ---------- tables and tiles ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; background: var(--surface); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.tile span { display: block; font-size: 13px; color: var(--muted); }
.tile b { display: block; font-size: 26px; margin-top: 4px; }
.tile small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.bad { border-color: var(--red); }
.tile.bad b { color: var(--red); }
.tile.good b { color: var(--green); }
.tag { display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.red { border-color: var(--red); color: var(--red); }
.tag.amber { border-color: var(--amber); color: var(--amber); }
.tag.green { border-color: var(--green); color: var(--green); }
.section { padding: 16px; display: grid; gap: 12px; }
.section h2 { font-size: 18px; }
.section > p { color: var(--muted); font-size: 14px; }
.foot { padding: 4px 16px 24px; color: var(--muted); font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 80;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; max-width: calc(100vw - 32px);
}
.toast.bad { border-color: var(--red); color: var(--red); }

/* ---------- admin: one card per TV ---------- */
.tvgrid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.tvcard {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 8px; min-height: 230px;
}
.tvcard.green { border-color: var(--green); }
.tvcard.amber { border-color: var(--amber); }
.tvcard.red { border-color: var(--red); }
.tvstate { font-size: 26px; font-weight: 700; line-height: 1.15; }
.tvcard.green .tvstate { color: var(--green); }
.tvcard.amber .tvstate { color: var(--amber); }
.tvcard.red .tvstate { color: var(--red); }
.tvbtns { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.tvbtns:empty { display: none; }
.tvbtns .btn { white-space: normal; line-height: 1.2; }

/* ---------- TV test page ---------- */
.steps { display: grid; gap: 12px; }
.step { display: flex; gap: 14px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.step > b { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; font-size: 17px; }
.step > div { min-width: 0; line-height: 1.5; }
.step .muted { display: block; font-size: 14px; }
.bigline { font-size: 30px; font-weight: 700; color: var(--ice); margin: 4px 0; letter-spacing: 0.02em; word-break: break-all; user-select: all; }
.checks { display: grid; gap: 4px; font-size: 14px; }

/* ---------- sign in ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px; display: grid; gap: 14px; }
.login .brand { justify-content: center; margin-bottom: 6px; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  /* Tables turn into a list of small cards: one line per column, with its name on the left. */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 4px 0; white-space: normal; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
  table.stack td[colspan] { display: block; text-align: left; }
  table.stack td[colspan]::before, table.stack td[data-label=""]::before { content: none; }
  table.stack td[data-label=""] .btn { width: 100%; }
}
@media (max-width: 560px) {
  .top { flex-wrap: wrap; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 12px 8px; }
  .brand { flex: 1 1 100%; }
  .brand svg { width: 30px; height: 30px; }
  .brand b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand > div { min-width: 0; }
  .top-right { width: 100%; flex-wrap: nowrap; justify-content: stretch; }
  .top-right .pill { flex: 1; text-align: center; padding: 10px 6px; }
  .clock { display: none; }
  .time { font-size: 60px; }
  .grid { padding: 12px; gap: 12px; }
  .card { min-height: 0; padding: 16px; }
  .banner, #alerts { margin: 10px 12px 0; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .section { padding: 12px 0; }
  .tile b { font-size: 22px; }
  .strip-actions { width: 100%; }
  .strip-actions .btn { flex: 1; }
  /* Pop-up forms slide up from the bottom and use the full width. */
  dialog, dialog.wide {
    width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0 0;
    border-radius: 18px 18px 0 0; border-width: 1px 0 0 0;
  }
  .dlg-foot .btn.ghost { flex: 0 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .card.warn, .card.over.loud, .strip.over.loud, body.alarm::after { animation: none; }
}
