/* CBC survey results portal. CAIS palette: red #E71341, blue #1D6A96, charcoal #2C2D2E */
:root {
  --red: #E71341;
  --red-dark: #C40F37;
  --blue: #1D6A96;
  --blue-dark: #165274;
  --blue-tint: #EEF4F8;
  --ink: #2C2D2E;
  --ink-2: #4A4B4D;
  --muted: #5F6062;
  --line: #E3E5E7;
  --grid: #EEF0F1;
  --page: #F6F7F8;
  --surface: #FFFFFF;
  /* chart colours (validated with the dataviz palette checker) */
  --series: #1D6A96;
  --detractor: #E71341;
  --passive: #A6ABAE;
  --promoter: #1D6A96;
  --radius: 8px;
  --font: "Montserrat", "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans", "Malgun Gothic", "Noto Sans Thai", sans-serif;
  color-scheme: light;
  accent-color: var(--blue);
}
* { box-sizing: border-box; }
html { scrollbar-color: #C9CDD0 transparent; }
body { margin: 0; background: var(--page); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; }
::selection { background: #D3E4EF; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.005em; text-wrap: balance; }
p { text-wrap: pretty; }
.muted { color: var(--muted); }
.logo { height: 26px; width: auto; display: block; }
[hidden] { display: none !important; }

/* ---- buttons & controls ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 14px;
  font: inherit; font-weight: 600; font-size: .9rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #C3C7CA; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
.btn.danger { color: var(--red-dark); }
.btn.danger.armed { background: var(--red-dark); border-color: var(--red-dark); color: #fff; }
.link { font: inherit; font-size: .85rem; font-weight: 600; color: var(--blue); background: none; border: 0; padding: 0; cursor: pointer; }
.link:hover { color: var(--blue-dark); text-decoration: underline; text-underline-offset: 3px; }
select, input[type=date], input[type=search], input[type=password] {
  font: inherit; font-size: .9rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); min-height: 36px; padding: 6px 10px;
}
select:focus, input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(29, 106, 150, .15); }

/* ---- header ---- */
header.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 24px; max-width: 1200px; margin: 0 auto; padding: 12px 24px 0; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font-weight: 600; padding-bottom: 12px; }
.brand span { padding-left: 12px; border-left: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; align-self: flex-end; }
.tabs a { white-space: nowrap; padding: 10px 12px 12px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--red); }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; padding-bottom: 12px; }
.top-actions form { margin: 0; }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 260px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px -8px rgba(30, 40, 50, .25);
}
.menu-list button { display: block; width: 100%; text-align: left; font: inherit; font-size: .9rem; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; color: var(--ink); }
.menu-list button:hover, .menu-list button:focus-visible { background: var(--blue-tint); }

/* ---- filter row ---- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; max-width: 1200px; margin: 0 auto; padding: 12px 24px 14px; border-top: 1px solid var(--grid); }
.filters label { display: grid; gap: 3px; font-size: .75rem; font-weight: 600; color: var(--muted); }
.filters .answer-filter { display: flex; gap: 6px; }
.filters .answer-filter select:first-child { max-width: 240px; }
.filters .answer-filter select:last-child { max-width: 220px; }
.filters select { max-width: 360px; }
.filters .count { margin-left: auto; align-self: center; font-size: .85rem; color: var(--muted); }
.filters .count strong { color: var(--ink); }

/* ---- page ---- */
main { max-width: 1200px; margin: 0 auto; padding: 24px 24px 64px; }
main[aria-busy="true"] .grid, main[aria-busy="true"] .cards { opacity: .55; transition: opacity .2s; }
.loading { padding: 48px 0; text-align: center; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 8px 0 14px; }
.section-head h2 { font-size: 1.15rem; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; min-width: 0; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.panel-head h3 { font-size: .98rem; line-height: 1.4; }
.panel-head .sub { margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.qnum { display: inline-block; min-width: 2.4em; margin-right: 6px; color: var(--muted); font-weight: 600; }
.empty { padding: 28px 0; text-align: center; color: var(--muted); }

/* stat tiles */
.stat .label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.stat .value { font-size: 2rem; font-weight: 600; line-height: 1.15; margin-top: 6px; }
.stat.hero .value { font-size: 3rem; }
.stat .note { font-size: .8rem; color: var(--muted); margin-top: 4px; }

/* ---- charts ---- */
.hbars { display: grid; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 38%) 1fr auto; align-items: center; gap: 12px; padding: 3px 4px; border-radius: 6px; cursor: default; }
.hbar:hover, .hbar:focus-visible { background: var(--page); }
.hbar .name { font-size: .88rem; color: var(--ink-2); line-height: 1.35; }
.hbar .track { height: 18px; }
.hbar .fill { height: 100%; min-width: 2px; background: var(--series); border-radius: 0 4px 4px 0; }
.hbar:hover .fill, .hbar:focus-visible .fill { background: var(--blue-dark); }
.hbar .val { font-size: .85rem; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; min-width: 92px; text-align: right; }
.hbar .val .pct { color: var(--muted); margin-left: 6px; }
.group-label { margin: 10px 0 2px; padding: 0 4px; font-size: .78rem; font-weight: 600; color: var(--muted); }
.group-label:first-child { margin-top: 0; }

svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { font-family: var(--font); font-size: 11px; fill: var(--muted); }
svg.chart .gridline { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis { stroke: #D5D8DB; stroke-width: 1; }
svg.chart .col { fill: var(--series); }
svg.chart .hit { fill: transparent; cursor: default; }
svg.chart .hit:hover + .col, svg.chart .hit:focus-visible + .col { fill: var(--blue-dark); }
svg.chart .hit:focus-visible { outline: none; }
svg.chart .label-strong { fill: var(--ink); font-weight: 600; }

.nps-head { display: flex; gap: 28px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.nps-score .value { font-size: 2.4rem; font-weight: 600; line-height: 1; }
.nps-score .label { font-size: .8rem; color: var(--muted); font-weight: 600; margin-top: 6px; }
.nps-parts { display: flex; gap: 18px; flex-wrap: wrap; font-size: .85rem; }
.key { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.key::before { content: ""; width: 12px; height: 12px; border-radius: 3px; background: var(--k); }
.key strong { font-variant-numeric: tabular-nums; }

/* compare (crosstab) */
.xtab-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { font-size: .78rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.xtab td.heat { text-align: right; font-variant-numeric: tabular-nums; min-width: 72px; border-bottom: 2px solid var(--surface); border-left: 2px solid var(--surface); }
.xtab th .n { display: block; font-weight: 500; }
.data-table { margin-top: 6px; }

/* text answers */
.texts { display: grid; gap: 8px; max-height: 420px; overflow: auto; padding-right: 4px; }
.text-item { padding: 10px 12px; background: var(--page); border-radius: 6px; font-size: .9rem; }
.text-item .meta { display: block; font-size: .75rem; color: var(--muted); margin-top: 4px; }
.text-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.text-tools input { flex: 1; max-width: 320px; }

/* responses table + drawer */
.rtable tbody tr { cursor: pointer; }
.rtable tbody tr:hover td, .rtable tbody tr:focus-visible td { background: var(--blue-tint); }
.rtable tbody tr:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: .85rem; color: var(--muted); }
.drawer-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(30, 35, 40, .28); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31; width: min(560px, 100%); overflow: auto;
  background: var(--surface); box-shadow: -8px 0 32px -12px rgba(30, 40, 50, .35); padding: 22px 24px 40px;
}
.drawer header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.drawer dl { margin: 0; }
.drawer dt { font-size: .78rem; font-weight: 600; color: var(--muted); margin-top: 14px; }
.drawer dd { margin: 3px 0 0; font-size: .92rem; }
.drawer dd ul { margin: 0; padding-left: 18px; }
.drawer .actions { display: flex; gap: 8px; margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line); }

/* tooltip: values lead, labels follow */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 280px; padding: 8px 10px;
  background: var(--ink); color: #fff; border-radius: 6px; font-size: .8rem; line-height: 1.4;
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, .35);
}
.tooltip strong { display: block; font-size: .95rem; font-variant-numeric: tabular-nums; }
.tooltip span { color: #D7DADC; }

/* ---- sign-in ---- */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-box { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login-box .logo { margin-bottom: 22px; }
.login-box h1 { font-size: 1.35rem; margin-bottom: 6px; }
.login-box p { margin: 0 0 20px; font-size: .9rem; }
.login-box label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.login-box input { width: 100%; margin-bottom: 14px; }
.login-box .btn { width: 100%; justify-content: center; min-height: 42px; }
.login-box .error { color: var(--red-dark); font-size: .85rem; margin: -4px 0 14px; }

@media (max-width: 900px) {
  .span-3, .span-4 { grid-column: span 6; }
  .span-6, .span-8 { grid-column: span 12; }
  .top-actions { margin-left: 0; }
}
@media (max-width: 560px) {
  .span-3, .span-4 { grid-column: span 12; }
  header.top { position: static; } /* filters make the header too tall to pin on a phone */
  .top-row, .filters, main { padding-left: 16px; padding-right: 16px; }
  .filters select, .filters .answer-filter select:first-child { max-width: 100%; }
  .filters label { width: 100%; }
  .tabs { overflow-x: auto; }
  .hbar { grid-template-columns: 1fr auto; }
  .hbar .track { grid-column: 1 / -1; grid-row: 2; }
  .filters .count { margin-left: 0; }
}
@media print {
  header.top .tabs, header.top .top-actions, .filters select, .filters input, .link, .btn { display: none !important; }
  header.top { position: static; border: 0; }
  body { background: #fff; }
  .panel { break-inside: avoid; border-color: #ddd; }
  .texts { max-height: none; overflow: visible; }
}
