:root {
  color-scheme: light;
  --ink: #20242a;
  --muted: #667085;
  --line: #d8dee7;
  --surface: #ffffff;
  --subtle: #f4f6f8;
  --accent: #087f5b;
  --accent-soft: #dff3eb;
  --blue: #1769aa;
  --watched: #2b8a3e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: #f6f7f9;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, select, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.page-header {
  padding: 20px clamp(14px, 3vw, 34px);
  background: #20242a;
  color: #fff;
}
.header-inner {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}
.page-header h1 { margin: 0; font-size: 24px; letter-spacing: 0; }
.page-header p { margin: 5px 0 0; color: #cbd1d8; font-size: 13px; }
.data-updated-label { color: #aeb6c0; font-size: 12px; white-space: nowrap; }

main { width: 100%; padding: 20px clamp(12px, 2vw, 28px) 36px; }
section { margin-bottom: 24px; }
h2 { margin: 0; font-size: 18px; letter-spacing: 0; }

.viewer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.mode-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  min-width: 260px;
  padding: 3px;
  border: 1px solid #bdc7d3;
  border-radius: 7px;
  background: #e9edf2;
}
.mode-button {
  min-height: 36px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #4a5563;
  cursor: pointer;
  font-weight: 700;
}
.mode-button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.14);
}
.history-actions { display: flex; align-items: center; gap: 10px; }
.unwatched-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  color: #344054;
  font-size: 13px;
  cursor: pointer;
}
.unwatched-toggle input { width: 17px; height: 17px; accent-color: var(--accent); }
.secondary-button {
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid #c9d1dc;
  border-radius: 6px;
  background: var(--surface);
  color: #344054;
  cursor: pointer;
}
.secondary-button:hover { background: #f0f3f6; }
.compact-button { min-height: 30px; padding: 4px 9px; font-size: 12px; }

.top-panel {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) minmax(500px, 1fr);
  gap: 18px;
  align-items: start;
}
.summary-section, .filter-section { min-width: 0; }
.summary-section h2, .filter-section h2 { margin-bottom: 10px; }
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 8px;
}
.summary-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}
.summary-label { color: var(--muted); font-size: 12px; }
.summary-value {
  min-height: 32px;
  margin-top: 3px;
  font-size: 23px;
  font-weight: 750;
  white-space: nowrap;
}
.summary-progress, .mobile-cell-progress {
  overflow: hidden;
  background: #e5e9ef;
}
.summary-progress { height: 4px; margin-top: 6px; border-radius: 2px; }
.summary-progress span, .mobile-cell-progress span {
  display: block;
  height: 100%;
  background: var(--watched);
}

.filter-controls {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-control {
  display: grid;
  min-width: 0;
  gap: 5px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: #475467;
  font-size: 12px;
}
#teamFilterControl { flex: 0 1 160px; }
.filter-control-streamer { flex: 0 1 190px; }
.date-range-control {
  flex: 1 1 300px;
  min-width: 300px;
}
.filter-controls select {
  width: 100%;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid #cbd3dd;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
}
.date-range-heading, .date-range-values, .date-range-action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.date-range-heading strong { color: var(--ink); font-size: 13px; }
.date-range-values { color: var(--muted); font-size: 11px; }
.date-range-values strong { color: #344054; }
.dual-range {
  --start-pct: 0%;
  --end-pct: 100%;
  position: relative;
  flex: 1;
  min-width: 170px;
  height: 30px;
}
.dual-range-track, .dual-range-fill {
  position: absolute;
  top: 12px;
  height: 5px;
  border-radius: 3px;
  pointer-events: none;
}
.dual-range-track { left: 0; right: 0; background: #d5dbe3; }
.dual-range-fill {
  left: var(--start-pct);
  right: calc(100% - var(--end-pct));
  background: var(--blue);
}
.dual-range-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 30px;
  margin: 0;
  appearance: none;
  background: transparent;
  pointer-events: none;
}
.dual-range-input::-webkit-slider-runnable-track { height: 5px; background: transparent; }
.dual-range-input::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
  margin-top: -6px;
  appearance: none;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  pointer-events: auto;
}
.dual-range-input::-moz-range-track { height: 5px; background: transparent; }
.dual-range-input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  pointer-events: auto;
}
.dual-range-input-start { z-index: 3; }
.dual-range-input-end { z-index: 4; }

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.matrix-status { color: var(--muted); font-size: 12px; }
.mobile-heading-meta {
  display: flex;
  align-items: center;
  gap: 7px;
}
.mobile-scroll-cue {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
}
.matrix-wrapper {
  overflow: auto;
  width: 100%;
  max-height: 76vh;
  border: 1px solid var(--line);
  background: var(--surface);
}
.archive-matrix {
  --pc-streamer-width: 148px;
  --pc-date-width: 180px;
  width: max-content;
  min-width: calc(var(--pc-streamer-width) + (var(--date-count, 18) * var(--pc-date-width)));
  table-layout: fixed;
  border-collapse: collapse;
}
.archive-matrix col.streamer-col { width: var(--pc-streamer-width); }
.archive-matrix col.date-col { width: var(--pc-date-width); }
.archive-matrix th, .archive-matrix td { border: 1px solid var(--line); }
.archive-matrix thead th {
  position: sticky;
  top: -1px;
  z-index: 4;
  padding: 7px;
  background: #eef1f4;
  font-size: 12px;
  white-space: nowrap;
}
.archive-matrix thead th.sticky-col { z-index: 5; }
.sticky-col { position: sticky; left: 0; z-index: 3; background: #f7f8fa; }
.streamer-cell {
  width: var(--pc-streamer-width);
  min-width: var(--pc-streamer-width);
  padding: 8px;
  font-size: 12px;
  text-align: left;
  vertical-align: middle;
}
.streamer-name,
.streamer-team { display: block; }
.streamer-name { line-height: 1.35; }
.streamer-team {
  margin-top: 3px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
  line-height: 1.25;
}
.empty-cell { height: 132px; background: #fbfcfd; }
.video-cell {
  height: 132px;
  padding: 6px;
  background: #fff;
  cursor: pointer;
  vertical-align: top;
}
.video-cell:hover { background: #edf7f3; }
.thumb-wrap {
  position: relative;
  width: 100%;
  height: 82px;
  overflow: hidden;
  border-radius: 6px;
  background: #e7ebef;
}
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; }
.cell-watch-control {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 1;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(52, 64, 84, 0.24);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.18);
  cursor: pointer;
}
.cell-watch-toggle {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--watched);
  cursor: pointer;
}
.count-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 28px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(32, 36, 42, 0.9);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}
.video-title {
  height: 31px;
  margin-top: 4px;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.35;
}
.cell-popup {
  position: absolute;
  z-index: 9999;
  width: 440px;
  max-width: calc(100vw - 24px);
  max-height: min(620px, 74vh);
  padding: 11px;
  border: 1px solid #cbd3dd;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(16, 24, 40, 0.2);
}
.popup-header, .mobile-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.popup-header { margin-bottom: 9px; font-size: 13px; }
.popup-body { display: grid; gap: 8px; overflow: auto; max-height: calc(min(620px, 74vh) - 54px); }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  padding: 0;
  border: 1px solid #cbd3dd;
  border-radius: 5px;
  background: #fff;
  color: #344054;
  cursor: pointer;
  font-weight: 800;
}
.icon-button:hover { background: #eef2f5; }
.watch-toggle.is-active { border-color: #8dcc9d; background: #e8f7ec; color: var(--watched); }

.media-item {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 9px;
  padding: 8px;
  border: 1px solid #e0e5eb;
  border-radius: 7px;
  background: #fff;
}
.media-item.is-watched { background: #f3f8f4; }
.media-thumb {
  width: 132px;
  height: 74px;
  border-radius: 5px;
  object-fit: cover;
}
.media-content { min-width: 0; }
.media-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-content h4 {
  display: -webkit-box;
  margin: 3px 0 7px;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.media-actions { display: flex; align-items: center; gap: 9px; }
.media-actions a {
  color: #0969aa;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}
.media-actions a:hover { text-decoration: underline; }
.source-link { color: #5d5f66 !important; }
.empty-message { margin: 12px 4px; color: var(--muted); font-size: 13px; }

.mobile-only { display: none; }
.mobile-matrix-wrapper {
  overflow: auto;
  max-height: 68vh;
  border: 1px solid var(--line);
  background: #fff;
}
.mobile-mini-matrix {
  --mobile-streamer-width: 82px;
  --mobile-date-width: 44px;
  width: calc(var(--mobile-streamer-width) + (var(--date-count, 18) * var(--mobile-date-width)));
  min-width: 0;
  table-layout: fixed;
  border-collapse: collapse;
}
.mobile-mini-matrix col.mobile-streamer-col { width: var(--mobile-streamer-width); }
.mobile-mini-matrix col.mobile-date-col { width: var(--mobile-date-width); }
.mobile-mini-matrix th, .mobile-mini-matrix td { border: 1px solid var(--line); }
.mobile-mini-matrix thead th {
  position: sticky;
  top: -1px;
  z-index: 4;
  height: 29px;
  padding: 4px 2px;
  background: #eef1f4;
  font-size: 10px;
  white-space: nowrap;
}
.mobile-mini-matrix thead th.mobile-sticky-col { z-index: 5; }
.mobile-sticky-col { position: sticky; left: 0; z-index: 3; background: #f7f8fa; }
.mobile-streamer-cell {
  width: var(--mobile-streamer-width);
  min-width: var(--mobile-streamer-width);
  max-width: var(--mobile-streamer-width);
  padding: 5px 4px;
  overflow: hidden;
  font-size: 10px;
  text-align: left;
  vertical-align: middle;
}
.mobile-streamer-name,
.mobile-streamer-team {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mobile-streamer-name { line-height: 1.15; }
.mobile-streamer-team {
  margin-top: 2px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 400;
  line-height: 1.1;
}
.mobile-empty-cell, .mobile-video-cell {
  width: var(--mobile-date-width);
  min-width: var(--mobile-date-width);
  max-width: var(--mobile-date-width);
  height: 40px;
}
.mobile-empty-cell { background: #fbfcfd; }
.mobile-video-cell {
  position: relative;
  padding: 3px;
  background: #fff;
  text-align: center;
  cursor: pointer;
}
.mobile-thumb-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 4px;
  background: #e7ebef;
}
.mobile-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.mobile-count-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  z-index: 1;
  min-width: 18px;
  height: 14px;
  padding: 0 2px;
  border-radius: 3px;
  background: rgba(32, 36, 42, 0.9);
  color: #fff;
  font-size: 8px;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
}
.mobile-cell-progress {
  position: absolute;
  right: 2px;
  bottom: 2px;
  left: 2px;
  height: 3px;
  border-radius: 2px;
}
.mobile-complete {
  position: absolute;
  top: 1px;
  left: 2px;
  z-index: 1;
  width: 13px;
  height: 13px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--watched);
  font-size: 9px;
  font-weight: 900;
  line-height: 13px;
}
.mobile-sheet-backdrop { position: fixed; inset: 0; z-index: 9998; background: rgba(16, 24, 40, 0.38); }
.mobile-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9999;
  max-height: 82vh;
  padding: 7px 12px 16px;
  border-radius: 12px 12px 0 0;
  background: #fff;
  box-shadow: 0 -8px 24px rgba(16, 24, 40, 0.22);
  transform: translateY(105%);
  transition: transform 0.2s ease;
}
.mobile-sheet.is-open { transform: translateY(0); }
.mobile-sheet-handle { width: 42px; height: 4px; margin: 2px auto 9px; border-radius: 2px; background: #cbd3dd; }
.mobile-sheet-header h3 { margin: 0; font-size: 14px; }
.mobile-sheet-body {
  display: grid;
  gap: 8px;
  max-height: calc(82vh - 58px);
  padding-top: 9px;
  overflow: auto;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10000;
  max-width: calc(100vw - 36px);
  padding: 9px 12px;
  border-radius: 6px;
  background: #20242a;
  color: #fff;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.error-box { padding: 24px; }

@media (max-width: 1160px) {
  .top-panel { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
  main { padding: 14px 10px 28px; }
  .page-header { padding: 15px 12px; }
  .header-inner { align-items: flex-start; }
  .page-header h1 { font-size: 19px; line-height: 1.3; }
  .data-updated-label { margin-top: 3px; }
  .viewer-toolbar { align-items: stretch; flex-direction: column; }
  .mode-switch { width: 100%; min-width: 0; }
  .history-actions { justify-content: space-between; }
  .summary-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-value { font-size: 21px; }
  .filter-controls { display: grid; grid-template-columns: 1fr; }
  #teamFilterControl,
  .filter-control-streamer,
  .date-range-control {
    width: 100%;
    min-width: 0;
  }
  .date-range-action-row { align-items: flex-end; }
  .dual-range { min-width: 0; }
  .media-item { grid-template-columns: 104px minmax(0, 1fr); }
  .media-thumb { width: 104px; height: 59px; }
  .media-content h4 { font-size: 11px; }
  .media-actions { gap: 7px; }
  .media-actions a { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-sheet, .toast { transition: none; }
}
