/* ==========================================================================
   EduTrack — Staff analytics dashboard. White · Inter · crimson #960E0B.
   Hand-rolled SVG/CSS charts, no dependencies.
   ========================================================================== */
:root {
  --brand: #960e0b; --brand-hover: #7a0b08;
  --ink: #222; --muted: #6a6a6a; --line: #ddd; --line-soft: #ececec;
  --bg: #f7f7f8; --card: #fff;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg);
  font-size: 14px; letter-spacing: -0.1px; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: #c13515; font-size: 13px; margin-top: 6px; }
a { color: inherit; text-decoration: none; }
button, input { font-family: inherit; }

.btn { font-size: 15px; font-weight: 500; border: 1px solid transparent; border-radius: 8px;
  padding: 0 18px; height: 44px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .13s, border-color .13s, color .13s, opacity .13s; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-outline { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-outline:hover { background: #f5f5f5; border-color: var(--ink); }
.btn-block { width: 100%; }
.btn-sm { height: 38px; padding: 0 13px; font-size: 13px; }

/* login / denied */
.login-view { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 20px;
  padding: 34px 30px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: rgba(0,0,0,.03) 0 1px 3px, rgba(0,0,0,.06) 0 8px 28px; }
.login-logo { width: 200px; height: auto; margin: 2px 0; }
.login-card h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; color: var(--brand); margin-top: 8px; }
.login-card label { display: flex; flex-direction: column; gap: 7px; font-size: 12px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.login-card input { font-size: 15px; font-weight: 400; text-transform: none; letter-spacing: -0.1px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; width: 100%; }
.login-card input:focus { outline: none; border-color: var(--ink); }
.btn-google { width: 100%; height: 50px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-size: 15px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 11px;
  transition: box-shadow .15s, border-color .15s; }
.btn-google:hover { box-shadow: rgba(0,0,0,.08) 0 3px 12px; border-color: #c9c9c9; }
.btn-google svg { width: 19px; height: 19px; }
.fineprint { font-size: 12.5px; line-height: 1.5; text-align: center; margin-top: 4px; }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1280px; margin: 0 auto; height: 66px; padding: 0 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.brand { display: flex; align-items: center; gap: 11px; }
.logo-mark { width: 38px; height: 38px; object-fit: contain; }
.wordmark { display: flex; flex-direction: column; line-height: 1.05; }
.logo-text { font-size: 17px; font-weight: 700; color: var(--brand); letter-spacing: -0.4px; }
.logo-sub { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .5px; text-transform: uppercase; margin-top: 2px; }
.user { display: flex; align-items: center; gap: 12px; }
#user-email { font-size: 13px; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* dashboard tabs */
.dash-tabs { position: sticky; top: 66px; z-index: 15; background: #fff; border-bottom: 1px solid var(--line); }
.dash-tabs-inner { max-width: 1280px; margin: 0 auto; padding: 0 28px; display: flex; gap: 6px; }
.dtab { display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 16px;
  background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer;
  color: var(--muted); font-size: 14px; font-weight: 600; transition: color .13s, border-color .13s; }
.dtab svg { width: 18px; height: 18px; }
.dtab:hover { color: var(--ink); }
.dtab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* filter chips (grade drill-in) */
.filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 18px 0 18px; }
.filterbar .flabel { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .4px;
  text-transform: uppercase; margin-right: 4px; }
.fchip { height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 9999px; background: #fff;
  color: var(--ink); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .13s, border-color .13s, color .13s; }
.fchip:hover { border-color: var(--ink); }
.fchip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.hm-click { cursor: pointer; border-radius: 5px; }
.hm-click:hover { color: var(--brand); }
.footnote { font-size: 12.5px; margin-top: 10px; }

/* content */
.content { max-width: 1280px; margin: 0 auto; padding: 26px 28px 72px; }
.loading { text-align: center; color: var(--muted); padding: 60px 0; }
.section-title { font-size: 15px; font-weight: 700; color: var(--ink); letter-spacing: .3px; text-transform: uppercase;
  margin: 34px 2px 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.section-title:first-of-type { margin-top: 20px; }

/* KPI */
.kpi-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
.kpi-row-4 { grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.kpi-v { font-size: 28px; font-weight: 700; letter-spacing: -0.8px; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1; }
.kpi-l { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 8px; }
.kpi-s { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* card grid */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px; min-width: 0;
  box-shadow: rgba(0,0,0,.02) 0 1px 3px; }
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; }
.card-sub { font-size: 12.5px; color: var(--muted); }

.mini-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 14px; }
.mini-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; flex: none; }

/* vertical bars */
.barsv { display: flex; align-items: flex-end; gap: 10px; min-height: 200px; padding-top: 8px; overflow-x: auto; }
.barcol { flex: 1 1 0; min-width: 26px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; }
.barstack { width: 100%; max-width: 46px; display: flex; flex-direction: column-reverse; border-radius: 6px 6px 0 0; overflow: hidden; background: #f0f0f0; }
.barstack .seg:first-child { border-radius: 6px 6px 0 0; }
.seg { width: 100%; }
.barval { font-size: 12px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.barlab { font-size: 12px; color: var(--muted); text-align: center; white-space: nowrap; }

/* horizontal stacked bars */
.stackh { display: flex; flex-direction: column; gap: 10px; }
.sh-row { display: grid; grid-template-columns: 170px 1fr 46px; align-items: center; gap: 12px; }
.sh-label { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sh-bar { display: flex; height: 18px; border-radius: 5px; overflow: hidden; background: #f0f0f0; }
.sh-seg { height: 100%; }
.sh-pct { font-size: 13px; font-weight: 600; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }

/* donut */
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; flex: none; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.lg { display: inline-flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--ink); }
.lg b { font-variant-numeric: tabular-nums; }

/* heatmap */
.heatmap-scroll { overflow-x: auto; }
.heatmap { display: inline-flex; flex-direction: column; gap: 3px; min-width: 100%; }
.hm-row { display: grid; grid-template-columns: 190px repeat(var(--cols, 8), minmax(30px, 1fr)); gap: 3px; align-items: center; }
.hm-head .hm-c { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; }
.hm-rowlab { font-size: 12.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 8px; }
.hm-cell { height: 30px; border-radius: 5px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.25); }
.hm-empty { background: #f0f0f0; }

/* table */
.table-scroll { overflow-x: auto; }
.dt { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.dt th { text-align: left; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .3px;
  text-transform: uppercase; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.dt th.r, .dt td.r { text-align: right; font-variant-numeric: tabular-nums; }
.dt td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); }
.dt tr:hover td { background: #fafafa; }
.dt td.danger { color: #c13515; font-weight: 600; }
.dt td.warn { color: #9a6a11; font-weight: 600; }
.dt td.muted { color: var(--muted); }

/* data-quality quick stats */
.qq { display: flex; gap: 24px; flex-wrap: wrap; }
.qq-item { min-width: 90px; }
.qq-v { font-size: 30px; font-weight: 700; letter-spacing: -0.6px; color: var(--ink); font-variant-numeric: tabular-nums; }
.qq-l { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.state-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 40px 28px; text-align: center; margin: 40px auto; max-width: 560px; }
.state-card h2 { font-size: 19px; font-weight: 700; margin-bottom: 10px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 13px 20px; border-radius: 10px; z-index: 40; box-shadow: rgba(0,0,0,.25) 0 10px 30px; font-size: 14px; }
.toast.err { background: #c13515; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- Asistente (chat) ---- */
.chat-card { display: flex; flex-direction: column; }
.chat-note { font-size: 12.5px; color: var(--muted); background: #faf3f3; border: 1px solid #f0e2e2;
  border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; line-height: 1.45; }
.chat-note strong { color: var(--brand); }
.chat-msgs { display: flex; flex-direction: column; gap: 10px; min-height: 180px; max-height: 460px;
  overflow-y: auto; padding: 4px 2px; }
.chat-b { max-width: 84%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.5;
  overflow-wrap: anywhere; }
.chat-b.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 5px; }
.chat-b.assistant { align-self: flex-start; background: #f2f2f4; color: var(--ink); border-bottom-left-radius: 5px; }
.chat-err { color: #c13515; }
.chat-typing { display: inline-flex; gap: 4px; padding: 2px 0; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: #b7b7bd;
  animation: chat-blink 1.2s infinite both; }
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.chat-suggest.hidden { display: none; }
.chat-chip { font-size: 12.5px; color: var(--brand); background: #faf3f3; border: 1px solid #eccaca;
  border-radius: 999px; padding: 7px 13px; cursor: pointer; transition: background .13s, border-color .13s; }
.chat-chip:hover { background: #f4e6e6; border-color: #e0b3b3; }
.chat-form { display: flex; gap: 10px; margin-top: 14px; }
.chat-input, #chat-input { flex: 1; height: 44px; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 14px; font-size: 14px; font-family: inherit; color: var(--ink); background: #fff; }
#chat-input:focus { outline: none; border-color: var(--brand); }
.chat-send { flex: none; }

/* responsive */
@media (max-width: 1000px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
  .kpi-row-4 { grid-template-columns: repeat(2, 1fr); }
  .topbar-inner, .content, .dash-tabs-inner { padding-left: 18px; padding-right: 18px; }
}
@media (max-width: 680px) {
  .kpi-row, .kpi-row-4 { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .sh-row { grid-template-columns: 110px 1fr 42px; gap: 8px; }
  #user-email { display: none; }
  .donut-wrap { gap: 16px; }
  .dash-tabs { top: 0; }
  .dtab { padding: 0 10px; font-size: 13px; }
}
