/* ============================================
   IMS — Web UI Stylesheet
   ============================================ */

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --purple: #7c3aed;
    --teal: #0891b2;
    --indigo: #4f46e5;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .1), 0 1px 2px rgba(0, 0, 0, .06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, .1), 0 2px 4px rgba(0, 0, 0, .06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    min-height: 100vh;
}

/* --- Navbar --- */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--gray-900);
    color: white;
    padding: 0 16px;
    min-height: 56px;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-admin {
    background: #1e1b4b;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    font-size: 24px;
}

.brand-text {
    font-weight: 700;
    font-size: 18px;
}

.brand-role {
    font-size: 12px;
    background: rgba(255, 255, 255, .15);
    padding: 2px 8px;
    border-radius: 4px;
}

.nav-links {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    justify-content: center;
}

.nav-link {
    color: rgba(255, 255, 255, .8);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    transition: background .15s, color .15s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, .1);
    color: white;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    color: rgba(255, 255, 255, .7);
}

.logout-link {
    background: rgba(220, 38, 38, .3);
    color: #fca5a5 !important;
}

.logout-link:hover {
    background: rgba(220, 38, 38, .5) !important;
}

/* --- Container --- */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--gray-300);
}

/* Clickable stat card links */
a.stat-card-link {
    text-decoration: none;
    color: inherit;
    display: contents;
}

/* Back-to-dashboard link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .85rem;
    color: var(--muted);
    text-decoration: none;
    margin-bottom: .5rem;
    transition: color .2s;
}

.back-link:hover {
    color: var(--primary);
}

.back-link svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

a.stat-card-link .stat-card {
    cursor: pointer;
    transition: transform .2s, box-shadow .2s;
}

a.stat-card-link .stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow), 0 6px 16px rgba(0, 0, 0, .1);
}

.stat-card.stat-blue {
    border-left-color: var(--primary);
}

.stat-card.stat-green {
    border-left-color: var(--success);
}

.stat-card.stat-orange {
    border-left-color: var(--warning);
}

.stat-card.stat-red {
    border-left-color: var(--danger);
}

.stat-card.stat-purple {
    border-left-color: var(--purple);
}

.stat-card.stat-teal {
    border-left-color: var(--teal);
}

.stat-card.stat-indigo {
    border-left-color: var(--indigo);
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    color: var(--gray-900);
}

.stat-label {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
}

/* --- Action Grid --- */
.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--gray-700);
    font-weight: 600;
    transition: box-shadow .15s, transform .15s;
}

.action-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.action-icon {
    font-size: 28px;
}

/* --- Section --- */
.section {
    margin-bottom: 28px;
}

.section h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--gray-800);
}

/* --- Card --- */
.card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

/* --- Table --- */
.table-container {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead th {
    background: var(--gray-100);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: var(--gray-50);
}

.data-table tbody tr.status-danger {
    background: #fef2f2;
}

.data-table tbody tr.status-warning {
    background: #fffbeb;
}

.data-table tbody tr.status-danger:hover {
    background: #fee2e2;
}

.data-table tbody tr.status-warning:hover {
    background: #fef3c7;
}

.empty-state {
    text-align: center;
    padding: 40px !important;
    color: var(--gray-400);
    font-style: italic;
}

.actions-cell {
    white-space: nowrap;
    display: flex;
    gap: 4px;
}

/* --- Badge --- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.badge.status-ok {
    background: #d1fae5;
    color: #065f46;
}

.badge.status-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge.status-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge.badge-add {
    background: #d1fae5;
    color: #065f46;
}

.badge.badge-update {
    background: #dbeafe;
    color: #1e40af;
}

.badge.badge-delete {
    background: #fee2e2;
    color: #991b1b;
}

.badge.badge-sell {
    background: #fef3c7;
    color: #92400e;
}

.badge.badge-price_update {
    background: #ede9fe;
    color: #5b21b6;
}

.badge.badge-role-admin {
    background: #fef3c7;
    color: #92400e;
}

.badge.badge-role-warehouse_staff {
    background: #dbeafe;
    color: #1e40af;
}

.badge.badge-role-dispatcher {
    background: #ede9fe;
    color: #5b21b6;
}

.badge.badge-role-driver {
    background: #d1fae5;
    color: #065f46;
}

.badge.badge-role-viewer {
    background: #e0e7ff;
    color: #3730a3;
}

/* --- Filter Bar --- */
.filter-bar {
    background: white;
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

/* Export dropdown */
.export-dropdown {
    position: relative;
    display: inline-block;
}

.export-dropdown .export-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    min-width: 120px;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-top: 4px;
    overflow: hidden;
}

.export-dropdown:hover .export-menu,
.export-dropdown .export-menu:hover {
    display: block;
}

.export-dropdown .export-menu a {
    display: block;
    padding: 8px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s;
}

.export-dropdown .export-menu a:hover {
    background: var(--gray-100);
}

.filter-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-form input,
.filter-form select {
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    background: white;
}

.filter-form input:focus,
.filter-form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--gray-300);
    background: white;
    color: var(--gray-700);
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
    line-height: 1.4;
}

.btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-edit {
    background: #f59e0b;
    color: white;
    border-color: #f59e0b;
}

.btn-edit:hover {
    background: #d97706;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-600);
}

.btn-outline:hover {
    background: var(--gray-100);
}

.btn-full {
    width: 100%;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 12px;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 4px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.form-row {
    display: flex;
    gap: 12px;
}

.inline-form {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-dialog {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-400);
    padding: 4px 8px;
    border-radius: 4px;
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
}

/* --- Alerts --- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.alert-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    opacity: .6;
}

.alert-close:hover {
    opacity: 1;
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    padding: 12px;
}

.page-info {
    font-size: 13px;
    color: var(--gray-500);
}

/* --- Login Page --- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-container {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.login-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--gray-900);
}

.login-subtitle {
    color: var(--gray-500);
    font-size: 14px;
    margin-top: 4px;
}

.login-form .form-group {
    margin-bottom: 16px;
}

.login-form input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 15px;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.login-footer {
    text-align: center;
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 20px;
    line-height: 1.6;
}

/* --- Utility --- */
.text-muted {
    color: var(--gray-400);
    font-size: 13px;
}

.text-green {
    color: #059669;
}

.text-red {
    color: #dc2626;
}

.text-amber {
    color: #d97706;
}

/* --- Background color cards --- */
.bg-blue {
    border-left-color: var(--primary);
    background: #eff6ff;
}

.bg-green {
    border-left-color: var(--success);
    background: #ecfdf5;
}

.bg-amber {
    border-left-color: var(--warning);
    background: #fffbeb;
}

.bg-red {
    border-left-color: var(--danger);
    background: #fef2f2;
}

.bg-purple {
    border-left-color: var(--purple);
    background: #f5f3ff;
}

.bg-cyan {
    border-left-color: var(--teal);
    background: #ecfeff;
}

.bg-indigo {
    border-left-color: var(--indigo);
    background: #eef2ff;
}

.bg-teal {
    border-left-color: #14b8a6;
    background: #f0fdfa;
}

.bg-orange {
    border-left-color: #f97316;
    background: #fff7ed;
}

/* --- Section Card --- */
.section-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.section-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--gray-700);
}

/* --- Form Grid --- */
.form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    padding: 8px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.full-width {
    flex-basis: 100%;
}

.form-grid textarea {
    width: 100%;
    resize: vertical;
}

/* --- Form Page (register, join, change-password) --- */
.form-page {
    max-width: 480px;
    margin: 40px auto;
}

.form-page h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--gray-900);
}

.form-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.form-footer {
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
}

.form-footer a {
    color: var(--primary);
    text-decoration: none;
}

.form-footer a:hover {
    text-decoration: underline;
}

/* --- Row Variants --- */
.row-warning {
    background: #fffbeb !important;
}

.row-muted {
    opacity: .6;
}

.row-total {
    background: var(--gray-100);
    font-weight: 600;
}

/* --- Inline form for filter bars --- */
.inline-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    background: white;
}

.inline-form input:focus,
.inline-form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

/* --- Additional btn variants --- */
.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-success:hover {
    background: #047857;
}

.btn-warning {
    background: var(--warning);
    color: white;
    border-color: var(--warning);
}

.btn-warning:hover {
    background: #b45309;
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
    border-color: var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

/* --- Badge status variants for orders/POs --- */
.badge-pending {
    background: #dbeafe;
    color: #1e40af;
}

.badge-processing {
    background: #fef3c7;
    color: #92400e;
}

.badge-completed {
    background: #d1fae5;
    color: #065f46;
}

.badge-cancelled {
    background: #fee2e2;
    color: #991b1b;
}

.badge-draft {
    background: #f3f4f6;
    color: #4b5563;
}

.badge-sent {
    background: #dbeafe;
    color: #1e40af;
}

.badge-shipped {
    background: #cffafe;
    color: #155e75;
}

.badge-received {
    background: #d1fae5;
    color: #065f46;
}

/* --- Token / invitation link input --- */
.token-input {
    width: 100%;
    min-width: 260px;
    font-size: 12px;
    padding: 6px 8px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: var(--gray-50);
    color: var(--gray-700);
    cursor: pointer;
}

.token-input:focus {
    outline: 2px solid var(--primary);
    background: white;
}

/* --- Copy button (inline clipboard) --- */
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: var(--gray-50);
    color: var(--gray-600);
    cursor: pointer;
    vertical-align: middle;
    transition: all .15s ease;
    line-height: 1.4;
}

.copy-btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-400);
    color: var(--gray-800);
}

.copy-btn.copy-ok {
    background: #d1fae5;
    border-color: #6ee7b7;
    color: #065f46;
}

.copy-id {
    font-family: monospace;
    font-size: 12px;
    user-select: all;
    vertical-align: middle;
}

/* --- Login footer link --- */
.login-footer a {
    color: var(--primary);
    text-decoration: none;
}

.login-footer a:hover {
    text-decoration: underline;
}

/* --- Notification bell --- */
.notif-bell {
    position: relative;
    font-size: 18px;
    padding: 6px 10px !important;
}

.notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border-radius: 8px;
    padding: 0 4px;
}

/* --- Notification list --- */
.notif-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notif-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: white;
    border-radius: var(--radius);
    padding: 14px 18px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--gray-300);
}

.notif-unread {
    border-left-color: var(--primary);
    background: #eff6ff;
}

.notif-content {
    flex: 1;
}

.notif-content p {
    margin: 4px 0 2px;
    font-size: 14px;
    color: var(--gray-600);
}

.badge-low_stock {
    background: #fef3c7;
    color: #92400e;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-manufacturing {
    background: #ede9fe;
    color: #5b21b6;
}

.badge-currency {
    background: #fef3c7;
    color: #78350f;
}

.badge-message {
    background: #dbeafe;
    color: #1e40af;
}

.badge-photo {
    background: #d1fae5;
    color: #065f46;
}

.badge-route {
    background: #e0f2fe;
    color: #0369a1;
}

/* --- Touch-friendly enhancements --- */
:root {
    --touch-min: 48px;
}

/* Ensure all interactive elements meet WCAG 2.5.8 touch target */
.btn,
.nav-link,
.modal-close,
.alert-close {
    min-height: var(--touch-min);
    min-width: var(--touch-min);
}

/* Active tap states for touch */
.btn:active {
    transform: scale(.97);
    opacity: .9;
}

.nav-link:active {
    background: rgba(255, 255, 255, .2);
}

.action-card:active {
    transform: scale(.97);
}

.stat-card {
    user-select: none;
}

/* Larger form controls for touch */
@media (pointer: coarse) {

    .form-group input,
    .form-group select,
    .filter-form input,
    .filter-form select,
    .inline-form input,
    .inline-form select,
    .form-grid input,
    .form-grid select,
    .form-grid textarea {
        min-height: var(--touch-min);
        font-size: 16px;
    }

    .data-table tbody td {
        padding: 14px 12px;
    }

    .data-table thead th {
        padding: 14px 12px;
    }
}

/* --- Mobile gate removed — all roles have mobile access --- */

/* --- Admin mobile layout (compact at <=768px) --- */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 8px;
    }

    .nav-links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 2px;
    }

    .nav-link {
        padding: 10px 12px;
        font-size: 13px;
    }

    .nav-user {
        flex-wrap: wrap;
        justify-content: center;
    }

    .filter-form {
        flex-direction: column;
    }

    .filter-form input,
    .filter-form select {
        width: 100%;
    }

    .form-row {
        flex-direction: column;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .action-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .login-container {
        width: 95%;
        padding: 24px;
    }

    .container {
        padding: 12px;
    }

    /* Horizontal-scrolling tables on mobile */
    .data-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .section-card {
        padding: 14px;
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-form input,
    .inline-form select {
        width: 100%;
    }

    .page-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .notif-item {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ============================================
   Dark Mode — Futuristic Theme
   ============================================ */
[data-theme="dark"] {
    --primary: #38bdf8;
    --primary-dark: #0ea5e9;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --purple: #a78bfa;
    --teal: #22d3ee;
    --indigo: #818cf8;
    --gray-50: #0a0e1a;
    --gray-100: #111827;
    --gray-200: #1e293b;
    --gray-300: #334155;
    --gray-400: #64748b;
    --gray-500: #94a3b8;
    --gray-600: #cbd5e1;
    --gray-700: #e2e8f0;
    --gray-800: #f1f5f9;
    --gray-900: #f8fafc;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 0 12px rgba(56, 189, 248, .04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, .4), 0 0 20px rgba(56, 189, 248, .06);
    --glow: 0 0 15px rgba(56, 189, 248, .15);
    --glow-strong: 0 0 30px rgba(56, 189, 248, .25);
}

/* Navbar — futuristic glass */
[data-theme="dark"] .navbar {
    background: rgba(10, 14, 26, .85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(56, 189, 248, .12);
}

[data-theme="dark"] .nav-link {
    color: rgba(203, 213, 225, .85);
}

[data-theme="dark"] .nav-link:hover {
    background: rgba(56, 189, 248, .1);
    color: #38bdf8;
}

[data-theme="dark"] .brand-role {
    background: rgba(56, 189, 248, .15);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, .2);
}

/* Surfaces — futuristic glass panels */
[data-theme="dark"] .stat-card,
[data-theme="dark"] .action-card,
[data-theme="dark"] .card,
[data-theme="dark"] .section-card,
[data-theme="dark"] .form-card,
[data-theme="dark"] .filter-bar,
[data-theme="dark"] .notif-item,
[data-theme="dark"] .modal-dialog {
    background: rgba(17, 24, 39, .7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(56, 189, 248, .08);
}

/* Dark export dropdown */
[data-theme="dark"] .export-dropdown .export-menu {
    background: rgba(17, 24, 39, .95);
    border: 1px solid rgba(56, 189, 248, .15);
}

[data-theme="dark"] .export-dropdown .export-menu a {
    color: #e2e8f0;
}

[data-theme="dark"] .export-dropdown .export-menu a:hover {
    background: rgba(56, 189, 248, .1);
}

[data-theme="dark"] .stat-card {
    border: 1px solid rgba(56, 189, 248, .12);
    box-shadow: var(--glow);
}

[data-theme="dark"] .btn {
    background: rgba(30, 41, 59, .8);
    border-color: rgba(56, 189, 248, .15);
    color: #e2e8f0;
}

[data-theme="dark"] .btn:hover {
    background: rgba(56, 189, 248, .12);
    border-color: rgba(56, 189, 248, .3);
    color: #38bdf8;
}

[data-theme="dark"] .btn-outline {
    background: transparent;
    border-color: rgba(56, 189, 248, .2);
    color: #94a3b8;
}

[data-theme="dark"] .btn-outline:hover {
    background: rgba(56, 189, 248, .08);
    color: #38bdf8;
}

[data-theme="dark"] .btn-primary {
    background: linear-gradient(135deg, #0ea5e9, #38bdf8);
    border-color: transparent;
    color: #0a0e1a;
    font-weight: 600;
    box-shadow: 0 0 12px rgba(56, 189, 248, .3);
}

[data-theme="dark"] .btn-primary:hover {
    background: linear-gradient(135deg, #38bdf8, #7dd3fc);
    box-shadow: 0 0 20px rgba(56, 189, 248, .5);
}

[data-theme="dark"] .btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

[data-theme="dark"] .btn-success {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

[data-theme="dark"] .btn-warning {
    background: var(--warning);
    border-color: var(--warning);
    color: white;
}

[data-theme="dark"] .btn-edit {
    background: #f59e0b;
    border-color: #f59e0b;
    color: white;
}

[data-theme="dark"] .btn-secondary {
    background: #475569;
    border-color: #64748b;
    color: #e2e8f0;
}

[data-theme="dark"] .filter-form input,
[data-theme="dark"] .filter-form select,
[data-theme="dark"] .inline-form input,
[data-theme="dark"] .inline-form select,
[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group select,
[data-theme="dark"] .form-group textarea,
[data-theme="dark"] .form-grid input,
[data-theme="dark"] .form-grid select,
[data-theme="dark"] .form-grid textarea,
[data-theme="dark"] .form-input {
    background: rgba(10, 14, 26, .6);
    color: #e2e8f0;
    border: 1px solid rgba(56, 189, 248, .12);
    transition: border-color .2s, box-shadow .2s;
}

[data-theme="dark"] .filter-form input:focus,
[data-theme="dark"] .filter-form select:focus,
[data-theme="dark"] .inline-form input:focus,
[data-theme="dark"] .inline-form select:focus,
[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group select:focus,
[data-theme="dark"] .form-group textarea:focus,
[data-theme="dark"] .form-grid input:focus,
[data-theme="dark"] .form-grid select:focus,
[data-theme="dark"] .form-grid textarea:focus,
[data-theme="dark"] .form-input:focus {
    border-color: rgba(56, 189, 248, .4);
    box-shadow: 0 0 8px rgba(56, 189, 248, .15);
    outline: none;
}

[data-theme="dark"] .token-input {
    background: rgba(10, 14, 26, .6);
    color: #e2e8f0;
}

[data-theme="dark"] .token-input:focus {
    background: rgba(17, 24, 39, .8);
    border-color: rgba(56, 189, 248, .4);
}

[data-theme="dark"] .copy-btn {
    background: var(--gray-800);
    border-color: var(--gray-600);
    color: var(--gray-300);
}

[data-theme="dark"] .copy-btn:hover {
    background: var(--gray-700);
    border-color: var(--gray-500);
    color: var(--gray-100);
}

[data-theme="dark"] .copy-btn.copy-ok {
    background: #064e3b;
    border-color: #10b981;
    color: #6ee7b7;
}

/* Table overrides — futuristic */
[data-theme="dark"] .data-table {
    border: 1px solid rgba(56, 189, 248, .08);
}

[data-theme="dark"] .data-table thead th {
    background: rgba(10, 14, 26, .6);
    color: #7dd3fc;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .05em;
}

[data-theme="dark"] .data-table tbody tr:hover {
    background: rgba(56, 189, 248, .06);
}

[data-theme="dark"] .data-table tbody tr:nth-child(even) {
    background: rgba(17, 24, 39, .4);
}

/* Row variants */
[data-theme="dark"] .row-warning {
    background: rgba(245, 158, 11, .15) !important;
}

[data-theme="dark"] .row-total {
    background: #1e293b;
}

/* Alerts */
[data-theme="dark"] .alert-error {
    background: rgba(239, 68, 68, .15);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, .3);
}

[data-theme="dark"] .alert-success {
    background: rgba(16, 185, 129, .15);
    color: #6ee7b7;
    border-color: rgba(16, 185, 129, .3);
}

[data-theme="dark"] .alert-warning {
    background: rgba(245, 158, 11, .15);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, .3);
}

/* Badges — softer on dark */
[data-theme="dark"] .badge.status-ok,
[data-theme="dark"] .badge-completed,
[data-theme="dark"] .badge-received,
[data-theme="dark"] .badge.badge-add {
    background: rgba(16, 185, 129, .2);
    color: #6ee7b7;
}

[data-theme="dark"] .badge.status-warning,
[data-theme="dark"] .badge-processing,
[data-theme="dark"] .badge-low_stock,
[data-theme="dark"] .badge.badge-sell,
[data-theme="dark"] .badge.badge-role-admin {
    background: rgba(245, 158, 11, .2);
    color: #fcd34d;
}

[data-theme="dark"] .badge.status-danger,
[data-theme="dark"] .badge-cancelled,
[data-theme="dark"] .badge.badge-delete {
    background: rgba(239, 68, 68, .2);
    color: #fca5a5;
}

[data-theme="dark"] .badge-pending,
[data-theme="dark"] .badge-sent,
[data-theme="dark"] .badge-info,
[data-theme="dark"] .badge-message,
[data-theme="dark"] .badge-route,
[data-theme="dark"] .badge.badge-update,
[data-theme="dark"] .badge.badge-role-warehouse_staff,
[data-theme="dark"] .badge.badge-role-viewer {
    background: rgba(59, 130, 246, .2);
    color: #93c5fd;
}

[data-theme="dark"] .badge-manufacturing {
    background: rgba(139, 92, 246, .2);
    color: #c4b5fd;
}

[data-theme="dark"] .badge-currency {
    background: rgba(245, 158, 11, .2);
    color: #fcd34d;
}

[data-theme="dark"] .badge-photo {
    background: rgba(16, 185, 129, .2);
    color: #6ee7b7;
}

[data-theme="dark"] .badge.badge-role-dispatcher {
    background: rgba(139, 92, 246, .2);
    color: #c4b5fd;
}

[data-theme="dark"] .badge.badge-role-driver {
    background: rgba(16, 185, 129, .2);
    color: #6ee7b7;
}

[data-theme="dark"] .badge-confirmed,
[data-theme="dark"] .badge-shipped {
    background: rgba(6, 182, 212, .2);
    color: #67e8f9;
}

[data-theme="dark"] .badge-draft {
    background: rgba(100, 116, 139, .3);
    color: #94a3b8;
}

[data-theme="dark"] .badge.badge-price_update {
    background: rgba(139, 92, 246, .2);
    color: #c4b5fd;
}

/* Background color stat cards */
[data-theme="dark"] .bg-blue {
    background: rgba(59, 130, 246, .1);
}

[data-theme="dark"] .bg-green {
    background: rgba(16, 185, 129, .1);
}

[data-theme="dark"] .bg-amber {
    background: rgba(245, 158, 11, .1);
}

[data-theme="dark"] .bg-red {
    background: rgba(239, 68, 68, .1);
}

[data-theme="dark"] .bg-purple {
    background: rgba(139, 92, 246, .1);
}

[data-theme="dark"] .bg-cyan {
    background: rgba(6, 182, 212, .1);
}

[data-theme="dark"] .bg-indigo {
    background: rgba(99, 102, 241, .1);
}

/* Notifications */
[data-theme="dark"] .notif-unread {
    background: rgba(59, 130, 246, .1);
}

/* Login page — futuristic */
[data-theme="dark"] .login-body {
    background: linear-gradient(135deg, #0a0e1a 0%, #0c1a2e 50%, #0a0e1a 100%);
}

[data-theme="dark"] .login-container {
    background: rgba(17, 24, 39, .8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(56, 189, 248, .12);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .6), 0 0 40px rgba(56, 189, 248, .08);
}

[data-theme="dark"] .login-form input {
    background: rgba(10, 14, 26, .6);
    color: #e2e8f0;
    border: 1px solid rgba(56, 189, 248, .12);
}

[data-theme="dark"] .login-form input:focus {
    border-color: rgba(56, 189, 248, .4);
    box-shadow: 0 0 8px rgba(56, 189, 248, .15);
}

/* Modal overlay */
[data-theme="dark"] .modal-overlay {
    background: rgba(0, 0, 0, .6);
}

/* Focus ring adjustment */
[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group select:focus,
[data-theme="dark"] .form-group textarea:focus,
[data-theme="dark"] .form-grid input:focus,
[data-theme="dark"] .form-grid select:focus,
[data-theme="dark"] .form-grid textarea:focus,
[data-theme="dark"] .filter-form input:focus,
[data-theme="dark"] .filter-form select:focus,
[data-theme="dark"] .inline-form input:focus,
[data-theme="dark"] .inline-form select:focus,
[data-theme="dark"] .login-form input:focus,
[data-theme="dark"] .form-input:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .25);
}

/* Utility text */
[data-theme="dark"] .text-green {
    color: #34d399;
}

[data-theme="dark"] .text-red {
    color: #f87171;
}

[data-theme="dark"] .text-amber {
    color: #fbbf24;
}

/* Theme toggle button */
.theme-toggle {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, .8);
    font-size: 18px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background .15s;
    min-height: var(--touch-min);
    min-width: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, .1);
    color: white;
}

/* Login page toggle (no navbar) */
.login-theme-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, .15);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    z-index: 10;
    transition: background .15s;
}

.login-theme-toggle:hover {
    background: rgba(255, 255, 255, .25);
}

/* Tablet touch panel layout (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .nav-link {
        padding: 10px 12px;
    }
}

/* --- Analytics --- */
.analytics-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-600);
    margin: 4px 0 16px;
}

.period-tabs {
    display: inline-flex;
    gap: 4px;
    margin-right: 8px;
}

.status-bar-container {
    display: flex;
    border-radius: var(--radius);
    overflow: hidden;
    height: 32px;
    gap: 2px;
}

.status-bar-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    padding: 0 8px;
    min-width: 60px;
}

[data-theme="dark"] .analytics-label {
    color: var(--gray-400);
}

/* ── Chart analytics ─────────────────────────────────────── */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.chart-card {
    min-height: 280px;
}

.chart-card h3 small {
    font-weight: 400;
    font-size: 12px;
    color: var(--gray-500);
}

.insights-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.insight-item {
    padding: 16px;
    border-radius: var(--radius);
    border-left: 4px solid var(--gray-300);
}

.insight-item strong {
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
}

.insight-item p {
    font-size: 14px;
    margin: 0;
    color: var(--gray-700);
}

.insight-peak {
    border-left-color: #10b981;
    background: rgba(16, 185, 129, 0.06);
}

.insight-slow {
    border-left-color: #f59e0b;
    background: rgba(245, 158, 11, 0.06);
}

[data-theme="dark"] .chart-card h3 small {
    color: var(--gray-400);
}

[data-theme="dark"] .insight-item p {
    color: var(--gray-300);
}

[data-theme="dark"] .insight-peak {
    background: rgba(16, 185, 129, 0.1);
}

[data-theme="dark"] .insight-slow {
    background: rgba(245, 158, 11, 0.1);
}

@media (max-width: 900px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }

    .insights-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Logistics: shipment & return badges ────────────────────────── */

.badge-created {
    background: #e0e7ff;
    color: #3730a3;
}

.badge-picked {
    background: #dbeafe;
    color: #1e40af;
}

.badge-packed {
    background: #c7d2fe;
    color: #4338ca;
}

.badge-in_transit {
    background: #fef3c7;
    color: #92400e;
}

.badge-out_for_delivery {
    background: #ffedd5;
    color: #9a3412;
}

.badge-delivered {
    background: #d1fae5;
    color: #065f46;
}

.badge-failed {
    background: #fee2e2;
    color: #991b1b;
}

.badge-returned {
    background: #fce7f3;
    color: #9d174d;
}

.badge-requested {
    background: #fef3c7;
    color: #92400e;
}

.badge-approved {
    background: #dbeafe;
    color: #1e40af;
}

.badge-rejected {
    background: #fee2e2;
    color: #991b1b;
}

/* ── Detail grid ────────────────────────────────────────────────── */

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.75rem 2rem;
    padding: 0.5rem 0;
}

.detail-grid div {
    padding: 4px 0;
    border-bottom: 1px solid var(--gray-200);
}

/* ── Tracking timeline ──────────────────────────────────────────── */

.timeline {
    position: relative;
    padding-left: 2rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-300);
}

.timeline-event {
    position: relative;
    margin-bottom: 1.5rem;
}

.timeline-dot {
    position: absolute;
    left: -2rem;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid white;
    box-shadow: 0 0 0 2px var(--primary);
}

.timeline-content {
    padding: 0.5rem 1rem;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}

.timeline-content .badge {
    margin-right: 0.5rem;
}

.timeline-content p {
    margin: 0.25rem 0;
}

.timeline-content small {
    font-size: 0.8rem;
}

/* ── Dark mode: logistics ───────────────────────────────────────── */

[data-theme="dark"] .detail-grid div {
    border-bottom-color: var(--gray-600);
}

[data-theme="dark"] .timeline::before {
    background: var(--gray-600);
}

[data-theme="dark"] .timeline-content {
    background: rgba(17, 24, 39, .85);
    border-color: rgba(56, 189, 248, .12);
    color: #e2e8f0;
}

[data-theme="dark"] .timeline-content strong {
    color: #f1f5f9;
}

[data-theme="dark"] .timeline-content .text-muted {
    color: #94a3b8 !important;
}

[data-theme="dark"] .timeline-content small {
    color: #64748b;
}

[data-theme="dark"] .timeline-dot {
    border-color: var(--gray-800);
}

[data-theme="dark"] .bg-teal {
    background: rgba(20, 184, 166, 0.1);
}

[data-theme="dark"] .bg-orange {
    background: rgba(249, 115, 22, 0.1);
}

[data-theme="dark"] .badge-created {
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
}

[data-theme="dark"] .badge-picked,
[data-theme="dark"] .badge-approved {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

[data-theme="dark"] .badge-packed {
    background: rgba(99, 102, 241, 0.2);
    color: #c7d2fe;
}

[data-theme="dark"] .badge-in_transit,
[data-theme="dark"] .badge-requested {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

[data-theme="dark"] .badge-out_for_delivery {
    background: rgba(249, 115, 22, 0.2);
    color: #fdba74;
}

[data-theme="dark"] .badge-delivered {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

[data-theme="dark"] .badge-failed,
[data-theme="dark"] .badge-rejected {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

[data-theme="dark"] .badge-returned {
    background: rgba(244, 114, 182, 0.2);
    color: #f9a8d4;
}

@media (max-width: 768px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Driver Mobile Cards --- */
.driver-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.driver-card {
    display: block;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    text-decoration: none;
    color: inherit;
    border-left: 4px solid #cbd5e1;
    transition: box-shadow .15s, transform .1s;
}

.driver-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.driver-card-urgent {
    border-left-color: #dc2626;
    background: #fef2f2;
}

.driver-card-high {
    border-left-color: #d97706;
    background: #fffbeb;
}

.driver-card-done {
    border-left-color: #059669;
    opacity: .75;
}

.driver-card-header {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.driver-card-body {
    margin-bottom: 8px;
}

.driver-card-body strong {
    font-size: 1.05em;
    display: block;
    margin-bottom: 2px;
}

.driver-card-body p {
    margin: 2px 0;
    font-size: .9em;
    color: var(--gray-600, #4b5563);
}

.driver-card-footer {
    display: flex;
    justify-content: space-between;
    font-size: .82em;
    color: var(--gray-500, #6b7280);
}

.driver-detail .section-card {
    margin-bottom: 16px;
}

.driver-detail-info p {
    margin: 4px 0;
}

/* Driver mobile-first: stack on phones */
@media (max-width: 480px) {
    .driver-cards {
        grid-template-columns: 1fr;
    }

    .driver-card {
        padding: 16px;
    }

    .driver-card-body strong {
        font-size: 1.15em;
    }
}

/* Dark mode driver cards */
[data-theme="dark"] .driver-card {
    background: #1e293b;
    border-left-color: #475569;
}

[data-theme="dark"] .driver-card-urgent {
    background: rgba(239, 68, 68, .1);
    border-left-color: #dc2626;
}

[data-theme="dark"] .driver-card-high {
    background: rgba(245, 158, 11, .1);
    border-left-color: #d97706;
}

[data-theme="dark"] .driver-card-body p {
    color: #94a3b8;
}

[data-theme="dark"] .driver-card-footer {
    color: #64748b;
}

/* ============================================
   Settings Sidebar
   ============================================ */
.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s, visibility .25s;
}

.settings-overlay.open {
    opacity: 1;
    visibility: visible;
}

.settings-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100vh;
    background: #fff;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .15);
    z-index: 201;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.settings-sidebar.open {
    transform: translateX(0);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
}

.settings-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--gray-800);
}

.settings-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--gray-500);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background .15s;
}

.settings-close:hover {
    background: var(--gray-100);
}

.settings-body {
    flex: 1;
    padding: 0;
}

.settings-section {
    padding: 16px 20px;
}

.settings-divider {
    height: 1px;
    background: var(--gray-200);
}

.settings-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.settings-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--teal));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
}

.settings-user-details {
    display: flex;
    flex-direction: column;
}

.settings-user-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--gray-800);
}

.settings-user-role {
    font-size: 12px;
    color: var(--gray-500);
}

.settings-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--gray-500);
    margin-bottom: 10px;
    display: block;
}

.settings-theme-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: var(--gray-700);
}

/* Toggle switch */
.settings-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.settings-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.settings-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--gray-300);
    border-radius: 24px;
    transition: background .25s;
}

.settings-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform .25s;
}

.settings-switch input:checked+.settings-slider {
    background: var(--primary);
}

.settings-switch input:checked+.settings-slider::before {
    transform: translateX(20px);
}

.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.settings-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--gray-700);
    text-decoration: none;
    transition: background .15s;
}

.settings-btn:hover {
    background: var(--gray-100);
}

.settings-btn-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.settings-btn-danger {
    color: var(--danger);
}

.settings-btn-danger:hover {
    background: rgba(220, 38, 38, .08);
}

/* Settings gear button in nav */
.settings-gear {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, .8);
    font-size: 20px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background .15s, transform .3s;
    min-height: var(--touch-min, 44px);
    min-width: var(--touch-min, 44px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.settings-gear:hover {
    background: rgba(255, 255, 255, .1);
    color: white;
    transform: rotate(45deg);
}

/* Dark mode settings sidebar */
[data-theme="dark"] .settings-sidebar {
    background: rgba(10, 14, 26, .95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid rgba(56, 189, 248, .1);
    box-shadow: 4px 0 30px rgba(0, 0, 0, .5), 0 0 40px rgba(56, 189, 248, .05);
}

[data-theme="dark"] .settings-overlay {
    background: rgba(0, 0, 0, .65);
}

[data-theme="dark"] .settings-header {
    border-bottom-color: rgba(56, 189, 248, .1);
}

[data-theme="dark"] .settings-title {
    color: #7dd3fc;
}

[data-theme="dark"] .settings-close {
    color: #94a3b8;
}

[data-theme="dark"] .settings-close:hover {
    background: rgba(56, 189, 248, .1);
}

[data-theme="dark"] .settings-divider {
    background: rgba(56, 189, 248, .08);
}

[data-theme="dark"] .settings-user-name {
    color: #f1f5f9;
}

[data-theme="dark"] .settings-user-role {
    color: #7dd3fc;
}

[data-theme="dark"] .settings-avatar {
    background: linear-gradient(135deg, #0ea5e9, #22d3ee);
    box-shadow: 0 0 12px rgba(56, 189, 248, .3);
}

[data-theme="dark"] .settings-label {
    color: #7dd3fc;
}

[data-theme="dark"] .settings-theme-row {
    color: #cbd5e1;
}

[data-theme="dark"] .settings-slider {
    background: #334155;
}

[data-theme="dark"] .settings-switch input:checked+.settings-slider {
    background: linear-gradient(135deg, #0ea5e9, #38bdf8);
    box-shadow: 0 0 8px rgba(56, 189, 248, .4);
}

[data-theme="dark"] .settings-btn {
    color: #cbd5e1;
}

[data-theme="dark"] .settings-btn:hover {
    background: rgba(56, 189, 248, .08);
    color: #38bdf8;
}

[data-theme="dark"] .settings-btn-danger {
    color: #f87171;
}

[data-theme="dark"] .settings-btn-danger:hover {
    background: rgba(239, 68, 68, .1);
    color: #fca5a5;
}

[data-theme="dark"] .settings-gear {
    color: rgba(203, 213, 225, .8);
}

[data-theme="dark"] .settings-gear:hover {
    background: rgba(56, 189, 248, .12);
    color: #38bdf8;
}

/* ============================================
   Futuristic Enhancements
   ============================================ */

/* Section cards — futuristic border glow on dark */
[data-theme="dark"] .section-card {
    border: 1px solid rgba(56, 189, 248, .08);
    border-radius: 12px;
}

[data-theme="dark"] .section-card h3 {
    color: #7dd3fc;
    letter-spacing: .02em;
}

/* Stats grid cards — glow on hover */
[data-theme="dark"] .stat-card:hover,
[data-theme="dark"] a.stat-card-link .stat-card:hover {
    box-shadow: var(--glow-strong);
    transform: translateY(-2px);
    transition: box-shadow .3s, transform .3s;
}

/* Page title futuristic */
[data-theme="dark"] h2 {
    color: #e2e8f0;
    letter-spacing: .02em;
}

/* Brand text glow */
[data-theme="dark"] .brand-text {
    color: #38bdf8;
    text-shadow: 0 0 12px rgba(56, 189, 248, .3);
}

/* Notification badge glow */
[data-theme="dark"] .notif-badge {
    box-shadow: 0 0 8px rgba(239, 68, 68, .5);
}

/* Charts card bg */
[data-theme="dark"] .chart-card {
    background: rgba(10, 14, 26, .6);
    border: 1px solid rgba(56, 189, 248, .08);
}

/* Status bar segments — glass effect */
[data-theme="dark"] .status-bar-segment {
    backdrop-filter: blur(4px);
}

/* Scrollbar futuristic */
[data-theme="dark"] ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: rgba(10, 14, 26, .4);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, .2);
    border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(56, 189, 248, .35);
}

/* --- Back to Top Button --- */
.back-to-top {
    position: fixed;
    bottom: 32px;
    right: 32px;
    z-index: 9000;
    width: 48px;
    height: 48px;
    border: 2px solid var(--primary);
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity .3s, visibility .3s, transform .3s, background .2s, box-shadow .2s;
    box-shadow: 0 4px 16px rgba(37, 99, 235, .35);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--primary-dark);
    box-shadow: 0 6px 24px rgba(37, 99, 235, .5);
    transform: translateY(-3px);
}

.back-to-top:active {
    transform: translateY(0);
}

[data-theme="dark"] .back-to-top {
    background: rgba(56, 189, 248, .15);
    border-color: #38bdf8;
    color: #38bdf8;
    box-shadow: 0 0 18px rgba(56, 189, 248, .3), 0 0 6px rgba(56, 189, 248, .15);
}

[data-theme="dark"] .back-to-top:hover {
    background: rgba(56, 189, 248, .3);
    box-shadow: 0 0 28px rgba(56, 189, 248, .45), 0 0 10px rgba(56, 189, 248, .25);
}