/* ============================================================
   VESPA Annotator — dark theme stylesheet
   bg #1e1e1e · text #ddd · accent #4da3ff
   ============================================================ */

:root {
  --bg:        #1e1e1e;
  --bg-panel:  #252526;
  --bg-raised: #2d2d30;
  --bg-hover:  #37373d;
  --border:    #3c3c3c;
  --text:      #ddd;
  --text-dim:  #888;
  --accent:    #4da3ff;
  --accent-dim:#2a5d94;
  --green:     #4caf50;
  --amber:     #e6b422;
  --red:       #e05252;
  /* face pose + off-screen lane — kept in step with the canvas colours in
     timeline.js (COL_POSE / COL_POSE_MISSING / COL_OFFSCREEN) */
  --pose-frontal: #7fd1ff;
  --pose-profile: #e07be0;
  --pose-missing: #ff9f43;
  --offscreen:    #b48ce0;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, "Liberation Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
  display: grid;
  grid-template-rows: auto 1fr 240px;  /* toolbar / middle / timeline */
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------------- generic controls ---------------- */

.btn {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.btn:hover   { background: var(--bg-hover); border-color: #555; }
.btn:active  { background: #1b1b1c; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn-accent {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.btn-accent:hover { background: #33689f; }

.btn-small { padding: 2px 8px; font-size: 12px; }

select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
}
select:hover { border-color: #555; }
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input[type="text"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-family: var(--font);
  font-size: 13px;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); }

input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* file inputs hidden inside styled label-buttons */
.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.file-btn:hover { background: var(--bg-hover); border-color: #555; }
.file-btn:active { background: #1b1b1c; }
.file-btn input[type="file"] {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
.file-btn-icon { font-size: 13px; }

kbd {
  background: var(--bg-raised);
  border: 1px solid #4a4a4a;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

/* ---------------- toolbar ---------------- */

#toolbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  min-height: 42px;
  flex-wrap: wrap;
  position: relative;
  z-index: 10;
}

.toolbar-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 2px;
}

.toolbar-spacer { flex: 1; }

#clip-select { max-width: 250px; }

.annotator-label { color: var(--text-dim); }
#annotator { width: 110px; }

/* Skip: lit amber while this clip is flagged unusable */
#btn-skip.btn-skipped {
  background: var(--amber);
  border-color: var(--amber);
  color: #111;
  font-weight: 600;
}
#btn-skip.btn-skipped:hover { background: #f0c344; }

#status-bar {
  /* grows into free toolbar space, but never squeezes below a readable 160px —
     below that it wraps onto its own row rather than truncating to "Cli…" */
  flex: 1 1 160px;
  min-width: 0;
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
}
#status-bar.status-info  { color: var(--accent); }
#status-bar.status-warn  { color: var(--amber); }
#status-bar.status-error { color: var(--red); }

#btn-help { font-weight: 700; min-width: 30px; }

/* ---------------- action bar (vertical tool column) ---------------- */

#actionbar {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 9px 8px 12px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.act-group {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--border);
}
.act-group:last-child { border-bottom: none; padding-bottom: 0; }

/* icon pairs and In/Out sit side by side rather than eating a row each */
.act-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.act-row > .btn.act { flex: 1; }
.act-row > .btn.act.act-icon { flex: 0 0 auto; }

.act-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--text-dim);
  user-select: none;
  padding-bottom: 1px;
}

.btn.act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 12px;
  text-align: left;
}
/* the shortcut hugs the right edge, so the column reads as one aligned list */
.btn.act > kbd { margin-left: auto; }
.btn.act.act-icon {
  padding: 4px 6px;
  justify-content: center;
  gap: 4px;
}
.btn.act.act-icon > kbd { margin-left: 2px; }

/* the shortcut printed on the button — a hint, not a separate control */
.btn.act kbd {
  font-size: 10px;
  padding: 0 4px;
  border-width: 1px;
  border-color: #4a4a4a;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-dim);
}

.btn.act.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}
.btn.act.active kbd {
  color: rgba(255, 255, 255, 0.85);
  border-color: rgba(255, 255, 255, 0.35);
}

#act-rec.active {
  background: var(--red); border-color: var(--red); color: #111;
}
#act-rec.active kbd {
  color: rgba(0, 0, 0, 0.65);
  border-color: rgba(0, 0, 0, 0.35);
  background: rgba(255, 255, 255, 0.25);
}

.act-edge-glyph { font-size: 9px; color: #7fd1ff; }

.act-range {
  flex: 1;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  min-width: 0;
  text-align: center;
  padding: 3px 6px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.act-range.act-range-set {
  color: var(--accent);
  border-style: solid;
  border-color: var(--accent-dim);
}

.act-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.45);
}
.act-lab-1 .act-swatch { background: var(--green); }
.act-lab-0 .act-swatch { background: #4a4a4a; }
.act-lab-2 .act-swatch { background: var(--amber); }
.act-pose-f .act-swatch { background: var(--pose-frontal); }
.act-pose-p .act-swatch { background: var(--pose-profile); }

/* pose readout echoes the timeline's pose strip colours */
#act-pose-state.pose-frontal { color: var(--pose-frontal); border-color: var(--pose-frontal); border-style: solid; }
#act-pose-state.pose-profile { color: var(--pose-profile); border-color: var(--pose-profile); border-style: solid; }
#act-pose-state.pose-unset   { color: var(--pose-missing); border-color: var(--pose-missing); border-style: dashed; }

#act-offscreen.btn.act { border-color: #6b4f8f; }
#act-offscreen.btn.act:hover { border-color: var(--offscreen); }

/* ---------------- restore banner ---------------- */

#restore-banner {
  position: absolute;
  top: 54px;   /* just under the toolbar */
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--amber);
  border-radius: 6px;
  padding: 8px 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
.restore-msg { color: var(--amber); }

/* ---------------- middle region ---------------- */

#middle {
  grid-row: 2;
  display: grid;
  grid-template-columns: 176px 258px 1fr;  /* tools / tracks / video */
  min-height: 0;
  overflow: hidden;
}

/* narrow windows: drop the track panel to its own scroll rather than
   squeezing the video to nothing */
@media (max-width: 1180px) {
  #middle { grid-template-columns: 168px 214px 1fr; }
}

/* ---------------- sidebar ---------------- */

#sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-controls {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 0 0 auto;
}

.ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctrl-row > label { color: var(--text-dim); flex: 0 0 auto; }
.ctrl-row input[type="range"] { flex: 1; min-width: 0; }
.ctrl-row select { flex: 1; }

.ctrl-value {
  font-family: var(--mono);
  font-size: 11px;
  min-width: 28px;
  text-align: right;
  color: var(--text);
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.ctrl-buttons { justify-content: space-between; }

/* track list */

.track-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.track-list-empty {
  padding: 16px 10px;
  color: var(--text-dim);
  text-align: center;
  font-style: italic;
}

.track-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  cursor: pointer;
  border-left: 3px solid transparent;
  user-select: none;
  white-space: nowrap;
}
.track-row:hover { background: var(--bg-hover); }

.track-row.selected {
  background: var(--accent-dim);
  border-left-color: var(--accent);
}

.track-chip {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.4);
}

.track-id {
  font-family: var(--mono);
  font-weight: 600;
  min-width: 40px;
}

.track-meta {
  flex: 1;
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}
.track-meta.needs-pose { color: var(--pose-missing); }

/* the off-screen lane is not a face: mark it as the odd row out */
.track-row.offscreen .track-id { color: var(--offscreen); }
.track-row.offscreen { border-bottom: 1px solid var(--border); }

/* ---------------- video area ---------------- */

#main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#video-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #131313;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#video {
  max-width: 100%;
  max-height: 100%;
  display: block;
  background: #000;
}

#overlay {
  position: absolute;
  left: 0;
  top: 0;
  /* overlay.js positions/sizes this over the displayed video rect */
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
  text-align: center;
  padding: 20px;
}
.empty-glyph { font-size: 42px; opacity: 0.4; }
.empty-title { font-size: 16px; color: var(--text-dim); }
#video-hint  { font-family: var(--mono); font-size: 12px; color: var(--accent); }
#video-note  { font-size: 12px; color: var(--text-dim); }

/* ---------------- transport ---------------- */

#transport {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}

#btn-play {
  min-width: 38px;
  font-size: 14px;
}

#fid-readout {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}

.rate-label { color: var(--text-dim); }
#rate-select { width: 76px; }

/* ---------------- timeline ---------------- */

#timeline-wrap {
  grid-row: 3;
  position: relative;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  overflow: hidden;
  min-height: 0;
}

#timeline {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#tl-tooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  max-width: 340px;
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  white-space: pre-line;
}

/* ---------------- help overlay ---------------- */

#help-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.help-modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  max-width: 940px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 26px 24px;
}

.help-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.help-header h2 { font-size: 17px; font-weight: 600; color: var(--accent); }
.help-close-hint { font-size: 12px; color: var(--text-dim); }
.help-note {
  font-size: 12px;
  color: var(--text-dim);
  margin: -4px 0 14px;
  max-width: 60ch;
}

.help-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 36px;
  align-items: start;
}

.help-table {
  border-collapse: collapse;
  width: 100%;
}
.help-table th {
  text-align: left;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 12px 0 4px;
  border-bottom: 1px solid var(--border);
}
.help-table tr:first-child th { padding-top: 0; }
.help-table td {
  padding: 4px 0;
  vertical-align: top;
}
.help-table td:first-child {
  width: 44%;
  padding-right: 14px;
  white-space: nowrap;
}
.help-table td:last-child { color: var(--text); }

@media (max-width: 900px) {
  .help-columns { grid-template-columns: 1fr; }
}

/* ---------------- scrollbars (webkit) ---------------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: #454545;
  border-radius: 5px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #555; }
