/* ========================================
   SMART IRRIGATION JWI - STYLES PARTAGES
   Fichier: /static/shared-styles.css
   v6.0 — Interface moderne avec sidebar
   ======================================== */

/* ========================================
   BASE & RESET
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ========================================
   VARIABLES CSS — Palette modernisee
   ======================================== */
:root {
    /* Couleurs principales */
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.25);
    --secondary: #8b5cf6;
    --accent: #06b6d4;
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.2);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.2);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.2);

    /* Fonds avec profondeur */
    --bg-base: #0c0f1a;
    --bg-surface: #141825;
    --bg-card: rgba(20, 24, 37, 0.7);
    --bg-card-hover: rgba(30, 35, 55, 0.8);
    --bg-elevated: rgba(255, 255, 255, 0.04);

    /* Compat anciennes variables */
    --bg-primary: #0c0f1a;
    --bg-secondary: #141825;

    /* Texte */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Bordures & effets */
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --glass: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow: rgba(0, 0, 0, 0.3);

    /* Layout */
    --sidebar-width: 260px;
}

/* ========================================
   BODY & LAYOUT
   ======================================== */
html {
    scrollbar-gutter: stable;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    animation: fadeIn 0.15s ease-in;
    overflow-x: hidden;
}

/* Fond gradient subtil */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse 80% 50% at 20% 10%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

@keyframes fadeIn {
    from { opacity: 0.95; }
    to { opacity: 1; }
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-logo {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
}

.sidebar-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-title {
    font-size: 0.9375rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.sidebar-subtitle {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.05em;
}

.sidebar-subtitle b {
    font-weight: 700;
    color: var(--primary-light);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow-y: auto;
}

.sidebar-section {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.75rem 0.75rem 0.5rem;
    margin-top: 0.5rem;
}

.sidebar-section:first-child {
    margin-top: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary-glow);
    color: var(--primary-light);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
}

.nav-icon {
    width: 20px;
    text-align: center;
    font-size: 1.125rem;
    flex-shrink: 0;
}

.nav-label {
    white-space: nowrap;
    overflow: hidden;
}

.nav-badge {
    margin-left: auto;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    font-size: 0.6875rem;
    font-weight: 600;
    background: var(--success-glow);
    color: var(--success);
}

/* Sidebar footer */
.sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid var(--border);
}

.sidebar-status {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    border-radius: 10px;
    background: var(--bg-elevated);
    font-size: 0.8125rem;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
    animation: pulse-glow 2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 4px var(--success); opacity: 1; }
    50% { box-shadow: 0 0 12px var(--success); opacity: 0.7; }
}

/* ========================================
   MAIN CONTENT AREA
   ======================================== */
.main {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    position: relative;
    z-index: 1;
    overflow-x: hidden;
}

/* ========================================
   TOPBAR
   ======================================== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 0.875rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(12, 15, 26, 0.8);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
    flex-wrap: wrap;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.topbar-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4375rem 0.875rem;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

/* ========================================
   ANCIEN HEADER — Compat (cache si sidebar presente)
   ======================================== */
.header {
    display: none;
}

/* ========================================
   CONTAINER
   ======================================== */
.container {
    max-width: 1440px;
    width: 100%;
    padding: 1.5rem 2rem 2rem;
    overflow-x: hidden;
}

/* ========================================
   CARDS — Glass morphism
   ======================================== */
.card {
    background: rgba(30, 36, 55, 0.85);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.card-icon {
    font-size: 1.25rem;
}

/* ========================================
   BUTTONS
   ======================================== */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    font-family: inherit;
    font-size: 0.875rem;
}

.btn:active {
    transform: scale(0.98);
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.btn-primary:hover {
    box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-elevated);
    border-color: var(--border-hover);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px var(--success-glow);
}

.btn-warning {
    background: var(--warning);
    color: white;
    box-shadow: 0 2px 8px var(--warning-glow);
}

.btn-danger {
    background: var(--danger);
    color: white;
    box-shadow: 0 2px 8px var(--danger-glow);
}

.btn-save {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.btn-save:active {
    transform: scale(0.98);
}

.btn-save:hover {
    box-shadow: 0 4px 16px var(--primary-glow);
    transform: translateY(-1px);
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

/* Ghost button (nouveau) */
.btn-ghost {
    padding: 0.375rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

/* Compat anciens boutons nav (masques dans sidebar layout) */
.btn-back {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 0.625rem;
    border-radius: 10px;
    display: none;
    align-items: center;
    gap: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.8125rem;
    white-space: nowrap;
    line-height: 1;
}

.btn-back .btn-label {
    display: none;
}

/* ========================================
   HEADER ACTIONS (compat)
   ======================================== */
.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-manage {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 0.5rem 1rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.875rem;
}

.btn-manage:active {
    transform: scale(0.95);
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.2rem;
}

.btn-icon:active {
    transform: scale(0.95);
}

/* ========================================
   FORMS - STYLES DE BASE
   ======================================== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-family: inherit;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-control::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

input[type="color"].form-control {
    height: 50px;
    cursor: pointer;
    padding: 0.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

/* ========================================
   FORMS - SELECT
   ======================================== */
select.form-control {
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05) !important;
    color: var(--text-primary) !important;
}

select.form-control option {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    padding: 0.75rem;
}

select.form-control option:hover {
    background: var(--primary) !important;
    color: white !important;
}

select.form-control option:checked {
    background: linear-gradient(135deg, var(--primary), var(--secondary)) !important;
    color: white !important;
}

select {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: var(--text-primary) !important;
}

select option {
    background-color: #141825 !important;
    color: #f1f5f9 !important;
}

/* ========================================
   TOGGLE SWITCH
   ======================================== */
.toggle-switch {
    position: relative;
    width: 56px;
    height: 32px;
    background: var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle-switch.active {
    background: var(--success);
}

.toggle-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch.active .toggle-slider {
    transform: translateX(24px);
}

/* ========================================
   MODAL
   ======================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    max-width: 400px;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    display: none;
    animation: slideUp 0.3s ease-out;
    z-index: 10001;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    font-weight: 500;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.toast-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}

.toast-error {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}

.toast::before {
    content: '';
    display: inline-block;
    margin-right: 0.5rem;
    font-size: 1.25rem;
}

.toast-success::before {
    content: '\2713';
}

.toast-error::before {
    content: '\26A0';
}

/* ========================================
   BADGES
   ======================================== */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.badge-active {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.badge-inactive {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-secondary);
}

.info-badge {
    padding: 0.25rem 0.625rem;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* ========================================
   LOADING
   ======================================== */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

/* ========================================
   TABS
   ======================================== */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: inherit;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}

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

/* ========================================
   SECTION HEADERS
   ======================================== */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* ========================================
   KPI CARDS
   ======================================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: rgba(30, 36, 55, 0.85);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    padding: 1.25rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    border-radius: 2px 2px 0 0;
}

.kpi-card:nth-child(1)::before { background: linear-gradient(90deg, var(--primary), var(--secondary)); }
.kpi-card:nth-child(2)::before { background: linear-gradient(90deg, var(--success), #34d399); }
.kpi-card:nth-child(3)::before { background: linear-gradient(90deg, var(--accent), #22d3ee); }
.kpi-card:nth-child(4)::before { background: linear-gradient(90deg, var(--warning), #fbbf24); }

.kpi-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.kpi-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
}

.kpi-icon.primary { background: var(--primary-glow); }
.kpi-icon.success { background: var(--success-glow); }
.kpi-icon.cyan { background: rgba(6, 182, 212, 0.15); }
.kpi-icon.warning { background: var(--warning-glow); }

.kpi-value {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.kpi-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ========================================
   SCROLLBAR
   ======================================== */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   RESPONSIVE
   ======================================== */

/* < 480px */
@media (max-width: 479px) {
    .main {
        font-size: 0.875rem;
    }

    .container {
        padding: 0.75rem;
    }

    .card {
        padding: 0.875rem;
        border-radius: 12px;
    }

    .card-title {
        font-size: 0.875rem;
    }

    .page-title { font-size: 1rem; }
    .form-label { font-size: 0.75rem; }
    .form-control, .form-select { font-size: 0.8125rem; }
    .btn { font-size: 0.75rem; padding: 0.5rem 0.875rem; }
    .section-header-title { font-size: 0.875rem; }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .kpi-card {
        padding: 0.875rem;
    }

    .kpi-value {
        font-size: 1.375rem;
    }

    .kpi-label { font-size: 0.6875rem; }

    .kpi-icon {
        width: 28px;
        height: 28px;
        font-size: 0.875rem;
    }

    .badge { font-size: 0.6875rem; }

    .modal-title { font-size: 1.25rem; }
}

/* 480px+ */
@media (min-width: 480px) {
    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* < 768px — Sidebar becomes bottom nav + font reduction mobile */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
        z-index: 200;
        background: rgba(20, 24, 37, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .sidebar-header,
    .sidebar-section,
    .sidebar-footer,
    .nav-label,
    .nav-badge { display: none; }

    /* Bottom-nav allegee en mobile : on masque les rubriques avancees */
    .sidebar .nav-item[href="/capteurs"],
    .sidebar .nav-item[href="/ml_dashboard"],
    .sidebar .nav-item[href="/custom_ihm"],
    .sidebar .nav-item-shutdown { display: none; }

    .sidebar-nav {
        flex-direction: row;
        justify-content: space-around;
        padding: 0.5rem;
        width: 100%;
        gap: 0;
        overflow-y: visible;
        overflow-x: auto;
    }

    .nav-item {
        flex-direction: column;
        padding: 0.5rem;
        gap: 0.125rem;
        font-size: 0.625rem;
        border-radius: 8px;
        min-width: 0;
    }

    .nav-item.active::before { display: none; }

    .nav-icon { font-size: 1.25rem; }

    .main {
        margin-left: 0;
        padding-bottom: 72px;
        font-size: 0.9375rem;
    }

    .container {
        padding: 1rem;
    }

    .topbar {
        padding: 0.75rem 1rem;
    }

    .page-title { font-size: 1.0625rem; }
    .card-title { font-size: 1rem; }
    .form-label { font-size: 0.8125rem; }
    .form-control, .form-select { font-size: 0.875rem; }
    .btn { font-size: 0.8125rem; }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .kpi-card { padding: 1rem; }
    .kpi-value { font-size: 1.5rem; }
    .kpi-icon { width: 32px; height: 32px; font-size: 1rem; }

    .card { padding: 1rem; }

    .toast {
        bottom: 5rem;
        right: 1rem;
        left: 1rem;
        max-width: none;
    }
}

/* Mobile paysage — forcer la bottom nav quand hauteur < 500px (téléphone horizontal) */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
        z-index: 200;
        background: rgba(20, 24, 37, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .sidebar-header,
    .sidebar-section,
    .sidebar-footer,
    .nav-label,
    .nav-badge { display: none; }

    /* Bottom-nav allegee en paysage mobile : on masque les rubriques avancees */
    .sidebar .nav-item[href="/capteurs"],
    .sidebar .nav-item[href="/ml_dashboard"],
    .sidebar .nav-item[href="/custom_ihm"],
    .sidebar .nav-item-shutdown { display: none; }

    .sidebar-nav {
        flex-direction: row;
        justify-content: space-around;
        padding: 0.375rem;
        width: 100%;
        gap: 0;
        overflow-y: visible;
        overflow-x: auto;
    }

    .nav-item {
        flex-direction: column;
        padding: 0.375rem;
        gap: 0.125rem;
        font-size: 0.5625rem;
        border-radius: 8px;
        min-width: 0;
    }

    .nav-item.active::before { display: none; }

    .nav-icon { font-size: 1.125rem; }

    .main {
        margin-left: 0;
        padding-bottom: 56px;
    }

    .container {
        padding: 0.75rem 1rem;
    }

    .topbar {
        padding: 0.5rem 1rem;
    }

    .toast {
        bottom: 4rem;
        right: 1rem;
        left: 1rem;
        max-width: none;
    }
}

/* 768px+ — Desktop */
@media (min-width: 769px) {
    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 1200px+ */
@media (max-width: 1200px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1201px) {
    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ========================================
   UTILITIES
   ======================================== */
.text-center { text-align: center; }
.text-secondary { color: var(--text-secondary); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* ========================================
   COMPAT — anciennes classes logo
   ======================================== */
.logo {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 1.125rem;
    font-weight: 700;
    flex-shrink: 0;
    min-width: 0;
    white-space: nowrap;
}

.logo-image {
    height: 40px;
    width: auto;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    flex-shrink: 0;
}

.logo-icon {
    font-size: 1.5rem;
}

.logo-page-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

.logo-text { display: none; }
.logo-slogan { display: none; }

.bold-letter {
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-nav { display: none; }

/* ========================================
   MODALS PERSONNALISES (JwiModal)
   Remplace alert() / confirm() natifs
   ======================================== */
body.jwi-modal-open { overflow: hidden; }

.jwi-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(8, 11, 22, 0.55);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.18s ease;
}
.jwi-modal-overlay--visible { opacity: 1; }
.jwi-modal-overlay--closing { opacity: 0; }

.jwi-modal {
    width: 100%;
    max-width: 460px;
    background: linear-gradient(160deg, rgba(30, 35, 55, 0.96), rgba(20, 24, 37, 0.96));
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow:
        0 25px 60px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    padding: 1.5rem 1.5rem 1.25rem;
    color: var(--text-primary);
    text-align: center;
    transform: translateY(8px) scale(0.97);
    opacity: 0;
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.18s ease;
    outline: none;
}
.jwi-modal-overlay--visible .jwi-modal {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.jwi-modal__icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 0.85rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
}

.jwi-modal__title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
    letter-spacing: -0.01em;
}

.jwi-modal__message {
    font-size: 0.94rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin-bottom: 1.35rem;
    word-wrap: break-word;
    white-space: normal;
}

.jwi-modal__actions {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

/* Variantes par type */
.jwi-modal--info    .jwi-modal__icon { background: rgba(99, 102, 241, 0.15); color: var(--primary-light); border: 1px solid rgba(99, 102, 241, 0.35); }
.jwi-modal--success .jwi-modal__icon { background: rgba(16, 185, 129, 0.15); color: var(--success);       border: 1px solid rgba(16, 185, 129, 0.4); }
.jwi-modal--warning .jwi-modal__icon { background: rgba(245, 158, 11, 0.15); color: var(--warning);       border: 1px solid rgba(245, 158, 11, 0.4); }
.jwi-modal--error   .jwi-modal__icon { background: rgba(239, 68, 68, 0.15);  color: var(--danger);        border: 1px solid rgba(239, 68, 68, 0.4); }
.jwi-modal--confirm .jwi-modal__icon { background: rgba(6, 182, 212, 0.15);  color: var(--accent);        border: 1px solid rgba(6, 182, 212, 0.4); }

/* Boutons modal */
.jwi-btn {
    -webkit-appearance: none;
    appearance: none;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0.6rem 1.15rem;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    min-width: 96px;
}
.jwi-btn:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}
.jwi-btn:active { transform: translateY(1px); }

.jwi-btn--primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 6px 18px var(--primary-glow);
}
.jwi-btn--primary:hover {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    box-shadow: 0 8px 24px var(--primary-glow);
}

.jwi-btn--danger {
    background: linear-gradient(135deg, var(--danger), #b91c1c);
    color: #fff;
    box-shadow: 0 6px 18px var(--danger-glow);
}
.jwi-btn--danger:hover {
    background: linear-gradient(135deg, #f87171, var(--danger));
    box-shadow: 0 8px 24px var(--danger-glow);
}

.jwi-btn--ghost {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    border-color: var(--border-hover);
}
.jwi-btn--ghost:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.18);
}

/* Toasts (non bloquants) */
.jwi-toast-host {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.jwi-toast {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: linear-gradient(160deg, rgba(30, 35, 55, 0.96), rgba(20, 24, 37, 0.96));
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.7rem 1rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
    pointer-events: auto;
    max-width: 360px;
}
.jwi-toast--visible {
    transform: translateX(0);
    opacity: 1;
}
.jwi-toast__icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    flex-shrink: 0;
}
.jwi-toast.jwi-modal--success .jwi-toast__icon { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.jwi-toast.jwi-modal--info    .jwi-toast__icon { background: rgba(99, 102, 241, 0.2); color: var(--primary-light); }
.jwi-toast.jwi-modal--warning .jwi-toast__icon { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.jwi-toast.jwi-modal--error   .jwi-toast__icon { background: rgba(239, 68, 68, 0.2);  color: var(--danger); }

@media (max-width: 480px) {
    .jwi-modal { max-width: 100%; padding: 1.25rem 1.1rem 1rem; }
    .jwi-modal__actions { flex-direction: column-reverse; }
    .jwi-modal__actions .jwi-btn { width: 100%; }
}

/* ═══════════════ AUTH USER BLOCK (sidebar footer) ═══════════════ */
.auth-user-block {
    margin-top: 0.75rem;
    padding: 0.625rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 8px;
    font-size: 0.8125rem;
}
.auth-user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.auth-user-icon { font-size: 0.875rem; }
.auth-user-name {
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.auth-role-badge {
    font-size: 0.65rem;
    text-transform: uppercase;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.03em;
}
.auth-role-admin {
    background: rgba(245, 158, 11, 0.18);
    color: var(--warning, #f59e0b);
}
.auth-role-viewer {
    background: rgba(99, 102, 241, 0.18);
    color: var(--primary-light, #818cf8);
}
.auth-logout-btn {
    width: 100%;
    padding: 0.4rem 0.6rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}
.auth-logout-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}
