:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #1e3a5f;
  --accent-2: #2f5d8a;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --info: #2563eb;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
}

.role-super_admin { --accent: #4338ca; --accent-2: #4f46e5; }
.role-principal   { --accent: #0f766e; --accent-2: #0d9488; }
.role-teacher     { --accent: #c2410c; --accent-2: #ea580c; }
.role-parent      { --accent: #1d4ed8; --accent-2: #2563eb; }
.role-accountant  { --accent: #15803d; --accent-2: #16a34a; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.hidden { display: none !important; }
.mt { margin-top: 14px; }

/* ---------- Screens ---------- */
.screen { min-height: 100vh; }
.screen.hidden { display: none; }

/* ---------- Login ---------- */
.login-panel { max-width: 420px; margin: 0 auto; padding: 48px 20px; }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.brand-mark {
  width: 56px; height: 56px; border-radius: 16px; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.brand-title { font-size: 24px; font-weight: 800; margin: 0; }
.brand-subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.form-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-control, select.form-control, textarea.form-control {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--ink);
}
.form-control:focus, select.form-control:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
textarea.form-control { resize: vertical; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: .15s;
}
.btn:hover { border-color: var(--accent-2); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-secondary { background: #f1f5f9; }
.btn-danger { background: #fff; border-color: #fca5a5; color: var(--danger); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- Portal shell ---------- */
.portal-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; background: #0f172a; color: #cbd5e1; padding: 18px;
  display: flex; flex-direction: column; gap: 16px; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.brand-panel { display: flex; gap: 10px; align-items: center; }
.brand-panel h2 { color: #fff; font-size: 16px; }
.user-card { background: rgba(255,255,255,.06); border-radius: 12px; padding: 12px; }
.user-card h3 { color: #fff; font-size: 14px; margin: 0; }
.nav-list { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #cbd5e1; text-decoration: none; font-size: 14px; font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { width: 20px; text-align: center; }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
.main-panel { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.menu-btn { display: none; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 10px; font-size: 18px; }
.page-title { font-size: 20px; margin: 0; }
.page-content { padding: 20px; max-width: 1100px; margin: 0 auto; }
.page-content.loading { opacity: .6; }

/* ---------- Cards & stats ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; gap: 8px; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-body { padding: 14px 18px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.stat-value { font-size: 24px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.stat-sub { font-size: 12px; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f8fafc; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td[data-label] { white-space: normal; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #eef2ff; color: #4338ca;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-warn { background: #fef3c7; color: #b45309; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.chip { display: inline-block; background: #eef2ff; color: #4338ca; border-radius: 999px; padding: 2px 8px; font-size: 12px; margin: 2px; }

/* ---------- Forms / toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { max-width: 260px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.form-grid label { font-size: 13px; font-weight: 600; display: flex; flex-direction: column; gap: 5px; }
.form-grid.two, .form-grid > label { min-width: 0; }
@media (min-width: 640px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid.two { grid-template-columns: repeat(2, 1fr); }
}
.muted select.form-control { font-weight: 400; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); }
.tab {
  padding: 10px 14px; border: 0; background: none; font-size: 14px; font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Alerts / empty ---------- */
.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin: 8px 0; }
.alert-info { background: #dbeafe; color: #1e3a8a; }
.alert-success { background: #dcfce7; color: #14532d; }
.alert-error { background: #fee2e2; color: #7f1d1d; }
.alert-warn { background: #fef3c7; color: #78350f; }
.empty-state { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- Toasts ---------- */
.toast-wrap { position: fixed; top: 14px; right: 14px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.toast {
  display: flex; gap: 8px; align-items: flex-start; background: #0f172a; color: #fff;
  padding: 11px 14px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 14px;
  transition: opacity .3s, transform .3s;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 500;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
@media (min-width: 640px) { .modal-overlay { align-items: center; padding: 20px; } }
.modal-card {
  background: #fff; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 20px;
}
@media (min-width: 640px) { .modal-card { border-radius: 18px; } }
.modal-card h2 { font-size: 17px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Photo grid ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-card { margin: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.photo-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #e2e8f0; }
.photo-card figcaption { padding: 8px 10px; font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.tagged { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.snap-thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; border: 2px solid var(--line); }
.tag-options { max-height: 260px; overflow-y: auto; margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }

/* ---------- Bars / charts ---------- */
.bar-row { display: grid; grid-template-columns: 110px 1fr 90px; gap: 10px; align-items: center; padding: 8px 0; }
.bar-label { font-size: 13px; font-weight: 600; }
.bar-track { background: #e2e8f0; border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; min-width: 2px; }
.bar-fill.fill-green { background: var(--success); }
.bar-fill.fill-red { background: var(--danger); }
.bar-value { font-size: 13px; font-weight: 700; text-align: right; }

/* ---------- Quick actions ---------- */
.quick-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; font-size: 15px; font-weight: 600; cursor: pointer; text-align: left;
  box-shadow: var(--shadow); color: var(--ink);
}
.quick-btn:hover { border-color: var(--accent-2); color: var(--accent); }

/* ---------- Announcements ---------- */
.ann-list { display: flex; flex-direction: column; gap: 10px; }
.ann-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.ann-item h3 { font-size: 14px; }
.ann-item p { margin: 4px 0; font-size: 14px; }

/* ---------- Face ---------- */
.face-cam { position: relative; width: 100%; }
.face-cam video { width: 100%; border-radius: 14px; max-height: 340px; background: #0f172a; }
.face-cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.face-match { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px dashed var(--line); }
#faceVideo, #faceCanvas { width: 100%; border-radius: 12px; background: #0f172a; }

/* ---------- Checkout ---------- */
.checkout { display: flex; flex-direction: column; gap: 12px; }
.checkout-amount { font-size: 30px; font-weight: 800; color: var(--accent); text-align: center; }
.pay-methods { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.child-switch { display: flex; align-items: center; gap: 8px; font-weight: 600; }

/* ---------- Timetable ---------- */
.tt-grid th, .tt-grid td { padding: 6px; text-align: center; }
.tt-hour { font-size: 12px; font-weight: 700; }
.tt-cell { min-width: 130px; }
.tt-cell select { font-size: 12px; padding: 5px; margin-bottom: 2px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .menu-btn { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
    transform: translateX(-100%); transition: transform .22s ease; width: 260px; height: 100vh;
  }
  .sidebar.open { transform: translateX(0); }
  .page-content { padding: 14px; }
  .topbar { padding: 12px 14px; }
  .tbl { display: block; }
  .tbl thead { display: none; }
  .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 6px; }
  .tbl td { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: right; padding: 8px 10px; }
  .tbl td::before { content: attr(data-label); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); text-align: left; }
  .tbl td[data-label] { white-space: normal; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 20px; }
  .search { max-width: 100%; }
  .bar-row { grid-template-columns: 90px 1fr 70px; }
}
