:root{
  --bg:#f5f7fd; --surface:#fff; --ink:#1f2540; --muted:#69708d; --line:#e3e7f4;
  --blue:#4f6df5; --blue-soft:#e6ebff; --green:#2fb67c; --green-soft:#ddf5ea;
  --purple:#8b6fe0; --purple-soft:#ece7fb; --orange:#f0963a; --orange-soft:#fdeedb;
  --red:#d9485f; --red-soft:#fde4e8; --radius:12px;
  --wk:#f0ecfb; --hol:#fde8ec;
  --font:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
@media (prefers-color-scheme:dark){
  :root{--bg:#141829; --surface:#1d2238; --ink:#e8ebf8; --muted:#9aa2c4; --line:#2c3354;
    --wk:#241f45; --hol:#3d2230; --blue-soft:#26305f; --green-soft:#1c3b31; --purple-soft:#32295a; --orange-soft:#4a3520; --red-soft:#4a2530}
}
*{box-sizing:border-box}
html,body{margin:0}
body{font-family:var(--font);background:var(--bg);color:var(--ink);line-height:1.5;font-size:16px;-webkit-text-size-adjust:100%}
h1,h2,h3{line-height:1.25;margin:0 0 .5rem}
h2{font-size:1.25rem}h3{font-size:1.05rem}
button,input,select,textarea{font:inherit;color:inherit}
:focus-visible{outline:3px solid var(--blue);outline-offset:2px}
.boot{padding:3rem;text-align:center;color:var(--muted)}
.hidden{display:none!important}

/* Log masuk */
.auth{min-height:100vh;display:grid;place-items:center;padding:1rem}
.auth-card{background:var(--surface);border:1px solid var(--line);border-radius:18px;padding:2rem;width:100%;max-width:400px}
.brand{display:flex;align-items:center;gap:.75rem;margin-bottom:1.25rem}
.brand-mark{width:44px;height:44px;border-radius:12px;background:var(--blue);display:grid;place-items:center;color:#fff;font-weight:700;font-size:1.3rem}
.brand b{font-size:1.3rem;letter-spacing:.02em;display:block}
.brand small{color:var(--muted);display:block;margin-top:-.15rem}
.motto{color:var(--muted);font-style:italic;margin:.75rem 0 0;font-size:.9rem}

/* Kerangka */
.shell{display:grid;grid-template-columns:230px 1fr;min-height:100vh}
.side{background:var(--surface);border-right:1px solid var(--line);padding:1rem;position:sticky;top:0;height:100vh;overflow:auto;display:flex;flex-direction:column;gap:.25rem}
.side .brand{margin-bottom:1rem}
.nav button{display:flex;width:100%;align-items:center;gap:.6rem;background:none;border:0;border-radius:10px;padding:.6rem .75rem;cursor:pointer;text-align:left;color:var(--muted);font-weight:500}
.nav button:hover{background:var(--blue-soft)}
.nav button[aria-current=page]{background:var(--blue-soft);color:var(--blue);font-weight:650}
.nav svg{width:20px;height:20px;flex:none}
.side-foot{margin-top:auto;font-size:.85rem;color:var(--muted);padding-top:1rem}
main{padding:1.25rem 1.5rem 5rem;max-width:1100px;width:100%}
.topbar{display:flex;flex-wrap:wrap;gap:.75rem;align-items:center;justify-content:space-between;margin-bottom:1rem}
.sync{display:flex;align-items:center;gap:.5rem;font-size:.85rem;color:var(--muted)}
.dot{width:9px;height:9px;border-radius:50%;background:var(--green)}
.dot.err{background:var(--red)}.dot.busy{background:var(--orange)}

/* Kawalan */
.btn{border:1px solid var(--line);background:var(--surface);border-radius:10px;padding:.5rem .9rem;cursor:pointer;font-weight:550;display:inline-flex;align-items:center;gap:.4rem;min-height:40px}
.btn:hover{background:var(--blue-soft)}
.btn.primary{background:var(--blue);border-color:var(--blue);color:#fff}
.btn.primary:hover{filter:brightness(1.08)}
.btn.good{background:var(--green);border-color:var(--green);color:#fff}
.btn.danger{color:var(--red);border-color:var(--red)}
.btn.danger.solid{background:var(--red);color:#fff}
.btn.sm{padding:.25rem .6rem;min-height:32px;font-size:.88rem}
.btn:disabled{opacity:.55;cursor:not-allowed}
.row{display:flex;flex-wrap:wrap;gap:.5rem;align-items:center}
.spread{justify-content:space-between}
input[type=text],input[type=email],input[type=password],input[type=date],input[type=time],input[type=number],input[type=search],select,textarea{
  width:100%;border:1px solid var(--line);background:var(--surface);border-radius:10px;padding:.5rem .7rem;min-height:40px}
textarea{min-height:70px;resize:vertical}
label{display:block;font-weight:550;font-size:.9rem;margin-bottom:.2rem}
.field{margin-bottom:.8rem}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:.75rem}
.help{font-size:.82rem;color:var(--muted);margin-top:.2rem}
.err-text{color:var(--red);font-size:.9rem;margin:.4rem 0}

.card{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);padding:1rem}
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:.75rem;margin-bottom:1rem}
.stat{display:flex;gap:.75rem;align-items:center}
.stat .ic{width:42px;height:42px;border-radius:12px;display:grid;place-items:center;flex:none}
.stat .ic svg{width:22px;height:22px}
.stat b{display:block;font-size:1.25rem;line-height:1.2}
.stat span{color:var(--muted);font-size:.85rem}
.t-blue{background:var(--blue-soft);color:var(--blue)}.t-green{background:var(--green-soft);color:var(--green)}
.t-purple{background:var(--purple-soft);color:var(--purple)}.t-orange{background:var(--orange-soft);color:var(--orange)}.t-red{background:var(--red-soft);color:var(--red)}

.alerts{display:grid;gap:.5rem;margin-bottom:1rem}
.alert{border-radius:10px;padding:.6rem .9rem;display:flex;gap:.6rem;align-items:center;border:1px solid transparent}
.alert.red{background:var(--red-soft);color:var(--red);border-color:var(--red)}
.alert.orange{background:var(--orange-soft);color:var(--orange)}
.alert.blue{background:var(--blue-soft);color:var(--blue)}
.alert.green{background:var(--green-soft);color:var(--green)}
.alert strong{font-weight:650}

.chips{display:flex;flex-wrap:wrap;gap:.4rem;margin-bottom:.75rem}
.chip{border:1px solid var(--line);background:var(--surface);border-radius:999px;padding:.3rem .8rem;cursor:pointer;font-size:.9rem;display:inline-flex;gap:.4rem;align-items:center}
.chip[aria-pressed=true]{background:var(--blue);color:#fff;border-color:var(--blue)}
.sw{width:10px;height:10px;border-radius:50%;display:inline-block;flex:none}

.list{display:grid;gap:.5rem}
.item{display:grid;grid-template-columns:auto 1fr auto;gap:.75rem;align-items:center;background:var(--surface);border:1px solid var(--line);border-left-width:5px;border-radius:10px;padding:.6rem .8rem;cursor:pointer;text-align:left;width:100%}
.item:hover{background:var(--blue-soft)}
.item .d{min-width:62px;text-align:center;font-size:.8rem;color:var(--muted)}
.item .d b{display:block;font-size:1.15rem;color:var(--ink)}
.item .t{font-weight:600}
.item .s{font-size:.85rem;color:var(--muted)}
.item .r{text-align:right;font-size:.88rem}
.badge{display:inline-block;border-radius:999px;padding:.1rem .6rem;font-size:.78rem;font-weight:600}
.b-belum{background:var(--orange-soft);color:var(--orange)}.b-dibayar{background:var(--green-soft);color:var(--green)}
.b-tertunggak{background:var(--red-soft);color:var(--red)}.b-ditangguh{background:var(--purple-soft);color:var(--purple)}
.b-dibatalkan{background:var(--line);color:var(--muted)}.b-peristiwa{background:var(--blue-soft);color:var(--blue)}
.amt{font-weight:650;white-space:nowrap}.amt.unset{color:var(--orange);font-weight:550}
.empty{padding:2rem;text-align:center;color:var(--muted);border:1px dashed var(--line);border-radius:12px}

/* Kalendar */
.cal-head{display:flex;flex-wrap:wrap;gap:.5rem;align-items:center;justify-content:space-between;margin-bottom:.75rem}
.cal{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--surface)}
.cal .dow{background:var(--blue-soft);padding:.4rem;text-align:center;font-weight:650;font-size:.85rem}
.cal .cell{min-height:104px;border-top:1px solid var(--line);border-left:1px solid var(--line);padding:.25rem;display:flex;flex-direction:column;gap:2px;overflow:hidden}
.cal .cell:nth-child(7n+8){border-left:0}
.cal .cell.out{background:var(--bg);opacity:.7}
.cal .cell.today .n{background:var(--blue);color:#fff}
.cal .n{width:24px;height:24px;border-radius:50%;display:grid;place-items:center;font-size:.8rem;font-weight:600}
.cal .cell.weekly{min-height:260px}
.pill{border:0;border-radius:6px;padding:1px 6px;font-size:.74rem;text-align:left;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;width:100%;border-left:4px solid;background:var(--blue-soft);color:var(--ink)}
.pill.pay{background:var(--orange-soft)}.pill.late{background:var(--red-soft)}.pill.done{background:var(--green-soft);text-decoration:line-through;text-decoration-color:var(--muted)}
.pill.off{opacity:.55;text-decoration:line-through}
.more{font-size:.72rem;color:var(--muted);background:none;border:0;cursor:pointer;text-align:left;padding:0 4px}

/* Jadual */
.tablewrap{overflow-x:auto;border:1px solid var(--line);border-radius:12px;background:var(--surface)}
table{border-collapse:collapse;width:100%;min-width:620px}
th,td{padding:.55rem .75rem;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}
th{background:var(--blue-soft);font-size:.85rem;white-space:nowrap}
td.num,th.num{text-align:right}
tfoot td{font-weight:700;background:var(--bg)}
.bar{height:10px;border-radius:6px;background:var(--line);overflow:hidden;display:flex;min-width:120px}
.bar i{display:block;height:100%}

/* Modal */
dialog{border:0;border-radius:16px;padding:0;width:min(560px,calc(100vw - 1.5rem));max-height:calc(100vh - 2rem);background:var(--surface);color:var(--ink)}
dialog::backdrop{background:rgba(15,20,40,.5)}
.dlg{padding:1.25rem;overflow:auto;max-height:calc(100vh - 2rem)}
.dlg-foot{display:flex;flex-wrap:wrap;gap:.5rem;justify-content:flex-end;margin-top:1rem}
.checks{display:flex;flex-wrap:wrap;gap:.5rem}
.checks label{display:inline-flex;align-items:center;gap:.4rem;border:1px solid var(--line);border-radius:999px;padding:.25rem .75rem;cursor:pointer;font-weight:500;margin:0}
.checks input{width:auto;min-height:0}
.kv{display:grid;grid-template-columns:130px 1fr;gap:.35rem .75rem;margin:.5rem 0}
.kv dt{color:var(--muted);font-size:.9rem}.kv dd{margin:0;overflow-wrap:anywhere}

#toasts{position:fixed;left:50%;transform:translateX(-50%);bottom:76px;display:grid;gap:.5rem;z-index:50;width:min(460px,calc(100vw - 1.5rem))}
.toast{background:var(--ink);color:var(--bg);border-radius:10px;padding:.65rem .9rem;box-shadow:0 6px 20px rgba(0,0,0,.25)}
.toast.err{background:var(--red);color:#fff}.toast.ok{background:var(--green);color:#fff}
.toast .btn{margin-left:.5rem}

.mobile-nav{display:none}
@media (max-width:820px){
  .shell{grid-template-columns:1fr}
  .side{display:none}
  main{padding:1rem .75rem 6rem}
  .mobile-nav{display:flex;position:fixed;bottom:0;left:0;right:0;background:var(--surface);border-top:1px solid var(--line);z-index:20;padding-bottom:env(safe-area-inset-bottom)}
  .mobile-nav button{flex:1;background:none;border:0;padding:.5rem .1rem;display:grid;justify-items:center;gap:2px;font-size:.68rem;color:var(--muted);cursor:pointer;min-height:56px}
  .mobile-nav button[aria-current=page]{color:var(--blue);font-weight:650}
  .mobile-nav svg{width:22px;height:22px}
  .grid2{grid-template-columns:1fr}
  .cal .cell{min-height:64px}
  .pill{font-size:.64rem;padding:0 3px}
  .item{grid-template-columns:auto 1fr}
  .item .r{grid-column:2;text-align:left}
}
@media print{.side,.mobile-nav,.topbar .btn{display:none}}

/* Saiz ikon dalam butang & amaran */
.btn svg,.alert svg{width:1.15em;height:1.15em;flex:none}
.alert svg{width:1.3em;height:1.3em}
.alert{align-items:flex-start}
.stat>div:last-child{min-width:0}
.stat b{font-size:1.1rem;overflow-wrap:anywhere}

/* Hujung minggu (Sabtu = Ahad, warna sama) dan cuti umum */
.cal .dow.wk{background:var(--wk);color:var(--purple)}
.cal .cell.wk{background:var(--wk)}
.cal .cell.hol{background:var(--hol)}
.cal .cell.out.wk,.cal .cell.out.hol{opacity:.7}
.hol-label{font-size:.7rem;line-height:1.2;color:var(--red);font-weight:600;padding:0 2px;overflow-wrap:anywhere}
@media (max-width:820px){.hol-label{font-size:.58rem}}
