:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --border: #e4e8f1;
  --text: #1c2333;
  --text-muted: #667085;
  --sidebar-bg: var(--brand-navy);
  --sidebar-text: rgba(255, 255, 255, 0.62);
  --sidebar-active: #F15A22;
  --green: #12875a;
  --green-bg: #e4f8ee;
  --amber: #b7791f;
  --amber-bg: #fdf3dd;
  --red: #c0392b;
  --red-bg: #fbe7e5;
  --gray-bg: #eef0f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --brand-navy: #152F5C;
  --brand-navy-light: #e7ebf3;
  --brand-orange: #F15A22;
  --brand-orange-dark: #d94c18;
  --brand-orange-light: rgba(241, 90, 34, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
}

#app { height: 100%; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

a { color: inherit; text-decoration: none; }

/* ---------------- App shell ---------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 26px;
}

.sidebar-logo {
  height: 68px;
  width: auto;
  max-width: 100%;
  display: block;
}

.sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0 10px 20px;
}

.nav-menu-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  padding: 0 12px;
  margin-bottom: 10px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand-orange), var(--brand-navy));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.brand-name { font-weight: 700; color: #fff; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: #8b96bd; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 999px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-bottom { margin-top: auto; padding: 0 10px 4px; }

.sidebar-account {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-account-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-orange);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-account-text { min-width: 0; }

.sidebar-account-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-account-role {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.env-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #ffcf7a;
  background: rgba(255, 207, 122, 0.12);
  border: 1px solid rgba(255, 207, 122, 0.3);
  padding: 5px 9px;
  border-radius: 999px;
}

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 64px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-title { font-size: 17px; font-weight: 700; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.env-pill-topbar {
  color: var(--amber);
  background: var(--amber-bg);
  border-color: #f0dca9;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-orange);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.content {
  padding: 26px 28px 60px;
  flex: 1;
}

.page-loading, .empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------------- Page header ---------------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 { font-size: 20px; margin: 0 0 4px; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 13px; max-width: 640px; }

.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--brand-orange); color: #fff; }
.btn-primary:hover { background: var(--brand-orange-dark); }

.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--gray-bg); }

.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: #f6d5d1; }

.btn-sm { padding: 6px 10px; font-size: 12px; }

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  padding: 4px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--gray-bg); color: var(--text); }

.link-btn {
  border: none;
  background: none;
  color: var(--brand-orange);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: 12.5px;
}
.link-btn:hover { text-decoration: underline; }

/* ---------------- Cards / KPIs ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad { padding: 20px 22px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.kpi-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.kpi-card-link:hover {
  border-color: var(--brand-orange);
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.12);
}

.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 28px 0 12px;
}

.two-col {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 980px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ---------------- Tables ---------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: #fafbfd;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13px;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbfe; }

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.table-toolbar-filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.mono { font-family: 'SFMono-Regular', Consolas, Menlo, monospace; font-size: 12.5px; color: var(--brand-navy); background: var(--brand-navy-light); padding: 2px 7px; border-radius: 5px; }

.cell-primary { font-weight: 600; }
.cell-muted { color: var(--text-muted); }

/* ---------------- Badges ---------------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-gray { background: var(--gray-bg); color: var(--text-muted); }
.badge-red { background: var(--red-bg); color: var(--red); }

/* ---------------- Forms ---------------- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid.single { grid-template-columns: 1fr; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 11.5px; color: var(--text-muted); font-weight: 400; }

.field input[type="text"],
.field input[type="email"],
.field input[type="number"],
.field input[type="date"],
.field input[type="search"],
.field select,
.field textarea {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 11px;
  background: var(--surface);
  color: var(--text);
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px var(--brand-orange-light);
}

.field textarea { resize: vertical; min-height: 70px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.search-input {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 11px;
  background: var(--bg);
  min-width: 220px;
}
.search-input input { border: none; background: transparent; outline: none; width: 100%; }

select.filter-select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  background: var(--surface);
}

/* ---------------- Modal ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 20, 35, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  z-index: 100;
  overflow-y: auto;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: modal-in 0.15s ease-out;
}

.modal-lg { max-width: 800px; }
.modal-xl { max-width: 980px; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }

.modal-body { padding: 22px; max-height: 72vh; overflow-y: auto; }

body.modal-open { overflow: hidden; }

/* ---------------- Tabs ---------------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.tab-btn {
  padding: 10px 16px;
  border: none;
  background: none;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-btn.active { color: var(--brand-navy); border-bottom-color: var(--brand-navy); }

/* ---------------- Progress bars ---------------- */

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--gray-bg);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--brand-orange);
  border-radius: 999px;
}
.progress-fill.green { background: var(--green); }
.progress-fill.amber { background: var(--amber); }

.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-row .progress-track { flex: 1; }
.progress-row .progress-label { font-size: 12px; font-weight: 700; width: 36px; text-align: right; }

/* ---------------- Simple bar chart (no external lib) ---------------- */

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 160px;
  padding: 10px 4px 0;
}

.bar-chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 8px;
}

.bar-chart-bar {
  width: 100%;
  max-width: 46px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #ff8a5c, var(--brand-orange));
  min-height: 3px;
}

.bar-chart-value { font-size: 11.5px; font-weight: 700; color: var(--text-muted); }
.bar-chart-label { font-size: 11px; color: var(--text-muted); text-align: center; }

/* ---------------- Misc ---------------- */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.chip {
  display: inline-block;
  background: var(--gray-bg);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  margin: 2px 3px 2px 0;
}

.divider { height: 1px; background: var(--border); margin: 18px 0; }

.text-muted { color: var(--text-muted); }
.small { font-size: 12px; }

.upload-drop {
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 22px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg);
}

.upload-drop.drag-over { border-color: var(--brand-orange); background: var(--brand-orange-light); }

.csv-preview-table {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 12px;
}

.bulk-cell-invalid {
  border-color: var(--red) !important;
  background: var(--red-bg);
}

.pill-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.pill-toggle button {
  border: none;
  background: var(--surface);
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}
.pill-toggle button.active { background: var(--brand-navy); color: #fff; }

.school-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 20px;
  margin-top: 10px;
}
.school-detail-grid .k { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.school-detail-grid .v { font-size: 13px; font-weight: 600; margin-top: 2px; }

/* ---------------- Toast ---------------- */

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1c2333;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.toast-error { background: var(--red); }
#toast.toast-success { background: var(--green); }

.empty-cell { color: var(--text-muted); font-style: italic; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d6dbe7; border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- Login page (brand) ---------------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-navy);
  padding: 24px;
}

.login-page-inner { display: flex; flex-direction: column; align-items: center; }

.login-card {
  width: 340px;
  max-width: 100%;
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.login-logo {
  height: 88px;
  width: auto;
  max-width: 100%;
  margin: 0 auto 18px;
  display: block;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 19px;
  color: var(--brand-navy);
  font-weight: 700;
}

.login-subtitle {
  margin: 0 0 22px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.login-card .field { text-align: left; margin-bottom: 14px; }
.login-card .field label { color: var(--brand-navy); font-size: 12.5px; font-weight: 600; }

.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
}

.login-card input:focus {
  outline: none;
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px rgba(241, 90, 34, 0.14);
}

.btn-brand-orange {
  width: 100%;
  background: var(--brand-orange);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-brand-orange:hover { background: #d94c18; }
.btn-brand-orange:disabled { opacity: 0.7; cursor: default; }

.login-forgot {
  display: inline-block;
  margin-top: 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand-orange);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}
.login-forgot:hover { text-decoration: underline; }

.login-footer {
  margin-top: 18px;
  text-align: center;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.65);
}

/* ---------------- Topbar logo ---------------- */

.topbar-left { display: flex; align-items: center; gap: 14px; }

.topbar-logo {
  height: 48px;
  width: auto;
  max-width: 100%;
  display: block;
}
