/* ============================================================
   MBG Distribution System — UI Design System
   Langkah: Phase 1 (Design Foundation)
   ============================================================ */

:root {
    /* Warna utama — Sky Blue */
    --mbg-primary: #38BDF8;
    --mbg-primary-dark: #0284C7;
    --mbg-primary-soft: #E0F2FE;
    --mbg-primary-tint: #F0F9FF;

    /* Latar & permukaan */
    --mbg-background: #F8FAFC;
    --mbg-surface: #FFFFFF;
    --mbg-glass: rgba(255, 255, 255, 0.72);
    --mbg-border: rgba(148, 163, 184, 0.20);
    --mbg-border-solid: #E2E8F0;

    /* Teks */
    --mbg-text: #0F172A;
    --mbg-text-secondary: #64748B;
    --mbg-text-muted: #94A3B8;

    /* Status */
    --mbg-success: #22C55E;
    --mbg-warning: #F59E0B;
    --mbg-danger: #EF4444;
    --mbg-info: #0EA5E9;

    /* Radius */
    --mbg-radius-sm: 8px;
    --mbg-radius-md: 12px;
    --mbg-radius-lg: 16px;

    /* Bayangan */
    --mbg-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --mbg-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
    --mbg-shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.10);

    /* Glass */
    --mbg-glass-blur: 14px;

    /* Layout */
    --mbg-sidebar-width: 264px;
}

/* ============================================================
   Base
   ============================================================ */

body {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14.5px;
    color: var(--mbg-text);
    background:
        radial-gradient(circle at 8% 6%, rgba(56, 189, 248, 0.07), transparent 32%),
        radial-gradient(circle at 96% 4%, rgba(14, 165, 233, 0.05), transparent 30%),
        var(--mbg-background);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--mbg-primary-dark); }
a:hover { color: var(--mbg-primary-dark); }

.min-w-0 { min-width: 0; }
.cursor-pointer { cursor: pointer; }

::selection { background: var(--mbg-primary-soft); }

/* ============================================================
   Glass surface
   ============================================================ */

.mbg-glass {
    background: var(--mbg-glass);
    -webkit-backdrop-filter: blur(var(--mbg-glass-blur));
    backdrop-filter: blur(var(--mbg-glass-blur));
    border: 1px solid var(--mbg-border);
    box-shadow: var(--mbg-shadow);
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
    width: var(--mbg-sidebar-width);
    min-height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1030;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--mbg-glass);
    -webkit-backdrop-filter: blur(var(--mbg-glass-blur));
    backdrop-filter: blur(var(--mbg-glass-blur));
    border-right: 1px solid var(--mbg-border);
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.04);
    display: flex;
    flex-direction: column;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 18px;
    border-bottom: 1px solid var(--mbg-border);
    color: var(--mbg-text);
    font-weight: 700;
    font-size: 1.02rem;
    line-height: 1.2;
}

.sidebar .brand .brand-mark {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: var(--mbg-radius-md);
    background: linear-gradient(135deg, var(--mbg-primary), var(--mbg-primary-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 6px 16px rgba(2, 132, 199, 0.28);
}

.sidebar .brand small {
    display: block;
    color: var(--mbg-text-muted);
    font-weight: 400;
    font-size: .72rem;
    line-height: 1.35;
}

.sidebar .nav { padding: 12px 12px 20px; }

.sidebar .nav-group {
    padding: 16px 14px 6px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--mbg-text-muted);
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    margin-bottom: 2px;
    border-radius: var(--mbg-radius-sm);
    color: var(--mbg-text-secondary);
    font-size: .885rem;
    font-weight: 500;
    position: relative;
    transition: background-color .18s ease, color .18s ease, transform .18s ease;
}

.sidebar .nav-link i { font-size: 1rem; width: 20px; text-align: center; color: var(--mbg-text-muted); transition: color .18s ease; }

.sidebar .nav-link:hover { background: rgba(224, 242, 254, 0.55); color: var(--mbg-primary-dark); }
.sidebar .nav-link:hover i { color: var(--mbg-primary-dark); }

.sidebar .nav-link.active {
    background: var(--mbg-primary-soft);
    color: var(--mbg-primary-dark);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.25);
}

.sidebar .nav-link.active i { color: var(--mbg-primary-dark); }

.sidebar .nav-link.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 4px 4px 0;
    background: var(--mbg-primary);
}

.sidebar-footer {
    margin-top: auto;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--mbg-border);
    font-size: .72rem;
    color: var(--mbg-text-muted);
    line-height: 1.5;
}

/* ============================================================
   Top navbar
   ============================================================ */

.navbar-top {
    background: var(--mbg-glass);
    -webkit-backdrop-filter: blur(var(--mbg-glass-blur));
    backdrop-filter: blur(var(--mbg-glass-blur));
    border-bottom: 1px solid var(--mbg-border);
    position: sticky;
    top: 0;
    z-index: 1020;
    min-height: 62px;
}

.navbar-top .page-title {
    font-size: .95rem;
    font-weight: 700;
    color: var(--mbg-text);
    line-height: 1.2;
}

.navbar-top .page-subtitle {
    font-size: .74rem;
    color: var(--mbg-text-muted);
    line-height: 1.3;
}

.navbar-top .btn-light,
.navbar-top .btn-outline-secondary {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--mbg-border);
    color: var(--mbg-text-secondary);
}

.navbar-top .btn-light:hover,
.navbar-top .btn-outline-secondary:hover {
    background: #fff;
    color: var(--mbg-primary-dark);
    border-color: var(--mbg-primary);
}

/* Profil pengguna (chip di pojok kanan navbar) */
.navbar-top .profile-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    padding: 0.3rem 0.7rem 0.3rem 0.35rem;
    border-radius: 50rem;
    border: 1px solid var(--mbg-border);
    background: rgba(255, 255, 255, 0.65);
    transition: var(--mbg-transition);
}

.navbar-top .profile-chip::after { display: none; }

.navbar-top .profile-chip:hover {
    border-color: rgba(56, 189, 248, 0.55);
    background: #fff;
    box-shadow: var(--mbg-shadow-sm);
}

.navbar-top .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--mbg-primary), var(--mbg-primary-dark));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.92rem;
    font-weight: 700;
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 3px 8px rgba(2, 132, 199, 0.28);
}

.navbar-top .avatar::after {
    content: "";
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--mbg-success);
    border: 2px solid #fff;
}

.navbar-top .profile-meta { line-height: 1.2; }

.navbar-top .profile-name {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--mbg-text);
    line-height: 1.2;
}

.navbar-top .profile-role {
    display: inline-block;
    margin-top: 2px;
    padding: 0.14em 0.55em;
    border-radius: 999px;
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1.4;
}

.navbar-top .profile-role.role-admin { background: #FEE2E2; color: #B91C1C; }
.navbar-top .profile-role.role-petugas { background: #E0F2FE; color: #0369A1; }
.navbar-top .profile-role.role-sekolah { background: #DCFCE7; color: #15803D; }

.navbar-top .profile-chevron {
    color: var(--mbg-text-muted);
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.navbar-top .profile-chip.show .profile-chevron { transform: rotate(180deg); }

.dropdown-menu {
    border: 1px solid var(--mbg-border);
    border-radius: var(--mbg-radius-md);
    box-shadow: var(--mbg-shadow-lg);
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(var(--mbg-glass-blur));
    backdrop-filter: blur(var(--mbg-glass-blur));
    padding: .5rem;
}

.dropdown-menu .dropdown-item {
    border-radius: var(--mbg-radius-sm);
    padding: .55rem .8rem;
    font-size: .875rem;
}

.dropdown-menu .dropdown-item:hover { background: var(--mbg-primary-tint); color: var(--mbg-primary-dark); }
.dropdown-menu .dropdown-item.text-danger:hover { background: #FEF2F2; color: var(--mbg-danger); }

/* ============================================================
   Content
   ============================================================ */

.content { margin-left: var(--mbg-sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }

main { flex: 1; }

/* ============================================================
   Cards
   ============================================================ */

.card {
    border: 1px solid var(--mbg-border);
    border-radius: var(--mbg-radius-md);
    box-shadow: var(--mbg-shadow-sm);
    background: var(--mbg-surface);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--mbg-border);
    padding: .9rem 1.15rem;
}

.card-header:first-child { border-radius: var(--mbg-radius-md) var(--mbg-radius-md) 0 0; }
.card-footer { background: #fff; border-top: 1px solid var(--mbg-border); }
.card-footer:last-child { border-radius: 0 0 var(--mbg-radius-md) var(--mbg-radius-md); }

/* Kartu statistik dashboard */
.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: var(--mbg-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex: 0 0 auto;
}

.stat-icon.bg-primary { background: var(--mbg-primary-soft) !important; color: var(--mbg-primary-dark) !important; }
.stat-icon.bg-success { background: #DCFCE7 !important; color: #16A34A !important; }
.stat-icon.bg-warning { background: #FEF3C7 !important; color: #D97706 !important; }
.stat-icon.bg-info    { background: #E0F2FE !important; color: #0284C7 !important; }
.stat-icon.bg-danger  { background: #FEE2E2 !important; color: #DC2626 !important; }
.stat-icon.bg-secondary { background: #F1F5F9 !important; color: #64748B !important; }

.card .stat-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
.card .stat-label { font-size: 15px; color: var(--mbg-text-secondary); }

/* ============================================================
   Buttons
   ============================================================ */

.btn { border-radius: var(--mbg-radius-sm); font-weight: 500; }

.btn-primary {
    background: var(--mbg-primary);
    border-color: var(--mbg-primary);
    color: #fff;
    box-shadow: 0 4px 14px rgba(56, 189, 248, 0.28);
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background: var(--mbg-primary-dark);
    border-color: var(--mbg-primary-dark);
    color: #fff;
}

.btn-outline-primary {
    border-color: var(--mbg-primary);
    color: var(--mbg-primary-dark);
}

.btn-outline-primary:hover {
    background: var(--mbg-primary);
    border-color: var(--mbg-primary);
    color: #fff;
}

.btn-light {
    background: #F8FAFC;
    border: 1px solid var(--mbg-border-solid);
    color: var(--mbg-text-secondary);
}

.btn-light:hover { background: #fff; color: var(--mbg-text); border-color: #CBD5E1; }

.btn-outline-secondary { color: var(--mbg-text-secondary); border-color: #CBD5E1; }
.btn-outline-secondary:hover { background: #F1F5F9; color: var(--mbg-text); }

.btn-outline-danger:hover { background: var(--mbg-danger); border-color: var(--mbg-danger); }

/* ============================================================
   Forms
   ============================================================ */

.form-label { font-size: .92rem; font-weight: 600; color: var(--mbg-text); margin-bottom: .35rem; }

.form-control, .form-select {
    border: 1px solid #CBD5E1;
    border-radius: var(--mbg-radius-sm);
    padding: .5rem .8rem;
    font-size: .9rem;
    color: var(--mbg-text);
    background-color: #fff;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--mbg-primary);
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.16);
}

.form-control::placeholder { color: var(--mbg-text-muted); }

.form-control.is-invalid, .form-select.is-invalid { border-color: var(--mbg-danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.12); }

.invalid-feedback { font-size: .78rem; }

.form-text { color: var(--mbg-text-muted); font-size: .78rem; }

/* ============================================================
   Tables
   ============================================================ */

.table { --bs-table-bg: transparent; font-size: .86rem; }

.table thead th {
    font-size: .87rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: black;
    background: #F8FAFC;
    border-bottom: 1px solid var(--mbg-border-solid);
    padding: .7rem 1rem;
    white-space: nowrap;
}

.table tbody td {
    padding: .75rem 1rem;
    border-bottom: 1px solid #F1F5F9;
    vertical-align: middle;
    font-size: 15px;
}

.table tbody tr:last-child td { border-bottom: none; }

.table-hover tbody tr { transition: background-color .15s ease; }
.table-hover tbody tr:hover { background: var(--mbg-primary-tint); }

.table .fw-semibold, .table .fw-bold { color: var(--mbg-text); }

/* ============================================================
   Badges (soft, sesuai design system)
   ============================================================ */

.badge { font-weight: 600; font-size: .82rem; padding: .42em .7em; border-radius: 999px; }

.badge.bg-secondary { background: #F1F5F9 !important; color: #475569; }
.badge.bg-info      { background: #E0F2FE !important; color: #0369A1; }
.badge.bg-warning   { background: #FEF3C7 !important; color: #B45309; }
.badge.bg-primary   { background: #DBEAFE !important; color: #1D4ED8; }
.badge.bg-success   { background: #DCFCE7 !important; color: #15803D; }
.badge.bg-danger    { background: #FEE2E2 !important; color: #B91C1C; }

/* ============================================================
   Alerts
   ============================================================ */

.alert { border-radius: var(--mbg-radius-md); border: 1px solid transparent; font-size: .875rem; }
.alert-success { background: #F0FDF4; border-color: #BBF7D0; color: #15803D; }
.alert-danger  { background: #FEF2F2; border-color: #FECACA; color: #B91C1C; }
.alert-warning { background: #FFFBEB; border-color: #FDE68A; color: #B45309; }
.alert-info    { background: #F0F9FF; border-color: #BAE6FD; color: #0369A1; }

/* ============================================================
   Modal
   ============================================================ */

.modal-content {
    border: 1px solid var(--mbg-border);
    border-radius: var(--mbg-radius-lg);
    box-shadow: var(--mbg-shadow-lg);
    background: rgba(255, 255, 255, 0.94);
    -webkit-backdrop-filter: blur(var(--mbg-glass-blur));
    backdrop-filter: blur(var(--mbg-glass-blur));
}

.modal-header {
    border-bottom: 1px solid var(--mbg-border);
    padding: 1rem 1.35rem;
}

.modal-title { font-size: 21px; font-weight: 700; }

.modal-body { padding: 1.35rem; }
.modal-footer { border-top: 1px solid var(--mbg-border); padding: .9rem 1.35rem; }

.modal-backdrop.show { opacity: .35; }

/* ============================================================
   Pagination
   ============================================================ */

.pagination { --bs-pagination-border-radius: var(--mbg-radius-sm); --bs-pagination-border-color: var(--mbg-border-solid); }
.pagination .page-link { color: var(--mbg-text-secondary); font-size: .84rem; }
.pagination .page-link:focus { box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.16); }
.pagination .active > .page-link {
    background: var(--mbg-primary);
    border-color: var(--mbg-primary);
    color: #fff;
}

/* ============================================================
   Toast notifications
   ============================================================ */

.mbg-toast-container {
    position: fixed;
    top: 76px;
    right: 20px;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(380px, calc(100vw - 40px));
}

.mbg-toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--mbg-radius-md);
    background: rgba(255, 255, 255, 0.94);
    -webkit-backdrop-filter: blur(var(--mbg-glass-blur));
    backdrop-filter: blur(var(--mbg-glass-blur));
    border: 1px solid var(--mbg-border);
    box-shadow: var(--mbg-shadow);
    font-size: .86rem;
    line-height: 1.45;
    animation: mbgToastIn .28s cubic-bezier(.21, 1.02, .73, 1) both;
}

.mbg-toast.leaving { animation: mbgToastOut .25s ease forwards; }

.mbg-toast .toast-icon {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    margin-top: 1px;
}

.mbg-toast .toast-body { flex: 1; color: var(--mbg-text); }
.mbg-toast .toast-title { font-weight: 700; font-size: .82rem; display: block; margin-bottom: 1px; }
.mbg-toast .toast-close { border: 0; background: none; color: var(--mbg-text-muted); font-size: .9rem; padding: 0 2px; }

.mbg-toast.success .toast-icon { background: #DCFCE7; color: #15803D; }
.mbg-toast.error .toast-icon { background: #FEE2E2; color: #B91C1C; }
.mbg-toast.warning .toast-icon { background: #FEF3C7; color: #B45309; }
.mbg-toast.info .toast-icon { background: #E0F2FE; color: #0369A1; }

@keyframes mbgToastIn {
    from { opacity: 0; transform: translateX(24px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes mbgToastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(24px); }
}

/* Konfirmasi hapus (modal) */
.mbg-confirm-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #FEF2F2;
    color: var(--mbg-danger);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    margin: 0 auto 14px;
}

/* ============================================================
   Empty state
   ============================================================ */

.empty-state {
    text-align: center;
    padding: 3.5rem 1.5rem;
    color: var(--mbg-text-muted);
}

.empty-state .empty-icon {
    width: 68px;
    height: 68px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--mbg-primary-tint);
    color: var(--mbg-primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7rem;
}

.empty-state .empty-title { font-size: 1rem; font-weight: 700; color: var(--mbg-text); margin-bottom: 4px; }
.empty-state .empty-desc { font-size: .85rem; margin-bottom: 16px; max-width: 380px; margin-left: auto; margin-right: auto; }

/* ============================================================
   GIS
   ============================================================ */

.leaflet-container { z-index: 1; border-radius: var(--mbg-radius-md); }

#main-map { height: 480px; border-radius: var(--mbg-radius-md); }
#tripMap, #coordinate-map { border-radius: var(--mbg-radius-md); z-index: 1; }

.leaflet-control-zoom a { border-radius: 6px !important; border-color: var(--mbg-border-solid) !important; color: var(--mbg-text-secondary) !important; }
.leaflet-control-zoom a:hover { background: var(--mbg-primary-soft) !important; color: var(--mbg-primary-dark) !important; }

/* Panel informasi rute di atas peta */
.map-info-panel {
    position: absolute;
    z-index: 500;
    bottom: 18px;
    left: 18px;
    padding: 12px 16px;
    border-radius: var(--mbg-radius-md);
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(var(--mbg-glass-blur));
    backdrop-filter: blur(var(--mbg-glass-blur));
    border: 1px solid var(--mbg-border);
    box-shadow: var(--mbg-shadow);
    font-size: .84rem;
    max-width: 280px;
}

.map-info-panel .info-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.map-info-panel .info-row i { color: var(--mbg-primary-dark); width: 18px; text-align: center; }
.map-info-panel .info-value { font-weight: 700; margin-left: auto; color: var(--mbg-text); }

/* ============================================================
   SCM flow (dashboard) — bentuk asli, hanya warna card soft
   ============================================================ */

.scm-flow .bg-secondary { background: #F1F5F9 !important; }
.scm-flow .bg-primary   { background: #E0F2FE !important; }
.scm-flow .bg-info      { background: #E0F2FE !important; }
.scm-flow .bg-success   { background: #DCFCE7 !important; }
.scm-flow .bg-warning   { background: #FEF3C7 !important; }

/* ============================================================
   Import & misc pages
   ============================================================ */

.border-dashed { border-style: dashed !important; }

.dropzone-hover {
    border-color: var(--mbg-primary) !important;
    background: var(--mbg-primary-tint) !important;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1199.98px) {
    .sidebar { --mbg-sidebar-width: 240px; }
}

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 8px 0 32px rgba(15, 23, 42, 0.12);
    }
    .sidebar.show { transform: translateX(0); }
    .content { margin-left: 0; }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 1029;
        background: rgba(15, 23, 42, 0.4);
    }
    .sidebar-backdrop.show { display: block; }
}

@media (max-width: 575.98px) {
    .mbg-toast-container { top: 68px; right: 12px; left: 12px; max-width: none; }
    main { padding: 1rem !important; }
    .table thead th, .table tbody td { padding: .6rem .75rem; }
}
