:root {
    --sidebar-width: 240px;
    --sidebar-bg: #1e2a38;
    --sidebar-text: #c9d3df;
    --sidebar-hover: #2d3e52;
    --sidebar-active: #0d6efd;
    --topbar-height: 56px;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 1030;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.1rem 1.2rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
    text-decoration: none;
}

#sidebar .sidebar-brand .brand-icon {
    font-size: 1.4rem;
}

/* Zones sidebar : Navigation (figée) / Subnets (scroll) / Administration + footer (figées) */
#sidebar .sidebar-nav {
    flex: 0 0 auto;
    padding-top: .25rem;
}
#sidebar .sidebar-subnets {
    flex: 1 1 auto;
    min-height: 0;                 /* indispensable pour que .subnet-list scrolle */
    display: flex;
    flex-direction: column;
}
#sidebar .subnet-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}
#sidebar .sidebar-admin {
    flex: 0 0 auto;
    border-top: 1px solid rgba(255,255,255,.08);
    padding-bottom: .25rem;
}

/* Champ de filtre des subnets */
#sidebar .subnet-filter {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin: .1rem .6rem .35rem;
    padding: .3rem .55rem;
    background: rgba(255,255,255,.06);
    border-radius: 6px;
    color: var(--sidebar-text);
}
#sidebar .subnet-filter i { opacity: .6; font-size: .85rem; }
#sidebar .subnet-filter input {
    flex: 1 1 auto;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    font-size: .85rem;
    min-width: 0;
}
#sidebar .subnet-filter input::placeholder { color: #7d90ad; }
#sidebar .subnet-filter button {
    background: none;
    border: none;
    color: #7d90ad;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 .2rem;
}
#sidebar .subnet-filter button:hover { color: #fff; }

#sidebar .nav-section {
    padding: .75rem 1rem .25rem;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: #5d7494;
}

#sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem 1.2rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 6px;
    margin: 1px .5rem;
    font-size: .9rem;
    transition: background .15s, color .15s;
}

#sidebar .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

#sidebar .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
}

#sidebar .nav-link .nav-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    opacity: .8;
}

#sidebar .sidebar-footer {
    margin-top: auto;
    padding: .75rem 1.2rem;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .82rem;
    color: #5d7494;
}

#sidebar .sidebar-footer a {
    color: var(--sidebar-text);
    text-decoration: none;
}

#sidebar .sidebar-footer a:hover {
    color: #fff;
}

/* ── Main content ── */
#main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar .page-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1e2a38;
    flex: 1;
}

.topbar .user-info {
    font-size: .85rem;
    color: #6c757d;
}

.page-content {
    padding: 1.75rem;
    flex: 1;
}

/* ── Cards & tables ── */
.card {
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    border-radius: 10px;
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #f0f2f5;
    border-radius: 10px 10px 0 0 !important;
    font-weight: 600;
}

.table-hover tbody tr:hover td {
    background: #f8f9ff;
}

.mac-address {
    font-family: 'Courier New', monospace;
    font-size: .85rem;
    letter-spacing: .03em;
    color: #495057;
}

.ip-address {
    font-family: 'Courier New', monospace;
    font-size: .9rem;
    font-weight: 500;
    color: #0d6efd;
}

/* ── Login page ── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e2a38 0%, #2d4a6e 100%);
}

.login-card {
    width: 380px;
    border: none;
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,.3);
}

.login-logo {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: .5rem;
}

/* ── Stats cards ── */
.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card .stat-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1;
    color: #1e2a38;
}

.stat-card .stat-label {
    font-size: .8rem;
    color: #6c757d;
    margin-top: .15rem;
}

/* ── Badges & status ── */
.sync-ok    { color: #198754; }
.sync-error { color: #dc3545; }

/* ── Responsive (minimal) ── */
@media (max-width: 768px) {
    #sidebar       { transform: translateX(-100%); }
    #main-content  { margin-left: 0; }
}

/* ── Groupes de réservations (vue subnet) ── */
.group-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: #e2e8f0;
    color: #1e293b;
    border-top: 1px solid #cbd5e1;
    border-bottom: 1px solid #cbd5e1;
    padding: .5rem .9rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}
.group-header:hover { background: #dbe3ec; }
.group-header .group-caret { width: 1em; opacity: .7; }
.group-header.group-header-none { color: #64748b; font-style: italic; }
.group-header .group-count {
    margin-left: .3rem;
    background: #475569;
    color: #fff;
    font-size: .72rem;
    font-weight: 600;
    font-style: normal;
    padding: .05rem .5rem;
    border-radius: 999px;
}
.group-header.group-header-none .group-count { background: #94a3b8; }

/* Tables de réservations (subnet.php) : layout fixe pour aligner les colonnes
   entre tous les groupes en mode groupé (chaque groupe a sa propre <table>). */
.res-table { table-layout: fixed; width: 100%; }
/* Hostname / Description : texte long cassé proprement au lieu de déborder */
.res-table td { word-break: break-word; }
/* Colonnes à contenu de longueur fixe (IP, MAC, date) : jamais sur 2 lignes,
   tronquées avec … si la largeur ne suffit pas. */
.res-table th, .res-table .nowrap-col { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Colonne d'actions (dernière) : boutons sur une seule ligne, jamais coupés */
.res-table td.text-end { white-space: nowrap; overflow: visible; }

/* Lignes d'en-tête de groupe dans un tableau (leases.php) */
tr.lease-group-row > td { padding: 0; border: 0; }
tr.lease-group-row .group-header { border-top: 0; }
/* Sous-en-tête (niveau 2 : groupe de réservation à l'intérieur d'un subnet) */
.group-header.group-subheader {
    background: #eef2f7;
    color: #334155;
    font-weight: 500;
    padding-left: 2.2rem;
    font-size: .85rem;
}
.group-header.group-subheader:hover { background: #e4eaf2; }
.group-header.group-subheader .group-count {
    background: #64748b;
    font-size: .68rem;
}
@media (prefers-color-scheme: dark) {
    .group-header.group-subheader { background: #232f3e; color: #cbd5e1; }
    .group-header.group-subheader:hover { background: #2b394b; }
}

.group-badge {
    display: inline-block;
    background: #e2e8f0;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    font-size: .8rem;
    font-weight: 500;
    padding: .1rem .55rem;
    border-radius: 4px;
}

/* Thème sombre : inversion des tons */
@media (prefers-color-scheme: dark) {
    .group-header {
        background: #2d3e52;
        color: #e2e8f0;
        border-color: #3d5169;
    }
    .group-header:hover { background: #354a63; }
    .group-header.group-header-none { color: #94a3b8; }
    .group-badge {
        background: #2d3e52;
        color: #e2e8f0;
        border-color: #3d5169;
    }
}

/* Bouton reset du filtre des réservations */
.reservation-filter { position: relative; }
.reservation-filter .res-filter-clear {
    position: absolute;
    right: .4rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 .2rem;
}
.reservation-filter .res-filter-clear:hover { color: #475569; }

/* Barre d'action de sélection multiple (bas de liste) */
.selection-bar {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem .9rem;
    border-top: 2px solid #b6c2e2;
    background: #e7ecfb;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, .12);
    position: sticky;
    bottom: 0;
    z-index: 5;
}
.selection-bar #selection-count { font-weight: 600; margin-right: auto; color: #1e293b; }
@media (prefers-color-scheme: dark) {
    .selection-bar {
        background: #33455c;
        border-top-color: #4a6489;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, .35);
    }
    .selection-bar #selection-count { color: #e2e8f0; }
}

/* ── Bargraph de remplissage de subnet ── */
:root {
    --sbg-reservation: #4f7cc4;
    --sbg-dynamic:     #d99a2b;
    --sbg-short:       #a855c0;
    --sbg-hole-a:      #c3ccd6;
    --sbg-hole-b:      #d7dde3;
    --sbg-border:      #cdd5df;
    --sbg-reserved:    #64748b;
    --sbg-pending-a:   #93c5fd;
    --sbg-pending-b:   #bfdbfe;
}
.sbg-wrap { margin-top: .5rem; }
.sbg-rate { font-size: .8rem; color: #64748b; margin-bottom: .25rem; }
.sbg-bar {
    position: relative;
    height: 30px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--sbg-border);
    background: repeating-linear-gradient(45deg,
        var(--sbg-hole-a), var(--sbg-hole-a) 5px,
        var(--sbg-hole-b) 5px, var(--sbg-hole-b) 10px);
}
.sbg-seg {
    position: absolute; top: 0; bottom: 0;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
    cursor: default;
}
.sbg-seg.sbg-reservation { background: var(--sbg-reservation); cursor: pointer; }
.sbg-seg.sbg-dynamic     { background: var(--sbg-dynamic); }
.sbg-seg.sbg-short-pool  { background: var(--sbg-short); }
.sbg-seg.sbg-reserved    { background: var(--sbg-reserved); }
.sbg-seg.sbg-pending     { background: repeating-linear-gradient(45deg,
    var(--sbg-pending-a), var(--sbg-pending-a) 6px,
    var(--sbg-pending-b) 6px, var(--sbg-pending-b) 12px); cursor: pointer; }
.sbg-seg.sbg-hole        { background: transparent; cursor: pointer; }
.sbg-seg:hover           { filter: brightness(1.08); outline: 2px solid rgba(0,0,0,.25); outline-offset: -2px; z-index: 2; }
/* Infobulle maison */
.sbg-tip {
    position: fixed; z-index: 3000; pointer-events: none;
    max-width: 280px; padding: 8px 11px;
    background: #fff; border: 1px solid var(--sbg-border); border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,.14);
    font-size: 12.5px; color: #334; display: none;
}
.sbg-tip.show { display: block; }
.sbg-tip .sbg-tip-title { font-weight: 700; margin-bottom: 3px; }
.sbg-tip .sbg-tip-row { display: flex; justify-content: space-between; gap: 12px; color: #556; }
.sbg-tip .sbg-tip-row b { color: #223; font-weight: 600; }
.sbg-tip .sbg-grp { display: inline-block; background: #eef2f7; border-radius: 20px;
    padding: 1px 8px; margin: 3px 4px 0 0; font-size: 11px; color: #334; }

@media (prefers-color-scheme: dark) {
    :root {
        --sbg-hole-a: #2a2f36;
        --sbg-hole-b: #232830;
        --sbg-border: #3a424d;
    }
    .sbg-rate { color: #94a3b8; }
    .sbg-tip { background: #1c2128; color: #c9d3df; }
    .sbg-tip .sbg-tip-row { color: #9aa7b4; }
    .sbg-tip .sbg-tip-row b { color: #e6edf3; }
    .sbg-tip .sbg-grp { background: #2a2f36; color: #c9d3df; }
    .sbg-seg:hover { outline-color: rgba(255,255,255,.35); }
}

/* ── Éditeur IP réservées (gouttière d'erreurs) ── */
.rip-editor { display:flex; border:1px solid var(--bs-border-color,#ced4da); border-radius:.375rem; overflow:hidden; background:var(--bs-body-bg,#fff); }
.rip-editor.rip-invalid { border-color:#dc3545; }
.rip-gutter { flex:0 0 28px; background:#f1f4f8; border-right:1px solid #dde3ea; overflow:hidden; position:relative; }
.rip-gutter-inner { position:absolute; top:0; left:0; right:0; padding-top:.375rem; }
.rip-gutter .rip-g-line { display:flex; align-items:center; justify-content:center; color:#dc3545; font-weight:700; cursor:help; }
.rip-ta { flex:1 1 auto; border:0; outline:0; resize:vertical; padding:.375rem .5rem; margin:0;
    font-family:'Courier New',monospace; font-size:13px; line-height:1.5; min-height:110px; background:transparent; color:#212529; }
.rip-status { font-size:12.5px; font-weight:600; margin-top:.35rem; }
.rip-status.ok { color:#0f7b34; } .rip-status.ko { color:#b02a37; }
.rip-tip { position:fixed; z-index:3000; pointer-events:none; background:#dc3545; color:#fff;
    font-size:12px; padding:5px 9px; border-radius:6px; box-shadow:0 4px 14px rgba(0,0,0,.2); display:none; max-width:260px; }

/* Rotation de l'icône Actualiser pendant le re-fetch AJAX (page Leases) */
@keyframes sbg-spin { to { transform: rotate(360deg); } }
.spin { display:inline-block; animation: sbg-spin .7s linear infinite; }

/* Flash des cartes de stats à l'actualisation manuelle (confirme le clic même sans changement) */
@keyframes stats-flash-kf {
    0%   { box-shadow: 0 0 0 2px #0d6efd, 0 0 12px rgba(13,110,253,.5); }
    100% { box-shadow: 0 0 0 0 transparent; }
}
.stats-flash .card { animation: stats-flash-kf 1s ease-out; }
