/* Fin-Tek Remote Assist - expert page.
   Brand colours from fin-tek.com and the Fin-Tek Ozone logo; Montserrat headings (self-hosted,
   SIL Open Font License - vendor/fonts/Montserrat-OFL.txt), system font for everything else.
   Layout: slim call bar, navy tool rail, and the video (or document) edge to edge with its
   controls floating on top, so the picture gets as much of the screen as possible. */

@font-face {
  font-family: 'Montserrat';
  font-weight: 600;
  font-display: swap;
  src: url('vendor/fonts/montserrat-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Montserrat';
  font-weight: 700;
  font-display: swap;
  src: url('vendor/fonts/montserrat-latin-700-normal.woff2') format('woff2');
}

:root {
  --brand: #114D91;        /* Fin-Tek blue (website) */
  --brand-mid: #3082BD;
  --sky: #47B2E9;          /* Fin-Tek light blue (website links) */
  --bg: #000000;
  --surface: #FFFFFF;
  --surface-2: #F4F6F8;
  --text: #020D18;
  --muted: #4A5A6A;
  --border: #D8E0E8;
  --control-border: #C9D3DD;
  --doc-bg: #E9EEF3;
  --frozen: #F0A030;       /* status colours: not brand, kept for meaning */
  --frozen-text: #1A1200;
  --ok: #2E7D32;
  --danger: #C62828;
  --rail: #114D91;
  --rail-text: #FFFFFF;
  --overlay: rgba(2, 13, 24, .66);
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #0F1F31;
    --surface-2: #142A40;
    --text: #E6EEF6;
    --muted: #9FB3C8;
    --border: #1F364F;
    --control-border: #2A4562;
    --brand: #4A90D9;
    --doc-bg: #1A2B3D;
    --ok: #3D9A43;
    --danger: #E5484D;
    --rail: #0B2A4C;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
h2, .call-title { font-family: Montserrat, "Segoe UI", system-ui, sans-serif; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button, input, select { font: inherit; color: inherit; }
button {
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 36px;
  cursor: pointer;
}
button:hover { filter: brightness(1.06); }
button:disabled { opacity: .45; cursor: default; filter: none; }
button:focus-visible, summary:focus-visible, input:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
button.accent { background: var(--frozen); border-color: var(--frozen); color: var(--frozen-text); font-weight: 700; }
input:not([type=range]):not([type=checkbox]), select {
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  padding: 5px 9px;
  min-height: 34px;
}
.muted { color: var(--muted); margin: 0 0 8px; }

/* ------------------------------------------------------------------ slim call bar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  min-height: 52px;
  padding: 4px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { height: 30px; width: auto; display: block; border-radius: 3px; }
.bar-sep { width: 1px; height: 26px; background: var(--border); }
.call { display: flex; align-items: baseline; gap: 10px; }
.call-title { font-weight: 700; font-size: 16px; color: var(--brand); }
.status { font-size: 12px; font-weight: 600; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.warn { color: #B26A00; }
.status.err { color: var(--danger); }
@media (prefers-color-scheme: dark) { .status.warn { color: #F0A030; } }

.join { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: end; }
.join label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 1px; }
.join input { width: 130px; }
body.connected .join { display: none; }
body:not(.connected) .call-only { display: none; }

.seg-group { display: flex; align-items: center; gap: 8px; }
.seg-label { font-size: 12px; font-weight: 600; color: var(--muted); }
body:not(.has-doc) .doc-only { display: none; }
.seg { display: flex; border: 2px solid var(--brand); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 32px; padding: 0 12px; background: var(--surface); color: var(--brand); font-weight: 600; }
.seg button + button { border-left: 1px solid var(--brand); }
.seg button.active { background: var(--brand); color: #fff; }
#headsetSeg button.active { background: var(--ok); color: #fff; }

.actions { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions > button { min-height: 38px; display: inline-flex; align-items: center; gap: 6px; }
.share { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.icon-btn {
  width: 38px; height: 38px; min-height: 38px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--control-border); border-radius: 8px; background: var(--surface); color: var(--muted);
  cursor: pointer;
}
#muteBtn { color: var(--text); }
#muteBtn.muted { background: var(--danger); border-color: var(--danger); color: #fff; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 300px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(2, 13, 24, .22);
}
.menu-panel h2, .settings-panel h2 { margin: 0 0 8px; font-size: 14px; font-weight: 600; color: var(--brand); }
.qr { margin-top: 10px; background: #fff; padding: 8px; border-radius: 6px; }
.qr svg { width: 100%; height: auto; display: block; }
.qr-note { margin: 6px 0 0; color: #333; font-size: 12px; text-align: center; word-break: break-all; }

/* ------------------------------------------------------------------ rail + stage */
.app { flex: 1; display: flex; min-height: 0; }

.rail {
  flex: 0 0 84px;
  background: var(--rail);
  color: var(--rail-text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0;
  overflow-y: auto;
}
.rail .tool {
  width: 68px; min-height: 52px; border: 0; border-radius: 10px; background: transparent;
  color: var(--rail-text); font-size: 11px; padding: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.rail .tool:hover { background: rgba(255, 255, 255, .12); filter: none; }
.rail .tool.active { background: #fff; color: var(--brand); font-weight: 700; }
.rail-sep { width: 48px; height: 1px; background: rgba(255, 255, 255, .25); margin: 6px 0; }
.swatches { display: grid; grid-template-columns: repeat(2, 28px); gap: 8px; justify-content: center; }
.swatch { width: 28px; height: 28px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .35); }
.swatch.active { border: 3px solid #fff; box-shadow: 0 0 0 2px var(--sky); }
.rail-width { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; margin-top: 6px; }
.rail-width input { width: 64px; }
.rail-btn { width: 68px; min-height: 40px; border: 0; background: transparent; color: var(--rail-text); font-size: 12px; }
.rail-btn:hover { background: rgba(255, 255, 255, .12); filter: none; }

.stage { position: relative; flex: 1; min-width: 0; display: flex; background: #000; }

/* Views. Single: one view fills the stage. With a document: the other view is a small window
   (.pip) in the corner; Split puts both side by side. */
.panes { position: relative; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); min-height: 0; }
body:not(.has-doc) #docCard { display: none; }
.panes.layout-both { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
.panes.pip-hidden .card.pip { display: none; }

.card { position: relative; display: flex; min-width: 0; min-height: 0; }
.card.on-headset::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 6;
  box-shadow: inset 0 0 0 3px var(--ok);
}
.card.pip {
  position: absolute; right: 16px; bottom: 16px; z-index: 10;
  width: min(384px, 34%); aspect-ratio: 16 / 9;
  border: 2px solid #fff; border-radius: 12px; overflow: hidden;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .45);
}
.card.pip .no-pip, .card.pip .placeholder small { display: none !important; }
.card:not(.pip) .pip-only { display: none !important; }

.viewport { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; }
.doc-viewport { background: var(--doc-bg); }
.viewport video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
/* Frozen still and document page: positioned (and zoomed) by layoutPane() in app.js. */
.viewport img.media { position: absolute; max-width: none; }
.ink { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.panes[data-tool="pan"] .viewport.zoomed .ink { cursor: grab; }
.viewport.panning .ink { cursor: grabbing; }
.placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 16px;
  color: #8A99A8; pointer-events: none;
}
.placeholder p { font-size: 18px; margin: 0 0 6px; }
.card.pip .placeholder p { font-size: 13px; }
.doc-viewport .placeholder { color: var(--muted); }

/* ------------------------------------------------------------------ floating controls */
.ov { position: absolute; z-index: 5; display: flex; align-items: center; gap: 6px; pointer-events: none; }
.ov > * { pointer-events: auto; }
.ov-tl { top: 10px; left: 10px; flex-wrap: wrap; max-width: calc(100% - 20px); }
.ov-tr { top: 10px; right: 10px; padding: 4px; background: var(--overlay); border-radius: 12px; }
.ov-bl { left: 10px; bottom: 10px; }
.ov-bc { left: 50%; bottom: 10px; transform: translateX(-50%); }
.ov-tr > button.accent { min-height: 38px; }
.ov-icon {
  width: 38px; height: 38px; min-height: 38px; padding: 0; border: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .16); color: #fff; cursor: pointer;
}
.card.pip .ov-tr { top: 6px; right: 6px; padding: 3px; }
.card.pip .ov-tr > button.accent { min-height: 30px; padding: 2px 10px; font-size: 12px; }
.card.pip .ov-icon { width: 30px; height: 30px; min-height: 30px; }
.card.pip .ov-tl { top: 6px; left: 6px; }
.pip-tools { display: inline-flex; gap: 4px; }

.badge {
  padding: 4px 9px; border-radius: 6px; font-weight: 700; font-size: 12px;
  letter-spacing: .03em; white-space: nowrap;
}
.badge.frozen { background: var(--frozen); color: var(--frozen-text); }
.badge.on-headset { background: var(--ok); color: #fff; letter-spacing: 0; font-weight: 600; }
.badge.live { background: var(--overlay); color: #fff; display: inline-flex; align-items: center; gap: 5px; font-size: 11px; }
.badge.live .dot { width: 7px; height: 7px; border-radius: 50%; background: #E53935; }
.chip {
  padding: 4px 10px; border-radius: 6px; background: var(--surface); color: var(--brand);
  font-weight: 600; font-size: 13px; box-shadow: 0 1px 3px rgba(2, 13, 24, .18);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48ch;
}
.stats { color: #C9D6E2; font: 12px/1.6 Consolas, monospace; background: rgba(2, 13, 24, .55); padding: 3px 8px; border-radius: 6px; }
.stats:empty { display: none; }

.pager {
  padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 1px 4px rgba(2, 13, 24, .14);
}
.pager button { min-height: 34px; border: 0; background: var(--surface-2); }
.pager #pageLabel { font-weight: 600; min-width: 100px; text-align: center; }

.zoombar {
  position: absolute; right: 10px; bottom: 10px; z-index: 5; display: flex; align-items: center; gap: 4px;
  background: rgba(2, 13, 24, .72); border-radius: 10px; padding: 4px;
}
.zoombar-left { right: auto; left: 10px; }
.zoombar button { min-height: 32px; padding: 3px 10px; min-width: 34px; border: 0; background: rgba(255, 255, 255, .14); color: #fff; }
.zoombar button.active { background: var(--brand-mid); }
.zoombar .zval { color: #fff; font: 600 12px Consolas, monospace; min-width: 40px; text-align: center; }
/* Keep the camera's zoom controls clear of the document's small window in the same corner. */
body.has-doc .panes.layout-cam:not(.pip-hidden) #camZoom { right: auto; left: 50%; transform: translateX(-50%); }

/* Camera settings pop-up (the gear-like sliders icon) */
.cam-settings { position: relative; }
.cam-settings summary { list-style: none; }
.cam-settings summary::-webkit-details-marker { display: none; }
.cam-settings[open] summary { background: var(--brand-mid); }
.settings-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; width: 300px; padding: 14px;
  background: var(--surface); color: var(--text); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
.cam-controls { display: flex; flex-direction: column; gap: 10px; }
.cam-controls .muted { margin: 0; }
.cam-controls .ctl { display: grid; grid-template-columns: 1fr; gap: 3px; }
.cam-controls .ctl label { font-size: 12px; color: var(--muted); }
.cam-controls .ctl .val { float: right; color: var(--text); font-variant-numeric: tabular-nums; }
.cam-controls select, .cam-controls input[type=range] { width: 100%; }
.cam-controls .toggle { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }

/* Brings a hidden small window back */
.pip-restore {
  position: absolute; right: 16px; bottom: 16px; z-index: 10;
  min-height: 38px; padding: 0 14px; border: 0; border-radius: 10px;
  background: var(--overlay); color: #fff; font-weight: 600;
}

.drop-hint {
  position: absolute; inset: 12px; display: flex; align-items: center; justify-content: center;
  background: rgba(17, 77, 145, .35); border: 3px dashed #fff; border-radius: 12px; color: #fff;
  font-size: 20px; font-weight: 600; pointer-events: none; z-index: 40;
}

/* Short-lived messages, bottom centre */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  max-width: min(640px, calc(100% - 32px)); margin: 0; padding: 10px 16px;
  background: #0B1A2B; color: #fff; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.toast.error { background: var(--danger); font-weight: 600; }

/* ------------------------------------------------------------------ narrow screens */
@media (max-width: 900px) {
  body { overflow: auto; }
  .app { flex-direction: column; }
  .rail { flex: 0 0 auto; flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 6px; }
  .rail .tool { width: 60px; min-height: 48px; }
  .rail-sep { width: 1px; height: 36px; margin: 0 4px; }
  .swatches { grid-template-columns: repeat(6, 28px); }
  .rail-width { margin-top: 0; }
  .panes.layout-both { grid-template-columns: minmax(0, 1fr); }
  .viewport { min-height: 56vw; }
  .card.pip { width: 46%; }
  .actions { margin-left: 0; }
}
