:root {
  --biru: #0b4cab;
  --biru-gelap: #062a6b;
  --biru-cair: #eaf2ff;
  --emas: #f2b418;
  --emas-gelap: #c98c00;
  --hijau: #17a65b;
  --merah: #e23a5c;
  --ungu: #8a4fd8;
  --oren: #f47b20;
  --teks: #12234a;
  --side: 240px;
}
* { box-sizing: border-box; }
body { font-family: 'Poppins', 'Segoe UI', sans-serif; background: #f4f7fd; color: var(--teks); font-size: 14px; margin: 0; }

/* ===== Sidebar ===== */
#sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side); background: linear-gradient(180deg, var(--biru-gelap), var(--biru) 70%, #0a3f92); color: #fff; overflow-y: auto; z-index: 1040; transition: transform .25s; }
.brand { display: flex; align-items: center; gap: 12px; padding: 16px; font-weight: 700; font-size: 18px; line-height: 1.2; border-bottom: 2px solid rgba(242,180,24,.6); }
.brand span { color: var(--emas); }
.brand img { width: 56px; height: 56px; object-fit: contain; background: #fff; border-radius: 50%; padding: 2px; }
#menu { padding: 10px; }
#menu a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; color: #fff; text-decoration: none; border-radius: 10px; margin-bottom: 2px; font-weight: 500; }
#menu a i { font-size: 18px; width: 22px; text-align: center; }
#menu a:hover { background: rgba(255,255,255,.12); }
#menu a.active { background: linear-gradient(90deg, var(--emas-gelap), var(--emas)); color: var(--biru-gelap); font-weight: 700; box-shadow: 0 4px 12px rgba(0,0,0,.25); }
#menu hr { margin: 8px 6px; opacity: .25; }
#backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1035; }

/* ===== Header ===== */
#wrap { margin-left: var(--side); min-height: 100vh; }
#topbar { display: flex; align-items: center; gap: 16px; padding: 14px 24px; color: #fff; background: linear-gradient(105deg, var(--biru-gelap) 0%, var(--biru) 62%, var(--emas) 62.4%, #ffe08a 64%, #0a3f92 64.5%, var(--biru-gelap) 100%); border-bottom: 3px solid var(--emas); }
#head-logo { width: 54px; height: 54px; object-fit: contain; background: #fff; border-radius: 50%; padding: 2px; }
.head-text h1 { font-size: 22px; font-weight: 700; margin: 0; }
.head-text p { margin: 0; opacity: .9; }
#btn-menu { display: none; background: none; border: 0; color: #fff; font-size: 28px; }
main { padding: 18px 24px 40px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; font-weight: 700; }
.page-head p { margin: 0; color: #5a6a8c; }
.page-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: #fff; border: 3px solid var(--emas); color: var(--biru); }
#page-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#page-tools .form-select, #page-tools .form-control { width: auto; border-color: #b9cdf0; font-weight: 600; }

/* ===== Butang ===== */
.btn-primary { --bs-btn-bg: var(--biru); --bs-btn-border-color: var(--biru); --bs-btn-hover-bg: var(--biru-gelap); --bs-btn-hover-border-color: var(--biru-gelap); }
.btn-gold { background: linear-gradient(90deg, #e9a60c, #ffc933); color: var(--biru-gelap); font-weight: 600; border: 0; }
.btn-gold:hover { filter: brightness(1.07); color: var(--biru-gelap); }
.btn-icon { padding: 2px 8px; }
.acts { white-space: nowrap; text-align: right; }

/* ===== Kad statistik ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stats.dash > .stat:last-child { grid-column: span 2; }
@media (min-width: 1200px) { .stats.dash { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 480px) { .stats.dash > .stat:last-child { grid-column: auto; } }
.stat { display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 14px; border: 1px solid rgba(0,0,0,.05); box-shadow: 0 3px 10px rgba(11,76,171,.08); background: var(--bg); }
.stat > i { width: 42px; height: 42px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 20px; color: #fff; background: var(--c); }
.stat small { display: block; font-weight: 600; font-size: 12px; }
.stat b { display: block; font-size: 21px; color: var(--c); line-height: 1.25; }
.stat em { display: block; font-style: normal; font-size: 11.5px; color: #52617f; }
.s-biru { --bg: #e3efff; --c: #1666d6; }
.s-hijau { --bg: #e2f7e9; --c: #128a4a; }
.s-merah { --bg: #ffe6ea; --c: #d42a4e; }
.s-emas { --bg: #fff3d1; --c: #b57d00; }
.s-ungu { --bg: #f1e7ff; --c: #7a3fcc; }
.s-oren { --bg: #ffeadb; --c: #d9620b; }
.s-teal { --bg: #ddf6f5; --c: #0b8785; }

/* ===== Panel & jadual ===== */
.panel { background: #fff; border: 1px solid #dbe6fa; border-radius: 14px; padding: 16px; box-shadow: 0 3px 12px rgba(11,76,171,.07); margin-bottom: 14px; }
.panel h3 { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
.panel h3 i { color: var(--emas-gelap); font-size: 19px; }
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid > .panel { margin: 0; min-width: 0; }
.g3 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); }
.chart-box { position: relative; height: 260px; }
.table { margin: 0; font-size: 13px; }
.table thead th { background: #d6e5ff; color: var(--biru-gelap); border-bottom: 0; vertical-align: middle; }
.table tfoot th, .table tfoot td { background: #fff3d1; font-weight: 700; }
.table td { vertical-align: middle; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.empty { text-align: center; color: #8391ad; padding: 22px !important; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid #eef2fb; }
.legend-row span.dot { width: 13px; height: 13px; border-radius: 3px; flex: none; }
.legend-row .name { flex: 1; }
.chip-cash, .chip-bank { display: flex; justify-content: space-between; padding: 12px 14px; border-radius: 10px; margin-bottom: 8px; font-weight: 600; }
.chip-cash { background: #e2f7e9; }
.chip-bank { background: #e3efff; }
.chip-total { background: #fff3d1; border-radius: 10px; padding: 12px; text-align: center; }
.chip-total b { display: block; font-size: 22px; }

/* ===== Pratonton & cetakan ===== */
.preview-bg { background: #8b95ab; }
.sheet { background: #fff; color: #000; margin: 0 auto 18px; padding: 12mm; width: 210mm; min-height: 297mm; box-shadow: 0 4px 18px rgba(0,0,0,.35); font-size: 12px; }
.sheet.landscape { width: 297mm; min-height: 210mm; }
#print-area { display: none; }
.r-head { display: flex; gap: 14px; align-items: center; border-bottom: 3px double var(--biru); padding-bottom: 8px; margin-bottom: 12px; }
.r-head img { width: 68px; height: 68px; object-fit: contain; }
.r-head h4 { margin: 0; font-size: 16px; font-weight: 700; color: var(--biru-gelap); }
.r-head div div { font-size: 11px; }
.r-title { text-align: center; font-weight: 700; font-size: 13px; margin: 0 0 10px; text-transform: uppercase; }
.r-sub { font-weight: 700; margin: 14px 0 4px; }
table.r { width: 100%; border-collapse: collapse; font-size: 11px; }
table.r th, table.r td { border: 1px solid #555; padding: 3px 5px; vertical-align: top; }
table.r th { background: #d6e5ff; text-align: center; }
table.r tr.total td, table.r tr.total th { background: #fff3d1; font-weight: 700; }
table.r td.num { text-align: right; }
table.r td.c { text-align: center; }
.jppm table.r { font-size: 9.5px; line-height: 1.3; }
.jppm table.r th, .jppm table.r td { padding: 1px 5px; }
.jppm .r-sub { margin-top: 8px; }
.jppm ~ .signs { margin-top: 28px; }
.jppm ~ .perakuan { margin-top: 8px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: start; }
.signs { display: flex; justify-content: space-between; gap: 24px; margin-top: 46px; break-inside: avoid; }
.signs div { flex: 1; text-align: center; font-size: 11px; }
.signs div span { display: block; border-top: 1px dotted #000; padding-top: 4px; }
.perakuan { margin-top: 16px; font-size: 11px; }

/* Resit & baucar: dua pada satu halaman A4 */
.slip { border: 2px solid var(--biru); box-shadow: inset 0 0 0 2px var(--emas); border-radius: 8px; padding: 6mm; height: 128mm; display: flex; flex-direction: column; margin-bottom: 8mm; break-inside: avoid; overflow: hidden; }
.slip .r-head { margin-bottom: 8px; }
.slip-title { background: var(--biru); color: #fff; text-align: center; font-weight: 700; padding: 5px; letter-spacing: 2px; border-radius: 4px; }
.slip table { width: 100%; margin-top: 8px; font-size: 12px; }
.slip td { padding: 4px 2px; vertical-align: top; }
.slip td.k { width: 42mm; font-weight: 600; }
.slip td.v { border-bottom: 1px dotted #777; }
.slip .amaun { display: inline-block; border: 2px solid var(--emas-gelap); background: #fff8e1; font-size: 18px; font-weight: 700; padding: 4px 16px; border-radius: 6px; }
.slip .signs { margin-top: auto; }
.slip .nota-komp { text-align: center; font-size: 10px; font-style: italic; margin-top: 6px; }

/* Sijil: kotak maklumat ditutup dan ditulis semula di atas gambar asal */
.sheet.sijil { padding: 0; width: 297mm; min-height: 0; height: 198mm; position: relative; overflow: hidden; container-type: inline-size; }
.sijil > img { width: 100%; height: 100%; display: block; }
.sijil-box { position: absolute; left: 18.4%; top: 49.4%; width: 63.4%; height: 17.5%; background: linear-gradient(90deg, #fdf6d8, #fffbe9 50%, #fdf6d8); display: flex; flex-direction: column; justify-content: center; padding-left: 3.4%; font-family: 'Times New Roman', serif; font-weight: 700; color: #0d3b24; font-size: 8.4mm; line-height: 1.38; }
.sijil-row { display: grid; grid-template-columns: 54mm 8mm 1fr; align-items: center; white-space: nowrap; }
.sijil-pengerusi { position: absolute; left: 0; right: 0; top: 83.3%; text-align: center; font-family: 'Times New Roman', serif; font-weight: 700; font-size: 3.8mm; color: #0d3b24; }

@media (max-width: 992px) {
  #sidebar { transform: translateX(-100%); }
  body.menu-open #sidebar { transform: none; }
  body.menu-open #backdrop { display: block; }
  #wrap { margin-left: 0; }
  #btn-menu { display: block; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .head-text h1 { font-size: 17px; }
}

@media print {
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; overflow: visible !important; height: auto !important; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .sheet { box-shadow: none; margin: 0; padding: 0; width: auto; min-height: 0; break-after: page; }
  .sheet:last-child { break-after: auto; }
  .sheet.landscape { width: auto; min-height: 0; }
  .sheet.sijil { width: 297mm; height: 198mm; }
  table.r thead { display: table-header-group; }
  table.r tr { break-inside: avoid; }
}
