/* ============================================================
   SAGT / Trafixys — Feuille de style
   Palette : bleu Trafixys #2E86C1 · vert accent #7CB342
   ============================================================ */

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

:root {
    --primary:        #2E86C1;
    --primary-hover:  #2471A3;
    --primary-light:  #EBF5FB;
    --accent:         #7CB342;
    --accent-hover:   #689F38;
    --danger:         #dc2626;
    --danger-hover:   #b91c1c;
    --danger-light:   #fef2f2;
    --warning:        #d97706;
    --warning-light:  #fffbeb;
    --success:        #16a34a;
    --success-light:  #f0fdf4;

    --sidebar-w:  250px;
    --topbar-h:   56px;
    --bg:         #f0f4f8;
    --surface:    #ffffff;
    --border:     #dce3eb;
    --shadow:     0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);

    --text:    #1a2332;
    --muted:   #5a6a7e;
    --radius:  10px;
}

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

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

/* ═══════════════════════════════════════════════════════════
   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;
}

.sidebar-brand {
    display: flex; align-items: center; justify-content: center;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0; text-decoration: none;
}
.sidebar-brand-logo {
    max-width: 180px;
    width: 100%;
    height: auto;
}

.sidebar-nav { flex: 1; padding: .5rem 0; overflow-y: auto; }

.nav-section-label {
    font-size: .6rem; font-weight: 700; letter-spacing: .12em;
    text-transform: uppercase; color: var(--muted);
    padding: 1rem 1.25rem .35rem; user-select: none;
}

.nav-link {
    display: flex; align-items: center; gap: .65rem;
    padding: .6rem 1.25rem; color: var(--muted);
    text-decoration: none; font-size: .84rem; font-weight: 500;
    border-left: 3px solid transparent;
    transition: all .15s ease;
    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: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.nav-icon svg { display: block; width: 18px; height: 18px; }
.nav-label   { flex: 1; }
.nav-chevron { font-size: .75rem; color: var(--muted); transition: transform .2s; }
.nav-chevron.open { transform: rotate(90deg); }

.nav-sub {
    display: none; background: var(--bg);
    border-left: 2px solid var(--border);
    margin: 0 0 .2rem 2.8rem; border-radius: 0 0 6px 6px;
}
.nav-sub.open { display: block; }

.nav-sub-link {
    display: block; padding: .45rem 1rem; font-size: .8rem;
    color: var(--muted); text-decoration: none;
    border-left: 2px solid transparent;
    transition: all .12s ease;
}
.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); }

.nav-sep { height: 1px; background: var(--border); margin: .6rem 1.25rem; }

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

.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(15,23,42,.45); z-index: 190;
    backdrop-filter: blur(2px);
}
.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 1.25rem; gap: .75rem;
    z-index: 180; box-shadow: var(--shadow);
}
.topbar-toggle {
    background: none; border: none; cursor: pointer;
    font-size: 1.4rem; color: var(--text); padding: .25rem; line-height: 1;
}

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

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.75rem; flex-wrap: wrap; gap: 1rem;
}
.page-title    { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: .82rem; color: var(--muted); margin-top: .15rem; }

/* ═══════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════ */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.5rem;
}
.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: .88rem; font-weight: 600; color: var(--text);
    display: flex; align-items: center; gap: .45rem;
}
.card-body { padding: 1.25rem; }

/* ── Stats ── */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem; margin-bottom: 2rem;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem 1.25rem; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: .35rem;
    transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-label {
    font-size: .7rem; color: var(--muted); font-weight: 600;
    text-transform: uppercase; letter-spacing: .06em;
}
.stat-value { font-size: 2.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.amber { color: var(--warning); }
.stat-value.muted { color: var(--muted); }

/* ── Carrefour card ── */
.carrefour-card { border-left: 4px solid var(--primary); }
.carrefour-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 1rem;
}
.info-block { display: flex; flex-direction: column; }
.info-label {
    font-size: .65rem; color: var(--muted); text-transform: uppercase;
    letter-spacing: .06em; font-weight: 600; margin-bottom: .2rem;
}
.info-value { font-size: .95rem; font-weight: 600; }

/* ═══════════════════════════════════════════════════════════
   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: .75rem 1rem; text-align: left; font-size: .67rem;
    letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted); font-weight: 600; white-space: nowrap;
}
td { padding: .8rem 1rem; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: #f7f9fb; }
.row-error td { background: var(--danger-light); }

/* ═══════════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════════ */
.badge {
    display: inline-block; padding: .2rem .6rem; border-radius: 6px;
    font-size: .72rem; font-weight: 600; white-space: nowrap;
}
.badge-blue   { background: #DCEEFB; color: #1A5276; }
.badge-green  { background: #D5F5E3; color: #186A3B; }
.badge-red    { background: #FADBD8; color: #922B21; }
.badge-amber  { background: #FEF9E7; color: #7D6608; }
.badge-gray   { background: #EAECEE; color: #5D6D7E; }
.badge-purple { background: #E8DAEF; color: #6C3483; }

.role-admin    { background: #DCEEFB; color: #1A5276; }
.role-operator { background: #D5F5E3; color: #186A3B; }
.role-viewer   { background: #EAECEE; color: #5D6D7E; }

.status-dot { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; font-size: .84rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.online  { background: var(--success); box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.dot.alert   { background: var(--warning); box-shadow: 0 0 0 3px rgba(217,119,6,.18); }
.dot.offline { background: var(--danger);  box-shadow: 0 0 0 3px rgba(220,38,38,.18); }

/* ═══════════════════════════════════════════════════════════
   BOUTONS
   ═══════════════════════════════════════════════════════════ */
.btn {
    display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1.1rem;
    border-radius: 8px; font-size: .84rem; font-weight: 500; cursor: pointer;
    text-decoration: none; border: 1px solid transparent;
    transition: all .15s ease; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-hover); box-shadow: var(--shadow); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: var(--danger-hover); }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover  { background: #b45309; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover  { background: #15803d; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-sm   { padding: .32rem .7rem; font-size: .78rem; border-radius: 6px; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ═══════════════════════════════════════════════════════════
   FORMULAIRES
   ═══════════════════════════════════════════════════════════ */
.form-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); max-width: 800px;
}
.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-section { margin-bottom: 1.5rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.form-section h2 { font-size: .95rem; font-weight: 600; margin-bottom: .75rem; color: var(--primary); }
.form-section h3 { font-size: .85rem; font-weight: 600; margin-bottom: .75rem; }
.form-row     { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3   { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-group   { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .85rem; }
.form-label   { font-size: .8rem; font-weight: 600; color: var(--text); }
.form-label .req { color: var(--danger); margin-left: .15rem; }
.form-control, input[type="text"], input[type="number"], input[type="password"],
input[type="email"], select, textarea {
    padding: .6rem .85rem; border: 1px solid var(--border); border-radius: 8px;
    font-size: .875rem; color: var(--text); background: var(--surface);
    transition: border-color .15s, box-shadow .15s; width: 100%;
    font-family: inherit;
}
.form-control:focus, input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(46,134,193,.12);
}
.form-hint  { font-size: .73rem; color: var(--muted); }
.form-actions { margin-top: 1.25rem; display: flex; gap: .75rem; }

/* ═══════════════════════════════════════════════════════════
   ALERTES
   ═══════════════════════════════════════════════════════════ */
.alert {
    padding: .85rem 1.15rem; border-radius: 8px; font-size: .84rem;
    display: flex; align-items: flex-start; gap: .6rem; margin-bottom: 1.25rem;
}
.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: #1A5276; border: 1px solid rgba(46,134,193,.2); }

/* ═══════════════════════════════════════════════════════════
   PAGE LOGIN
   ═══════════════════════════════════════════════════════════ */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #2E86C1 0%, #1A5276 50%, #0E3856 100%);
    padding: 1.5rem;
}
.login-card {
    background: var(--surface); border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2); width: 100%; max-width: 420px;
}
.login-header {
    padding: 2.5rem 2rem 1.5rem; text-align: center;
    border-bottom: 1px solid var(--border);
}
.login-header img { max-width: 200px; height: auto; margin-bottom: .5rem; }
.login-logo { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.login-logo span { color: var(--text); font-weight: 400; }
.login-subtitle { font-size: .8rem; color: var(--muted); margin-top: .4rem; }
.login-body { padding: 2rem 2rem; display: flex; flex-direction: column; gap: 1.1rem; }
.login-footer {
    padding: 1rem 2rem; border-top: 1px solid var(--border);
    text-align: center; background: var(--bg); border-radius: 0 0 16px 16px;
}
.login-footer small { font-size: .72rem; color: var(--muted); }

/* ═══════════════════════════════════════════════════════════
   DIVERS
   ═══════════════════════════════════════════════════════════ */
.filter-bar { display: flex; gap: .75rem; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; }
.filter-bar select, .filter-bar input { max-width: 280px; }
.pagination { display: flex; gap: .5rem; justify-content: center; margin-top: 1.5rem; }
.inline-form { display: inline-flex; gap: .5rem; align-items: center; }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }
code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    font-size: .82rem; background: var(--bg); padding: .15rem .45rem; border-radius: 5px;
    border: 1px solid var(--border);
}
.monospace { font-family: 'SFMono-Regular', Consolas, monospace; font-size: .82rem; }
.daemon-status { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }

/* ── Carte ── */
#map-full { height: calc(100vh - 130px); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); }
#map-picker { height: 320px; border-radius: var(--radius); border: 1px solid var(--border); margin-top: .75rem; box-shadow: var(--shadow); }
.leaflet-container { font-family: inherit; }
.leaflet-popup-content { min-width: 200px; font-size: .85rem; }

/* ═══════════════════════════════════════════════════════════
   LIGNES DE FEUX
   ═══════════════════════════════════════════════════════════ */
.feux-section { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.feux-title { font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: .75rem; display: flex; align-items: center; gap: .5rem; }
.feux-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.feu-item {
    display: flex; align-items: center; gap: .6rem;
    padding: .5rem .65rem; background: var(--bg); border-radius: 8px;
    border: 1px solid var(--border); transition: box-shadow .15s;
}
.feu-item:hover { box-shadow: var(--shadow); }
.feu-pastille {
    width: 22px; height: 22px; border-radius: 50%;
    flex-shrink: 0; border: 2px solid rgba(0,0,0,.15);
}
.feu-off         { background: #4a5568; }
.feu-red         { background: #dc2626; box-shadow: 0 0 8px rgba(220,38,38,.5); }
.feu-red-blink   { background: #dc2626; animation: feu-blink 1s infinite; }
.feu-amber       { background: #d97706; box-shadow: 0 0 8px rgba(217,119,6,.5); }
.feu-amber-blink { background: #d97706; animation: feu-blink 1s infinite; }
.feu-green       { background: #16a34a; box-shadow: 0 0 8px rgba(22,163,74,.5); }
.feu-green-blink { background: #16a34a; animation: feu-blink 1s infinite; }
.feu-red-amber   { background: linear-gradient(135deg, #dc2626 50%, #d97706 50%); }
.feu-none        { background: #e5e7eb; border-style: dashed; }
.feu-unknown     { background: #9ca3af; }
@keyframes feu-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: .2; }
}
.feu-info { display: flex; flex-direction: column; min-width: 0; }
.feu-num { font-size: .75rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feu-label { font-size: .65rem; color: var(--muted); }

/* ═══════════════════════════════════════════════════════════
   REFRESH INDICATOR & ANIMATIONS
   ═══════════════════════════════════════════════════════════ */
.refresh-indicator {
    display: flex; align-items: center; gap: .5rem;
    font-size: .78rem; color: var(--muted); font-weight: 500;
}
.pulse-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--success); display: inline-block;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(22,163,74,.4); }
    50% { opacity: .7; box-shadow: 0 0 0 6px rgba(22,163,74,0); }
}
.stat-flash {
    animation: flash .4s ease;
}
@keyframes flash {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}
.dashboard-grid {
    display: grid; grid-template-columns: 1fr; gap: 1.25rem;
    margin-bottom: 1.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, .form-row-3 { 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; }
    table { font-size: .8rem; }
    th, td { padding: .6rem .75rem; }
    .form-card { max-width: 100%; }
    .carrefour-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .carrefour-grid { grid-template-columns: 1fr; }
    .login-card { border-radius: 12px; }
    .login-header { padding: 1.75rem 1.25rem 1.25rem; }
    .login-body { padding: 1.5rem 1.25rem; }
}
