/* ============================================================
   SETTINGS PAGE — Bel-Up Harmonized
   ============================================================ */

/* Variables spécifiques aux réglages utilisant les tokens globaux de style.css */
:root {
    --bg-input: rgba(0, 0, 0, 0.2);
    --border-hi: rgba(255, 255, 255, 0.15);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    --warning: #f59e0b;
    --purple: #a78bfa;
}

.light-mode {
    --bg-input: rgba(0, 0, 0, 0.05);
    --border-hi: rgba(0, 0, 0, 0.12);
}


/* ── TAB CONTENT ── */
.tab-content {
    padding: 2.5rem 2rem 7rem;
    max-width: 1400px;
    margin: 0 auto;
}

.tab-panel {
    display: none;
    /* Animation retirée pour un affichage instantané */
    will-change: transform, opacity;
}

.tab-panel.active {
    display: block;
}

/* ── SECTION ── */
.section {
    margin-bottom: 3rem;
    scroll-margin-top: 130px;
}

.section-head {
    display: flex;
    align-items: center;
    gap: .85rem;
    margin-bottom: 1.1rem;
}

.section-icon {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.section-head h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

.section-head p {
    font-size: .85rem;
    color: var(--text-secondary);
    margin-top: .15rem;
}

/* ── CARD ── */
.card {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 
        0 4px 24px -1px rgba(0, 0, 0, 0.2),
        inset 0 0 20px rgba(255, 255, 255, 0.02);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease, border-color 0.3s ease;
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 
        0 12px 40px -4px rgba(0, 0, 0, 0.4),
        inset 0 0 20px rgba(255, 255, 255, 0.04);
}

.light-mode .card {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 
        0 4px 20px rgba(0, 0, 0, 0.04);
}

.card-label {
    padding: 1.1rem 1.6rem;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.card-label svg {
    opacity: 0.9;
    color: var(--accent);
}

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    padding: 1.4rem 1.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.2s ease;
}

.light-mode .row {
    border-bottom-color: rgba(0, 0, 0, 0.04);
}

.row:last-child {
    border-bottom: none;
}

.row:hover {
    background: rgba(255, 255, 255, 0.02);
}

.light-mode .row:hover {
    background: rgba(0, 0, 0, 0.01);
}

.row-info {
    flex: 1;
    min-width: 0;
}

.row-label {
    font-size: .98rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: .55rem;
}

.row-desc {
    font-size: .83rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: .25rem;
    line-height: 1.45;
}

.row-ctrl {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: .7rem;
}

/* ── CHIPS ── */
.chip {
    font-size: .7rem;
    font-weight: 600;
    padding: .2rem .6rem;
    border-radius: 999px;
    letter-spacing: .02em;
}

.chip-warn {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}

.chip-info {
    background: rgba(99, 102, 241, 0.12);
    color: var(--accent);
}

.chip-ok {
    background: rgba(22, 163, 74, 0.12);
    color: #16a34a;
}

.chip-purple {
    background: rgba(147, 51, 234, 0.12);
    color: #9333ea;
}

/* ── SLIDER ── */
.sl-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .4rem;
    min-width: 210px;
}

.sl-top {
    display: flex;
    align-items: baseline;
    gap: .3rem;
}

.sl-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    font-weight: 600;
    min-width: 3.5rem;
    text-align: right;
}

.sl-unit {
    font-size: .8rem;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 200px;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-input);
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* ── NUMBER INPUT ── */
.num-wrap {
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition);
}

.num-wrap:focus-within {
    border-color: var(--accent);
}

.num-btn {
    width: 38px;
    height: 38px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.num-btn:hover {
    color: var(--text-primary);
    background: var(--border);
}

input[type="number"] {
    width: 85px;
    height: 38px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    outline: none;
}

/* ── TOGGLE ── */
.toggle {
    position: relative;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.toggle input {
    display: none;
}

.ttrack {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: var(--transition);
}

.ttrack::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: transform 0.25s cubic-bezier(.34, 1.56, .64, 1), background var(--transition);
}

.toggle input:checked+.ttrack {
    background: rgba(74, 222, 128, 0.15);
    border-color: var(--accent-mint);
}

.toggle input:checked+.ttrack::after {
    transform: translateX(22px);
    background: var(--accent-mint);
}

/* ── SELECT ── */
.sel {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: .92rem;
    font-weight: 500;
    padding: .55rem 2.2rem .55rem 1rem;
    appearance: none;
    cursor: pointer;
    outline: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    transition: border-color var(--transition);
}

.sel:focus {
    border-color: var(--accent-cyan);
}

/* ── MODE SELECTOR ── */
.mode-group {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.mode-btn {
    padding: .5rem 1.1rem;
    border-radius: var(--radius-md);
    font-size: .88rem;
    font-weight: 500;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.mode-btn:hover {
    border-color: var(--border-hi);
    color: var(--text-primary);
}

.mode-btn.sel-green {
    background: rgba(74, 222, 128, 0.1);
    border-color: var(--accent-mint);
    color: var(--accent-mint);
    font-weight: 600;
}

.mode-btn.sel-blue {
    background: rgba(56, 189, 248, 0.1);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    font-weight: 600;
}

/* ── IP DISPLAY ── */
.ip-display {
    display: flex;
    align-items: center;
    gap: .7rem;
}

.ip-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: .95rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: .55rem 1.2rem;
    min-width: 170px;
    text-align: center;
}

.ip-status {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ip-status.up {
    background: var(--accent-mint);
    box-shadow: 0 0 10px var(--accent-mint);
}

.ip-status.down {
    background: var(--text-secondary);
    opacity: 0.5;
}

/* ── SENSOR ROW ── */
.sensor-row {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    align-items: center;
    gap: 1.2rem;
    padding: 1rem 1.6rem;
    border-bottom: 1px solid var(--border);
}

.sensor-row:last-child {
    border-bottom: none;
}

.sensor-num {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: .85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* ── ANIMATIONS ── */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section {
    /* Animation retirée pour supprimer le délai d'apparition */
    will-change: transform, opacity;
}

.section:nth-child(1),
.section:nth-child(2),
.section:nth-child(3) {
    animation: none !important;
    animation-delay: 0s !important;
}

/* ── SAVED FLASH ── */
.saved-flash {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 300;
    background: rgba(74, 222, 128, 0.15);
    border: 1px solid var(--accent-mint);
    border-radius: 12px;
    padding: 0.6rem 1.2rem;
    font-size: .9rem;
    font-weight: 600;
    color: var(--accent-mint);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(10px);
}

.saved-flash.show {
    opacity: 1;
    transform: translateY(0);
}

/* SÉPARATEUR */
.sep {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.5rem 0;
}

/* PREINSTALL RESULTS */
.preinstall-result {
    display: flex;
    gap: 1.2rem;
    margin-top: 0.5rem;
    padding: 1.5rem 1.6rem;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.1);
}

.preinstall-result-item {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.meters-dashboard {
    display: none;
    /* Managed by JS/Classes */
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 0;
    padding: 0 1.6rem 2rem;
    width: 100%;
}

.meters-dashboard.show-flex {
    display: grid !important;
}

.meters-col {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.meters-col-title {
    font-size: 0.75rem;
    color: var(--text-cyan);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    margin: 1.5rem 0 0.75rem;
    padding-left: 0.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.9;
}

@media (max-width: 1000px) {
    .meters-dashboard {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
}

.preinstall-result-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ── METERS DASHBOARD (2 COLS) ── */
.meters-dashboard {
    display: none; /* Managed by JS/Classes */
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 0;
    padding: 0 1.6rem 2rem;
    width: 100%;
}

/* Specificity fix: Seul l'admin voit le dashboard des compteurs, même s'il est activé par JS */
body.role-admin .meters-dashboard.show-flex,
html.role-admin .meters-dashboard.show-flex {
    display: grid !important;
}

.meters-dashboard.show-flex {
    display: none; /* Cache par défaut si pas admin */
}

.meters-col {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.meters-col-title {
    font-size: 0.75rem;
    color: var(--text-cyan);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    margin: 1.5rem 0 0.75rem;
    padding-left: 0.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.9;
}

@media (max-width: 1000px) {
    .meters-dashboard {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
}

.preinstall-result-value {
    font-size: 2rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: #fff;
}

/* RESPONSIVE */
@media (max-width: 820px) {
    .tab-content {
        padding: 1.5rem 1.2rem 7rem;
    }

    .settings-tabs-inner {
        padding: 0.75rem 1rem;
    }

    .row {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .row-ctrl,
    .sl-wrap {
        width: 100%;
        align-items: flex-start;
    }

    input[type="range"] {
        width: 100%;
    }
}

/* ── ROLE VISIBILITY ── */
/* Both users and installers see the same simple page */
.admin-only {
    display: none !important;
}

.settings-tabs-bar {
    display: none !important;
}

.installer-only {
    display: none !important;
}

body.role-admin .installer-only {
    display: block !important;
}

/* Ensure hidden-row always wins, except when we want to show it as flex */
.row.hidden-row:not(.show-flex).installer-only {
    display: none !important;
}

/* ── PRE-RENDER STATE LOCKING ── */
/* Ces règles forcent l'affichage immédiat des lignes si l'état est détecté dans le head */
html.state-backup-on #rowSocBack,
html.state-dyness-on #rowDynTariff,
html.state-antideco-on #rowPvLimit,
html.state-breaker-on #rowBreakerCalibre {
    display: flex !important;
}

/* On s'assure que role-admin est aussi traité prioritairement par html si body n'est pas prêt */
html.role-admin .installer-only {
    display: block !important;
}

.meter-card::before {
    content: '└';
    position: absolute;
    left: 1.45rem;
    top: 1.5rem;
    color: var(--accent);
    font-size: 1.1rem;
    font-weight: 400;
    opacity: 0.8;
}

.meter-card {
    background: rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 18px;
    padding: 1.4rem 1.4rem 1.4rem 2.8rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2), 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.meter-card:hover {
    background: rgba(0, 0, 0, 0.22);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.3), 0 8px 25px rgba(0, 0, 0, 0.2);
}

.meter-name {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text-primary);
}

.light-mode .meter-card {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.03);
}

.light-mode .meter-card:hover {
    border-color: var(--accent);
}

.light-mode .meter-name {
    color: var(--text-primary);
}

.meter-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.meter-ip {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-cyan);
    opacity: 0.9;
}

.meter-badge {
    font-size: 0.65rem;
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 8px;
    border-radius: 4px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.meter-controls {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    align-items: flex-end;
    gap: 1.2rem;
}

.meter-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.meter-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.85;
}

@media (max-width: 600px) {
    .meter-controls {
        grid-template-columns: 1fr;
    }
    .meter-actions {
        justify-content: center;
        margin-top: 0.5rem;
    }
}

.meter-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    grid-column: 4;
}

.btn-meter-add,
.btn-meter-del {
    height: 35px;
    background: linear-gradient(135deg, var(--accent), #4f46e5);
    color: #fff;
    border: none;
    padding: 0 1.2rem;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-meter-add:hover,
.btn-meter-del:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.3);
}

.btn-meter-del {
    width: 38px;
    height: 38px;
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-meter-del:hover {
    background: #ef4444;
    color: #fff;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

.meter-field .sel {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    padding: 0.65rem 2.2rem 0.65rem 0.9rem;
    font-size: 0.88rem;
    border-radius: 10px;
    color: var(--text-primary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
}

.light-mode .meter-field .sel {
    background: var(--bg-input);
    border-color: rgba(0, 0, 0, 0.1);
    color: #1e293b;
}

.tab-content {
    padding-top: 1.5rem !important;
}

/* ── HIDDEN ELEMENTS ── */
.row.hidden-row {
    display: none !important;
}

/* ── PREMIUM NESTED ROWS ── */
.row.nested-row:not(.hidden-row) {
    background: rgba(0, 0, 0, 0.18);
    margin: 0;
    padding-left: 2.6rem;
    border-top: 1px solid rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    animation: slideNested .35s cubic-bezier(0.16, 1, 0.3, 1) both;
    position: relative;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
}

.row.nested-row:not(.hidden-row)::before {
    content: '└';
    position: absolute;
    left: 1.4rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent);
    font-size: 1.1rem;
    font-weight: 400;
    opacity: 0.8;
}

@keyframes slideNested {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.light-mode .row.nested-row:not(.hidden-row) {
    background: rgba(0, 0, 0, 0.04);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.03);
    border-top-color: rgba(0, 0, 0, 0.05);
    border-bottom-color: rgba(0, 0, 0, 0.05);
}