/* ==========================================================================
   Group Engagement Recognition Dashboard
   Palette: validated categorical/status set (see dataviz skill palette.md).
   Light mode only.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&family=Nunito:wght@400;600;700;800&display=swap');

:root {
  color-scheme: light;

  /* chrome */
  --surface-1:      #fcfcfb;
  --surface-2:      #ffffff;
  --page-plane:     #fef6e4;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);

  /* sequential (blue) for magnitude encodings */
  --seq-100: #cde2fb;
  --seq-300: #6da7ec;
  --seq-500: #256abf;
  --seq-700: #0d366b;

  /* status -- fixed, never re-themed; used ONLY for engagement level + match state */
  --status-good:     #0ca30c;   /* High engagement / Match */
  --status-warning:  #d98c00;   /* Medium engagement -- darkened from spec #fab219 for AA text contrast */
  --status-critical: #d03b3b;   /* Low engagement / Mismatch */

  /* categorical -- used only for the H / M source-folder tag, slots 1 & 7 */
  --cat-h: #2a78d6;
  --cat-m: #4a3aa7;
  --cat-all: #d9581c; /* "All videos" toggle -- distinct from both cat-h and cat-m */

  --radius-sm: 10px;
  --radius-md: 18px;
  --radius-lg: 28px;
  --shadow-soft: 0 6px 20px rgba(11,11,11,0.08), 0 2px 6px rgba(11,11,11,0.06);
  --shadow-pop:  0 16px 40px rgba(11,11,11,0.18), 0 4px 12px rgba(11,11,11,0.10);

  --font-display: 'Baloo 2', 'Segoe UI Rounded', system-ui, -apple-system, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .display { font-family: var(--font-display); font-weight: 700; letter-spacing: 0.2px; }

a { color: var(--seq-700); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- header ---------- */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ffe9a8 0%, #ffd1dc 45%, #c7e9ff 100%);
  border-bottom: 3px solid var(--border);
  padding: 40px 0 34px;
}
.hero-blobs { position: absolute; inset: 0; pointer-events: none; opacity: 0.55; }
.hero-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; flex-wrap: wrap; position: relative; }
.hero-intro { flex: 1 1 480px; max-width: 660px; }
.hero h1 { font-size: clamp(28px, 4vw, 40px); margin: 0 0 6px; color: #23231f; }
.hero p.sub { margin: 0; font-size: 16px; color: #4c463a; font-weight: 600; }

.btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: 999px;
  padding: 13px 22px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-soft);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-2px) scale(1.02); box-shadow: var(--shadow-pop); }
.btn:active { transform: translateY(0) scale(0.99); }
.btn-primary { background: #23231f; color: #fffdf6; }

/* ---------- primary Dashboard/Data tabs ---------- */
.maintabs { display: flex; gap: 8px; padding: 16px 20px; }
.maintabs button {
  font-family: var(--font-display); font-weight: 700; font-size: 14px; padding: 10px 20px;
  border-radius: var(--radius-sm); border: 2px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); cursor: pointer; box-shadow: var(--shadow-soft);
}
.maintabs button.active { border-color: var(--seq-500); color: var(--seq-500); background: color-mix(in srgb, var(--seq-500) 10%, var(--surface-2)); }

main { padding: 34px 0 80px; }
section.panel { margin-bottom: 44px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.section-head h2 { font-size: 24px; margin: 0; }
.section-head .hint { color: var(--text-secondary); font-size: 14px; }

.hero-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; flex: 0 0 auto; width: 250px; }
.hero-actions .btn-row { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.hero-actions .btn { width: 100%; justify-content: center; padding: 11px 18px; font-size: 14px; }

.legend-key {
  width: 100%; margin-top: 4px;
  background: var(--surface-2); border: 2px solid var(--border);
  border-radius: var(--radius-md); padding: 10px 14px;
  box-shadow: var(--shadow-soft);
}
.legend-key-title {
  margin: 0 0 6px; font-family: var(--font-display); font-weight: 800; font-size: 12px;
  text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted);
}
.legend-key-row {
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; color: var(--text-primary); padding: 3px 0;
}
.legend-swatch { width: 14px; height: 14px; border-radius: 5px; flex: 0 0 auto; }
.legend-swatch.swatch-good { background: var(--status-good); }
.legend-swatch.swatch-warn { background: var(--status-warning); }
.legend-swatch.swatch-bad { background: var(--status-critical); }

.data-legend { margin-bottom: 18px; }
.data-legend .legend-key-title .hint { text-transform: none; letter-spacing: normal; font-weight: 400; font-size: 12px; }

/* ---------- cards / stat tiles ---------- */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  padding: 20px;
}
.overview-card { display: flex; align-items: center; justify-content: center; gap: 48px; flex-wrap: nowrap; width: fit-content; max-width: 100%; margin: 0 auto; }
.overview-info { flex: 0 1 320px; }
#overview-videos-donut { flex: 0 0 auto; }
.overview-info .chart-title { margin-top: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.level-dot { display: inline-block; width: 12px; height: 12px; border-radius: 4px; background: currentColor; margin-right: 8px; vertical-align: 1px; }
.stat-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-soft);
}
.stat-tile .icon { font-size: 26px; display:block; margin-bottom: 6px; }
.stat-tile .value { font-family: var(--font-display); font-size: 32px; font-weight: 800; line-height: 1; }
.stat-tile .label { color: var(--text-secondary); font-size: 13px; font-weight: 700; margin-top: 6px; }

/* ---------- filter bar ---------- */
.filterbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.pillgroup { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px; box-shadow: var(--shadow-soft); }
.pillgroup button {
  border: none; background: transparent; padding: 8px 16px; border-radius: 999px;
  font-family: var(--font-display); font-weight: 700; font-size: 13px; cursor: pointer;
  color: var(--text-secondary);
}
.pillgroup button.active { background: var(--seq-500); color: #fff; }
.pillgroup button.pill-h.active, .grouptabs button.tab-h.active { background: var(--cat-h); color: #fff; }
.pillgroup button.pill-m.active, .grouptabs button.tab-m.active { background: var(--cat-m); color: #fff; }
.pillgroup button.pill-all.active, .grouptabs button.tab-all.active { background: var(--cat-all); color: #fff; }
.grouptabs button.tab-h.active, .grouptabs button.tab-m.active, .grouptabs button.tab-all.active { border-color: transparent; }

.searchbox {
  flex: 1 1 220px; max-width: 320px;
  border: 1px solid var(--border); border-radius: 999px; padding: 9px 16px;
  background: var(--surface-2); color: var(--text-primary); font-family: var(--font-body); font-size: 14px;
}
.searchbox:focus { outline: 2px solid var(--seq-300); outline-offset: 1px; }
input.searchbox-text { border-radius: var(--radius-sm); }
input.searchbox-text::placeholder { color: var(--text-muted); }

.btn-export { padding: 9px 18px; font-size: 13px; box-shadow: none; }

.viewtoggle button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  padding: 8px 14px; font-family: var(--font-display); font-weight: 700; font-size: 13px; cursor: pointer;
}
.viewtoggle { display: inline-flex; border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow-soft); }
.viewtoggle button.active { background: var(--seq-500); color: #fff; }
.viewtoggle.datatabs { margin-bottom: 20px; }
.viewtoggle.datatabs button { padding: 11px 20px; font-size: 14px; }
.viewtoggle.videotabs { margin-bottom: 20px; }
.viewtoggle.videotabs button { padding: 11px 20px; font-size: 14px; }

/* ---------- badges/chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-display); font-weight: 700; font-size: 12px;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.badge-h { background: var(--cat-h); color: #fff; min-width: 26px; justify-content: center; }
.badge-m { background: var(--cat-m); color: #fff; min-width: 26px; justify-content: center; }
.badge-level {
  color: #fff;
}
.badge-level.High { background: var(--status-good); }
.badge-level.Medium { background: var(--status-warning); }
.badge-level.Low { background: var(--status-critical); }
.badge-outline.High { color: var(--status-good); border: 2px solid var(--status-good); background: color-mix(in srgb, var(--status-good) 20%, var(--surface-2)); }
.badge-outline.Medium { color: var(--status-warning); border: 2px solid var(--status-warning); background: color-mix(in srgb, var(--status-warning) 22%, var(--surface-2)); }
.badge-outline.Low { color: var(--status-critical); border: 2px solid var(--status-critical); background: color-mix(in srgb, var(--status-critical) 20%, var(--surface-2)); }
.badge-outline { padding: 3px 9px; cursor: help; }

.chip-match { color: var(--status-good); font-weight: 800; }
.chip-mismatch { color: var(--status-critical); font-weight: 800; }

/* ---------- video grid / cards ---------- */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.video-card {
  background: var(--surface-2); border: 1px solid var(--border); border-left: 6px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft); padding: 16px; cursor: pointer; transition: transform 0.12s ease, box-shadow .12s ease;
}
.video-card.group-h { border-left-color: var(--cat-h); }
.video-card.group-m { border-left-color: var(--cat-m); }
.video-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-pop); }
.video-card .vc-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.video-card .vc-name { font-family: var(--font-display); font-weight: 800; font-size: 17px; }
.video-card .vc-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.video-card .vc-compare { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--gridline); font-size: 13px; }
.video-card video { width: 100%; border-radius: var(--radius-sm); background: #000; display: block; margin: 10px 0; }
#videos-grid.video-grid .video-card { cursor: default; }
#videos-grid.video-grid .video-card:hover { transform: none; box-shadow: var(--shadow-soft); }

/* ---------- table view ---------- */
.table-wrap { overflow-x: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-soft); padding: 6px 20px; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 760px; }
table.data-table th, table.data-table td { text-align: left; padding: 12px 18px; border-bottom: 1px solid var(--gridline); white-space: nowrap; }
table.data-table th { font-family: var(--font-display); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); cursor: pointer; user-select: none; }
table.data-table th:hover { color: var(--text-primary); }
table.data-table tbody tr:hover { background: color-mix(in srgb, var(--seq-100) 25%, transparent); cursor: pointer; }
table.data-table td.num { font-variant-numeric: tabular-nums; }
table.data-table td.cell-good { background: color-mix(in srgb, var(--status-good) 22%, var(--surface-2)); color: var(--status-good); font-weight: 700; }
table.data-table td.cell-warn { background: color-mix(in srgb, var(--status-warning) 22%, var(--surface-2)); color: var(--status-warning); font-weight: 700; }
table.data-table td.cell-bad { background: color-mix(in srgb, var(--status-critical) 22%, var(--surface-2)); color: var(--status-critical); font-weight: 700; }
table.data-table th.col-filter-cell { cursor: default; padding: 6px 10px 10px; }
table.data-table th.col-filter-cell:hover { color: var(--text-muted); }
table.data-table .col-filter {
  width: 100%; font-family: var(--font-body); font-weight: 400; font-size: 12.5px; text-transform: none;
  letter-spacing: normal; color: var(--text-primary); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 6px; background: var(--surface-1); cursor: pointer;
}

/* ---------- detail panel ---------- */
.detail-panel {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop); padding: 22px; margin-top: 18px;
}
.detail-panel .dp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px;}
.detail-panel .dp-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; padding: 4px;}
.dp-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 10px; margin: 14px 0; }
.dp-stats .mini { background: var(--page-plane); border-radius: var(--radius-sm); padding: 10px 12px; }
.dp-stats .mini .k { font-size: 11px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; }
.dp-stats .mini .v { font-family: var(--font-display); font-weight: 800; font-size: 18px; }

.timeline { display: flex; gap: 2px; flex-wrap: wrap; margin: 10px 0; }
.timeline .tick { width: 22px; height: 34px; border-radius: 6px; position: relative; cursor: pointer; }
.timeline .tick.High { background: var(--status-good); }
.timeline .tick.Medium { background: var(--status-warning); }
.timeline .tick.Low { background: var(--status-critical); }
.timeline .tick .tsec { position:absolute; bottom:2px; left:0; right:0; text-align:center; font-size:9px; color: rgba(255,255,255,.85); font-weight:700; }
.tl-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-top: 4px; flex-wrap: wrap;}
.tl-legend span.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

.tooltip-pop {
  position: fixed; z-index: 60; max-width: 240px;
  background: var(--text-primary); color: var(--surface-1);
  font-size: 12.5px; padding: 8px 10px; border-radius: 8px; box-shadow: var(--shadow-pop);
  pointer-events: none; line-height: 1.4;
}

/* ---------- charts (svg) ---------- */
.chart-row { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }
@media (max-width: 820px) { .chart-row { grid-template-columns: 1fr; } }
svg.chart text { font-family: var(--font-body); fill: var(--text-secondary); }
svg.chart .barval { font-weight: 800; fill: var(--text-primary); }
svg.chart .axislabel { font-size: 11px; fill: var(--text-muted); }
svg.chart .axistitle { font-size: 11.5px; font-weight: 700; fill: var(--text-secondary); }
.chart-title { font-family: var(--font-display); font-weight: 700; font-size: 15px; margin: 0 0 4px; }
.chart-subtitle { font-size: 12.5px; color: var(--text-muted); margin: 0 0 10px; }
.bar-tooltip-target { cursor: pointer; }
.bar-tooltip-target:hover { opacity: 0.85; }

.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-secondary); margin-top: 8px; flex-wrap: wrap; }
.chart-legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; background: var(--seq-500); }
.chart-legend .swatch-light { opacity: 0.4; }

/* confusion matrix */
.cm-wrap { overflow-x: auto; }
table.cm { border-collapse: collapse; font-size: 13px; }
table.cm th, table.cm td { padding: 12px 16px; text-align: center; border: 1px solid var(--gridline); }
table.cm th { font-family: var(--font-display); background: var(--page-plane); }
table.cm td.cell { font-family: var(--font-display); font-weight: 800; font-size: 17px; color: var(--surface-1); }
table.cm td.diag { outline: 3px solid var(--status-good); outline-offset: -3px; }
table.cm .corner { background: transparent; border: none; }

/* group tabs */
.grouptabs { display: flex; gap: 8px; margin-bottom: 16px; }
.grouptabs button {
  font-family: var(--font-display); font-weight: 700; font-size: 14px; padding: 10px 18px;
  border-radius: var(--radius-sm); border: 2px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); cursor: pointer;
}
.grouptabs button.active { border-color: var(--seq-500); color: var(--seq-500); background: color-mix(in srgb, var(--seq-500) 10%, var(--surface-2));}

/* Interactive Group Summaries: tint every stat tile and chart card with the
   selected tab's color, so it's unmistakable which group is being shown.
   box-shadow (not outline) so the colored ring follows the rounded corners. */
#group-summaries[data-active-group="H"] .stat-tile,
#group-summaries[data-active-group="H"] .chart-row .card {
  box-shadow: 0 0 0 3px var(--cat-h) inset, var(--shadow-soft);
  background: color-mix(in srgb, var(--cat-h) 9%, var(--surface-2));
}
#group-summaries[data-active-group="M"] .stat-tile,
#group-summaries[data-active-group="M"] .chart-row .card {
  box-shadow: 0 0 0 3px var(--cat-m) inset, var(--shadow-soft);
  background: color-mix(in srgb, var(--cat-m) 9%, var(--surface-2));
}
#group-summaries[data-active-group="Overall"] .stat-tile,
#group-summaries[data-active-group="Overall"] .chart-row .card {
  box-shadow: 0 0 0 3px var(--cat-all) inset, var(--shadow-soft);
  background: color-mix(in srgb, var(--cat-all) 9%, var(--surface-2));
}

.note {
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--status-warning) 40%, transparent);
  border-radius: var(--radius-md); padding: 14px 18px; font-size: 14px; color: var(--text-primary);
}
.note strong { font-family: var(--font-display); }

.arrow { color: var(--text-muted); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10,10,10,0.55);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface-2); color: var(--text-primary);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  max-width: 760px; width: 100%; padding: 0; margin-bottom: 40px;
  animation: pop-in .18s ease;
}
@keyframes pop-in { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  position: sticky; top: 0; background: var(--surface-2);
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid var(--border); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-header h3 { margin: 0; font-size: 20px; }
.modal-header button { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 8px 24px 26px; }
.modal-body h4 { font-family: var(--font-display); font-size: 15px; margin: 22px 0 8px; color: var(--seq-500);}
.modal-body p { margin: 6px 0; color: var(--text-primary); font-size: 14.5px; }
.modal-body ul { margin: 6px 0; padding-left: 22px; }
.modal-body pre {
  background: var(--page-plane); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.5;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
}
.modal-body .kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; margin: 8px 0 14px; }
.modal-body .kv dt { color: var(--text-muted); font-weight: 700; }
.modal-body .kv dd { margin: 0; }
.modal-body .instr-card {
  background: color-mix(in srgb, var(--seq-100) 30%, var(--surface-2));
  border-left: 4px solid var(--seq-500);
  border-radius: var(--radius-sm); padding: 12px 16px; margin: 10px 0;
}
.modal-body .instr-card p { margin: 4px 0; }

footer { text-align: center; color: var(--text-muted); font-size: 13px; padding: 30px 0 50px; }
footer a { color: var(--text-muted); text-decoration: underline; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 600px) {
  .stat-tile .value { font-size: 26px; }
  .hero { padding: 30px 0 26px; }
}
