
/* ========================================= */
/* 1. VARIABLES & THEME                      */
/* ========================================= */
:root {
    /* Dark Theme Variables */
    --bg-body: #212121;
    --bg-sidebar: #171717;
    --bg-card: #2f2f2f;
    --bg-hover: #424242;
    
    --text-primary: #ececec;
    --text-secondary: #b3b3b3;
    --text-muted: #666666;
    
    --border-color: #424242;
    --border-subtle: #3a3a3a;
    
    /* Brand Colors */
    --color-urea: #FFDE00;     /* Kuning Baru */
    --color-npk: #38bdf8;      /* Sky Blue */
    --color-success: #4ade80;  /* Green */
    --color-danger: #f87171;   /* Red */
    --color-stock: #a8a29e;    /* Stone */
    --color-accent-1: #ffffff; /* Putih */
    
    /* Medal Colors */
    --color-gold: #fbbf24;
    --color-silver: #94a3b8;
    --color-bronze: #d97706;

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 64px;
    --card-radius: 16px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; outline: none; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
    font-size: 14px;
}

/* ========================================= */
/* 2. SIDEBAR                                */
/* ========================================= */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 100;
    transition: transform var(--transition);
    transform: translateX(0); /* Default Desktop Visible */
}

.sidebar.closed {
    transform: translateX(-100%);
}

.brand {
    padding-bottom: 20px;
    border-bottom: none;
    margin-bottom: 10px;
    white-space: nowrap;
    overflow: hidden;
    display: flex;
    align-items: center;
    min-height: 50px; 
}

.brand-content { display: flex; flex-direction: column; margin-left: 10px; }
.brand h2 { font-size: 20px; font-weight: 800; color: var(--text-primary); margin: 0; line-height: 1.2; letter-spacing: 0.5px; }
.brand h2 span { font-weight: 400; color: var(--color-urea); }
.brand p { font-size: 11px; color: var(--text-secondary); margin: 2px 0 0 0; font-weight: 400; letter-spacing: 0.5px; }

.nav-header { 
    font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); 
    margin: 16px 12px 8px; letter-spacing: 1px; white-space: nowrap; transition: opacity 0.2s; 
}

.nav-item {
    display: flex; align-items: center; gap: 14px;
    padding: 12px; border-radius: 12px; cursor: pointer; color: var(--text-secondary);
    font-size: 14px; font-weight: 500; transition: all 0.2s;
    margin-bottom: 4px; white-space: nowrap; overflow: hidden;
}
.nav-item i { width: 20px; text-align: center; font-size: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-hover); color: var(--text-primary); font-weight: 600; }
.nav-item.active i { color: var(--color-urea); }

.nav-spacer { flex-grow: 1; }
.nav-login { margin-top: auto; border-top: none; padding-top: 10px; }

.sidebar-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 90;
    display: none; opacity: 0; transition: opacity 0.3s;
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* ========================================= */
/* 3. MAIN CONTENT                           */
/* ========================================= */
.main-content {
    flex: 1; margin-left: var(--sidebar-width); display: flex;
    flex-direction: column; height: 100vh; overflow: hidden;
    transition: margin-left var(--transition);
}
.main-content.closed { margin-left: 0; }

/* HEADER */
header {
    height: var(--header-height);
    background: var(--bg-body); 
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px; flex-shrink: 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
    z-index: 40; position: relative;
}
.header-left { display: flex; align-items: center; gap: 20px; }

.btn-toggle-sidebar {
    background: transparent; border: none; color: var(--text-secondary);
    font-size: 18px; cursor: pointer; padding: 8px; border-radius: 8px;
}
.btn-toggle-sidebar:hover { background: var(--bg-hover); color: var(--text-primary); }

.page-title h1 { font-size: 16px; font-weight: 700; color: var(--text-primary); margin-bottom: 0px; }
.page-title p { font-size: 11px; color: var(--text-secondary); }

.header-actions { display: flex; align-items: center; gap: 12px; }

/* CUSTOM DROPDOWN (NEUTRAL THEME) */
.custom-select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    background-color: var(--bg-body); 
    border: 1px solid var(--border-color); 
    color: var(--text-primary); 
    
    width: auto; min-width: 90px; 
    padding: 8px 32px 8px 14px; border-radius: 8px; 
    font-size: 12px; font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 600; cursor: pointer; outline: none;
    
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 8px center; background-size: 16px;
    
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.custom-select:hover { border-color: var(--text-secondary); background-color: var(--bg-hover); }
.custom-select:focus { border-color: var(--text-primary); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3); }
.custom-select option { background-color: var(--bg-card); color: var(--text-primary); padding: 10px; }

.content-scroll { flex: 1; overflow-y: auto; padding: 20px 32px 40px; }

/* GRIDS */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 20px; }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.ranking-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 30px; }

.card {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--card-radius); padding: 24px;
    display: flex; flex-direction: column; transition: transform 0.2s;
    position: relative; min-width: 0;
}
.card:hover { border-color: var(--border-subtle); }

/* ========================================= */
/* 4. KPI MODERN STYLE (NEW DESIGN)          */
/* ========================================= */

.kpi-modern {
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Header Baris: Judul Kiri, Ikon Kanan */
.kpi-head-modern {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.kpi-title-modern {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    margin-top: 4px; /* Rata tengah vertikal dgn ikon */
}

.kpi-icon { 
    width: auto; height: auto; border-radius: 0;
    display: flex; align-items: center; justify-content: center; 
    font-size: 18px; background: transparent; color: var(--text-primary);
}
.icon-urea { color: var(--color-urea); }
.icon-npk { color: var(--color-npk); }

/* Angka Utama */
.kpi-main-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 12px;
}

.kpi-big {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.kpi-pct-small {
    font-size: 14px;
    font-weight: 700;
}
.pct-urea { color: var(--color-urea); }
.pct-npk { color: var(--color-npk); }

/* Progress Bar Modern (Abu Gelap) */
.progress-track-modern {
    height: 6px;
    width: 100%;
    background: #404040; 
    border-radius: 10px;
    margin-bottom: 12px;
    overflow: hidden;
}
.progress-bar { height: 100%; border-radius: 10px; }
.bg-urea { background: var(--color-urea); }
.bg-npk { background: var(--color-npk); }

/* Detail Bawah */
.kpi-detail-row {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.kpi-detail-row span span {
    color: var(--text-secondary);
    font-weight: 600;
}

.kpi-sisa-row {
    font-size: 11px;
    color: var(--color-danger);
    font-weight: 600;
}

/* Style Growth Legend */
.kpi-subtext {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.growth-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid rgba(255,255,255,0.05);
    padding-top: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-secondary);
}

.dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.bg-grey { background: #666; }

/* CHART HEADERS & FILTER BUTTONS */
.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.chart-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.big-icon { font-size: 15px; }

.btn-group { background: var(--bg-body); padding: 4px; border-radius: 10px; display: flex; gap: 2px; width: auto; }

/* FIX TOMBOL GOYANG */
.btn-filter {
    background: transparent;
    border: 1px solid transparent; 
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700; 
    cursor: pointer;
    transition: all 0.2s;
}

.btn-filter:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-filter.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    border-color: var(--border-color); 
}

#btn-nas-urea.active, 
#btn-prov-urea.active { 
    color: var(--color-urea) !important;
    border-color: var(--color-urea) !important;
    background: rgba(255, 222, 0, 0.1);
}

#btn-nas-npk.active,
#btn-prov-npk.active { 
    color: var(--color-npk) !important;
    border-color: var(--color-npk) !important;
    background: rgba(56, 189, 248, 0.1);
}

.chart-canvas-container { position: relative; height: 280px; width: 100%; }

/* RANKINGS LIST */
.rank-list { display: flex; flex-direction: column; gap: 0; }
.rank-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border-color); }
.rank-item:last-child { border-bottom: none; }

.rank-left { display: flex; align-items: center; gap: 15px; }

.rank-num { 
    width: 28px; min-width: 28px; height: 28px; border-radius: 6px; background: var(--bg-body); 
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 800; color: var(--text-secondary);
}
.rank-num.medal-box { background: transparent; font-size: 18px; }
.rank-num.warn { background: rgba(239, 68, 68, 0.15); color: var(--color-danger); }

.rank-name { font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-val { font-size: 13px; font-weight: 700; text-align: right; }
.val-best { color: var(--color-accent-1); }
.val-warn { color: var(--color-danger); }

/* RANK COLORS */
.medal-gold { color: #FFD700; filter: drop-shadow(0 0 2px rgba(255, 215, 0, 0.3)); }
.medal-silver { color: #C0C0C0; filter: drop-shadow(0 0 2px rgba(192, 192, 192, 0.3)); }
.medal-bronze { color: #CD7F32; filter: drop-shadow(0 0 2px rgba(205, 127, 50, 0.3)); }
.rank-name.gold { color: var(--color-gold); }
.rank-name.silver { color: var(--color-silver); }
.rank-name.bronze { color: var(--color-bronze); }

/* FOOTER */
.footer {
    text-align: center; padding: 30px 0 10px; color: var(--text-muted);
    border-top: none; margin-top: 20px;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.footer h4 { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin: 0; }
.footer p { font-size: 10px; opacity: 0.6; margin: 0; letter-spacing: 1px; }

/* LOGIN MODAL */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px);
    z-index: 999; display: none; justify-content: center; align-items: center;
}
.modal-box {
    background: var(--bg-card); width: 100%; max-width: 320px;
    padding: 30px; border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5); text-align: center;
    border-radius: 16px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 16px; margin: 0; color: var(--text-primary); }
.modal-header button { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 16px; }

.input-square {
    width: 100%; padding: 12px; margin-bottom: 20px;
    background: var(--bg-body); border: 1px solid var(--border-color);
    color: var(--text-primary); font-family: inherit; font-size: 14px;
    border-radius: 8px; outline: none;
}
.input-square:focus { border-color: var(--text-primary); }
.btn-square {
    width: 100%; padding: 12px; background: var(--text-primary); color: var(--bg-body);
    font-weight: 700; border: none; cursor: pointer; border-radius: 8px; transition: 0.2s;
}
.btn-square:hover { opacity: 0.9; }

/* LOADER */
#loader {
    position: fixed; inset: 0; background: var(--bg-body); z-index: 9999;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.spinner {
    width: 40px; height: 40px; border: 3px solid var(--border-color);
    border-top-color: var(--color-urea); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin-bottom: 16px;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- FITUR TAMBAHAN: AI & FLIP CARD --- */
.card-flip-container {
    perspective: 1000px;
    height: 380px; 
    position: relative;
}

.card-flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.card-flip-inner.flipped {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--card-radius);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.card-back {
    transform: rotateY(180deg);
    background: linear-gradient(145deg, #2a2a2a, #222);
}

/* Tombol AI */
.ai-icon-btn {
    background: var(--bg-hover);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    width: 28px; height: 28px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 12px; transition: all 0.2s;
}
.ai-icon-btn:hover { background: var(--border-color); color: var(--text-primary); }

.btn-back {
    align-self: flex-start;
    background: transparent; border: none; color: var(--text-muted);
    font-size: 11px; font-weight: 700; cursor: pointer;
    margin-bottom: 15px; display: flex; align-items: center; gap: 6px;
}
.btn-back:hover { color: var(--text-primary); }

.ai-content {
    font-size: 12px; line-height: 1.6; color: var(--text-secondary);
    flex: 1; overflow-y: auto;
}
.ai-content h4 { 
    color: var(--text-primary); font-size: 12px; text-transform: uppercase; 
    letter-spacing: 1px; margin-bottom: 12px; border-bottom: 1px solid var(--border-subtle); 
    padding-bottom: 8px; display: flex; align-items: center; gap: 8px; 
}

/* ========================================= */
/* 5. RESPONSIVE (MOBILE OPTIMIZATION)       */
/* ========================================= */

@media (max-width: 768px) {

    /* --- 1. LAYOUT UTAMA --- */
    .sidebar { transform: translateX(-100%); width: 240px; }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
    
    body { font-size: 12px; }
    
    header { 
        padding: 0 16px; height: 56px; 
        min-height: 56px; flex-shrink: 0; 
    }
    .brand h2 { font-size: 16px; }
    .page-title h1 { font-size: 14px; }
    .page-title p { font-size: 10px; }

    /* --- 2. GRID KARTU (KPI) --- */
    .kpi-grid { 
        grid-template-columns: 1fr 1fr; 
        gap: 12px; 
        margin-bottom: 12px; /* GAP SEIMBANG */
    }
    
    /* STYLE KARTU BARU DI MOBILE */
    .kpi-modern {
        padding: 14px;
        min-height: 140px;
        justify-content: flex-start;
    }
    .kpi-big { font-size: 20px; } 
    .kpi-pct-small { font-size: 12px; }
    
    .kpi-head-modern { margin-bottom: 6px; }
    .kpi-title-modern { font-size: 9px; }
    .kpi-icon { font-size: 16px; }

    .kpi-detail-row, .kpi-sisa-row, .legend-item { font-size: 9px; }
    .kpi-detail-row { flex-direction: column; gap: 2px; } 
    .kpi-sisa-row { margin-top: 4px; }

    /* --- 3. GRAFIK & LAINNYA --- */
    /* GAP SEIMBANG: Set margin-bottom sama dengan gap kpi (12px) */
    .chart-grid { 
        grid-template-columns: 1fr; 
        gap: 12px; 
        margin-bottom: 12px; 
    }

    .ranking-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        /* Margin bottom ranking diatur oleh padding content-scroll */
    }

    .chart-header { margin-bottom: 10px; }
    .chart-title { font-size: 13px; }
    .btn-filter { padding: 4px 8px; font-size: 10px; }

    /* --- PERBAIKAN GRAFIK FULL (TIDAK MENGECIL) --- */
    
    /* 1. Atur Tinggi Kartu Flip */
    .card-flip-container { 
        height: 380px; 
        width: 100%;
        margin-bottom: 0; /* Gap dihandle oleh chart-grid */
    }

    /* 2. Gunakan Flexbox pada sisi kartu agar isinya memanjang */
    .card-front, .card-back { 
        padding: 16px; 
        display: flex;       
        flex-direction: column; 
    }

    /* 3. Paksa grafik mengisi sisa ruang (FIX Grafik Mengecil) */
    .chart-canvas-container { 
        height: auto !important; /* Jangan dipaksa 200px */
        flex-grow: 1;            /* Mengisi ruang kosong */
        width: 100%;
        position: relative;
        min-height: 0;           
    }

    /* --- 4. FOOTER --- */
    .content-scroll { 
        padding: 12px 16px; 
        padding-bottom: 80px; 
    }
    .footer { margin-top: 0; padding-bottom: 0; }
    .header-actions { margin-left: auto; }
}
