/* =========================================================================
   visualize — control room
   Dark by design: this runs on a laptop next to a vision mixer, often in a
   dim gantry, and the operator needs the on-air state readable at a glance.
   ========================================================================= */

:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232c;
  --line: #2a323d;
  --ink: #e7edf5;
  --muted: #93a1b3;
  --accent: #2f81f7;
  --live: #ff3b30;
  --ok: #2ea043;
  --warn: #d29922;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#root.booting { padding: 60px; color: var(--muted); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* -------------------------------------------------------------- app shell */

.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }

.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brandmark { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brandmark .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--live); box-shadow: 0 0 12px var(--live); }
.brandmark strong { font-size: 16px; letter-spacing: 0.02em; }

.tenant-switch {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.tenant-switch .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.tenant-switch .name { font-weight: 650; margin-top: 2px; }

nav.menu { display: flex; flex-direction: column; gap: 2px; }

nav.menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 500;
}

nav.menu a:hover { background: var(--panel-2); text-decoration: none; }
nav.menu a.active { background: var(--accent); color: #fff; }
nav.menu .ico { width: 18px; text-align: center; opacity: 0.9; }

.side .spacer { flex: 1; }

.main { padding: 26px 32px 80px; max-width: 1500px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 680; letter-spacing: -0.01em; }
.page-head p { color: var(--muted); margin-top: 4px; }

/* ----------------------------------------------------------------- panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.panel > h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 14px;
  font-weight: 650;
}

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ------------------------------------------------------------------ forms */

label.field { display: block; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 550; }

input[type="text"], input[type="number"], input[type="datetime-local"], input[type="date"],
input[type="time"], input[type="password"], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 9px 11px;
  font: inherit;
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 129, 247, 0.22); }
textarea { resize: vertical; min-height: 68px; }
input[type="color"] { width: 46px; height: 34px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 570;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { border-color: #3d4855; background: #222b36; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4b93f8; }
.btn.danger { background: var(--live); border-color: var(--live); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--muted);
}

.chip.live { background: rgba(255, 59, 48, 0.14); border-color: var(--live); color: #ff8a84; }
.chip.ok { background: rgba(46, 160, 67, 0.14); border-color: var(--ok); color: #7ee094; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }

/* ------------------------------------------------------- tenant overview */

.tenant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

.tenant-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tenant-card:hover { border-color: var(--accent); }
.tenant-card img { width: 64px; height: 64px; object-fit: contain; }
.tenant-card .name { font-size: 17px; font-weight: 650; }

/* --------------------------------------------------------------- live bar */

.onair {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
}

.onair.is-live { border-left-color: var(--live); background: linear-gradient(90deg, rgba(255, 59, 48, 0.1), transparent 40%); }
.onair .state { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.onair .what { font-size: 19px; font-weight: 670; }

.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--live); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ------------------------------------------------------------ take panel */

.take-group { margin-bottom: 16px; }
.take-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin-bottom: 8px; }
.take-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px; }

.take {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  width: 100%;
}

.take:hover { border-color: var(--accent); }
.take.on { border-color: var(--live); background: rgba(255, 59, 48, 0.12); }
.take .t { font-weight: 620; }
.take .opts { display: flex; gap: 6px; flex-wrap: wrap; }

.opt {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.opt.sel { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------------------------------------------------------------- clock */

.clockface {
  font-family: var(--mono);
  font-size: 46px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.scoreboard .team { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.scoreboard .team img { width: 64px; height: 64px; object-fit: contain; }
.scoreboard .digits { font-size: 46px; font-weight: 700; font-variant-numeric: tabular-nums; }
.scoreboard .stepper { display: flex; gap: 6px; align-items: center; }

/* ---------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); padding: 6px 8px; font-weight: 650; }
td { padding: 4px 8px; border-top: 1px solid var(--line); }
td.shrink { width: 1%; white-space: nowrap; }
/* A shrink-to-fit cell would otherwise clip a select down to a few letters. */
td.shrink select { min-width: 150px; }

.roster-row { display: grid; grid-template-columns: 74px 1fr 34px; gap: 8px; align-items: center; margin-bottom: 6px; }

/* ----------------------------------------------------------- asset picker */

.asset-picker { display: flex; align-items: center; gap: 10px; }

.asset-preview {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg) repeating-conic-gradient(#1a1f27 0% 25%, #12161c 0% 50%) 50% / 14px 14px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
}

.asset-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; }

.media-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--panel-2);
  text-align: center;
  cursor: pointer;
}

.media-item:hover { border-color: var(--accent); }
.media-item.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47, 129, 247, 0.3); }
.media-item .thumb { height: 78px; display: grid; place-items: center; margin-bottom: 8px; }
.media-item .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.media-item .fn { font-size: 11px; color: var(--muted); word-break: break-all; }

/* ---------------------------------------------------------------- preview */

.preview-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0a0d11 repeating-conic-gradient(#151a21 0% 25%, #0f1319 0% 50%) 50% / 28px 28px;
  overflow: hidden;
}

.preview-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

.url-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.url-box code { flex: 1; font-family: var(--mono); font-size: 12.5px; word-break: break-all; color: #9fd0ff; }

/* ----------------------------------------------------------------- toast */

#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }

.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toast-in 200ms ease both;
  max-width: 360px;
}

.toast.err { border-left-color: var(--live); }
.toast.ok { border-left-color: var(--ok); }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- dialog */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 90;
  padding: 20px;
}

.dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  width: min(680px, 100%);
  max-height: 86vh;
  overflow: auto;
}

.dialog h2 { font-size: 18px; margin-bottom: 14px; }

/* --------------------------------------------------------------- offline */

.offline-banner {
  background: rgba(210, 153, 34, 0.16);
  border: 1px solid var(--warn);
  color: #f0c674;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 14px;
}
