/* ===========================================================================
   Pact — control surface
   One accent colour, and it means something: #E8402A marks a live feed.
   =========================================================================== */

:root {
  --ground:    #12161c;
  --panel:     #1a1f28;
  --raised:    #222a35;
  --hairline:  #2b3442;
  --hairline-2:#3a4555;

  --bone:      #e9e6e0;
  --dim:       #808b99;
  --dimmer:    #4d5663;

  --tally:     #e8402a;
  --seal:      #9e3340;
  --ok:        #5fd4a8;

  --rail: 232px;
  --bar: 52px;

  --ui: "Saira", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ground);
  color: var(--bone);
  font-family: var(--ui);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Grain. Low enough to read as texture on a monitor, not as an effect. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

:focus-visible {
  outline: 1px solid var(--ok);
  outline-offset: 2px;
}

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

.shell {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  grid-template-rows: var(--bar) 1fr;
  grid-template-areas: "bar bar" "rail wall";
  height: 100%;
}

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

.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  border-bottom: 1px solid var(--hairline);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--bone);
}

.brand svg { display: block; }

.brand b {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.055em;
}

.bar-stats {
  display: flex;
  gap: 18px;
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.bar-stats i { font-style: normal; color: var(--bone); }

/* ------------------------------------------------------------------ rail -- */

.rail {
  grid-area: rail;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--hairline);
  background: var(--panel);
  min-height: 0;
}

.rail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--dim);
}

.rail-head span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dimmer);
  font-variant-numeric: tabular-nums;
}

.rail-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0 8px;
  margin: 0;
  list-style: none;
}

.rail-item {
  display: grid;
  grid-template-columns: 7px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 2px;
  cursor: pointer;
  color: var(--bone);
}

.rail-item:hover { background: var(--raised); }

.rail-item[aria-selected="true"] {
  background: var(--raised);
  box-shadow: inset 2px 0 0 var(--tally);
}

.rail-item .led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tally);
  box-shadow: 0 0 7px -1px var(--tally);
}

.rail-item .nm {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-item .el {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.rail-empty {
  padding: 10px 16px;
  font-size: 12.5px;
  color: var(--dimmer);
  line-height: 1.5;
}

.rail-foot {
  padding: 12px;
  border-top: 1px solid var(--hairline);
}

/* --------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--hairline-2);
  border-radius: 2px;
  background: var(--raised);
  color: var(--bone);
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn:hover { border-color: var(--dim); background: #27303c; }

.btn-primary {
  background: var(--seal);
  border-color: var(--seal);
  color: #fff;
}

.btn-primary:hover { background: #b23a48; border-color: #b23a48; }

.btn-ghost {
  width: auto;
  background: transparent;
  border-color: var(--hairline-2);
}

/* ------------------------------------------------------------------ wall -- */

.wall {
  grid-area: wall;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  grid-auto-rows: min-content;
  gap: 14px;
  align-content: start;
}

/* ------------------------------------------------------------------ tile -- */

.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0c1014;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  overflow: hidden;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #0c1014;
}

/* Burnt-in clock, the way an NVR overlays it on the image itself. */
.tile .clock {
  position: absolute;
  top: 7px;
  right: 9px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: rgba(233, 230, 224, 0.82);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* Under-monitor display: channel, name, tally. Borrowed from multiviewers. */
.tile .umd {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  background: linear-gradient(to top, rgba(8, 11, 14, 0.94), rgba(8, 11, 14, 0));
}

.tile .ch {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.tile .nm {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile .kind {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dimmer);
  margin-left: auto;
}

.tile .tally {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tally);
  box-shadow: 0 0 8px -1px var(--tally);
  flex: none;
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  50% { opacity: 0.45; }
}

/* Brackets appear on the tile you are pointing at, not on all of them. */
.tile::before,
.tile::after {
  content: "";
  position: absolute;
  width: 13px;
  height: 13px;
  opacity: 0;
  transition: opacity 120ms ease;
  pointer-events: none;
  z-index: 2;
}

.tile::before {
  top: 5px; left: 5px;
  border-top: 1px solid var(--tally);
  border-left: 1px solid var(--tally);
}

.tile::after {
  bottom: 5px; right: 5px;
  border-bottom: 1px solid var(--tally);
  border-right: 1px solid var(--tally);
}

.tile:hover::before,
.tile:hover::after { opacity: 1; }

.tile.connecting video { opacity: 0.25; }

/* --------------------------------------------------- no signal / slots --- */

/* A dead channel on a real wall is not blank. It shows you it is dead. */
.slot {
  position: relative;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  overflow: hidden;
  background:
    repeating-linear-gradient(
      -45deg,
      transparent 0 9px,
      rgba(123, 136, 153, 0.045) 9px 18px
    ),
    #0e1217;
  display: grid;
  place-items: center;
}

.slot::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 44px;
  background: linear-gradient(
    to bottom,
    transparent,
    rgba(123, 136, 153, 0.05),
    transparent
  );
  animation: sweep 7s linear infinite;
}

@keyframes sweep {
  from { top: -44px; }
  to   { top: 100%; }
}

.slot span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dimmer);
  letter-spacing: 0.1em;
  z-index: 1;
}

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

dialog {
  padding: 0;
  border: 1px solid var(--hairline-2);
  border-radius: 3px;
  background: var(--panel);
  color: var(--bone);
  max-width: 400px;
  width: calc(100% - 32px);
}

dialog::backdrop { background: rgba(6, 8, 11, 0.74); }

.dlg {
  padding: 22px;
  text-align: center;
}

.dlg h2 {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.dlg p {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--dim);
  line-height: 1.55;
}

.qr {
  width: 188px;
  height: 188px;
  margin: 0 auto 16px;
  padding: 11px;
  background: #fff;
  border-radius: 2px;
}

.qr canvas, .qr img { display: block; width: 100%; height: 100%; }

.code {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  margin-bottom: 6px;
}

.join-url {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--dim);
  word-break: break-all;
  margin-bottom: 18px;
}

.dlg-actions { display: flex; gap: 8px; }

/* ------------------------------------------------------------ join page -- */

body.join {
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 28px 20px;
}

.join-card {
  width: 100%;
  max-width: 460px;
}

.join-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 26px;
}

.join-head b {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.055em;
}

.join-card h1 {
  margin: 0 0 7px;
  font-size: 25px;
  font-weight: 500;
  letter-spacing: -0.012em;
  line-height: 1.2;
}

.join-card > p {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--dim);
  line-height: 1.55;
  max-width: 46ch;
}

.preview {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0c1014;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 14px;
}

.preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dimmer);
  letter-spacing: 0.1em;
  background:
    repeating-linear-gradient(
      -45deg,
      transparent 0 9px,
      rgba(123, 136, 153, 0.045) 9px 18px
    );
}

.field { margin-bottom: 12px; }

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  background: var(--ground);
  border: 1px solid var(--hairline-2);
  border-radius: 2px;
  color: var(--bone);
  font-family: var(--ui);
  font-size: 14px;
}

.field input:focus-visible { border-color: var(--ok); outline: none; }

.sources { display: flex; gap: 8px; margin-bottom: 14px; }

.sources .btn { flex: 1; }

.sources .btn[aria-pressed="true"] {
  border-color: var(--bone);
  background: #2b3542;
}

.status {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--dim);
  margin-top: 13px;
  min-height: 1.4em;
  line-height: 1.5;
}

.status.live { color: var(--tally); }
.status.err  { color: #ff8a7a; }

.live-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border: 1px solid var(--tally);
  border-radius: 2px;
  background: rgba(232, 64, 42, 0.07);
  margin-bottom: 14px;
}

.live-banner .tally {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--tally);
  box-shadow: 0 0 8px -1px var(--tally);
  flex: none;
  animation: breathe 2.4s ease-in-out infinite;
}

.live-banner div { font-size: 13px; }
.live-banner small { display: block; color: var(--dim); font-size: 12px; }

.notice {
  padding: 12px 14px;
  border: 1px solid var(--hairline-2);
  border-left: 2px solid var(--seal);
  border-radius: 2px;
  background: var(--panel);
  font-size: 13px;
  color: var(--dim);
  line-height: 1.55;
  margin-bottom: 16px;
}

.notice b { color: var(--bone); font-weight: 500; }

.notice code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--bone);
}

/* --------------------------------------------------------------- mobile -- */

@media (max-width: 760px) {
  body { overflow: auto; }

  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--bar) auto 1fr;
    grid-template-areas: "bar" "rail" "wall";
    height: auto;
    min-height: 100%;
  }

  .rail { border-right: 0; border-bottom: 1px solid var(--hairline); }
  .rail-list { max-height: 180px; }
  .wall { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
