/* MCR Operator Monitoring Panel.
 *
 * Builds on techex.css tokens (--bg, --surface, --border, --text, --muted,
 * --accent, --accent-2, --warn, --danger, --radius...). Dark is the default via
 * theme.js. House rules: no left-edge accent strips anywhere; differentiate with
 * full borders, background tint, and heading colour only. Target wall is a
 * 2560x1440 monitor; the card grid is sized for five games + one system tile.
 */

/* --- MCR-specific tokens, defined for both themes --- */
:root {
  --mcr-header-h: 48px;
  --mcr-gap: 12px;
  --lamp-ok: #2f6b46;        /* calm green, reads as "fine" not "look at me" */
  --lamp-ok-text: #9fe7bd;
  --lamp-active: var(--danger);
  --lamp-latched: var(--warn);
  --lamp-off: #33405f;
  --ok: #16a34a;
  --live: #16a34a;
  --poll: #f59e0b;
  --downcol: #dc2626;
}

:root:not([data-theme="dark"]) {
  --lamp-ok: #cfe9d8;
  --lamp-ok-text: #1a6b3d;
  --lamp-off: #dfe3ea;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Fira Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header strip ===== */
.mcr-header {
  height: var(--mcr-header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.mcr-header .brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.mcr-header .brand .mark {
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
}
.mcr-header .spacer { flex: 1; }
.mcr-header .clock {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.mcr-header .clock b { color: var(--text); font-weight: 600; }
.mcr-header a { color: var(--muted); text-decoration: none; }
.mcr-header a:hover { color: var(--accent); }

.hdr-user { display: flex; flex-direction: column; line-height: 1.15; }
.hdr-user .u { font-weight: 600; font-size: 13px; }
.hdr-user .r { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

/* status dot (WS link / instance health) */
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block; flex: 0 0 auto;
  background: var(--muted);
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.down { background: var(--danger); }
.dot.pulse { animation: dotpulse 1.6s ease-in-out infinite; }
@keyframes dotpulse { 50% { opacity: 0.35; } }

/* transport badge */
.badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em;
  padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}
.badge.live { color: #fff; background: var(--live); border-color: var(--live); }
.badge.poll { color: #3a2c05; background: var(--poll); border-color: var(--poll); }
.badge.down { color: #fff; background: var(--downcol); border-color: var(--downcol); }

/* small icon button (theme toggle, header actions) */
.iconbtn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.iconbtn:hover { border-color: var(--accent); color: var(--accent); }

/* ===== Wall ===== */
.wall {
  height: calc(100dvh - var(--mcr-header-h));
  padding: var(--mcr-gap);
  display: grid;
  gap: var(--mcr-gap);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}
/* 4-or-fewer games collapse to a tighter grid */
.wall[data-count="1"] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.wall[data-count="2"] { grid-template-columns: repeat(2, 1fr); grid-template-rows: 1fr; }
.wall[data-count="3"],
.wall[data-count="4"] { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }

/* ===== Game card ===== */
.game {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: grid;
  /* title | video (absorbs slack) | sources | lamps | scte | health */
  grid-template-rows: auto minmax(120px, 1fr) auto auto auto auto;
  min-height: 0;
  min-width: 0;
}
.game.break-active { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.game.degraded { border-color: var(--danger); }

.game .g-title {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  min-height: 32px;
}
.game .g-title .name { font-weight: 600; font-size: 13.5px; }
.game .g-title .net {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--muted); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 4px; text-transform: uppercase;
}
.game .g-title .spacer { flex: 1; }

/* video: fills the flexible grid row; contain keeps 16:9 letterboxed */
.g-video {
  position: relative;
  background: #000;
  min-height: 0;
  cursor: pointer;
  overflow: hidden;
}
.g-video video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.g-video .vph {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; gap: 6px; flex-direction: column;
  background: repeating-linear-gradient(45deg, #0b0b0f, #0b0b0f 12px, #101018 12px, #101018 24px);
}
.g-video .v-overlay {
  position: absolute; left: 6px; bottom: 6px; right: 6px;
  display: flex; gap: 6px; align-items: center; pointer-events: none;
}
.v-chip {
  font-size: 10.5px; font-weight: 600;
  background: rgba(0,0,0,0.55); color: #eaeaea;
  padding: 2px 6px; border-radius: 4px;
  font-variant-numeric: tabular-nums;
}
.v-chip.err { background: rgba(220,38,38,0.85); color: #fff; }
.v-chip.ok { background: rgba(22,163,74,0.8); color: #fff; }

/* source buttons */
.g-sources {
  display: flex; gap: 6px; padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; align-items: center;
}
.g-sources .lbl { font-size: 11px; color: var(--muted); margin-right: 2px; }
.src-btn {
  font: inherit; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); border-radius: 7px; padding: 5px 12px; cursor: pointer;
  position: relative; min-width: 52px;
}
.src-btn:hover:not(:disabled) { border-color: var(--accent); }
.src-btn.active {
  background: var(--accent-2); border-color: var(--accent-2); color: #fff;
}
.src-btn.pending {
  border-color: var(--warn); color: var(--warn);
  animation: srcpulse 1s ease-in-out infinite;
}
.src-btn.unconfirmed { border-color: var(--warn); color: var(--warn); border-style: dashed; }
.src-btn.slate.active { background: var(--warn); border-color: var(--warn); color: #241a02; }
.src-btn:disabled { opacity: 0.6; cursor: not-allowed; }
@keyframes srcpulse { 50% { background: color-mix(in srgb, var(--warn) 18%, var(--surface-2)); } }

/* ETR-290 P1 lamps */
.g-lamps { padding: 6px 8px; border-bottom: 1px solid var(--border); display: grid; gap: 4px; }
.lamp-row { display: flex; align-items: center; gap: 6px; }
.lamp-row .leg {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em;
  color: var(--muted); width: 34px; flex: 0 0 auto; text-transform: uppercase;
}
.lamp-row .clr {
  margin-left: auto; font-size: 10px; color: var(--muted);
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 5px; padding: 1px 6px; cursor: pointer;
}
.lamp-row .clr:hover { border-color: var(--accent); color: var(--accent); }
.lamps { display: flex; gap: 4px; }
.lamp {
  position: relative;
  width: 40px; height: 26px; border-radius: 5px;
  background: var(--lamp-off);
  display: flex; align-items: center; justify-content: center;
  font-size: 9.5px; font-weight: 700; color: var(--muted);
  border: 1px solid transparent;
  cursor: default;
  font-variant-numeric: tabular-nums;
}
.lamp.ok { background: var(--lamp-ok); color: var(--lamp-ok-text); }
.lamp.active { background: var(--lamp-active); color: #fff; border-color: #fff2; }
.lamp.latched { background: var(--lamp-off); border-color: var(--lamp-latched); color: var(--lamp-latched); }
.lamp .cnt {
  position: absolute; top: -5px; right: -4px;
  background: var(--text); color: var(--bg);
  font-size: 8.5px; padding: 0 3px; border-radius: 6px; min-width: 12px; text-align: center;
}

/* SCTE ticker */
.g-scte {
  padding: 6px 8px; border-bottom: 1px solid var(--border);
  display: grid; gap: 3px; min-height: 0; overflow: hidden;
  align-content: start;
}
.g-scte .scte-hd { display: flex; align-items: center; gap: 8px; }
.g-scte .scte-hd .t { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.brk-countdown {
  margin-left: auto; font-size: 11px; font-weight: 700;
  color: #241a02; background: var(--warn); padding: 1px 8px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.scte-line {
  display: flex; gap: 8px; align-items: baseline;
  font-size: 11.5px; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scte-line .ts { color: var(--muted); }
.scte-line .kind { font-weight: 700; width: 30px; }
.scte-line .kind.out { color: var(--warn); }
.scte-line .kind.in { color: var(--accent-2); }
.scte-line .kind.sig { color: var(--accent); }
.scte-line .src { color: var(--muted); font-size: 10px; margin-left: auto; }
.g-scte .empty { color: var(--muted); font-size: 11px; font-style: italic; }

/* health strip */
.g-health {
  padding: 6px 8px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  background: var(--surface-2);
}
.hchip {
  font-size: 10.5px; display: inline-flex; gap: 5px; align-items: center;
  border: 1px solid var(--border); border-radius: 5px; padding: 2px 7px;
  font-variant-numeric: tabular-nums;
}
.hchip .k { color: var(--muted); }
.hchip.alarm { border-color: var(--danger); color: var(--danger); }
.hchip.warn { border-color: var(--warn); color: var(--warn); }

/* breaks tray (future) */
.g-tray { padding: 6px 8px; border-top: 1px solid var(--border); }
.g-tray summary { font-size: 11px; color: var(--muted); cursor: pointer; }
.g-tray .tray-body { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* system tile (6th cell) */
.system {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: auto;
}
.system h2 { font-size: 13px; font-weight: 650; margin: 0; }
.system .sys-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.system .sys-sec { border-top: 1px solid var(--border); padding-top: 8px; }
.system .audit-line { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ===== enlarge modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.8);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 24px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 90vw; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column;
}
.modal .m-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.modal .m-head .spacer { flex: 1; }
.modal video { max-width: 88vw; max-height: 72vh; background: #000; }
.modal .m-meters { display: flex; gap: 10px; padding: 8px 12px; flex-wrap: wrap; }

/* ===== login ===== */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-lift);
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.login-card button { width: 100%; margin-top: 18px; }
.login-card .brand { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-weight: 700; }
.login-card .brand .mark { color: var(--accent); font-size: 20px; }

/* ===== admin ===== */
.admin-wrap { max-width: 1200px; margin: 0 auto; padding: 20px; }
.admin-nav { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.admin-nav a {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 13px; background: var(--surface);
}
.admin-nav a:hover { border-color: var(--accent); color: var(--accent); }
.admin-nav a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel h2 { font-size: 15px; margin: 0 0 12px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form-grid input, .form-grid select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font: inherit;
}
.form-grid .full { grid-column: 1 / -1; }
.row-actions { display: flex; gap: 6px; }

.toast-host { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow-lift); max-width: 360px;
}
.toast.ok { border-color: var(--accent-2); }
.toast.err { border-color: var(--danger); }
.toast.warn { border-color: var(--warn); }

.muted { color: var(--muted); }
.hidden { display: none !important; }
