/* SiteView technician dashboard.
   One loud element: the viewfinder with amber corner marks and the amber shutter.
   Everything else stays quiet so the live picture carries the screen. */

:root {
  color-scheme: light;
  --ground: #e4e8e7;      /* concrete */
  --surface: #ffffff;
  --surface-2: #f1f3f3;
  --ink: #15232c;         /* blue-slate */
  --ink-soft: #4d5d66;
  --line: #cdd4d4;
  --signal: #e9a100;      /* hi-vis amber: live, shutter */
  --signal-ink: #1d1600;
  --ok: #2b8656;
  --stop: #b8381f;
  --focus: #1f6fd1;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --font: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ground: #10171c;
    --surface: #18222a;
    --surface-2: #202c35;
    --ink: #e6ecee;
    --ink-soft: #9fb0b8;
    --line: #2e3c46;
    --ok: #4fbf84;
    --stop: #e8664a;
    --focus: #6aa8ff;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font: 15px/1.45 var(--font);
  color: var(--ink);
  background: var(--ground);
  font-variant-numeric: tabular-nums;
}

button, input, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.app {
  display: grid;
  grid-template-columns: 330px 1fr;
  grid-template-rows: auto 1fr;
  height: 100%;
}

/* ---------- top bar ---------- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand small { font-weight: 400; color: var(--ink-soft); margin-left: 6px; font-size: 14px; }
.topbar .spacer { flex: 1; }
.who { color: var(--ink-soft); font-size: 14px; }
.who a { color: inherit; margin-left: 10px; }

/* ---------- left rail ---------- */
.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.new-link { padding: 18px 20px 20px; border-bottom: 1px solid var(--line); }
.new-link h2, .history h2 { font-size: 15px; margin: 0 0 12px; }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 3px; }
.field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.field input:focus { background: var(--surface); }
.field input:user-invalid { border-color: var(--stop); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.primary:hover { filter: brightness(1.15); }
.btn.danger { color: var(--stop); }
.btn.block { width: 100%; }

.history { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 12px 20px; }
.history h2 { padding: 0 8px; }
.session-list { list-style: none; margin: 0; padding: 0; }
.session-list button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  width: 100%;
  text-align: left;
  padding: 10px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}
.session-list button:hover { background: var(--surface-2); }
.session-list button[aria-current="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--ink); }
.session-list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-list .meta { grid-column: 1 / -1; font-size: 13px; color: var(--ink-soft); }
.session-list .meta.by { font-size: 12px; }
.session-list .meta.by:empty { display: none; }
.empty { color: var(--ink-soft); font-size: 14px; padding: 4px 8px; }

.chip {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  align-self: center;
}
.chip.live { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.chip.pending { color: var(--ink); }

/* ---------- main stage ---------- */
.stage { min-width: 0; min-height: 0; overflow-y: auto; padding: 22px 28px 40px; }

.stage-empty {
  max-width: 46ch;
  margin: 12vh auto 0;
  color: var(--ink-soft);
}
.stage-empty h1 { color: var(--ink); font-size: 22px; margin: 0 0 8px; letter-spacing: -0.01em; }

.session-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin-bottom: 14px; }
.session-head h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.session-head .sub { color: var(--ink-soft); }
.linkish { border: 0; background: none; padding: 0; color: var(--focus); font-size: 14px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.linkbox {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.linkbox code { font-size: 15px; font-weight: 600; flex: 1 1 260px; overflow-wrap: anywhere; }
.sms-send { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex-basis: 100%; padding-top: 8px; border-top: 1px solid var(--line); }
.sms-send input {
  width: 170px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.sms-status { font-size: 13px; color: var(--ok); font-weight: 600; }

/* The viewfinder */
.viewfinder {
  position: relative;
  aspect-ratio: 16 / 9;
  max-height: 68vh;
  width: 100%;
  background: #05080a;
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.viewfinder video { width: 100%; height: 100%; object-fit: contain; display: block; background: #05080a; }
.viewfinder .mark { position: absolute; width: 34px; height: 34px; border: 0 solid rgba(255, 255, 255, 0.28); pointer-events: none; transition: border-color 0.3s; }
.viewfinder .mark.tl { top: 14px; left: 14px; border-top-width: 3px; border-left-width: 3px; }
.viewfinder .mark.tr { top: 14px; right: 14px; border-top-width: 3px; border-right-width: 3px; }
.viewfinder .mark.bl { bottom: 14px; left: 14px; border-bottom-width: 3px; border-left-width: 3px; }
.viewfinder .mark.br { bottom: 14px; right: 14px; border-bottom-width: 3px; border-right-width: 3px; }
.viewfinder.is-live .mark { border-color: var(--signal); }

.viewfinder .overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: #d9e2e6;
  font-size: 16px;
}
.viewfinder .overlay[hidden] { display: none; }
.viewfinder .readout {
  position: absolute;
  left: 60px;
  bottom: 16px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 1px 2px #000;
  display: flex;
  align-items: center;
  gap: 12px;
}
.readout .q { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
.readout .q i { width: 9px; height: 9px; border-radius: 50%; background: #8a979d; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35); }
.readout .q.good i { background: #4fbf84; }
.readout .q.fair i { background: var(--signal); }
.readout .q.poor i { background: #e8664a; }
.viewfinder .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.viewfinder .flash.go { animation: flash 0.35s ease-out; }
@keyframes flash { from { opacity: 0.7; } to { opacity: 0; } }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 14px 0 22px; }
.shutter {
  padding: 11px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--signal);
  color: var(--signal-ink);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}
.shutter:hover { filter: brightness(1.06); }
.shutter:disabled { opacity: 0.4; cursor: not-allowed; }
.shutter kbd { font: inherit; font-size: 12px; font-weight: 600; opacity: 0.7; margin-left: 6px; }
.controls .spacer { flex: 1; }

/* Snapshots */
.snaps-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.snaps-head .spacer { flex: 1; }
.snaps h2 { font-size: 15px; margin: 0; }
a.btn { text-decoration: none; color: inherit; }
a.btn.is-disabled { opacity: 0.45; }
.snap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.snap {
  display: block;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  cursor: zoom-in;
  text-align: left;
}
.snap img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface-2); }
.snap span { display: block; padding: 6px 8px; font-size: 12px; color: var(--ink-soft); }
.snap .tags { display: flex; gap: 4px; padding-top: 0; }
.snap .tags em { font-style: normal; font-weight: 600; font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--ink); }

/* Lightbox + mark-up editor */
dialog.lightbox {
  width: min(1200px, 96vw);
  max-height: 96vh;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  overflow: hidden auto;
}
dialog.lightbox::backdrop, dialog.details::backdrop { background: rgba(5, 8, 10, 0.78); }

.lb-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.lb-tools .spacer { flex: 1; }
.lb-tools.is-viewing-original .seg,
.lb-tools.is-viewing-original .swatches,
.lb-tools.is-viewing-original .btn { opacity: 0.4; pointer-events: none; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  padding: 6px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.swatches { display: inline-flex; gap: 6px; }
.swatches button {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--sw, #e5322d);
  cursor: pointer;
}
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); border-color: transparent; }

.btn.small { padding: 5px 10px; font-size: 14px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-soft); cursor: pointer; }

.lb-stage { position: relative; background: #05080a; min-height: 200px; display: grid; place-items: center; }
.lb-stage canvas {
  display: block;
  max-width: 100%;
  max-height: 62vh;
  touch-action: none;
  cursor: crosshair;
}
.lb-loading { color: #c7d2d7; margin: 0; padding: 60px 20px; }
.lb-text {
  position: absolute;
  min-width: 180px;
  padding: 2px 6px;
  border: 1px dashed rgba(255, 255, 255, 0.7);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  font-weight: 700;
  outline: none;
}

.lightbox .lb-body { padding: 12px 16px 16px; display: grid; gap: 10px; }
.lb-meta { margin: 0; font-size: 13px; color: var(--ink-soft); }
.lightbox textarea {
  width: 100%;
  min-height: 64px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  resize: vertical;
}
.lb-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.lb-actions .spacer { flex: 1; }

/* Session details dialog */
dialog.details {
  width: min(420px, 94vw);
  padding: 20px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
}
dialog.details h2 { font-size: 17px; margin: 0 0 14px; }
dialog.details .lb-actions { margin-top: 16px; }

/* Password sign-in page */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  padding: 28px 24px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.login-card h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.login-org { margin: 2px 0 20px; color: var(--ink-soft); font-size: 14px; }
.login-card .btn { margin-top: 8px; padding: 10px 14px; }
.login-error {
  margin: 0 0 14px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--stop) 12%, transparent);
  color: var(--stop);
  font-size: 14px;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--surface);
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.toast[hidden] { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .history { max-height: 260px; }
  .stage { padding: 18px 14px 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .viewfinder .flash.go { animation: none; }
  .viewfinder .mark { transition: none; }
}

[hidden] { display: none !important; }
