:root {
    --bg-body: #080b12;
    --bg-card: #111622;
    --bg-hover: #1a2133;
    
    --text-main: #f1f5f9;
    --text-muted: #8b95a5;
    --text-cyan: #00f2fe;
    
    --accent-orange: #ff7e5f;
    --color-purple: #8b5cf6;
    --color-teal: #14b8a6;
    --color-rose: #f43f5e;
    --color-yellow: #f59e0b;
    
    --border-dark: #222a3f;
    --radius-md: 16px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

/* Mobile-first base styles: column layout, allow vertical scroll */
body {
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    overflow-y: auto; /* Benarkan skrol pada peranti kecil */
    display: flex;
    flex-direction: column;
}

/* SCROLLBAR CUSTOM UNTUK JADUAL SAHAJA */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a344d; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #3d4b6e; }

/* SIDEBAR (disembunyi pada mobile, ditunjuk pada desktop melalui media query)
   Mobile behaviour: sidebar hidden by default to prioritise content.
   Desktop (>=1024px) will show sidebar as a fixed column. */
.sidebar {
    /* Off-canvas drawer for mobile */
    position: fixed;
    top: 0;
    left: -280px;
    height: 100%;
    width: 240px;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    flex-shrink: 0;
    z-index: 40;
    transition: left 260ms ease;
    box-shadow: 0 6px 24px rgba(0,0,0,0.6);
}
.sidebar.open { left: 0; }

/* overlay shown when sidebar open on mobile */
.overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    opacity: 0; visibility: hidden; transition: opacity 200ms ease;
    z-index: 30;
}
.overlay.active { opacity: 1; visibility: visible; }

.logo-box {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--color-purple), var(--color-teal));
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; color: white; margin-bottom: 30px;
}

.months-list {
    list-style: none; display: flex; flex-direction: column; gap: 18px;
    font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
}
.months-list li { cursor: pointer; transition: 0.2s; }
.months-list li:hover { color: var(--text-main); }
.months-list li.active { color: var(--color-yellow); font-weight: 800; }

/* KANDUNGAN UTAMA (Grid Induk) */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 12px 12px;
    gap: 12px;
    min-width: 0;
}

/* HEADER PADAT (Sejalur sahaja) */
.top-navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: auto;
    flex-shrink: 0;
    background: var(--bg-card);
    padding: 12px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-dark);
    gap: 12px;
    flex-wrap: wrap;
}

.top-navbar > div {
    flex: 1 1 auto;
    min-width: 0;
}

.top-navbar .nav-title {
    font-size: 1rem;
}

/* menu button visible on mobile to toggle sidebar */
.menu-btn {
    background: transparent; border: 0; color: var(--text-main); font-size: 1.1rem; padding: 8px; border-radius: 8px; cursor: pointer;
}
.menu-btn:focus { outline: 2px solid rgba(255,255,255,0.06); }

.nav-title {
    font-weight: 700; font-size: 1.1rem; color: var(--text-main);
    display: flex; align-items: center; gap: 10px;
}
.nav-title span { color: var(--text-muted); font-size: 0.8rem; font-weight: 500; }

/* PENAPIS TABUNG (Kompak) */
.filter-section { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-btn {
    background: transparent; border: 1px solid var(--border-dark); color: var(--text-muted);
    padding: 6px 14px; border-radius: 20px; font-size: 0.8rem; font-weight: 600;
    cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.filter-btn:hover { background: rgba(255,255,255,0.05); color: var(--text-main); }
.filter-btn.active {
    background: var(--color-teal); color: #000; border-color: var(--color-teal); font-weight: 700;
}

.action-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}
.top-action {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-dark);
    border-radius: 12px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}
.top-action:hover {
    background: rgba(255,255,255,0.08);
    transform: translateY(-1px);
}
.top-action i {
    font-size: 0.95rem;
}

.grand-total {
    font-size: 1.3rem; font-weight: 800; color: var(--text-cyan); letter-spacing: -0.5px;
}

.live-status {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(255,255,255,0.02);
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid var(--border-dark);
    display: inline-block;
    margin-left: 10px;
}

/* GRID DASHBOARD (Penuh Ketinggian yang Tinggal) */
.dashboard-grid {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

/* KAD ASAS */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-dark);
    display: flex;
    flex-direction: column;
    padding: 15px;
    position: relative;
    overflow: hidden;
}

.card-title {
    font-size: 0.8rem; color: var(--text-muted); font-weight: 600; margin-bottom: 5px;
    display: flex; justify-content: space-between; align-items: center;
}
.card-value { font-size: 1.6rem; font-weight: 800; color: var(--text-main); line-height: 1.2; }

/* PENEMPATAN GRID KAD */
.kpi-1, .kpi-2, .kpi-3, .kpi-4 { grid-column: span 3; justify-content: center;}

.kpi-1 { background: linear-gradient(135deg, #1f2937, #111827); border-color: #374151; }
.kpi-1 .card-value { color: var(--accent-orange); font-size: 1.8rem; }

.chart-main { grid-column: span 5; }
.chart-side { grid-column: span 3; }
.table-area { grid-column: span 4; padding: 0; }

/* CARTA */
.chart-container { flex-grow: 1; position: relative; width: 100%; min-height: 180px; margin-top: 10px; }

/* LIST TABUNG KECIL (Dalam Kad Carta Pie) */
.mini-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; flex-grow: 1; overflow-y: auto;}
.mini-item { display: flex; justify-content: space-between; font-size: 0.8rem; padding: 6px 10px; background: rgba(255,255,255,0.03); border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer }
.mini-item.active { border-color: var(--border-dark); background: rgba(255,255,255,0.08); }
.mini-item-name { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-weight: 500;}
.dot { width: 8px; height: 8px; border-radius: 50%; }

/* JADUAL PADAT (Scroll dalam kad sahaja) */
.table-header { padding: 15px; border-bottom: 1px solid var(--border-dark); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.table-wrapper { flex-grow: 1; overflow-x: auto; }

table { width: 100%; min-width: 420px; border-collapse: collapse; font-size: 0.8rem; text-align: left; }
th { position: sticky; top: 0; background: var(--bg-card); color: var(--text-muted); padding: 10px 15px; font-weight: 600; border-bottom: 1px solid var(--border-dark); z-index: 1; white-space: nowrap;}
td { padding: 10px 15px; border-bottom: 1px solid rgba(255,255,255,0.03); color: var(--text-main); white-space: nowrap; }
tr:hover td { background: rgba(255,255,255,0.03); }

.tag-tabung { font-size: 0.7rem; padding: 3px 8px; border-radius: 4px; background: #222a3f; color: var(--text-muted); font-weight: 600; text-transform: uppercase;}
.val-amaun { font-weight: 700; color: var(--text-main); font-family: monospace; font-size: 0.9rem;}

/* Responsive Ringkas (Hanya untuk skrin yang sangat kecil, tapi asal sasaran desktop) */
/* Desktop and large tablet styles */
@media (min-width: 1024px) {
    body { flex-direction: row; }
    .sidebar {
        width: 70px;
        background-color: var(--bg-card);
        border-right: 1px solid var(--border-dark);
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 20px 0;
        flex-shrink: 0;
        z-index: 10;
    }
    .main-content { padding: 15px 20px; gap: 15px; }
    .dashboard-grid {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        grid-template-rows: 85px minmax(0, 1fr);
        gap: 15px;
    }
    .chart-container { min-height: 240px; }

    .kpi-1, .kpi-2, .kpi-3, .kpi-4 { grid-column: span 3; }
    .chart-main { grid-column: span 5; }
    .chart-side { grid-column: span 3; }
    .table-area { grid-column: span 4; }

    /* show sidebar when desktop */
    .sidebar.open { display: flex; }
}

/* Small adjustments for medium screens */
@media (min-width: 768px) and (max-width: 1023px) {
    .chart-container { min-height: 220px; }
    .top-navbar { padding: 12px 16px; }
    .filter-btn { font-size: 0.75rem; padding: 6px 12px; }
}

@media (max-width: 767px) {
    .top-navbar { padding: 12px 14px; }
    .nav-title { font-size: 0.95rem; }
    .filter-btn { flex: 1 1 auto; min-width: 140px; }
    .grand-total { width: 100%; text-align: right; }
    .dashboard-grid { gap: 10px; }
    .chart-container { min-height: 180px; }
}

body.theme-light {
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-hover: #e2e8f0;
    --text-main: #1f2937;
    --text-muted: #475569;
    --text-cyan: #0f766e;
    --accent-orange: #f97316;
    --color-purple: #7c3aed;
    --color-teal: #0f766e;
    --color-rose: #be123c;
    --color-yellow: #d97706;
    --border-dark: #cbd5e1;
}

body.theme-light .card { border-color: rgba(148,163,184,0.25); }
body.theme-light .sidebar { background: #ffffff; }
body.theme-light .top-navbar { background: #ffffff; }
body.theme-light table, body.theme-light th, body.theme-light td { background: transparent; color: var(--text-main); }
body.theme-light .table-header { border-bottom-color: rgba(148,163,184,0.25); }
body.theme-light .mini-item { background: #f8fafc; }
body.theme-light .mini-item.active { background: #e2e8f0; }

@media print {
    body, .main-content {
        background: #fff;
        color: #000;
    }
    .sidebar, .menu-btn, .action-buttons, .filter-section, .grand-total, .top-navbar, .mini-list {
        display: none !important;
    }
    .main-content { padding: 0; }
    .dashboard-grid { display: block; gap: 0; }
    .card { border: none; box-shadow: none; background: transparent; }
    .table-wrapper { overflow: visible; }
    table { min-width: 0; font-size: 0.85rem; }
    th, td { background: transparent !important; }
}
