:root {
  --navy: #0a3a8a; --navy-d: #062a66; --blue: #2f80d8; --sky: #e8f1fc;
  --gold: #d9a420; --gold-l: #f2d06b;
  --bg: #eef3fa; --text: #1b2a41; --muted: #6b7a90; --line: #dfe7f2;
  --green: #1e9e57; --red: #d64545; --amber: #e19b1a;
  --sidebar-w: 250px; --radius: 12px;
  --shadow: 0 2px 10px rgba(10, 58, 138, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--navy); }
small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 50; overflow: hidden;
  background: linear-gradient(180deg, #0c43a0 0%, #062a66 100%); color: #fff; padding: 18px 14px; display: flex; flex-direction: column;
}
.sidebar::after {
  content: ""; position: absolute; left: -40%; bottom: -60px; width: 200%; height: 200px; pointer-events: none;
  background: radial-gradient(ellipse at 60% 100%, rgba(242, 208, 107, .55), rgba(217, 164, 32, .15) 45%, transparent 70%);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 18px; }
.brand-logo { width: 48px; height: 48px; flex: none; display: grid; place-items: center; font-size: 30px; color: var(--gold-l); }
.brand-logo img, .tb-school img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.2; }
.nav { display: flex; flex-direction: column; gap: 4px; position: relative; z-index: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 10px; color: #dbe7ff; text-decoration: none; font-weight: 500; transition: background .15s; }
.nav a i { width: 20px; text-align: center; }
.nav a:hover { background: rgba(255, 255, 255, .1); }
.nav a.active { background: linear-gradient(90deg, var(--gold-l), var(--gold)); color: var(--navy-d); font-weight: 700; box-shadow: 0 2px 8px rgba(0, 0, 0, .2); }
.backdrop { display: none; }

/* ---------- Topbar ---------- */
.main { margin-left: var(--sidebar-w); min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; background: #fff; padding: 12px 24px; border-bottom: 1px solid var(--line); }
.tb-school { width: 46px; height: 46px; display: grid; place-items: center; font-size: 34px; color: var(--gold); flex: none; }
.tb-title h1 { margin: 0; font-size: 22px; color: var(--navy); line-height: 1.15; }
.tb-title p { margin: 2px 0 0; color: var(--muted); }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.chip { border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; white-space: nowrap; background: #fafcff; }
.chip i { color: var(--navy); margin-right: 4px; }
.bell { position: relative; border: 0; background: none; font-size: 22px; color: var(--navy); cursor: pointer; padding: 4px 6px; }
.bell-n { position: absolute; top: -4px; right: -4px; background: var(--gold); color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
.sep { width: 1px; height: 30px; background: var(--line); }
.user { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.user-av { width: 34px; height: 34px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; }
.menu-btn { display: none; }
.view { padding: 22px 24px 40px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Butang & borang ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 9px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; transition: filter .15s, background .15s; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.primary { background: linear-gradient(180deg, #1456b8, var(--navy)); color: #fff; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--navy); }
.btn.ghost:hover { background: var(--sky); }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--navy); width: 32px; height: 32px; border-radius: 8px; font-size: 14px; }
.icon-btn:hover { background: var(--sky); }
.icon-btn.danger { color: var(--red); }
.icon-btn.danger:hover { background: #fdeaea; }

input, select, textarea { font: inherit; color: var(--text); }
.fld { display: flex; flex-direction: column; gap: 5px; }
.fld > span { font-weight: 600; font-size: 12.5px; color: #3b4c66; }
.fld input, .fld select, .fld textarea, .toolbar select, .search input {
  border: 1px solid #cdd8e8; border-radius: 9px; padding: 9px 11px; background: #fff; width: 100%;
}
.fld input:focus, .fld select:focus, .fld textarea:focus, .toolbar select:focus, .search input:focus { outline: 2px solid rgba(47, 128, 216, .35); border-color: var(--blue); }
.req { color: var(--red); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fld.full { grid-column: 1 / -1; }
.form-err { margin-top: 12px; background: #fdeaea; color: #a32727; border-radius: 8px; padding: 9px 12px; font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar select { width: auto; min-width: 150px; }
.search { position: relative; flex: 1 1 240px; max-width: 340px; }
.search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 36px; }
.spacer { flex: 1; }

/* ---------- Panel ---------- */
.panel { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 18px; }
.panel-h { background: linear-gradient(90deg, var(--navy), #0d4aa8); color: #fff; padding: 10px 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.panel-b { padding: 16px; }
.panel-b.nopad { padding: 0; }
.banner { background: #fff8e1; border: 1px solid #f2d98a; color: #6b5200; border-radius: 10px; padding: 12px 16px; margin-bottom: 18px; }
.banner.err { background: #fdeaea; border-color: #f0b4b4; color: #a32727; }

/* ---------- Jadual ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { background: #f4f7fc; text-align: left; padding: 10px 12px; font-size: 12.5px; color: #3b4c66; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid #edf2f9; vertical-align: top; }
.tbl tbody tr:hover { background: #f8fbff; }
.tbl .num { width: 44px; color: var(--muted); }
.tbl .center, th.center { text-align: center; }
.tbl .actions { white-space: nowrap; text-align: right; width: 84px; }
.tbl td.empty, .empty { text-align: center; color: var(--muted); padding: 28px; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; }
.avatar.L { background: var(--blue); } .avatar.P { background: var(--gold); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; color: var(--muted); flex-wrap: wrap; gap: 8px; }
.pager-btns { display: flex; align-items: center; gap: 10px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.green { background: #dff5e8; color: #14753f; }
.badge.gold { background: #fff0c2; color: #8a6200; }
.badge.amber { background: #fdecc8; color: #9a5f00; }
.badge.blue { background: #dcebfc; color: #0d5ab3; }
.badge.red { background: #fde0e0; color: #b02a2a; }
.badge.grey { background: #e9edf3; color: #55637a; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 18px; }
.kpi { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: flex; gap: 14px; align-items: center; }
.kpi-ic { width: 60px; height: 60px; border-radius: 12px; flex: none; background: linear-gradient(135deg, #1456b8, var(--navy-d)); color: #fff; display: grid; place-items: center; font-size: 26px; }
.kpi-b { flex: 1; min-width: 0; }
.kpi-l { font-weight: 500; }
.kpi-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.kpi-v { font-size: 30px; font-weight: 800; color: var(--navy-d); line-height: 1.1; }
.kpi-d { font-weight: 700; font-size: 13px; white-space: nowrap; }
.delta.good { color: var(--green); } .delta.bad { color: var(--red); }
.kpi-s { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid .panel { margin-bottom: 0; }
.g-top { grid-template-columns: 1.25fr 1.35fr 1fr; }
.g-bot { grid-template-columns: 1fr 1.35fr 1fr; }
.g-set { grid-template-columns: 1.2fr 1fr; align-items: start; }
.prof { display: flex; gap: 14px; align-items: center; }
.donut { position: relative; width: 170px; height: 170px; flex: none; }
.donut-c { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-c b { font-size: 22px; color: var(--navy-d); line-height: 1; } .donut-c span { color: var(--muted); }
.chart-box { position: relative; height: 230px; }
.mini { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini th { text-align: left; padding: 6px 8px; font-weight: 700; border-bottom: 1px solid var(--line); }
.mini td { padding: 6px 8px; border-bottom: 1px solid #f0f4fa; }
.mini .r, .mini th.r { text-align: right; }
.mini.wide th, .mini.wide td { padding: 9px 12px; }
.mini tr.link { cursor: pointer; } .mini tr.link:hover { background: #f4f8fd; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }
.stat-list { display: flex; flex-direction: column; gap: 10px; }
.stat { display: flex; align-items: center; gap: 12px; background: linear-gradient(90deg, #e3eefb, #f2f7fd); border-radius: 10px; padding: 12px 14px; text-decoration: none; color: var(--text); font-weight: 500; }
.stat i { color: var(--navy); font-size: 18px; width: 24px; text-align: center; }
.stat span { flex: 1; } .stat b { font-size: 22px; color: var(--navy-d); }
.stat:hover { filter: brightness(.97); }
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; text-decoration: none; color: var(--text); border-bottom: 1px solid #edf2f9; }
.alert > i:first-child { color: var(--navy); font-size: 18px; width: 22px; text-align: center; }
.alert > i:last-child { color: var(--muted); font-size: 12px; }
.alert span { flex: 1; }
.alert.warn { background: #fff4d2; } .alert.warn > i:first-child { color: var(--amber); }
.alert:hover { background: #f1f6fd; } .alert.warn:hover { background: #ffecb5; }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(6, 30, 70, .55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(720px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); background: linear-gradient(90deg, var(--navy), #0d4aa8); color: #fff; border-radius: 14px 14px 0 0; }
.modal-h h3 { margin: 0; font-size: 17px; } .modal-h .icon-btn { color: #fff; }
.modal-h .icon-btn:hover { background: rgba(255, 255, 255, .15); }
.modal-b { padding: 18px; overflow-y: auto; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
#toastRoot { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f7a45; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); font-weight: 600; transition: opacity .4s; }
.toast.err { background: var(--red); } .toast.hide { opacity: 0; }

/* ---------- Tetapan ---------- */
.logo-row { display: flex; gap: 16px; align-items: center; }
.logo-prev { width: 84px; height: 84px; border: 1px dashed #b7c6dc; border-radius: 12px; display: grid; place-items: center; font-size: 40px; color: var(--gold); background: #fafcff; flex: none; }
.logo-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-row input[type=file] { display: block; margin-bottom: 8px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.warn-note { background: #fff8e1; border-radius: 8px; padding: 10px 12px; font-size: 13px; color: #6b5200; }
#cnt { margin-top: 12px; }

/* ---------- Laporan ---------- */
.rep-ctl { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.rep-ctl .fld { min-width: 180px; }
.rep-filters { display: flex; gap: 14px; flex-wrap: wrap; }
.report { background: #fff; max-width: 1000px; margin: 0 auto 24px; padding: 30px 34px; box-shadow: var(--shadow); border-radius: 6px; color: #000; }
.rh { display: flex; align-items: center; gap: 16px; justify-content: center; border-bottom: 3px double var(--navy); padding-bottom: 12px; }
.rh img, .rh > i { width: 64px; height: 64px; object-fit: contain; font-size: 52px; color: var(--navy); display: grid; place-items: center; }
.rh h2 { margin: 0; font-size: 20px; text-transform: uppercase; } .rh h3 { margin: 2px 0 0; font-size: 14px; font-weight: 500; }
.rt { text-align: center; margin: 16px 0 2px; font-size: 17px; text-transform: uppercase; }
.rs { text-align: center; margin: 0 0 14px; color: #444; }
.rsec { margin: 18px 0 6px; font-size: 14px; color: var(--navy-d); }
.rtbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rtbl th, .rtbl td { border: 1px solid #9aa7bb; padding: 5px 8px; text-align: left; }
.rtbl th { background: #e8eef8; }
.rtbl td.center { text-align: center; color: #666; }
.sum { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.sum div { flex: 1; min-width: 110px; border: 1px solid #9aa7bb; border-radius: 6px; padding: 8px; text-align: center; }
.sum b { display: block; font-size: 20px; color: var(--navy-d); } .sum span { font-size: 12px; color: #444; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.sign { display: flex; justify-content: space-between; gap: 40px; margin-top: 44px; }
.sign div { flex: 1; } .sign p { margin: 0 0 40px; }
.sign span { display: block; border-bottom: 1px solid #000; } .sign small { color: #000; margin-top: 4px; }
.rf { text-align: right; font-size: 11px; color: #666; margin-top: 16px; }

/* ---------- Responsif ---------- */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .g-top, .g-bot { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 40; }
  .main { margin-left: 0; }
  .menu-btn { display: block; font-size: 20px; }
  .tb-school, .chip { display: none; }
  .g-top, .g-bot, .g-set { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; } .view { padding: 16px 14px 32px; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .form-grid, .cols2 { grid-template-columns: 1fr; }
  .tb-title h1 { font-size: 17px; } .tb-title p, .user span:last-child, .sep { display: none; }
  .prof { flex-direction: column; }
  .toolbar select, .search { max-width: none; flex: 1 1 100%; width: 100%; }
}
@media (max-width: 420px) { .kpis { grid-template-columns: 1fr; } }

/* ---------- Cetak ---------- */
@media print {
  .sidebar, .topbar, .no-print, .backdrop, #toastRoot, #modalRoot { display: none !important; }
  .main { margin: 0 !important; }
  body { background: #fff; font-size: 12px; }
  .view { padding: 0 !important; }
  .report { box-shadow: none; border-radius: 0; padding: 0; max-width: none; margin: 0; }
  .rtbl { font-size: 11px; }
  .rtbl thead { display: table-header-group; }
  .rtbl tr, .sum div, .sign { page-break-inside: avoid; }
  .rsec { page-break-after: avoid; }
  @page { size: A4; margin: 14mm; }
}
