:root {
  --navy: #0a1f4d;
  --navy-2: #0f2d6b;
  --blue: #1d5fd8;
  --gold: #f5b82e;
  --gold-d: #d99a0b;
  --bg: #e9f0fb;
  --card: #ffffff;
  --text: #12264d;
  --muted: #64748b;
  --line: #dbe4f3;
  --red: #e5484d;
  --green: #22a45d;
  --sidebar-w: 224px;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Poppins', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

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

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  flex: none;
  background:
    radial-gradient(120% 60% at 0% 100%, rgba(245, 184, 46, .28), transparent 55%),
    linear-gradient(180deg, #0a1f4d 0%, #0b2a66 60%, #0a1f4d 100%);
  color: #fff;
  position: fixed; top: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column;
  z-index: 40;
  overflow-y: auto;
}
.brand { padding: 22px 16px 14px; text-align: center; border-bottom: 1px solid rgba(255, 255, 255, .12); margin: 0 12px; }
.brand-logo { height: 54px; display: flex; align-items: center; justify-content: center; color: var(--gold); font-size: 40px; }
.brand-logo img { max-height: 54px; max-width: 90px; object-fit: contain; }
.brand h2 { font-size: 18px; font-weight: 700; margin-top: 8px; }
.brand small { display: block; font-size: 11px; opacity: .8; margin-top: 2px; }

.nav { padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 9px;
  font-weight: 500; font-size: 13.5px; color: #e8efff;
  transition: background .15s;
}
.nav a i { width: 20px; text-align: center; font-size: 16px; }
.nav a:hover { background: rgba(255, 255, 255, .1); }
.nav a.active { background: var(--gold); color: var(--navy); font-weight: 700; }
.side-foot { margin-top: auto; padding: 18px; font-size: 40px; color: var(--gold); opacity: .85; text-align: center; }

#backdrop { display: none; }

/* ---------- Main ---------- */
#main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 22px;
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 2px 8px rgba(10, 31, 77, .25);
}
#menu-btn { display: none; }
.title-wrap { display: flex; align-items: center; gap: 12px; margin-right: auto; min-width: 0; }
.title-icon {
  width: 40px; height: 40px; border-radius: 9px; background: var(--gold); color: var(--navy);
  display: grid; place-items: center; font-size: 20px; flex: none;
}
#page-title { font-size: 22px; font-weight: 700; line-height: 1.2; }
#page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#view { padding: 18px 22px 30px; }

.loading { text-align: center; padding: 60px; color: var(--muted); }

/* ---------- Penapis ---------- */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter {
  display: flex; align-items: center; gap: 8px;
  background: #0d2a66; border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 8px; padding: 4px 6px 4px 12px; color: #fff; font-size: 13px; font-weight: 500;
}
.filter select, .filter input {
  background: #fff; color: var(--navy); border: 0; border-radius: 6px; padding: 5px 8px; font-weight: 600; outline: none;
}

/* ---------- Butang ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; font-size: 13px; cursor: pointer;
  transition: filter .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.ghost { background: rgba(255, 255, 255, .12); color: #fff; border: 1px solid rgba(255, 255, 255, .3); }
.modal .btn.ghost { background: #eef3fc; color: var(--navy); border-color: var(--line); }
.btn.ghost-dark { background: #fff; color: var(--navy-2); border: 1px solid #c3d2ee; }
.btn.danger { background: var(--red); color: #fff; }
.btn.push { margin-left: auto; }
.icon-btn { background: transparent; border: 0; cursor: pointer; width: 32px; height: 32px; border-radius: 7px; color: var(--navy-2); }
.icon-btn:hover { background: #e4ecfa; }
.icon-btn.del { color: var(--red); }
#topbar .icon-btn { color: #fff; font-size: 18px; }
#topbar .icon-btn:hover { background: rgba(255, 255, 255, .12); }

/* ---------- Kad / Panel ---------- */
.card, .panel { background: var(--card); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(20, 50, 110, .08); border: 1px solid #d6e2f5; }
.card { padding: 14px; margin-bottom: 16px; }
.panel { overflow: hidden; }
.panel-h {
  background: var(--navy); color: #fff; font-weight: 600; font-size: 15px;
  padding: 10px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 3px solid var(--gold);
}
.panel-h i { color: var(--gold); }
.panel-b { padding: 14px; }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; margin-bottom: 16px; }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }

.period-note { margin-bottom: 12px; color: var(--muted); }
.period-note b { color: var(--navy-2); }
.warn { color: var(--red); font-weight: 600; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 16px; }
.kpis.four { grid-template-columns: repeat(4, 1fr); }
.kpi {
  border-radius: var(--radius); padding: 14px; display: flex; align-items: center; gap: 12px;
  border: 1px solid rgba(0, 0, 0, .06); box-shadow: 0 2px 8px rgba(20, 50, 110, .07);
}
.kpi > i { font-size: 30px; }
.kpi .k-label { display: block; font-weight: 600; font-size: 12.5px; }
.kpi .k-value { display: block; font-size: 28px; line-height: 1.15; font-weight: 800; }
.kpi small { font-size: 12px; font-weight: 500; opacity: .85; }
.kpi.blue { background: #dfeafc; color: #1d4fae; }
.kpi.green { background: #dcf3e4; color: #16803f; }
.kpi.red { background: #fde0e0; color: #c4262c; }
.kpi.gold { background: #fdecc5; color: #a8700a; }
.kpi.purple { background: #e8e0fa; color: #6a3fc7; }
.kpi.sky { background: #dff1fb; color: #0d5f86; }
.kpi .k-label, .kpi .k-value, .kpi small { color: #12264d; }
.kpi.red .k-value { color: #c4262c; }
.kpi.green .k-value { color: #16803f; }

/* ---------- Carta ---------- */
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 300px; }
.trend-panel { display: flex; flex-direction: column; }
.trend-panel > .panel-h { flex-shrink: 0; }
.trend-panel > .chart-box { flex: 1; height: 0; min-height: 260px; }
.donut-wrap { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.donut { position: relative; width: 340px; max-width: 100%; height: 270px; flex: none; margin: 0 auto; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 210px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-weight: 600; font-size: 13px; }
.legend li span { flex: 1; }
.legend li em { font-style: normal; font-weight: 500; color: var(--muted); font-size: 12.5px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; flex: none; }
.legend .dot { margin: 0; }
.dot.lg { width: 22px; height: 22px; border-radius: 6px; margin: 0; }
.avg-badge {
  position: absolute; top: 0; right: 0; z-index: 2; background: var(--navy); border: 2px solid var(--gold);
  color: #fff; border-radius: 10px; padding: 5px 14px; text-align: center;
}
.avg-badge small { display: block; font-size: 10.5px; }
.avg-badge b { color: var(--gold); font-size: 22px; line-height: 1.1; }

.mini-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini { border-radius: 10px; padding: 12px 8px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.mini i { font-size: 24px; }
.mini span { font-weight: 600; font-size: 12.5px; }
.mini b { font-size: 21px; font-weight: 800; }
.mini small { font-size: 11px; }
.mini.green { background: #dcf3e4; color: #16803f; }
.mini.red { background: #fde0e0; color: #c4262c; }
.mini.purple { background: #e8e0fa; color: #6a3fc7; }
.mini.sky { background: #dff1fb; color: #0d5f86; }
.mini span, .mini small { color: #12264d; }

/* ---------- Jadual ---------- */
.table-wrap { overflow-x: auto; }
.tall-scroll { max-height: 440px; overflow-y: auto; }
.short-scroll { max-height: 260px; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th.l, .tbl td.l { text-align: left; }
.tbl thead th { background: #eaf1fd; color: var(--navy); font-weight: 700; position: sticky; top: 0; z-index: 1; }
.tbl tbody tr:hover { background: #f5f9ff; }
.tbl.compact { font-size: 12px; }
.tbl.compact th, .tbl.compact td { padding: 5px 7px; }
.tbl tfoot td { background: #fbe9b5; font-weight: 800; color: var(--navy); border-bottom: 0; }
.tbl .act { white-space: nowrap; }
.empty-row { text-align: center !important; color: var(--muted); padding: 24px !important; }
.muted { color: var(--muted); }
.link-more { display: inline-block; margin-top: 10px; color: var(--blue); font-weight: 600; font-size: 12.5px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; color: #fff; background: #888; }
.badge.ok { background: var(--green); }
.badge.off { background: #94a3b8; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.search { display: flex; align-items: center; gap: 8px; background: #f2f6fd; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; flex: 1; min-width: 200px; max-width: 360px; }
.search input { border: 0; background: transparent; outline: none; padding: 9px 0; width: 100%; }
.sel { border: 1px solid var(--line); background: #f2f6fd; border-radius: 8px; padding: 9px 10px; outline: none; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding-top: 12px; color: var(--muted); font-size: 12.5px; }
.pager:empty { display: none; }

/* ---------- Borang / Modal ---------- */
.fld { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 13px; }
.fld > span { font-weight: 600; color: var(--navy-2); }
.fld input, .fld select, .fld textarea, .inline-form input {
  border: 1px solid #c3d2ee; background: #fff; border-radius: 8px; padding: 9px 11px; outline: none; width: 100%;
}
.fld input:focus, .fld select:focus, .inline-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29, 95, 216, .15); }
.fld input[type=color] { height: 42px; padding: 3px; width: 90px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { background: #fff6dc; border: 1px solid #f3dc9a; color: #7a5a06; border-radius: 8px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 12px; }
.hint:empty { display: none; }

.modal-overlay { position: fixed; inset: 0; background: rgba(6, 18, 48, .55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 480px; max-width: 100%; max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal.small { width: 400px; }
.modal.wide { width: 640px; }
.modal-head { background: var(--navy); color: #fff; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid var(--gold); }
.modal-head h3 { font-size: 16px; }
.modal-head .icon-btn { color: #fff; }
.modal-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal > .modal-body { padding: 18px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); background: #f6f9ff; }
.modal > .modal-foot { margin-top: 0; }
.confirm-msg { margin: 0; line-height: 1.6; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 12px; }
.mini-months { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; margin-bottom: 12px; text-align: center; }
.mini-months div { background: #eef3fc; border-radius: 6px; padding: 4px 0; }
.mini-months small { display: block; font-size: 10px; color: var(--muted); }
.mini-months b { font-size: 13px; }

#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--navy); color: #fff; border-left: 4px solid var(--gold); border-radius: 8px; padding: 10px 16px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); transition: opacity .4s, transform .4s; font-size: 13px; }
.toast.err { border-left-color: var(--red); }
.toast.ok i { color: var(--gold); }
.toast.err i { color: #ff8b8f; }
.toast.hide { opacity: 0; transform: translateX(20px); }

/* ---------- Halaman kosong ---------- */
.empty { text-align: center; padding: 50px 20px; }
.empty > i { font-size: 46px; color: var(--gold); margin-bottom: 10px; }
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--muted); margin: 0 0 16px; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.settings .row-actions { justify-content: flex-start; }

/* ---------- Tetapan ---------- */
.settings { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; align-items: start; }
.school-form { display: flex; gap: 18px; flex-wrap: wrap; }
.logo-box { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.logo-prev { width: 96px; height: 96px; border-radius: 12px; background: var(--navy); color: var(--gold); display: grid; place-items: center; font-size: 46px; overflow: hidden; }
.logo-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }
.school-fields { flex: 1; min-width: 220px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 10px; }
.chk { display: flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; }
.chk input { accent-color: var(--blue); width: 16px; height: 16px; }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 130px; width: auto; }

/* ---------- Laporan ---------- */
.report-head { text-align: center; margin-bottom: 14px; }
.report-head h2 { font-size: 18px; color: var(--navy); }
.report-head h3 { font-size: 15px; font-weight: 600; margin-top: 2px; }
.report-head small { color: var(--muted); }

/* ---------- Responsif ---------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
  .settings { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  #sidebar { transform: translateX(-100%); transition: transform .25s; }
  body.menu-open #sidebar { transform: none; }
  body.menu-open #backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 35; }
  #main { margin-left: 0; }
  #menu-btn { display: inline-block; }
  #topbar { padding: 10px 14px; }
  #view { padding: 14px; }
  #page-title { font-size: 17px; }
}
@media (max-width: 560px) {
  .kpis, .kpis.four { grid-template-columns: repeat(2, 1fr); }
  .two { grid-template-columns: 1fr; }
  .kpi .k-value { font-size: 22px; }
  .avg-badge { position: static; margin-bottom: 6px; display: inline-block; }
}

/* ---------- Cetak ---------- */
@media print {
  body { background: #fff; }
  #sidebar, #topbar, .no-print, #backdrop, #toast-root { display: none !important; }
  #main { margin: 0; }
  #view { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .tbl th, .tbl td { padding: 3px 5px; font-size: 10px; }
  .tbl thead th { background: #eee !important; position: static; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tbl tfoot td { background: #fbe9b5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
[hidden] { display: none !important; }
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(100%, 420px); }
.auth-card .fld { margin: 12px 0; }
.auth-error { color: #b91c1c; }
