:root {
  --blue: #1d4ed8;
  --blue-dark: #1e3a8a;
  --ink: #111827;
  --muted: #6b7280;
  --line: #d7dde8;
  --soft: #f5f7fb;
  --green: #15803d;
  --amber: #b45309;
  --red: #dc2626;
  --card: #ffffff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f8fafc;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 44px; height: 44px; object-fit: contain; }
.brand strong { display: block; font-size: 24px; letter-spacing: 0; }
.brand span { display: block; color: var(--muted); font-size: 13px; }

nav { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
button, .button {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1f2937;
  border-radius: 8px;
  min-height: 42px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .button:hover { border-color: var(--blue); color: var(--blue); }
button.active, .primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.ghost { background: #f8fafc; }
.danger { background: #fee2e2; border-color: #fecaca; color: var(--red); }

main { max-width: 1240px; margin: 0 auto; padding: 28px; }
.app-footer {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 28px 28px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}
.auth-card, .panel, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}
.auth-card { max-width: 520px; margin: 56px auto; padding: 28px; }
.panel { margin: 20px 0; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}
.panel-body { padding: 22px; }
h1, h2, h3 { margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(28px, 4vw, 44px); }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p { line-height: 1.5; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 16px;
  align-items: end;
  margin-bottom: 20px;
}
.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.notice, .help-box {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  border-radius: 8px;
  padding: 12px 14px;
}
.help-box p { margin: 4px 0 0; }

label { display: block; font-weight: 800; margin: 0 0 7px; color: #374151; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  min-height: 42px;
  padding: 9px 11px;
  font: inherit;
  background: #fff;
}
textarea { min-height: 110px; resize: vertical; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.stat span { color: var(--muted); font-weight: 700; }
.stat strong { display: block; margin-top: 8px; font-size: 30px; }

.school-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.card { padding: 16px; }
.school-card {
  border-left: 5px solid #cbd5e1;
}
.school-card.good { border-left-color: var(--green); }
.school-card.warn { border-left-color: var(--amber); }
.school-card.bad { border-left-color: var(--red); }
.card-title { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 800;
  background: #e0edff;
  color: #1d4ed8;
}
.pill.good { background: #dcfce7; color: var(--green); }
.pill.warn { background: #fef3c7; color: var(--amber); }
.pill.bad { background: #fee2e2; color: var(--red); }
.pill.admin-pill { background: #ede9fe; color: #6d28d9; }
.pill.ok-pill { background: #dcfce7; color: var(--green); }
.pill.suspended-pill { background: #fee2e2; color: var(--red); }

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
}
.dot.good { background: var(--green); }
.dot.warn { background: var(--amber); }
.dot.bad { background: var(--red); }

.metric-row { margin-top: 14px; }
.metric-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 5px;
}
.metric-head strong { color: var(--ink); }
.metric-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}
.metric-fill {
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  transition: width 180ms ease;
}
.metric-fill.good { background: var(--green); }
.metric-fill.warn { background: var(--amber); }
.metric-fill.bad { background: var(--red); }
.metric-fill.empty { background: #cbd5e1; }

.crece-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 14px;
}
.mini-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.crece-grade {
  display: inline-flex;
  align-items: center;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1e3a8a;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--blue-dark); color: #fff; }
tr:last-child td { border-bottom: 0; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.compact-actions { margin-top: 0; gap: 6px; }
.compact-actions button { padding: 8px 10px; font-size: 13px; }
button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.muted { color: var(--muted); }
.hidden { display: none !important; }
.message { margin: 12px 0; padding: 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.message.error { border-color: #fecaca; background: #fff1f2; color: #991b1b; }
.message.ok { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.message.info { border-color: #bfdbfe; background: #eff6ff; color: #1e3a8a; }
.message.warn { border-color: #fde68a; background: #fffbeb; color: #92400e; }

.subtle-panel {
  background: #fff7f7;
  border-color: #fecaca;
}

.danger-zone {
  border-color: #fecaca;
  background: #fffafa;
}

.danger-zone h3 {
  color: #991b1b;
}

@page {
  size: letter;
  margin: 0.55in;
}

.report-body {
  background: #e5e7eb;
  color: #111827;
}

.report-main {
  max-width: 8.5in;
  margin: 0 auto;
  padding: 0.45in;
  background: #fff;
}

.report-page {
  min-height: 10in;
  page-break-after: always;
}

.report-page:last-of-type {
  page-break-after: auto;
}

.report-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--blue);
}

.report-header img {
  width: 66px;
  height: 66px;
  object-fit: contain;
}

.report-header h1 {
  margin: 0;
  color: var(--blue-dark);
  font-size: 25px;
  line-height: 1.15;
}

.report-header p {
  margin: 5px 0 0;
  color: #374151;
  font-weight: 800;
}

.report-header small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.report-content {
  font-size: 13px;
  line-height: 1.45;
}

.report-section {
  margin: 0 0 28px;
}

.report-section h2 {
  margin: 24px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--blue);
  color: var(--blue-dark);
  font-size: 18px;
  line-height: 1.2;
}

.report-table-wrap {
  display: flex;
  justify-content: center;
  margin: 10px 0 14px;
  overflow-x: visible;
}

.report-table-wrap.narrow .report-table {
  max-width: 680px;
}

.report-table {
  width: auto;
  min-width: 72%;
  border-collapse: collapse;
  background: #fff;
  font-size: 12px;
}

.report-table th {
  padding: 7px 9px;
  border: 1px solid #1e3a8a;
  background: var(--blue-dark);
  color: #fff;
  text-align: center;
  font-weight: 800;
}

.report-table td {
  padding: 7px 9px;
  border: 1px solid #d1d5db;
  text-align: center;
  vertical-align: middle;
}

.report-table td:first-child {
  text-align: left;
  font-weight: 700;
}

.report-table tbody tr:nth-child(even) td {
  background: #f9fafb;
}

.legend-table td:first-child {
  width: 32px;
  text-align: center;
}

.txt-good { color: var(--green); }
.txt-warn { color: #b45309; }
.txt-bad { color: var(--red); }
.txt-empty { color: var(--muted); }

.level-cell {
  font-weight: 800;
}

.level-cell.good {
  background: #dcfce7 !important;
  color: var(--green);
}

.level-cell.warn {
  background: #fef3c7 !important;
  color: #b45309;
}

.level-cell.bad {
  background: #fee2e2 !important;
  color: var(--red);
}

.level-cell.empty {
  background: #f3f4f6 !important;
  color: var(--muted);
}

.report-average,
.report-footnote,
.report-legend {
  margin: 10px 0 16px;
  color: #374151;
}

.report-footnote,
.report-legend {
  font-size: 11px;
}

.report-chart {
  max-width: 760px;
  min-height: 250px;
  margin: 18px auto 16px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.svg-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.report-interpretation {
  margin: 8px 0 0;
}

.report-interpretation p {
  display: flex;
  gap: 8px;
  margin: 7px 0;
}

.bullet-square,
.legend-square {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 5px;
  border-radius: 2px;
  vertical-align: -1px;
  background: var(--blue);
}

.bullet-square {
  flex: 0 0 11px;
  margin-top: 4px;
}

.legend-square.good { background: #15803d; }
.legend-square.warn { background: #d97706; }
.legend-square.bad { background: #dc2626; }

.report-notes {
  margin: 18px 0 46px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.report-notes p {
  margin: 4px 0;
}

.report-footer {
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 20px;
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: 14px; }
  main { padding: 16px; }
  nav { justify-content: flex-start; }
  .toolbar, .grid-2, .grid-3, .grid-4, .stats { grid-template-columns: 1fr; }
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  @page {
    size: letter;
    margin: 0.45in;
  }
  .topbar, .toolbar, nav, .actions, button { display: none !important; }
  body, .report-body { background: #fff; }
  main, .report-main { max-width: none; padding: 0; margin: 0; }
  .panel, .card, .auth-card { box-shadow: none; border-color: #bbb; }
  .report-page {
    min-height: auto;
    break-after: page;
    page-break-after: always;
  }
  .report-page:last-of-type {
    break-after: auto;
    page-break-after: auto;
  }
  .report-header,
  .report-table-wrap,
  .report-chart,
  .report-interpretation {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .report-table {
    font-size: 11px;
  }
  .report-table th,
  .report-table td {
    padding: 5px 7px;
  }
  .report-section {
    margin-bottom: 20px;
  }
  .report-section h2 {
    margin-top: 18px;
  }
  .report-footer {
    position: static;
    background: #fff;
  }
}
