/* ============================================================
   DAB — Feuille de style commune (thème clair Citeos)
   ============================================================ */

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

:root {
    /* Palette */
    --primary:        #9c0a4b;
    --primary-hover:  #ee7f01;
    --primary-light:  #eff6ff;
    --danger:         #dc2626;
    --danger-hover:   #b91c1c;
    --danger-light:   #fef2f2;
    --warning:        #d97706;
    --warning-light:  #fffbeb;
    --success:        #16a34a;
    --success-light:  #f0fdf4;

    /* Layout */
    --sidebar-w:  240px;
    --topbar-h:   52px;
    --bg:         #f1f5f9;
    --surface:    #ffffff;
    --border:     #e2e8f0;
    --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);

    /* Typographie */
    --text:    #1e293b;
    --muted:   #64748b;
    --radius:  8px;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════ */

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform .25s ease;
}

/* ── Brand ── */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    text-decoration: none;
}
.sidebar-brand img {
    height: 28px;
    width: auto;
    flex-shrink: 0;
}
.sidebar-brand-name {
    font-size: .9rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -.01em;
    line-height: 1.2;
}
.sidebar-brand-name span {
    display: block;
    font-size: .65rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: .05em;
    text-transform: uppercase;
}

/* ── Navigation ── */
.sidebar-nav {
    flex: 1;
    padding: .6rem 0;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem 1.25rem;
    color: var(--muted);
    text-decoration: none;
    font-size: .845rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background .12s, color .12s, border-color .12s;
    cursor: pointer;
    user-select: none;
}
.nav-link:hover        { background: var(--bg); color: var(--text); }
.nav-link.active       { background: var(--primary-light); color: var(--primary);
                         border-left-color: var(--primary); font-weight: 600; }
.nav-link.group-active { color: var(--text); font-weight: 600; }

.nav-icon    { flex-shrink: 0; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; line-height: 0; }
.nav-icon svg { display: block; }
.nav-label   { flex: 1; }
.nav-chevron { font-size: .7rem; color: var(--muted); transition: transform .2s; }
.nav-chevron.open { transform: rotate(90deg); }

/* Sous-menu */
.nav-sub {
    display: none;
    background: var(--bg);
    border-left: 2px solid var(--border);
    margin: 0 0 .15rem 2.6rem;
    border-radius: 0 0 4px 4px;
}
.nav-sub.open { display: block; }

.nav-sub-link {
    display: block;
    padding: .42rem .9rem;
    font-size: .8rem;
    color: var(--muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: color .12s, border-color .12s, background .12s;
}
.nav-sub-link:hover  { color: var(--text); background: rgba(0,0,0,.03); }
.nav-sub-link.active { color: var(--primary); font-weight: 600;
                       border-left-color: var(--primary); }

/* ── Footer sidebar ── */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: .9rem 1.25rem;
    flex-shrink: 0;
}
.sidebar-user { margin-bottom: .75rem; }
.sidebar-user strong { display: block; font-size: .83rem; color: var(--text); }
.sidebar-user small  { font-size: .73rem; color: var(--muted); }

/* ── Overlay mobile ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.4);
    z-index: 190;
}
.sidebar-overlay.visible { display: block; }

/* ═══════════════════════════════════════════════════════════
   TOPBAR MOBILE
   ═══════════════════════════════════════════════════════════ */
.topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 1rem;
    gap: .75rem;
    z-index: 180;
    box-shadow: var(--shadow);
}
.topbar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--text);
    padding: .3rem;
    line-height: 1;
}
.topbar img { height: 26px; width: auto; }
.topbar-title {
    font-size: .9rem;
    font-weight: 700;
    color: var(--primary);
}

/* ═══════════════════════════════════════════════════════════
   PAGE WRAPPER
   ═══════════════════════════════════════════════════════════ */
.page-wrapper {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}
.container {
    width: 100%;
    padding: 2rem 1.75rem;
}

/* ── Page header ── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.page-title    { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: .8rem; color: var(--muted); margin-top: .15rem; }

/* ═══════════════════════════════════════════════════════════
   CARDS & STATS
   ═══════════════════════════════════════════════════════════ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.card-title {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: .4rem;
}
.card-body { padding: 1.25rem; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: .3rem;
}
.stat-label { font-size: .72rem; color: var(--muted); font-weight: 500;
              text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-value.green { color: var(--success); }
.stat-value.red   { color: var(--danger); }
.stat-value.blue  { color: var(--primary); }
.stat-value.muted { color: var(--muted); }

/* ═══════════════════════════════════════════════════════════
   TABLEAU
   ═══════════════════════════════════════════════════════════ */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead tr { background: var(--bg); }
th {
    padding: .7rem 1rem;
    text-align: left;
    font-size: .68rem;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}
td { padding: .75rem 1rem; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: #fafbfc; }

/* ═══════════════════════════════════════════════════════════
   STATUTS & BADGES
   ═══════════════════════════════════════════════════════════ */
.status-dot { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.libre    { background: var(--success); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.dot.bouchon  { background: var(--danger);  box-shadow: 0 0 0 3px rgba(220,38,38,.15); }
.dot.inactive { background: #cbd5e1; }

.libre-text   { color: var(--success); }
.bouchon-text { color: var(--danger); }

/* Animation pulse pour bouchon actif */
.dot.bouchon.pulse {
    animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 3px rgba(220,38,38,.15); }
    50%      { box-shadow: 0 0 0 6px rgba(220,38,38,.3); }
}

.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 5px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #dc2626; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-gray   { background: #f1f5f9; color: #64748b; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.role-admin    { background: #dbeafe; color: #1d4ed8; }
.role-operator { background: #d1fae5; color: #065f46; }
.role-viewer   { background: #f3f4f6; color: #374151; }

/* ═══════════════════════════════════════════════════════════
   BOUTONS
   ═══════════════════════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: 6px;
    font-size: .84rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background .15s, box-shadow .15s;
    white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-hover); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: var(--danger-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-sm   { padding: .3rem .65rem; font-size: .78rem; }
.btn-icon { padding: .35rem .45rem; }

/* ═══════════════════════════════════════════════════════════
   FORMULAIRES
   ═══════════════════════════════════════════════════════════ */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 640px;
}
.form-header {
    padding: 1.1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.form-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.1rem; }
.form-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: .75rem;
    justify-content: flex-end;
}
.form-row     { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group   { display: flex; flex-direction: column; gap: .35rem; }
.form-label   { font-size: .8rem; font-weight: 600; color: var(--text); }
.form-label .req { color: var(--danger); margin-left: .15rem; }
.form-control {
    padding: .55rem .75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .875rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(156,10,75,.1);
}
.form-control.error { border-color: var(--danger); }
.form-hint  { font-size: .73rem; color: var(--muted); }
.form-check { display: flex; align-items: center; gap: .5rem; cursor: pointer; }
.form-check input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }

/* ═══════════════════════════════════════════════════════════
   ALERTES
   ═══════════════════════════════════════════════════════════ */
.alert {
    padding: .75rem 1rem;
    border-radius: 6px;
    font-size: .84rem;
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    margin-bottom: 1rem;
}
.alert-error   { background: var(--danger-light);  color: #991b1b; border: 1px solid rgba(220,38,38,.2); }
.alert-success { background: var(--success-light); color: #14532d; border: 1px solid rgba(22,163,74,.2); }
.alert-warning { background: var(--warning-light); color: #78350f; border: 1px solid rgba(217,119,6,.2); }
.alert-info    { background: var(--primary-light); color: #1e3a8a; border: 1px solid rgba(29,78,216,.2); }

/* ═══════════════════════════════════════════════════════════
   PAGE LOGIN
   ═══════════════════════════════════════════════════════════ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    padding: 1.5rem;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
}
.login-header {
    padding: 2rem 2rem 1.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
}
.login-header img  { height: 42px; width: auto; margin-bottom: .75rem; }
.login-logo        { font-size: 1.35rem; font-weight: 700; color: var(--primary); }
.login-logo span   { color: var(--text); font-weight: 400; }
.login-subtitle    { font-size: .78rem; color: var(--muted); margin-top: .3rem; }
.login-body        { padding: 1.75rem 2rem; display: flex; flex-direction: column; gap: 1.1rem; }
.login-footer      { padding: 1rem 2rem; border-top: 1px solid var(--border); text-align: center; }
.login-footer small { font-size: .72rem; color: var(--muted); }

/* ═══════════════════════════════════════════════════════════
   DAB — SPECIFIQUE
   ═══════════════════════════════════════════════════════════ */
.vehicle-count { font-size: 1.1rem; font-weight: 700; }
.modbus-addr   { font-family: monospace; font-size: .78rem; color: var(--muted); }
.device-id     { font-family: monospace; font-size: .78rem; color: var(--muted); }

/* Pagination */
.pagination {
    display: flex;
    gap: .35rem;
    align-items: center;
    justify-content: center;
    margin-top: 1.25rem;
}
.pagination a, .pagination span {
    padding: .35rem .7rem;
    border-radius: 5px;
    font-size: .8rem;
    text-decoration: none;
    border: 1px solid var(--border);
    color: var(--text);
    background: var(--surface);
}
.pagination a:hover { background: var(--bg); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled { opacity: .4; cursor: default; }

/* Filtres inline */
.filters {
    display: flex;
    gap: .75rem;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.filters .form-group { min-width: 150px; }
.filters .form-control { font-size: .82rem; padding: .45rem .65rem; }

/* ═══════════════════════════════════════════════════════════
   MODALES (dialog)
   ═══════════════════════════════════════════════════════════ */
dialog {
    border: none;
    border-radius: var(--radius);
    padding: 0;
    max-width: 500px;
    width: 90%;
    margin: auto;
    box-shadow: var(--shadow-md);
    background: var(--surface);
}
dialog::backdrop {
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(2px);
}
dialog[open] {
    animation: dialog-in .2s ease-out;
}
@keyframes dialog-in {
    from { opacity: 0; transform: scale(.95) translateY(-10px); }
    to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* Modale de confirmation (suppression, etc.) */
.confirm-dialog {
    max-width: 420px;
    text-align: center;
}
.confirm-dialog .confirm-body {
    padding: 2rem 1.5rem 1rem;
}
.confirm-dialog .confirm-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: .75rem;
}
.confirm-dialog .confirm-icon.danger {
    background: var(--danger-light);
    color: var(--danger);
}
.confirm-dialog .confirm-icon svg {
    width: 24px;
    height: 24px;
}
.confirm-dialog .confirm-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: .4rem;
}
.confirm-dialog .confirm-message {
    font-size: .84rem;
    color: var(--muted);
    line-height: 1.5;
}
.confirm-dialog .confirm-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: .75rem;
    justify-content: center;
}

/* ═══════════════════════════════════════════════════════════
   DIVERS
   ═══════════════════════════════════════════════════════════ */
.text-muted    { color: var(--muted); }
.text-right    { text-align: right; }
.section-title {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: .75rem;
}
.actions-cell { display: flex; gap: .4rem; align-items: center; }
.mt-1 { margin-top: .5rem; }
.mb-1 { margin-bottom: .5rem; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-md);
    }
    .sidebar.open { transform: translateX(0); }

    .topbar { display: flex; }

    .page-wrapper {
        margin-left: 0;
        padding-top: var(--topbar-h);
    }

    .form-row         { grid-template-columns: 1fr; }
    .stats-grid       { grid-template-columns: repeat(2, 1fr); }
    .container        { padding: 1.25rem 1rem; }
    .page-header      { flex-direction: column; align-items: flex-start; }
    .filters          { flex-direction: column; }

    table     { font-size: .8rem; }
    th, td    { padding: .6rem .75rem; }
    .form-card { max-width: 100%; }
}

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