@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f4f5f6;
  --surface: #ffffff;
  --surface-2: rgba(255,255,255,0.6);
  --text: #0f1729;
  --text-soft: #334155;
  --muted: #65758b;
  --border: #e2e8f0;
  --border-soft: #eef0f3;
  --accent: #8b5cf6;
  --accent-strong: #7c3aed;
  --accent-deeper: rgb(154, 108, 229);
  --accent-bg: #ede9fe;
  --accent-border: #c4b5fd;
  --good: #059669;
  --good-bg: #d1fae5;
  --warn: #c2410c;
  --warn-bg: #ffedd5;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
/* TV mode: html/body lock to viewport, no scroll */
html.tv, html.tv body { height: 100%; overflow: hidden; margin: 0; padding: 0; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { color: var(--accent-deeper); }

/* ── hero / header ───────────────────────── */
.hero {
  position: relative;
  overflow: hidden;
  width: 100%;
  padding: 36px 48px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(139,92,246,0.22) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(124,58,237,0.18) 0%, transparent 50%),
    #0f1729;
  color: #fff;
}
.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 18px; }
.logo {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deeper));
  display: grid; place-items: center;
  font-weight: 700; color: white; font-size: 26px;
  box-shadow: 0 8px 24px -8px rgba(124, 58, 237, 0.45);
}
.hero h1 {
  font-size: 32px; margin: 0; letter-spacing: -0.02em;
  font-weight: 700; line-height: 1.1; color: #fff;
}
.hero .subtitle {
  color: rgba(255,255,255,0.78);
  font-size: 14px; margin-top: 6px; max-width: 520px;
}
.hero-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hero-actions a, .hero-actions button {
  font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; font-size: 13px; font-weight: 500;
  border-radius: 10px; border: 1px solid var(--accent-border);
  background: var(--accent-bg); color: var(--accent-deeper);
  transition: background 0.15s, border-color 0.15s;
}
.hero-actions a:hover, .hero-actions button:hover {
  background: #e0d8fd; border-color: var(--accent); color: var(--accent-deeper);
}

/* ── main / sections ─────────────────────── */
main {
  padding: 36px 48px 80px;
  max-width: 1400px;
  margin: 0 auto;
}
.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent-strong);
  margin: 0 0 12px;
  font-weight: 600;
}
.section-title {
  font-size: 24px; font-weight: 700;
  margin: 0 0 6px; letter-spacing: -0.015em;
  line-height: 1.2;
}
.section-desc {
  color: var(--muted); font-size: 14px; margin: 0 0 22px;
}
.section { margin-bottom: 40px; }

/* ── card ────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 22px 18px;
  display: flex; flex-direction: column;
  transition: box-shadow 0.3s ease, transform 0.1s;
  position: relative; overflow: hidden; isolation: isolate;
}
.card::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(270deg, rgba(154, 108, 229, 0.10) 0%, rgba(154, 108, 229, 0.03) 30%, rgba(255,255,255,0) 65%);
  opacity: 0; transition: opacity 0.55s ease; pointer-events: none; z-index: 0;
}
.card:hover::before { opacity: 1; }
.card:hover { box-shadow: 0 8px 28px -10px rgba(124, 58, 237, 0.22); }
.card > * { position: relative; z-index: 1; }

/* ── metric card ─────────────────────────── */
.metric-card .eyebrow {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.18em;
  color: var(--accent-strong); font-weight: 600; margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px;
}
.metric-card .user-dot {
  width: 10px; height: 10px; border-radius: 999px; display: inline-block;
}
.metric-card .name {
  font-size: 14px; color: var(--text-soft); font-weight: 500;
  margin: 0 0 8px;
}
.metric-card .value {
  font-size: 44px; font-weight: 700; letter-spacing: -0.02em;
  line-height: 1.1; color: var(--text);
  display: flex; align-items: baseline; gap: 6px;
}
.metric-card .value .unit { font-size: 18px; color: var(--muted); font-weight: 600; }
.metric-card .delta {
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--border-soft);
  font-size: 13px; display: flex; align-items: center; gap: 8px;
}
.delta-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.delta-pill.up { background: var(--good-bg); color: var(--good); border: 1px solid #a7f3d0; }
.delta-pill.down { background: var(--warn-bg); color: var(--warn); border: 1px solid #fdba74; }
.delta-pill.flat { background: #f1f5f9; color: var(--text-soft); border: 1px solid var(--border); }
.delta-label { color: var(--muted); font-size: 12px; }

/* ── chip ────────────────────────────────── */
.chip {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text-soft);
  border: 1px solid var(--border);
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip.accent { color: var(--accent-deeper); border-color: var(--accent-border); background: var(--accent-bg); }
.chip.good { color: var(--good); border-color: #a7f3d0; background: var(--good-bg); }
.chip.warn { color: var(--warn); border-color: #fdba74; background: var(--warn-bg); }
.chip .dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }

/* ── buttons + inputs ────────────────────── */
.btn, button.btn {
  cursor: pointer;
  text-align: center; text-decoration: none;
  background: var(--accent); color: #fff;
  font-weight: 600; font-size: 13.5px;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--accent);
  font-family: inherit;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--accent-deeper); border-color: var(--accent-deeper); color: #fff; }
.btn:active { transform: scale(0.98); }
.btn-secondary, button.btn-secondary {
  cursor: pointer;
  background: var(--accent-bg);
  color: var(--accent-deeper);
  border: 1px solid var(--accent-border);
  font-weight: 500; font-size: 12.5px;
  padding: 9px 13px; border-radius: 10px;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary:hover { background: #e0d8fd; border-color: var(--accent); color: var(--accent-deeper); }
.btn-danger, button.btn-danger {
  cursor: pointer;
  background: #fff; color: var(--warn);
  border: 1px solid #fdba74;
  padding: 7px 11px; border-radius: 8px;
  font-size: 12px; font-weight: 500;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-danger:hover { background: var(--warn-bg); }

label.field { display: block; margin-bottom: 12px; }
label.field-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-soft); }
label.field > .label, .modal-label {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="color"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="color"] { padding: 4px; height: 40px; width: 60px; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

form.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
form.inline-form .field { margin-bottom: 0; flex: 1 1 160px; min-width: 0; }
form.inline-form .actions { display: flex; gap: 8px; }

/* ── table ───────────────────────────────── */
.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.table th, .table td {
  text-align: left; padding: 12px 14px; font-size: 13px;
  border-bottom: 1px solid var(--border-soft);
}
.table th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.16em;
  color: var(--muted); font-weight: 600; background: #fafbfc;
}
.table tr:last-child td { border-bottom: 0; }
.table td.actions-cell { text-align: right; white-space: nowrap; }

/* ── toast ───────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 18px 12px 14px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 500; color: var(--text);
  box-shadow: 0 14px 36px -14px rgba(15, 23, 41, 0.28);
  z-index: 200; animation: toastIn 0.25s ease;
}
.toast.toast-out { animation: toastOut 0.45s ease forwards; }
.toast-check {
  width: 22px; height: 22px; border-radius: 999px;
  background: var(--good-bg); color: var(--good);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; flex: 0 0 auto;
}
.toast.warn .toast-check { background: var(--warn-bg); color: var(--warn); }

/* ── login ───────────────────────────────── */
.login-shell {
  min-height: 100vh; display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(139,92,246,0.10) 0%, transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(124,58,237,0.10) 0%, transparent 45%),
    var(--bg);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px;
  width: min(420px, 100%);
  box-shadow: 0 20px 60px -20px rgba(15, 23, 41, 0.18);
}
.login-card .logo { margin-bottom: 18px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card .subtitle { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.login-error {
  background: var(--warn-bg); color: var(--warn);
  border: 1px solid #fdba74; padding: 10px 14px;
  border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}

/* ── display (rotating public, TV-fit, no scroll) ─ */
/* Pinned to viewport edges with old-school fixed positioning — works on any browser. */
.display-page {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.display-stage {
  flex: 1 1 0%;
  min-height: 0;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: none;
  margin: 0;
}
.display-stage .view-indicator { flex: 0 0 auto; margin: 0; }
.display-stage .view-dot { width: 10px; height: 10px; }
.display-stage .view-name { font-size: 13px; letter-spacing: 0.22em; }

#slides {
  flex: 1 1 0%;
  min-height: 0;
  position: relative;
}
.slide {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  flex-direction: column;
}
.slide.active { display: flex; }
.slide > .section-label,
.slide > .section-title,
.slide > .section-desc { flex: 0 0 auto; margin: 0; }
.slide > .section-label { font-size: 13px; letter-spacing: 0.22em; margin-bottom: 4px; }
.slide > .section-title { font-size: 28px; margin-bottom: 2px; }
.slide > .section-desc { font-size: 14px; margin-bottom: 12px; color: var(--muted); }

/* ── grid: auto-balanced cells with hard fallback ── */
.display-stage .grid {
  flex: 1 1 0%;
  min-height: 0;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: 1fr;
}
.display-stage .grid[data-count="1"] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.display-stage .grid[data-count="2"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.display-stage .grid[data-count="3"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr; }
.display-stage .grid[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.display-stage .grid[data-count="5"],
.display-stage .grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr 1fr; }
.display-stage .grid[data-count="7"],
.display-stage .grid[data-count="8"] { grid-template-columns: repeat(4, 1fr); grid-template-rows: 1fr 1fr; }
.display-stage .grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.display-stage .grid[data-count="10"],
.display-stage .grid[data-count="11"],
.display-stage .grid[data-count="12"] { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr); }

.display-stage .card {
  padding: 18px 20px;
  border-radius: 16px;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.display-stage .metric-card .eyebrow { font-size: 12px; letter-spacing: 0.22em; margin-bottom: 6px; }
.display-stage .metric-card .user-dot { width: 10px; height: 10px; }
.display-stage .metric-card .name { font-size: 16px; margin-bottom: 8px; }
.display-stage .metric-card .value { font-size: 64px; letter-spacing: -0.03em; line-height: 1; }
.display-stage .metric-card .value .unit { font-size: 24px; }
.display-stage .metric-card .delta { font-size: 14px; padding-top: 10px; margin-top: 10px; }
.display-stage .delta-pill { font-size: 12px; padding: 2px 9px; }
.display-stage .delta-label { font-size: 12px; }

/* Scale up on bigger screens (desktop/TV) */
@media (min-width: 1280px) and (min-height: 720px) {
  .display-stage { padding: 24px 32px; gap: 14px; }
  .slide > .section-title { font-size: 36px; }
  .display-stage .metric-card .value { font-size: 96px; }
  .display-stage .metric-card .value .unit { font-size: 32px; }
  .display-stage .metric-card .name { font-size: 18px; }
  .display-stage .metric-card .delta { font-size: 16px; }
  .display-stage .delta-pill { font-size: 14px; }
  .display-stage .delta-label { font-size: 14px; }
}
@media (min-width: 1600px) and (min-height: 900px) {
  .display-stage .metric-card .value { font-size: 112px; }
}

/* ── graph view ──────────────────────────────────── */
.display-stage .graph-wrap {
  flex: 1 1 0%;
  min-height: 0;
  padding: 16px 20px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.display-stage .graph-canvas {
  flex: 1 1 0%;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.display-stage .graph-canvas > canvas {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
}
.display-stage .graph-legend {
  flex: 0 0 auto;
  padding-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 80px;
  overflow: hidden;
}
.display-stage .graph-legend .chip { font-size: 13px; padding: 3px 10px; }
.display-stage .graph-legend .chip .dot { width: 10px; height: 10px; }

.display-stage .empty {
  flex: 1 1 0%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.view-indicator { display: flex; gap: 8px; align-items: center; }
.view-dot.active { background: var(--accent); transform: scale(1.25); }
.view-name { color: var(--accent-strong); font-weight: 600; margin-left: 6px; text-transform: uppercase; }
.view-name .paused { color: var(--warn); margin-left: 8px; }

/* Base styles for non-display pages (admin/me) only. Display overrides above. */
.empty {
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: 14px; padding: 60px 24px;
  text-align: center; color: var(--muted);
}
.graph-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px;
  display: flex; flex-direction: column; gap: 18px;
}
.graph-legend {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding-top: 16px;
}

.progress-bar {
  height: 3px; width: 100%; background: var(--border-soft);
  position: relative; overflow: hidden;
  flex: 0 0 auto;
}
.progress-bar .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent); width: 0%;
  transition: width 0.5s linear;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(10px); }
}

/* ── small text helpers ──────────────────── */
.muted { color: var(--muted); }
.text-soft { color: var(--text-soft); }
.row-spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ── responsive ──────────────────────────── */
@media (max-width: 700px) {
  .hero, main, .display-stage { padding-left: 20px; padding-right: 20px; }
  .grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 24px; }
}
