/* ==========================================================================
   CONSO — identité visuelle
   Une salle de contrôle domestique : cadrans, compteurs, chiffres qui
   comptent. Le cuivre pour le fioul, le cyan pour l'eau — partout, sans
   exception, pour qu'on sache toujours de quel circuit on parle.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root {
    --bg:            #14171c;
    --bg-panel:      #1b1f26;
    --bg-raised:     #212630;
    --bg-inset:      #101317;
    --border:        #2c323c;
    --border-soft:   #232833;

    --text:          #ece9e2;
    --text-dim:      #9aa1ac;
    --text-faint:    #666e7a;

    --fioul:         #e8963c;
    --fioul-soft:    #4a3623;
    --fioul-glow:    rgba(232, 150, 60, 0.18);

    --eau:           #33b7c6;
    --eau-soft:      #1f3c42;
    --eau-glow:      rgba(51, 183, 198, 0.18);

    --danger:        #e4573d;
    --danger-soft:   #402420;
    --success:       #6fcf97;

    --radius-s: 6px;
    --radius-m: 10px;
    --radius-l: 16px;

    --font-display: 'Space Grotesk', 'IBM Plex Sans', sans-serif;
    --font-body: 'IBM Plex Sans', sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

body {
    background-image:
        radial-gradient(circle at 12% 8%, rgba(232, 150, 60, 0.05), transparent 40%),
        radial-gradient(circle at 88% 92%, rgba(51, 183, 198, 0.06), transparent 45%);
    background-attachment: fixed;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--text); }
p { margin: 0 0 0.75em; color: var(--text-dim); }
a { color: inherit; }

.tabular { font-variant-numeric: tabular-nums; }

::selection { background: var(--fioul); color: #14171c; }

:focus-visible {
    outline: 2px solid var(--eau);
    outline-offset: 2px;
}

/* ==========================================================================
   Squelette de page (connecté)
   ========================================================================== */

.app {
    display: grid;
    grid-template-columns: 232px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar__brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 4px 10px 26px;
}

.sidebar__brand-mark {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 0.02em;
}

.sidebar__brand-mark span { color: var(--fioul); }

.sidebar__brand-sub {
    font-size: 11px;
    color: var(--text-faint);
    padding: 0 10px 18px;
    margin-top: -14px;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav__link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: var(--radius-s);
    text-decoration: none;
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 500;
    transition: background 0.12s ease, color 0.12s ease;
}

.nav__link:hover { background: var(--bg-raised); color: var(--text); }

.nav__link.is-active {
    background: var(--bg-raised);
    color: var(--text);
    box-shadow: inset 3px 0 0 var(--fioul);
}

.nav__link .icone { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar__footer {
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
}

.sidebar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    font-size: 13px;
}

.sidebar__avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 13px;
    color: #14171c;
    flex-shrink: 0;
}

.sidebar__user-name { color: var(--text); font-weight: 500; }
.sidebar__user-role { color: var(--text-faint); font-size: 11px; }

.main {
    min-width: 0;
    padding: 28px 36px 60px;
}

.topbar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

.topbar__title { font-size: 24px; }
.topbar__subtitle { font-size: 13.5px; color: var(--text-faint); margin-top: 3px; }

/* ==========================================================================
   Boutons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-s);
    border: 1px solid var(--border);
    background: var(--bg-raised);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.08s ease, border-color 0.12s ease, background 0.12s ease;
}

.btn .icone { width: 16px; height: 16px; }
.btn:hover { border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }

.btn--fioul { background: var(--fioul); border-color: var(--fioul); color: #1c1305; font-weight: 600; }
.btn--fioul:hover { background: #f0a34e; border-color: #f0a34e; }

.btn--eau { background: var(--eau); border-color: var(--eau); color: #062226; font-weight: 600; }
.btn--eau:hover { background: #43c6d5; border-color: #43c6d5; }

.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); }

.btn--ghost { background: transparent; border-color: transparent; padding: 8px 10px; }
.btn--ghost:hover { background: var(--bg-raised); }

.btn--sm { padding: 6px 12px; font-size: 13px; }
.btn--block { width: 100%; justify-content: center; }

/* ==========================================================================
   Panneaux / cartes
   ========================================================================== */

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-l);
    padding: 22px;
}

.panel + .panel { margin-top: 20px; }

.panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    gap: 12px;
    flex-wrap: wrap;
}

.panel__header h2 { font-size: 15px; }
.panel__header .sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }

.grid {
    display: grid;
    gap: 20px;
}

.grid--2 { grid-template-columns: 1fr 1fr; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--kpi { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1100px) {
    .grid--2, .grid--3, .grid--kpi { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
    .grid--2, .grid--3, .grid--kpi { grid-template-columns: 1fr; }
}

/* KPI */

.kpi {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    padding: 16px 18px;
}

.kpi__label { font-size: 12px; color: var(--text-faint); margin-bottom: 8px; }
.kpi__value { font-family: var(--font-display); font-size: 26px; font-weight: 600; }
.kpi__value small { font-size: 14px; color: var(--text-dim); font-weight: 500; }
.kpi__delta { font-size: 12px; margin-top: 6px; }
.kpi__delta--up { color: var(--danger); }
.kpi__delta--down { color: var(--success); }

.kpi--fioul { border-top: 2px solid var(--fioul); }
.kpi--eau { border-top: 2px solid var(--eau); }

/* ==========================================================================
   Cadran (jauge fioul)
   ========================================================================== */

.cadran {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 6px;
}

.cadran__svg { width: 100%; max-width: 260px; }

.cadran__arc-bg { fill: none; stroke: var(--bg-inset); stroke-width: 14; stroke-linecap: round; }
.cadran__arc-val {
    fill: none;
    stroke-width: 14;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s cubic-bezier(.4,0,.2,1);
}

.cadran__chiffre {
    font-family: var(--font-display);
    font-size: 40px;
    font-weight: 700;
}

.cadran__unite { font-size: 15px; color: var(--text-dim); font-weight: 500; }
.cadran__legende { font-size: 12.5px; color: var(--text-faint); margin-top: 4px; text-align: center; }

.cadran--fioul .cadran__arc-val { stroke: var(--fioul); }
.cadran--fioul .cadran__chiffre { color: var(--fioul); }

/* ==========================================================================
   Odomètre (compteur d'eau à roues mécaniques)
   ========================================================================== */

.odometre {
    display: flex;
    gap: 3px;
    justify-content: center;
    margin: 14px 0 10px;
}

.odometre__roue {
    width: 30px;
    height: 42px;
    background: linear-gradient(180deg, #232a30 0%, #171c20 55%, #0d1013 100%);
    border: 1px solid #383f47;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 600;
    color: var(--eau);
    text-shadow: 0 0 8px var(--eau-glow);
    box-shadow: inset 0 2px 3px rgba(0,0,0,.6), inset 0 -1px 0 rgba(255,255,255,.04);
}

.odometre__roue--separateur {
    background: transparent;
    border: none;
    color: var(--text-faint);
    width: 12px;
    box-shadow: none;
}

/* ==========================================================================
   Formulaires
   ========================================================================== */

.champ { margin-bottom: 18px; }
.champ label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 6px;
}
.champ .aide { font-size: 12px; color: var(--text-faint); margin-top: 5px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=file], select, textarea {
    width: 100%;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-s);
    padding: 11px 13px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14.5px;
    transition: border-color 0.12s ease;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--eau);
    outline: none;
}

textarea { resize: vertical; min-height: 70px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-s);
    padding: 12px 14px;
}
.checkbox-row input { width: auto; }

fieldset { border: none; padding: 0; margin: 0 0 18px; }
fieldset[disabled] { opacity: 0.4; }

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border-soft);
}

/* ==========================================================================
   Tableaux
   ========================================================================== */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
    text-align: left;
    font-size: 11.5px;
    text-transform: none;
    color: var(--text-faint);
    font-weight: 500;
    padding: 0 12px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border-soft);
    white-space: nowrap;
    color: var(--text);
}

tbody tr:hover { background: var(--bg-raised); }
tbody tr:last-child td { border-bottom: none; }

td.num, th.num { text-align: right; font-family: var(--font-display); }

.ligne-anomalie td { background: var(--danger-soft); }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions .btn { padding: 6px 8px; }
.row-actions .icone { width: 15px; height: 15px; }

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
}

.badge--fioul { color: var(--fioul); border-color: var(--fioul-soft); background: var(--fioul-soft); }
.badge--eau { color: var(--eau); border-color: var(--eau-soft); background: var(--eau-soft); }
.badge--defaut { color: var(--text-dim); }
.badge--alerte { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }

/* ==========================================================================
   Alertes / messages flash
   ========================================================================== */

.alerte {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 13px 16px;
    border-radius: var(--radius-m);
    font-size: 14px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}

.alerte .icone { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

.alerte--succes { background: rgba(111, 207, 151, 0.1); border-color: rgba(111, 207, 151, 0.3); color: var(--success); }
.alerte--erreur { background: var(--danger-soft); border-color: rgba(228, 87, 61, 0.35); color: #f29a8b; }
.alerte--info { background: var(--eau-soft); border-color: rgba(51, 183, 198, 0.3); color: var(--eau); }

/* ==========================================================================
   Vide / états
   ========================================================================== */

.etat-vide {
    text-align: center;
    padding: 46px 20px;
    color: var(--text-faint);
}
.etat-vide h3 { color: var(--text-dim); margin-bottom: 8px; font-size: 15px; }

/* ==========================================================================
   Graphiques
   ========================================================================== */

.chart-box { position: relative; height: 260px; }

/* ==========================================================================
   Page de connexion / installation
   ========================================================================== */

.ecran-plein {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.ecran-plein::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(600px circle at 18% 20%, var(--fioul-glow), transparent 60%),
        radial-gradient(600px circle at 82% 80%, var(--eau-glow), transparent 60%);
    pointer-events: none;
}

.carte-connexion {
    width: 100%;
    max-width: 400px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-l);
    padding: 38px 34px;
    position: relative;
    z-index: 1;
    animation: apparition 0.5s ease;
}

@keyframes apparition {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.carte-connexion__brand {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}
.carte-connexion__brand span { color: var(--fioul); }

.carte-connexion__tagline {
    text-align: center;
    font-size: 13px;
    color: var(--text-faint);
    margin-bottom: 30px;
}

@media (prefers-reduced-motion: reduce) {
    .carte-connexion, .cadran__arc-val { animation: none; transition: none; }
}

/* ==========================================================================
   Responsive — sidebar en barre basse sur mobile
   ========================================================================== */

@media (max-width: 880px) {
    .app { grid-template-columns: minmax(0, 1fr); }
    html, body { max-width: 100%; overflow-x: hidden; }
    .main { min-width: 0; max-width: 100%; }
    .panel, .table-wrap { max-width: 100%; }
    .grid > *, .form-row > *, .champ { min-width: 0; }
    .grid--2, .grid--3, .form-row { grid-template-columns: minmax(0, 1fr); }
    .grid--kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    input, select, textarea { max-width: 100%; min-width: 0; box-sizing: border-box; }
    /* Champs date : sur mobile (Safari iPhone surtout) ils ont une largeur propre
       qui dépasse du cadre. On les force à épouser leur conteneur. */
    input[type=date] {
        -webkit-appearance: none;
        appearance: none;
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        text-align: left;
    }
    input[type=date]::-webkit-date-and-time-value { text-align: left; min-height: 1.4em; }
    input[type=date]::-webkit-datetime-edit { padding: 0; max-width: 100%; }

    .sidebar {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        top: auto;
        height: auto;
        flex-direction: row;
        padding: 8px 6px;
        border-right: none;
        border-top: 1px solid var(--border);
        z-index: 20;
    }
    .sidebar__brand, .sidebar__brand-sub, .sidebar__footer { display: none; }
    .sidebar { width: 100%; box-sizing: border-box; background: var(--bg-panel); }
    .nav { flex-direction: row; justify-content: space-around; width: 100%; min-width: 0; flex: 1; }
    .nav__link { flex-direction: column; justify-content: flex-start; flex: 1 1 0; min-width: 0; gap: 4px; font-size: 10.5px; padding: 6px 2px; text-align: center; }
    .nav__link.is-active { box-shadow: none; }
    .main { padding: 20px 16px 90px; }
    .topbar__title { font-size: 20px; }
}

/* Éléments réservés au mobile : masqués par défaut, affichés par mobile.css */
.mobile-only { display: none; }
