:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e4e8ee;
  --border-strong: #d3dae3;
  --text: #17233b;
  --text-dim: #55647c;
  --text-faint: #8794a8;
  --navy: #1f3b8f;
  --navy-dark: #16296b;
  --navy-soft: #eaeefb;
  --blue: #3760c9;
  --red: #d92d20;
  --green: #067647;
  --green-soft: #e6f4ec;
  --amber: #b54708;
  --amber-soft: #fdf3e7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 35, 59, .05), 0 4px 16px rgba(23, 35, 59, .05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.container { max-width: 1160px; margin: 0 auto; padding: 0 24px; }

/* ---------- brand mark ---------- */
.brand-mark {
  width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0;
  background: var(--navy); color: #fff;
  font-weight: 800; font-size: 16px; letter-spacing: .02em;
  display: flex; align-items: center; justify-content: center;
}
.brand-mark-lg { width: 60px; height: 60px; border-radius: 14px; font-size: 22px; margin: 0 auto 18px; }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 44px 36px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 21px; letter-spacing: -.01em; }
.login-sub { color: var(--text-dim); margin: 8px 0 26px; line-height: 1.5; }
.login-card input {
  width: 100%; padding: 13px 14px; border-radius: 9px; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  font: inherit; font-size: 16px;
}
.login-card input:focus { outline: 2px solid var(--navy); outline-offset: -1px; border-color: var(--navy); }
.login-card button {
  width: 100%; padding: 13px; border: 0; border-radius: 9px; cursor: pointer;
  background: var(--navy); color: #fff; font: inherit; font-weight: 600; font-size: 15px;
}
.login-card button:hover { background: var(--navy-dark); }
.login-error { color: var(--red); margin-top: 14px; font-size: 13.5px; }

/* ---------- header & tabs ---------- */
.site-head {
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.head-row {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 16px; padding-bottom: 14px;
}
.brand { display: flex; gap: 13px; align-items: center; }
.brand-name { font-weight: 700; font-size: 16.5px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--text-faint); margin-top: 1px; }

.logout {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-dim);
  border-radius: 8px; padding: 8px 16px; cursor: pointer; font: inherit; font-size: 13.5px;
}
.logout:hover { color: var(--text); border-color: var(--text-faint); }

.tabs { display: flex; gap: 4px; overflow-x: auto; }
.nav-item {
  border: 0; background: none; cursor: pointer; font: inherit;
  color: var(--text-dim); font-weight: 500; font-size: 14.5px;
  padding: 11px 14px 13px; border-bottom: 2.5px solid transparent;
  white-space: nowrap; display: flex; align-items: center; gap: 7px;
}
.nav-item:hover { color: var(--text); }
.nav-item.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }

/* ---------- page head ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 18px; flex-wrap: wrap; margin: 30px 0 22px;
}
.page-head h2 { font-size: 24px; letter-spacing: -.02em; }
.page-sub { color: var(--text-dim); margin-top: 5px; font-size: 14px; max-width: 560px; line-height: 1.5; }
.page-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.range-group {
  display: flex; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 9px; overflow: hidden;
}
.range-group button {
  border: 0; background: none; color: var(--text-dim); padding: 8px 13px;
  cursor: pointer; font: inherit; font-size: 13px;
}
.range-group button + button { border-left: 1px solid var(--border); }
.range-group button.active { background: var(--navy-soft); color: var(--navy); font-weight: 600; }

select, .ghost-btn {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: 9px; padding: 8px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.ghost-btn { color: var(--text-dim); }
.ghost-btn:hover { color: var(--text); border-color: var(--text-faint); }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.cards-3 { grid-template-columns: repeat(3, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card-label { color: var(--text-faint); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; font-weight: 600; margin-bottom: 8px; }
.card-value { font-size: 31px; font-weight: 700; letter-spacing: -.02em; color: var(--navy-dark); }
.card-value-sm { font-size: 20px; line-height: 1.3; padding-top: 5px; }
.card-sub { color: var(--text-faint); font-size: 12.5px; margin-top: 6px; min-height: 15px; }

/* ---------- panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 24px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.panel-narrow { max-width: 580px; }
.panel-head { margin-bottom: 18px; }
.panel-head h3 { font-size: 16.5px; letter-spacing: -.01em; display: flex; align-items: center; }
.panel-hint { color: var(--text-dim); font-size: 13px; line-height: 1.55; display: block; margin-top: 4px; max-width: 640px; }

.chart-wrap { height: 280px; position: relative; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; color: var(--text-faint); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em;
  padding: 8px 12px; border-bottom: 1px solid var(--border-strong);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar-cell { min-width: 140px; }
.bar { height: 8px; border-radius: 4px; background: var(--navy); opacity: .85; }
.muted { color: var(--text-faint); font-size: 12.5px; }
.empty { color: var(--text-dim); text-align: center; padding: 38px 12px !important; font-size: 14px; }

/* ---------- badges & chips ---------- */
.badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  padding: 2.5px 8px; border-radius: 6px; vertical-align: 1.5px; text-transform: uppercase;
  margin-right: 4px;
}
.badge-qr { background: var(--navy-soft); color: var(--navy); }
.badge-link { background: var(--green-soft); color: var(--green); }
.chip-gps {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .05em;
  padding: 2px 6px; border-radius: 5px; vertical-align: 1.5px;
  background: var(--green-soft); color: var(--green);
}

/* ---------- live ---------- */
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--red); animation: pulse 1.6s infinite;
}
.live-dot-lg { width: 10px; height: 10px; margin-right: 9px; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
tr.new-row td { animation: flash 2s ease-out; }
@keyframes flash { from { background: var(--navy-soft); } to { background: transparent; } }

/* ---------- QR & links ---------- */
.qr-form { display: flex; gap: 10px; flex-wrap: wrap; }
.qr-form select, .qr-form input {
  padding: 11px 13px; border-radius: 9px;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); font: inherit;
}
.qr-form input:focus, .qr-form select:focus,
.settings-form input:focus, .settings-form select:focus, .settings-form textarea:focus {
  outline: 2px solid var(--navy); outline-offset: -1px;
}
.qr-form input[type="text"] { flex: 1; min-width: 240px; }
.qr-form .qr-dest { flex-basis: 100%; font-size: 13.5px; }
.qr-form button {
  padding: 11px 26px; border: 0; border-radius: 9px; cursor: pointer;
  background: var(--navy); color: #fff; font: inherit; font-weight: 600;
}
.qr-form button:hover { background: var(--navy-dark); }
.qr-note {
  margin-top: 14px; font-size: 13px; line-height: 1.55;
  background: var(--amber-soft); color: var(--amber);
  border-radius: 8px; padding: 10px 14px;
}
.qr-note a { color: var(--navy); font-weight: 600; }

.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 14px; }
.qr-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center; box-shadow: var(--shadow);
}
.qr-card-archived { opacity: .72; background: var(--bg); }
.qr-card-archived:hover { opacity: 1; }

.archived-bar { margin-top: 20px; }
.archived-bar.hidden { display: none; }
.link-btn {
  background: none; border: 0; cursor: pointer; font: inherit; font-size: 13.5px;
  color: var(--text-dim); text-decoration: underline; padding: 4px 0;
}
.link-btn:hover { color: var(--text); }
.qr-card img {
  width: 150px; height: 150px; border-radius: 8px;
  border: 1px solid var(--border);
}
.link-tile {
  width: 150px; height: 150px; margin: 0 auto; border-radius: 8px;
  background: var(--green-soft); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.link-tile svg { width: 54px; height: 54px; stroke: var(--green); }
.qr-card h4 { margin: 14px 0 4px; font-size: 15.5px; }
.qr-card .qr-url { color: var(--text-faint); font-size: 12px; word-break: break-all; margin-bottom: 5px; }
.qr-dest-note { color: var(--green); font-size: 12px; word-break: break-all; margin-bottom: 5px; font-weight: 600; }
.qr-dest-none { color: var(--text-faint); font-weight: 400; }
.qr-card .qr-scans { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }
.qr-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.qr-actions a, .qr-actions button {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-dim);
  font: inherit; font-size: 12.5px; border-radius: 7px; padding: 7px 11px;
  cursor: pointer; text-decoration: none;
}
.qr-actions a:hover, .qr-actions button:hover { color: var(--text); border-color: var(--text-faint); }
.qr-actions .danger:hover { color: var(--red); border-color: var(--red); }
.qr-actions .primary {
  background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600;
}
.qr-actions .primary:hover { background: var(--navy-dark); color: #fff; }

/* ---------- settings ---------- */
.settings-form { display: flex; flex-direction: column; gap: 18px; }
.settings-form label { display: flex; flex-direction: column; gap: 6px; color: var(--text); font-size: 13.5px; font-weight: 600; }
.settings-form input, .settings-form select, .settings-form textarea {
  padding: 11px 13px; border-radius: 9px; resize: vertical; font-weight: 400;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); font-family: inherit; font-size: 14px;
}
.field-hint { color: var(--text-faint); font-size: 12.5px; font-weight: 400; line-height: 1.5; }
.settings-form button {
  align-self: flex-start; padding: 11px 26px; border: 0; border-radius: 9px; cursor: pointer;
  background: var(--navy); color: #fff; font: inherit; font-weight: 600;
}
.settings-form button:hover { background: var(--navy-dark); }
.saved { color: var(--green); font-size: 13.5px; font-weight: 600; }

/* ---------- fullscreen display (kept dark: this is what goes on air) ---------- */
.display {
  position: fixed; inset: 0; z-index: 50; background: #000; color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.display-inner { text-align: center; }
.display-channel {
  font-size: clamp(22px, 4vw, 42px); font-weight: 800; letter-spacing: -.02em; margin-bottom: 4vh;
}
.display img {
  width: min(58vh, 78vw); border-radius: 24px; background: #fff; padding: min(2.2vh, 18px);
}
.display-label { margin-top: 3.5vh; font-size: clamp(16px, 2.4vw, 26px); color: #cbd5e1; }
.display-hint { margin-top: 1.2vh; font-size: clamp(13px, 1.6vw, 18px); color: #64748b; }
.display-close {
  position: fixed; top: 18px; right: 18px; width: 42px; height: 42px;
  border-radius: 50%; border: 1px solid #333; background: #111; color: #888;
  font-size: 16px; cursor: pointer;
}
.display-close:hover { color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .page-head { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 560px) {
  .cards, .cards-3 { grid-template-columns: 1fr; }
  .head-row { padding-top: 12px; padding-bottom: 10px; }
  .container { padding: 0 14px; }
}

main.container { padding-bottom: 70px; }
