/* Base tokens and components are shared with Upload Assistant so the two
   tools look like one family. SightGlass-specific pieces follow below. */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1c2330;
  --muted: #5b6472;
  --line: #dde2e9;
  --accent: #2456d6;
  --accent-ink: #ffffff;
  --ok: #1a7f4b;
  --err: #c0392b;
  --placeholder: #a9b1bd;
  /* Heat ramps: retention lost (warm) and regained by rewatches (cool),
     diverging from a neutral grey, so "nothing happened" reads as no colour. */
  --heat-0: #eef1f5;
  --heat-drop-1: #f6c9a6;
  --heat-drop-2: #e3825c;
  --heat-drop-3: #c0392b;
  --heat-gain-3: #2456d6;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
.wrap { max-width: 980px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
/* The analysis page needs the room for transcript + retention graph. */
.wrap.wide { max-width: 1240px; }
header.site { margin-bottom: 1.5rem; }
header.site h1 { margin: 0; font-size: 1.6rem; flex: 1 1 auto; min-width: 0; }
header.site p { margin: .25rem 0 0; color: var(--muted); }
.site-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.site-title-row .btn { flex: 0 0 auto; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.card-head h2 { margin: 0; }
label.field { display: block; margin-bottom: 1rem; font-weight: 600; font-size: .9rem; }
label.field input[type="text"],
label.field input[type="url"],
label.field input[type="password"] {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .5rem .65rem;
  font: inherit;
  font-weight: 400;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
::placeholder { color: var(--placeholder); opacity: 1; font-weight: 400; }

button, .btn {
  display: inline-block;
  font: inherit;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 6px;
  padding: .55rem 1.1rem;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
button.secondary, .btn.secondary {
  background: #fff;
  color: var(--accent);
}
/* Secondary buttons fill blue on hover so a click is unmistakable. */
button:hover:not(:disabled), .btn:hover {
  background: #1c46b0;
  border-color: #1c46b0;
  color: #fff;
}
button:active:not(:disabled), .btn:active {
  background: #16358f;
  border-color: #16358f;
  color: #fff;
  transform: translateY(1px);
}
button:focus-visible, .btn:focus-visible {
  outline: 3px solid rgba(36, 86, 214, .35);
  outline-offset: 2px;
}
button:disabled { opacity: .5; cursor: default; }
button.small, .btn.small { padding: .3rem .7rem; font-size: .82rem; }
/* Destructive secondary: outlined red, fills red on hover — same treatment as
   Upload Assistant's link-warning button. */
button.danger {
  background: #fff;
  border-color: var(--err);
  color: var(--err);
}
button.danger:hover:not(:disabled) {
  background: var(--err);
  border-color: var(--err);
  color: #fff;
}
button.danger:active:not(:disabled) { background: #8c2818; border-color: #8c2818; }
.toolbar { display: flex; gap: .5rem; margin: .5rem 0 0; flex-wrap: wrap; align-items: center; }

.error {
  background: #fdecea;
  border: 1px solid #f5c6c1;
  color: var(--err);
  border-radius: 8px;
  padding: .75rem 1rem;
  margin-bottom: 1rem;
}
.success {
  background: #eaf7ee;
  border: 1px solid #bfe3c9;
  color: var(--ok);
  border-radius: 8px;
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
}
.warn {
  background: #fff8e6;
  border: 1px solid #f0d9a0;
  color: #8a6100;
  border-radius: 8px;
  padding: .7rem .9rem;
  margin-bottom: 1rem;
  font-size: .88rem;
}
.warn code { font-size: .82rem; }
.note {
  background: #eef4ff;
  border: 1px solid #cfdefb;
  color: #23438f;
  border-radius: 8px;
  padding: .7rem .9rem;
  margin-bottom: 1rem;
  font-size: .88rem;
}
.formerror {
  background: #fdecea;
  border: 1px solid #f5c6c1;
  color: var(--err);
  border-radius: 8px;
  padding: .7rem .9rem;
  margin-bottom: .9rem;
  font-size: .9rem;
  font-weight: 600;
}
.invalid, input.invalid {
  border-color: var(--err) !important;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, .12);
}
.pill {
  display: inline-flex;
  align-items: center;
  line-height: 1;
  font-size: .7rem; font-weight: 600; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: .25rem .55rem;
}
.pill-success { color: #fff; background: var(--ok); border-color: var(--ok); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
a { color: var(--accent); }

/* Progress indicator shown below the submit button while working */
.progress {
  display: flex;
  align-items: center;
  gap: .55rem;
  margin-top: .85rem;
  color: var(--muted);
  font-size: .9rem;
}
.wheel {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .wheel { animation-duration: 2.4s; }
}

/* ===================== SightGlass ===================== */

/* ---------- Index: URL entry + connected channels ---------- */
.urlrow { display: flex; gap: .6rem; align-items: stretch; }
.urlrow input {
  flex: 1 1 auto;
  min-width: 0;
  padding: .55rem .7rem;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
.urlrow button { flex: 0 0 auto; }
@media (max-width: 560px) {
  .urlrow { flex-direction: column; }
}
.chanlist { display: grid; gap: .5rem; margin-bottom: .9rem; }
.chanrow {
  display: flex;
  align-items: center;
  gap: .75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .75rem;
  background: #fff;
}
.chanrow img, .chanrow .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--heat-0);
}
.chanrow .chan-name { flex: 1 1 auto; min-width: 0; font-weight: 600; font-size: .92rem; }
.chanrow .chan-name span { display: block; font-weight: 400; font-size: .8rem; color: var(--muted); }
.chanrow form { margin: 0; }

/* ---------- Result: video header ---------- */
.video-head { display: flex; gap: 1.1rem; align-items: flex-start; }
.video-head .thumb {
  width: 196px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  object-fit: cover;
  flex: 0 0 auto;
  background: var(--heat-0);
  border: 1px solid var(--line);
}
.video-head .vh-body { flex: 1 1 auto; min-width: 0; }
.video-head h2 { margin: 0 0 .3rem; font-size: 1.2rem; line-height: 1.3; }
.video-head .meta { color: var(--muted); font-size: .88rem; margin-bottom: .55rem; }
.video-head .meta span + span::before { content: "·"; margin: 0 .45rem; }
@media (max-width: 640px) {
  .video-head { flex-direction: column; }
  .video-head .thumb { width: 100%; }
}

/* Stat tiles — label style borrowed from Upload Assistant's link chips. */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .75rem;
  margin-top: 1.1rem;
}
.stat {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem .8rem;
}
.stat-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
}
.stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .76rem; color: var(--muted); }

/* ---------- Result: timeline heat map ---------- */
.heatmap-wrap { position: relative; }
.heatmap {
  display: flex;
  gap: 2px;
  height: 44px;
}
.heatmap .cell {
  flex: 1 1 0;
  min-width: 0;
  border-radius: 2px;
  background: var(--heat-0);
  cursor: pointer;
  /* Taller invisible hit area than the thin cell itself. */
  position: relative;
}
.heatmap .cell:hover, .heatmap .cell.active { outline: 2px solid var(--ink); outline-offset: 1px; z-index: 1; }
/* Classic retention graph, directly under the heat map on the same x-axis. */
.classic {
  position: relative;
  height: 200px;
  margin-top: .6rem;
  cursor: crosshair;
}
.classic svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.chart .axis-label { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .heat-slice { stroke-width: .5; }
.chart .grid.over-heat { stroke: rgba(28, 35, 48, .1); }
.heat-axis {
  position: relative;
  height: 1.3rem;
  margin-top: .3rem;
  font-size: .75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.heat-axis span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.heat-axis span:first-child { transform: none; }
.heat-axis span:last-child { transform: translateX(-100%); }
.legend {
  display: flex;
  align-items: center;
  gap: .9rem;
  flex-wrap: wrap;
  font-size: .78rem;
  color: var(--muted);
}
.legend .ramp {
  display: inline-block;
  width: 120px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
  margin: 0 .35rem;
  background: linear-gradient(90deg, var(--heat-0), var(--heat-drop-1), var(--heat-drop-2), var(--heat-drop-3));
}
.legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: .3rem;
}

/* Hover tooltip shared by the heat map and the retention graph. */
.tip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font-size: .78rem;
  line-height: 1.35;
  padding: .4rem .55rem;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(15, 22, 33, .22);
  max-width: 360px;
  font-variant-numeric: tabular-nums;
}
.tip b { font-weight: 700; }
.tip .tip-lines {
  display: block;
  margin-top: .4rem;
  padding-top: .4rem;
  border-top: 1px solid rgba(255, 255, 255, .2);
}
.tip .tip-line { display: block; color: rgba(255, 255, 255, .92); }
.tip .tip-line + .tip-line { margin-top: .3rem; }
.tip .tip-time { color: rgba(255, 255, 255, .6); margin-right: .4rem; }
.tip .tip-more { display: block; margin-top: .3rem; color: rgba(255, 255, 255, .6); }

/* Floating return button — the primary button style, lifted off the page. */
.back-to-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 30;
  box-shadow: 0 8px 22px rgba(15, 22, 33, .22);
}
@media (max-width: 560px) {
  .back-to-top { right: 1rem; bottom: 1rem; }
}
/* ---------- Result: biggest drops / rewatch spikes ---------- */
.moments { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; margin-top: 1.25rem; }
@media (max-width: 860px) { .moments { grid-template-columns: 1fr; } }
.moments h3 { margin: 0 0 .55rem; font-size: .9rem; font-weight: 700; }
.moment-list { display: grid; gap: .45rem; }
.moment {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: .7rem;
  align-items: baseline;
  text-align: left;
  width: 100%;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  padding: .45rem .7rem;
  font-weight: 400;
  font-size: .86rem;
}
.moment:hover:not(:disabled) { background: #f7f9ff; border-color: var(--line); color: var(--ink); }
.moment:active:not(:disabled) { background: #eef3ff; border-color: var(--line); color: var(--ink); }
.moment .m-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .8rem; }
.moment .m-delta { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.moment .m-text {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.moment .m-text.gap { font-style: italic; color: var(--muted); }

/* ---------- Result: transcript × retention ---------- */
/* Graph column width lives on :root because both the sticky header and the
   body grid need it, and they're siblings. */
:root { --graph-w: 240px; }
@media (max-width: 720px) { :root { --graph-w: 110px; } }
.tx {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--graph-w);
}
.tx-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--graph-w);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
}
.tx-header .cols, .tx-row {
  display: grid;
  grid-template-columns: 6px 3.6rem minmax(0, 1fr) 4.6rem;
  column-gap: .75rem;
}
.tx-header .cols { padding: .55rem 0 .45rem; }
.tx-header .cols span:last-child { text-align: right; }
.tx-axis { position: relative; }
.tx-axis span {
  position: absolute;
  bottom: .45rem;
  transform: translateX(-50%);
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.tx-lines { position: relative; }
.tx-row {
  align-items: start;
  padding: .45rem 0;
  border-bottom: 1px solid #eef1f5;
  cursor: default;
}
.tx-row:last-child { border-bottom: 0; }
.tx-row .heat {
  align-self: stretch;
  border-radius: 3px;
  background: var(--heat-0);
  margin: -.2rem 0;
}
.tx-row .time {
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-top: .1rem;
  text-decoration: none;
}
.tx-row a.time:hover { color: var(--accent); text-decoration: underline; }
.tx-row .text { font-size: .93rem; line-height: 1.5; }
.tx-row .text.gap { font-style: italic; color: var(--muted); }
.tx-row .ret { text-align: right; font-variant-numeric: tabular-nums; }
.tx-row .ret b { display: block; font-size: .95rem; line-height: 1.35; }
.tx-row .ret small { display: block; font-size: .74rem; color: var(--muted); white-space: nowrap; }
.tx-row .ret small.steep { color: var(--err); font-weight: 600; }
.tx-row .ret small.gain { color: var(--accent); font-weight: 600; }
/* Hover and the jump-to flash use an inset outline, not a background: every
   row's heat tint is an inline background that would hide either one. */
.tx-row.hover { box-shadow: inset 0 0 0 2px rgba(28, 35, 48, .45); }
.tx-row.flash { animation: flash 1.8s ease-out; }
@keyframes flash {
  0%, 40% { box-shadow: inset 0 0 0 3px var(--accent); }
  100% { box-shadow: inset 0 0 0 3px rgba(36, 86, 214, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .tx-row.flash { animation: none; box-shadow: inset 0 0 0 3px var(--accent); }
}
.tx-graph { position: relative; border-left: 1px solid var(--line); }
.tx-graph svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: #eef1f5; stroke-width: 1; }
.chart .grid.base { stroke: var(--line); }
.chart .area { fill: rgba(36, 86, 214, .08); }
.chart .curve { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; opacity: .55; }
.chart .dot { fill: var(--accent); stroke: #fff; stroke-width: 2; }
