:root {
  --navy: #0a2a6e; --navy2: #0f3d94; --blue: #1f5fd1; --gold: #f2b705; --gold2: #ffe08a;
  --bg: #eef2fa; --card: #fff; --ink: #1b2a4e; --muted: #6b7a99; --line: #e1e7f3;
  --ok: #1f9d62; --warn: #c98a00; --bad: #d64545;
  --r: 14px; --shadow: 0 2px 10px rgba(15, 40, 100, .08);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font-family: "Poppins", "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); font-size: 14px; }
h1, h2, h3, p { margin: 0; }
code { background: #eef2fb; padding: 1px 6px; border-radius: 5px; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: 12px; margin-top: 8px; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }
#print-host { display: none; }

/* ---------- Rangka ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex-shrink: 0; background: linear-gradient(180deg, var(--navy) 0%, #07235c 70%, #0a2a6e 100%);
  color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30; }
.brand { padding: 22px 16px 14px; text-align: center; font-weight: 600; font-size: 12.5px; letter-spacing: .4px; line-height: 1.35; }
.brand img { width: 74px; height: 74px; object-fit: contain; display: block; margin: 0 auto 8px; }
.brand i { font-size: 46px; color: var(--gold); display: block; margin-bottom: 10px; }
.sidebar nav { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; color: #dbe5ff; text-decoration: none;
  padding: 11px 14px; border-radius: 12px; font-weight: 500; transition: .15s; }
.sidebar nav a i { width: 20px; text-align: center; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .1); }
.sidebar nav a.active { background: linear-gradient(90deg, var(--gold), #ffd54a); color: var(--navy); font-weight: 700; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.side-foot { padding: 12px 16px; font-size: 11px; color: #9db3e8; text-align: center; border-top: 1px solid rgba(255,255,255,.12); }

.main { flex: 1; min-width: 0; }
.topbar { position: relative; display: flex; align-items: center; gap: 16px; padding: 14px 24px; min-height: 92px; overflow: hidden;
  background: linear-gradient(90deg, #fff 0%, #f4f8ff 55%, #dfeafe 100%); border-bottom: 1px solid var(--line); }
.topbar .hat { font-size: 40px; color: var(--navy); }
.topbar .title { position: relative; z-index: 2; }
.topbar h1 { font-size: 26px; font-weight: 800; color: var(--navy); letter-spacing: .3px; line-height: 1.15; }
.topbar p { font-weight: 600; color: #26407f; letter-spacing: .5px; }
.topbar .banner { position: absolute; right: 0; top: 0; bottom: 0; width: 42%; z-index: 1; background: var(--banner) center/cover no-repeat;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 40%); mask-image: linear-gradient(90deg, transparent, #000 40%); }
.menu-btn { display: none; }
#view { padding: 18px 24px 40px; outline: none; }

/* ---------- Kad ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; min-width: 0; }
.card h3 { font-size: 15px; color: var(--navy); font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h3 i { color: var(--navy2); }
.card.gold { background: linear-gradient(135deg, #fff8e0, #fff); border: 1px solid var(--gold2); }
.card.error pre { white-space: pre-wrap; font-size: 12px; background: #fff4f4; padding: 10px; border-radius: 8px; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid > .card, .grid > .stack > .card { margin-bottom: 0; }
.g-top { grid-template-columns: 1.7fr 1.1fr 1fr; }
.g-bottom { grid-template-columns: 1fr 1.6fr; }
.g-two { grid-template-columns: 1fr 1fr; }
.g-enrol { grid-template-columns: 1.7fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.chart-box { position: relative; height: 270px; }
.chart-box.tall { height: 520px; }

/* ---------- KPI ---------- */
.filterbar { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; background: var(--card); padding: 10px 16px; border-radius: var(--r); box-shadow: var(--shadow); margin-bottom: 16px; }
.filterbar label { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--navy); }
.filterbar select { font-family: inherit; padding: 7px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi { position: relative; display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: var(--r); background: #fff; color: var(--navy);
  box-shadow: var(--shadow); overflow: hidden; }
.kpi::after { content: ""; position: absolute; right: -20px; bottom: -28px; width: 120px; height: 60px; background: var(--gold); opacity: .8; transform: rotate(-18deg); border-radius: 40px; }
.kpi.navy { background: linear-gradient(135deg, var(--navy), var(--navy2)); color: #fff; }
.kpi > i { font-size: 36px; color: var(--gold); }
.kpi span { display: block; font-weight: 600; font-size: 14px; opacity: .9; }
.kpi b { font-size: 36px; font-weight: 800; line-height: 1.1; }
.kpi em { position: relative; z-index: 2; margin-left: auto; font-style: normal; font-size: 11.5px; font-weight: 600; background: rgba(255,255,255,.9);
  color: var(--navy); padding: 5px 9px; border-radius: 8px; text-align: center; }
.kpi:not(.navy) em { background: #eef3ff; }
.kpi em.up { color: var(--ok); } .kpi em.down { color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { display: flex; align-items: center; gap: 12px; background: #fff; padding: 14px 16px; border-radius: var(--r); box-shadow: var(--shadow); }
.stat > i { font-size: 22px; color: #fff; background: var(--navy2); width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.stat b { font-size: 22px; color: var(--navy); font-weight: 700; }
.stat small { display: block; font-size: 11px; color: var(--muted); }

.mini2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini2 > div { background: #f3f7ff; border-radius: 12px; padding: 10px 12px; text-align: center; }
.card.gold .mini2 > div { background: #fff1c2; }
.mini2 small { display: block; font-weight: 600; color: var(--muted); font-size: 12px; }
.mini2 b { font-size: 24px; color: var(--navy); font-weight: 800; }
.line { margin-top: 10px; font-size: 13px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: #dcf5e8; color: #14774a; } .pill.warn { background: #fff0cc; color: #9a6a00; } .pill.bad { background: #fde1e1; color: #b02f2f; }

/* ---------- Bar mendatar ---------- */
.hbars { display: flex; flex-direction: column; gap: 10px; max-height: 360px; overflow-y: auto; padding-right: 6px; }
.hbar { display: grid; grid-template-columns: 52px 1fr 58px; gap: 10px; align-items: center; font-weight: 600; }
.hbar .track { height: 18px; background: #e9eef9; border-radius: 99px; overflow: hidden; }
.hbar .fill { height: 100%; background: linear-gradient(90deg, var(--navy), var(--blue)); border-radius: 99px; }
.hbar b { text-align: right; color: var(--navy); }

/* ---------- Jadual ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap.short { max-height: 330px; } .table-wrap.tall { max-height: 62vh; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { position: sticky; top: 0; background: var(--navy); color: #fff; padding: 9px 12px; text-align: left; font-weight: 600; white-space: nowrap; z-index: 1; }
.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: #f5f8ff; }
.tbl .num { text-align: right; width: 54px; } .tbl .c { text-align: center; } .tbl .act { white-space: nowrap; text-align: right; width: 90px; }
.tbl .yes { color: var(--ok); }
.tbl .empty, .empty { text-align: center; color: var(--muted); padding: 24px; }
.tbl .tot { background: linear-gradient(90deg, #fff1b8, #ffe08a); color: var(--navy); font-weight: 700; text-align: center; }
.tbl th.tot { background: var(--gold); }
.tbl tr.subtotal td { background: #eaf0ff; font-weight: 700; }
.tbl tr.grand td { background: var(--navy); color: #fff; font-weight: 700; }
.tbl tr.dim td { color: #a5b0c8; }
.tbl.summary td, .tbl.summary th { text-align: center; white-space: nowrap; padding: 8px 8px; }
.tbl.summary td:first-child { text-align: left; font-weight: 600; } .tbl.summary td:first-child i { color: var(--navy2); width: 18px; }
.tbl tfoot td { background: #eaf0ff; font-weight: 700; text-align: center; padding: 8px 6px; }
.grid-edit input { width: 66px; padding: 5px 4px; border: 1px solid transparent; border-radius: 6px; text-align: center; background: #f6f8fd; font-family: inherit; font-size: 12.5px; }
.grid-edit input:hover { border-color: var(--line); } .grid-edit input:focus { outline: 2px solid var(--blue); background: #fff; }
.grid-edit input.saved { background: #d9f6e6; }
.grid-edit td { padding: 4px 3px; text-align: center; } .grid-edit td:first-child { text-align: left; padding-left: 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.search { position: relative; } .search i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }
.search input { padding: 8px 12px 8px 32px; border: 1px solid var(--line); border-radius: 10px; font-family: inherit; min-width: 220px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .inline-label select, select.inline { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-family: inherit; background: #fff; }
select.inline { font-size: 13px; font-weight: 600; color: var(--navy); }
.inline-label { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--navy); }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 12px; color: var(--muted); }

/* ---------- Butang ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent; border-radius: 10px; padding: 8px 15px; font-family: inherit;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: .15s; }
.btn.primary { background: linear-gradient(135deg, var(--navy2), var(--blue)); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn.ghost:hover { background: #f1f5ff; }
.btn.danger, .btn.primary.danger { background: var(--bad); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; cursor: pointer; width: 32px; height: 32px; border-radius: 8px; color: var(--navy2); font-size: 14px; }
.icon-btn:hover { background: #e8efff; } .icon-btn.del { color: var(--bad); } .icon-btn.del:hover { background: #fde8e8; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button { border: 0; background: #fff; padding: 9px 18px; border-radius: 99px; font-family: inherit; font-weight: 600; color: var(--navy); cursor: pointer; box-shadow: var(--shadow); }
.tabs button.on { background: var(--navy); color: #fff; }

/* ---------- Modal & borang ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 20, 55, .55); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: #fff; border-radius: 16px; width: min(520px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { color: var(--navy); font-size: 17px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.confirm-msg { line-height: 1.6; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; } .field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.req { color: var(--bad); }
.field input:not([type=checkbox]), .field select, .field textarea { padding: 9px 11px; border: 1px solid #cfd8ec; border-radius: 10px; font-family: inherit; font-size: 13.5px; width: 100%; background: #fff; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--blue); border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px !important; color: var(--ink) !important; font-weight: 500 !important; padding-top: 8px; }
.form-actions { margin-top: 16px; text-align: right; }

.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; margin: 12px 0; }
.day { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 4px 0; cursor: pointer; font-family: inherit; display: flex; flex-direction: column; align-items: center; }
.day small { color: var(--muted); font-size: 10.5px; } .day b { height: 20px; font-size: 15px; }
.day.wk { background: #f1f3f8; } .day.p { background: #dcf5e8; border-color: #8fd7b2; color: #14774a; } .day.a { background: #fde1e1; border-color: #f0a3a3; color: #b02f2f; }

.img-set { display: grid; grid-template-columns: 1fr 1.6fr; gap: 16px; margin-top: 16px; }
.img-set label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.img-prev { height: 100px; border: 2px dashed var(--line); border-radius: 12px; display: grid; place-items: center; margin-bottom: 8px; overflow: hidden; background: #f7f9fe; color: var(--muted); }
.img-prev img { max-width: 100%; max-height: 100%; object-fit: contain; } .img-prev.wide img { width: 100%; height: 100%; object-fit: cover; }
.steps { padding-left: 20px; line-height: 1.8; margin: 8px 0 14px; }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-weight: 500; animation: slide .25s; transition: opacity .4s; }
.toast.err { background: var(--bad); } .toast i { margin-right: 6px; } .toast.hide { opacity: 0; }
@keyframes slide { from { transform: translateY(14px); opacity: 0; } }

/* ---------- Responsif ---------- */
@media (max-width: 1280px) { .g-top { grid-template-columns: 1fr 1fr; } .g-top .stack { grid-column: 1 / -1; flex-direction: row; } .g-top .stack > * { flex: 1; } }
@media (max-width: 1000px) {
  .kpis { grid-template-columns: 1fr 1fr; } .g-bottom, .g-two, .g-enrol { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -250px; transition: left .25s; } .sidebar.open { left: 0; box-shadow: 8px 0 30px rgba(0,0,0,.3); }
  .menu-btn { display: block; position: relative; z-index: 3; font-size: 20px; }
}
@media (max-width: 640px) {
  .kpis, .g-top { grid-template-columns: 1fr; } .g-top .stack { flex-direction: column; }
  #view { padding: 12px; } .topbar h1 { font-size: 18px; } .form-grid, .img-set { grid-template-columns: 1fr; }
  .topbar .banner { display: none; }
}

/* ---------- Cetak ---------- */
@media print {
  body.printing #app, body.printing #toasts, body.printing .overlay { display: none !important; }
  body.printing #print-host { display: block; padding: 10mm; background: #fff; color: #000; font-size: 11px; }
  body.printing #print-host h2 { font-size: 16px; margin-bottom: 4px; }
  body.printing #print-host table { width: 100%; border-collapse: collapse; margin-top: 10px; }
  body.printing #print-host th, body.printing #print-host td { border: 1px solid #555; padding: 3px 6px; text-align: left; }
  body.printing #print-host th { background: #e6e6e6; }
  .print-foot { margin-top: 10px; font-size: 10px; color: #555; }
  body:not(.printing) #print-host { display: none; }
}
