:root {
    --brand-primary: #2f6feb;
    --brand-primary-dark: #1e4fb8;
    --brand-accent: #14b8a6;
    --sidebar-bg-1: #10182c;
    --sidebar-bg-2: #1b2745;
    --surface: #ffffff;
    --page-bg: #f3f5fa;
    --text-main: #1f2433;
    --text-muted: #6b7488;
    --border-soft: #e7eaf3;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-soft: 0 4px 18px rgba(20, 30, 60, 0.06);
    --shadow-hover: 0 10px 28px rgba(20, 30, 60, 0.10);
}

* { box-sizing: border-box; }

body {
    background-color: var(--page-bg);
    font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
    color: var(--text-main);
    margin: 0;
}

a { text-decoration: none; }

/* ---------- App shell / layout ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 264px;
    min-width: 264px;
    background: linear-gradient(180deg, var(--sidebar-bg-1), var(--sidebar-bg-2));
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 22px 16px;
    z-index: 20;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px 22px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 18px;
}

.brand-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.brand-title { font-weight: 700; font-size: 16px; line-height: 1.3; }
.brand-sub { font-size: 12px; color: rgba(255,255,255,0.55); }

.brand-logo-img {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    background: #fff;
    flex-shrink: 0;
    padding: 3px;
}

.nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    overflow-y: auto;
}

.nav-list .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: rgba(255,255,255,0.72);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14.5px;
    font-weight: 600;
    position: relative;
    transition: background-color .15s ease, color .15s ease;
}

.nav-list .nav-link i { font-size: 17px; width: 20px; text-align: center; }

.nav-list .nav-link:hover {
    background-color: rgba(255,255,255,0.06);
    color: #fff;
}

.nav-list .nav-link.active {
    background: linear-gradient(90deg, rgba(47,111,235,0.9), rgba(20,184,166,0.55));
    color: #fff;
    box-shadow: var(--shadow-soft);
}

.nav-badge {
    margin-inline-start: auto;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 7px;
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 14px;
    margin-top: 10px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px;
    margin-bottom: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.user-name { font-size: 13.5px; font-weight: 700; }
.user-role { font-size: 11.5px; color: rgba(255,255,255,0.5); }

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.06);
    color: #fff;
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.1);
}

.logout-btn:hover { background: rgba(239,68,68,0.25); color: #fff; }

.sidebar-toggle {
    position: fixed;
    top: 14px;
    inset-inline-start: 14px;
    z-index: 40;
    background: var(--sidebar-bg-1);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    width: 42px;
    height: 42px;
    font-size: 20px;
    box-shadow: var(--shadow-soft);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10,14,26,0.5);
    z-index: 15;
    display: none;
}

/* ---------- Main / topbar ---------- */

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-title h1 {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    color: var(--text-main);
}

.topbar-title p, .topbar-title .page-subtitle {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

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

.topbar-bell {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--page-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    font-size: 18px;
}

.topbar-bell-dot {
    position: absolute;
    top: 8px;
    inset-inline-end: 9px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid var(--surface);
}

.app-content {
    padding: 24px 28px 40px;
    flex: 1;
}

.app-flash { border: none; border-radius: var(--radius-md); }

/* ---------- Cards / surfaces ---------- */

.card {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-soft);
    font-weight: 700;
    padding: 16px 18px;
}

.card-body { padding: 18px; }

.stat-card {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-soft);
    background: var(--surface);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-soft);
    transition: transform .15s ease, box-shadow .15s ease;
}

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

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: #fff;
    flex-shrink: 0;
}

.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 13px; color: var(--text-muted); font-weight: 600; }

.bg-grad-blue { background: linear-gradient(135deg, #2f6feb, #5b8def); }
.bg-grad-teal { background: linear-gradient(135deg, #0d9488, #14b8a6); }
.bg-grad-orange { background: linear-gradient(135deg, #ea580c, #fb923c); }
.bg-grad-red { background: linear-gradient(135deg, #dc2626, #f87171); }
.bg-grad-purple { background: linear-gradient(135deg, #7c3aed, #a78bfa); }

.chart-card { border-radius: var(--radius-lg); border: 1px solid var(--border-soft); box-shadow: var(--shadow-soft); background: var(--surface); }
.chart-card .card-header { font-weight: 700; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.chart-sm { height: 190px; }
.chart-wrap.chart-lg { height: 380px; }

/* ---------- Buttons ---------- */

.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; }
.btn-primary { background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark)); border: none; }
.btn-primary:hover { background: linear-gradient(135deg, var(--brand-primary-dark), var(--brand-primary-dark)); }
.btn-dark { background: var(--sidebar-bg-1); border: none; }

/* ---------- Tables ---------- */

.table-card { border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border-soft); box-shadow: var(--shadow-soft); background: var(--surface); }
.table { margin-bottom: 0; }
.table thead th {
    white-space: nowrap;
    background: #f8f9fc;
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
    border-bottom: 1px solid var(--border-soft);
    padding: 12px 14px;
}
.table tbody td { padding: 12px 14px; vertical-align: middle; font-size: 14px; }
.table tbody tr:hover { background-color: #f7f9fd; }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 40px; color: #cbd3e6; margin-bottom: 10px; display: block; }

/* ---------- Badges ---------- */

.badge-life-ok { background-color: #198754; }
.badge-life-warn { background-color: #fd7e14; }
.badge-life-danger { background-color: #dc3545; }

/* ---------- Forms ---------- */

.form-label { font-weight: 600; font-size: 13.5px; color: var(--text-main); }
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    padding: 9px 12px;
    font-size: 14px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(47,111,235,0.12);
}

/* ---------- Login page ---------- */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(1200px 600px at 15% -10%, #22345f 0%, #0e1526 55%, #0a0f1c 100%);
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    padding: 34px 30px;
}

.auth-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    margin: 0 auto 14px;
}

.auth-logo-img {
    max-height: 64px;
    max-width: 200px;
    object-fit: contain;
    display: block;
    margin: 0 auto 14px;
}

/* ---------- Tire wear / life visualization ---------- */

.wear-gauge-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.wear-gauge { position: relative; width: 152px; height: 152px; }
.wear-gauge canvas { width: 152px !important; height: 152px !important; }
.wear-gauge-center {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; pointer-events: none;
}
.wear-gauge-pct { font-size: 30px; font-weight: 800; line-height: 1; color: var(--text-main); }
.wear-gauge-icon { font-size: 15px; margin-bottom: 2px; }
.wear-gauge-status {
    font-size: 12.5px; font-weight: 700; margin-top: 8px; padding: 3px 12px; border-radius: 999px;
    display: inline-flex; align-items: center; gap: 5px;
}
.wear-gauge-status.wear-ok { color: #15803d; background: rgba(22,163,74,0.12); }
.wear-gauge-status.wear-warn { color: #b45309; background: rgba(217,119,6,0.12); }
.wear-gauge-status.wear-danger { color: #b91c1c; background: rgba(220,38,38,0.12); }
.wear-gauge-status.wear-none { color: var(--text-muted); background: var(--page-bg); }

.wear-stat-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 9px 12px; border-radius: var(--radius-sm); background: var(--page-bg); margin-bottom: 8px;
}
.wear-stat-row:last-child { margin-bottom: 0; }
.wear-stat-label { font-size: 12.5px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.wear-stat-value { font-size: 14px; font-weight: 700; color: var(--text-main); }
.wear-stat-value.wear-highlight { color: var(--brand-primary); }

.wear-bar-wrap { display: flex; align-items: center; gap: 8px; min-width: 100px; }
.wear-bar-track { flex: 1; height: 8px; border-radius: 999px; background: #e9edf5; overflow: hidden; }
.wear-bar-fill { height: 100%; border-radius: 999px; transition: width .35s ease; }
.wear-bar-fill.wear-ok { background: linear-gradient(90deg, #16a34a, #22c55e); }
.wear-bar-fill.wear-warn { background: linear-gradient(90deg, #d97706, #f59e0b); }
.wear-bar-fill.wear-danger { background: linear-gradient(90deg, #dc2626, #f87171); }
.wear-bar-text { font-size: 12px; font-weight: 700; color: var(--text-muted); min-width: 36px; }

.wear-mini-ring { position: relative; width: 42px; height: 42px; flex-shrink: 0; }
.wear-mini-ring canvas { width: 42px !important; height: 42px !important; }
.wear-mini-ring-text {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-size: 10.5px; font-weight: 800; color: var(--text-main); pointer-events: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        right: 0;
        transform: translateX(100%);
        transition: transform .2s ease;
    }
    html[dir="rtl"] .sidebar { transform: translateX(100%); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }
    .app-topbar { padding-inline-start: 64px; }
}
