/* daiconnotation — dark analyst UI */
:root {
  --bg: #101216;
  --panel: #181b21;
  --panel-2: #1f242c;
  --line: #2a303a;
  --text: #e8e6e1;
  --dim: #98a1ad;
  --accent: #ff5a36;
  --accent-soft: #ff5a3626;
  --gold: #ffb02e;
  --good: #3fb950;
  --bad: #f85149;
  --radius: 8px;
  font-size: 15px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win — even over classes that set their
   own display (e.g. flex/grid rows that are admin-only). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  min-height: 100vh;
}

h1, h2 { margin: 0; font-weight: 650; }
button { font: inherit; }
kbd {
  font-family: ui-monospace, Consolas, monospace;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 0.85em;
}

.dim { color: var(--dim); font-size: 0.86rem; }
.accent { color: var(--accent); }
.error { color: var(--bad); font-size: 0.9rem; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 1.15rem; letter-spacing: 0.02em; white-space: nowrap; }

.search-wrap { position: relative; flex: 1; max-width: 420px; }
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 320px;
  overflow: auto;
  z-index: 30;
  box-shadow: 0 8px 24px #0009;
}
.search-results button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
}
.search-results button:hover, .search-results button:focus-visible { background: var(--accent-soft); }
.search-results .syn { color: var(--dim); font-size: 0.82rem; }

.topbar-actions { display: flex; gap: 8px; margin-left: auto; }

/* ------------------------------------------------------------------ inputs */
input, select {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 10px;
  width: 100%;
}
input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--dim); }
button.ghost { background: transparent; }
button.accent-btn { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.accent-btn:hover { filter: brightness(1.1); }
button.danger { color: var(--bad); }
button.danger:hover { border-color: var(--bad); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 1px 7px;
  margin-left: 4px;
}

/* ------------------------------------------------------------------ layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  align-items: start;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

.video-pane, .frame-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

/* ------------------------------------------------------------------ video */
video-player {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  /* Video.js 10 skin theming hooks */
  --media-accent-color: var(--accent);
  --media-accent-text-color: #fff;
  --media-border-radius: var(--radius);
}
video-player video {
  display: block;
  width: 100%;
  height: auto;
}

.marker-bar {
  position: relative;
  height: 16px;
  margin: 8px 2px 2px;
  border-radius: 4px;
  background: var(--panel-2);
  cursor: pointer;
}
.marker-bar .tick {
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 2px;
  margin-left: -1px;
  background: #4a5260;
  border-radius: 1px;
}
.marker-bar .tick.annotated { top: 1px; bottom: 1px; background: var(--gold); }
.marker-bar .tick.current { background: var(--accent); width: 3px; }
.marker-bar .tick:hover { background: var(--accent); }

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.time-readout {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.95rem;
  background: var(--panel-2);
  border-radius: 6px;
  padding: 4px 8px;
}
.keys-hint { margin-left: auto; }

/* ------------------------------------------------------------------ frame */
.frame-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.frame-time { font-family: ui-monospace, Consolas, monospace; font-size: 1rem; }
.frame-head-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.frame-stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  user-select: none;
}
.frame-stage img { display: block; width: 100%; height: auto; }
.frame-stage svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.frame-stage.drawing { cursor: crosshair; }

.frame-stage svg .poly {
  fill: #ffffff00;
  stroke: var(--gold);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  pointer-events: visible; /* catch clicks on the transparent fill too */
  transition: fill 120ms;
}
.frame-stage svg .poly:hover { fill: #ffb02e2e; }
.frame-stage svg .poly.selected { stroke: var(--accent); fill: #ff5a3630; }
.frame-stage.drawing svg .poly { pointer-events: none; }

.frame-stage svg .draft {
  fill: #ff5a361a;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.frame-stage svg .vertex {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  cursor: grab;
}
.frame-stage svg .vertex.first { fill: var(--gold); }

.draw-hint {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: #000c;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.8rem;
  pointer-events: none;
}

/* --------------------------------------------------------------- polygon panel */
.polygon-panel { margin-top: 12px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 1rem; }
.panel-actions { display: flex; gap: 6px; }

.connection-list {
  list-style: none;
  margin: 10px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.connection {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
}
.connection .score {
  min-width: 42px;
  text-align: center;
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 700;
  border-radius: 6px;
  padding: 2px 6px;
  background: var(--bg);
}
.connection .score.pos { color: var(--good); }
.connection .score.neg { color: var(--bad); }
.connection .votes { display: flex; flex-direction: column; gap: 2px; }
.connection .vote {
  padding: 0 7px;
  line-height: 1.25;
  font-size: 0.8rem;
  border-radius: 5px;
}
.connection .vote.mine.up { background: var(--good); border-color: var(--good); color: #04140a; }
.connection .vote.mine.down { background: var(--bad); border-color: var(--bad); color: #190405; }
.connection .term-link {
  background: none;
  border: 0;
  color: var(--text);
  font-size: 0.98rem;
  cursor: pointer;
  text-align: left;
  padding: 2px 4px;
  flex: 1;
}
.connection .term-link:hover { color: var(--accent); text-decoration: underline; }
.connection .counts { font-size: 0.78rem; color: var(--dim); white-space: nowrap; }

.chip {
  font-size: 0.72rem;
  border-radius: 999px;
  padding: 1px 8px;
  border: 1px solid var(--line);
  color: var(--dim);
  white-space: nowrap;
}
.chip.pending { border-color: var(--gold); color: var(--gold); }
.chip.new { border-color: var(--accent); color: var(--accent); }

.panel-foot { display: flex; gap: 8px; flex-wrap: wrap; }

/* ----------------------------------------------------------------- dialogs */
.dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  width: min(440px, 92vw);
  box-shadow: 0 16px 48px #000c;
}
.dialog.wide { width: min(640px, 94vw); }
.dialog::backdrop { background: #000a; }
.dialog h2 { font-size: 1.05rem; margin-bottom: 4px; }
.dialog label { display: block; margin: 10px 0; font-size: 0.9rem; }
.dialog label input { margin-top: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.dialog-close { padding: 2px 9px; }
.dialog input[type="search"] { margin-bottom: 10px; }

.term-create { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 12px; }
@media (max-width: 640px) { .term-create { grid-template-columns: 1fr; } }

.terms-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 46vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.terms-list li {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.terms-list .term-name {
  background: none;
  border: 0;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: 0.95rem;
}
.terms-list .term-name:hover { color: var(--accent); }
.terms-list .syns { color: var(--dim); font-size: 0.82rem; flex: 1; }
.terms-list .uses { color: var(--dim); font-size: 0.78rem; white-space: nowrap; }
.terms-list .row-actions { display: flex; gap: 4px; }
.terms-list .row-actions button { padding: 2px 8px; font-size: 0.8rem; }
.terms-list.compact li { padding: 6px 10px; }

.syn-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.78rem;
  margin: 2px 3px 2px 0;
}
.syn-chip button {
  background: none;
  border: 0;
  color: var(--dim);
  cursor: pointer;
  padding: 0 2px;
  font-size: 0.8rem;
}
.syn-chip button:hover { color: var(--bad); }

.pending-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; }
.pending-list li {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.pending-list .jump {
  background: none;
  border: 0;
  color: var(--gold);
  cursor: pointer;
  font-family: ui-monospace, Consolas, monospace;
  padding: 0;
}
.pending-list .jump:hover { text-decoration: underline; }
.pending-list .row-actions { margin-left: auto; display: flex; gap: 6px; }

.turnstile-dialog { width: auto; }
#turnstileContainer { min-height: 68px; display: grid; place-items: center; margin: 10px 0; }

/* suggest dialog */
#suggestNewWrap {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
#suggestNewWrap summary {
  cursor: pointer;
  color: var(--dim);
}
#suggestNewWrap summary:hover { color: var(--text); }
#suggestNewForm {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

/* ------------------------------------------------------- admin login page */
.admin-login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px;
  width: min(360px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { font-size: 1.15rem; }
.login-card form { display: flex; flex-direction: column; gap: 4px; }
.login-card form button { margin-top: 10px; }
.login-card a { color: var(--accent); text-decoration: none; }
.login-card a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ toasts */
.toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  align-items: center;
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 8px 16px;
  box-shadow: 0 8px 24px #000a;
  animation: toast-in 160ms ease-out;
  max-width: 80vw;
}
.toast.ok { border-left-color: var(--good); }
.toast.err { border-left-color: var(--bad); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
