:root {
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #0dcaf0;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-600: #6c757d;
    --gray-800: #343a40;
    --gray-900: #212529;
    --sidebar-width: 260px;
    --white: #fff;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 10px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    min-height: 100vh;
}

a {
    text-decoration: none;
    color: var(--primary);
}

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

/* Layout */
.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1a1f36 0%, #0d1127 100%);
    color: var(--white);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--white);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-header h2 .logo-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.sidebar-header small {
    display: block;
    color: rgba(255,255,255,0.5);
    font-size: 12px;
    margin-top: 4px;
    padding-left: 46px;
}

.sidebar-nav {
    padding: 16px 0;
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

.nav-section {
    padding: 8px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.35);
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: rgba(255,255,255,0.06);
    color: var(--white);
}

.nav-link.active {
    background: rgba(255,255,255,0.08);
    color: var(--white);
    border-left-color: var(--primary);
}

.nav-link .icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

/* Admin link */
.admin-link {
    color: #ffc107 !important;
}

.admin-link:hover {
    color: #ffcd39 !important;
    background: rgba(255,193,7,0.1);
}

/* Sidebar footer */
.sidebar-footer {
    flex-shrink: 0;
    width: 100%;
    background: rgba(0,0,0,0.2);
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* User info */
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--white);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: rgba(255,255,255,0.45);
}

.logout-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: rgba(255,255,255,0.5);
    font-size: 18px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.logout-btn:hover {
    background: rgba(220,53,69,0.2);
    color: #dc3545;
}

/* Language switcher */
.lang-switcher {
    padding: 12px 20px;
}

.lang-switcher span {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.35);
    margin-bottom: 8px;
}

.lang-buttons {
    display: flex;
    gap: 8px;
}

.lang-btn {
    flex: 1;
    padding: 6px 12px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    background: transparent;
    color: rgba(255,255,255,0.7);
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.lang-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--white);
}

.lang-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 0;
}

/* Top Bar */
.topbar {
    background: var(--white);
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--gray-900);
}

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

/* Mobile toggle */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-800);
}

/* Page Content */
.page-content {
    padding: 32px;
}

/* Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.blue { background: #e7f1ff; color: var(--primary); }
.stat-icon.green { background: #d1e7dd; color: var(--success); }
.stat-icon.orange { background: #fff3cd; color: #cc8a00; }
.stat-icon.red { background: #f8d7da; color: var(--danger); }

.stat-info h3 {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
}

.stat-info p {
    font-size: 13px;
    color: var(--gray-600);
    margin-top: 4px;
}

/* Tables */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table thead th {
    background: var(--gray-100);
    padding: 12px 16px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-600);
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

table tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--gray-200);
    font-size: 14px;
}

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

table tbody tr:hover {
    background: var(--gray-100);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
    color: var(--white);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-success:hover {
    background: #157347;
    color: var(--white);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #bb2d3b;
    color: var(--white);
}

.btn-warning {
    background: #ffc107;
    color: var(--gray-900);
}

.btn-warning:hover {
    background: #ffca2c;
    color: var(--gray-900);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-800);
}

.btn-outline:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
}

.btn-group {
    display: flex;
    gap: 6px;
}

/* Badge / Status */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-pending { background: #fff3cd; color: #664d03; }
.badge-in_transit { background: #cff4fc; color: #055160; }
.badge-delivered { background: #d1e7dd; color: #0f5132; }
.badge-cancelled { background: #f8d7da; color: #842029; }
.badge-low { background: #f8d7da; color: #842029; }
.badge-ok { background: #d1e7dd; color: #0f5132; }

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--gray-800);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
    background: var(--white);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13,110,253,0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236c757d' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 01.753 1.659l-4.796 5.48a1 1 0 01-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    resize: vertical;
}

/* Formset table */
.formset-table {
    width: 100%;
    margin-bottom: 16px;
}

.formset-table th {
    padding: 8px 12px;
    font-size: 13px;
    background: var(--gray-100);
}

.formset-table td {
    padding: 8px 12px;
}

.formset-table .form-control {
    padding: 8px 10px;
}

/* Delete confirm */
.confirm-box {
    text-align: center;
    padding: 40px;
}

.confirm-box h3 {
    font-size: 20px;
    margin-bottom: 12px;
}

.confirm-box p {
    color: var(--gray-600);
    margin-bottom: 24px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-600);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 20px;
}

/* Detail page */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.detail-item {
    padding: 16px;
    background: var(--gray-100);
    border-radius: 8px;
}

.detail-item label {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--gray-600);
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 4px;
}

.detail-item span {
    font-size: 16px;
    font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .page-content {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .topbar {
        padding: 12px 16px;
    }

    .topbar h1 {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Checkbox */
.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.form-check-input {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

.form-check label {
    cursor: pointer;
    font-size: 14px;
}

/* User badges */
.badge-admin {
    background: #fff3cd;
    color: #664d03;
}

.badge-user {
    background: #cff4fc;
    color: #055160;
}

.badge-active {
    background: #d1e7dd;
    color: #0f5132;
}

.badge-inactive {
    background: #f8d7da;
    color: #842029;
}

/* ── Route Map Card ─────────────────────────────── */
.route-card .card-header {
    flex-wrap: wrap;
    gap: 12px;
}

.route-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.route-stat {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.route-stat.blue  { background: #e7f1ff; color: #0a58ca; }
.route-stat.green { background: #d1e7dd; color: #0f5132; }
.route-stat.gray  { background: var(--gray-200); color: var(--gray-600); }

.route-stat-loading {
    font-size: 13px;
    color: var(--gray-600);
    font-style: italic;
}

.route-addresses {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background: var(--gray-100);
    border-bottom: 1px solid var(--gray-200);
    flex-wrap: wrap;
}

.route-point {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex: 1;
    min-width: 180px;
}

.point-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-top: 3px;
    flex-shrink: 0;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.from-dot { background: var(--success); }
.to-dot   { background: var(--danger); }

.route-point-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.route-point-info strong {
    font-size: 13px;
    color: var(--gray-900);
}

.route-point-info span {
    font-size: 12px;
    color: var(--gray-600);
}

.route-arrow {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    opacity: 0.6;
}


#supplyMap {
    width: 100%;
    z-index: 1;
}

.map-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 200px;
    color: var(--gray-600);
    font-size: 14px;
}

.map-spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.map-error {
    padding: 18px 24px;
    color: #842029;
    background: #f8d7da;
    border-radius: 0 0 var(--radius) var(--radius);
    font-size: 14px;
}

.map-popup strong {
    display: block;
    margin-bottom: 2px;
}

@media (max-width: 600px) {
    .route-addresses {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .route-arrow {
        transform: rotate(90deg);
        align-self: center;
    }
}
