/* ==========================================================================
   SRE Engine — feuille de style générique unique
   Layout: sidebar fixe à gauche + topbar + contenu, inspiré de Ploi.io
   ========================================================================== */

:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-text: #1f2430;
    --color-text-muted: #6b7280;

    --sidebar-bg: #10131a;
    --sidebar-bg-hover: #1c212c;
    --sidebar-text: #c9ccd3;
    --sidebar-text-muted: #7d828f;
    --sidebar-active-bg: #262c3a;
    --sidebar-active-text: #ffffff;
    --sidebar-accent: #3b82f6;

    --color-accent: #3b82f6;
    --color-accent-hover: #2563eb;
    --color-danger: #ef4444;
    --color-danger-bg: #fef2f2;
    --color-danger-border: #fecaca;
    --color-success: #22c55e;
    --color-success-bg: #f0fdf4;
    --color-success-border: #bbf7d0;
    --color-warning: #f59e0b;
    --color-warning-bg: #fffbeb;
    --color-warning-border: #fde68a;
    --color-info: #3b82f6;
    --color-info-bg: #eff6ff;
    --color-info-border: #bfdbfe;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --sidebar-width: 240px;
    --topbar-height: 64px;

    --shadow-sm: 0 1px 2px rgba(16, 19, 26, 0.06);
    --shadow-md: 0 4px 12px rgba(16, 19, 26, 0.08);

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

button {
    font-family: inherit;
    cursor: pointer;
}

h1, h2, h3, h4, p {
    margin: 0;
}

/* --------------------------------------------------------------------------
   Structure globale : sidebar + contenu
   -------------------------------------------------------------------------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* --------------------------------------------------------------------------
   Sidebar (menu de navigation gauche)
   -------------------------------------------------------------------------- */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.sidebar + .space {
    width: var(--sidebar-width);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 1.25rem 1.25rem;
    font-weight: 400;
    font-size: 1.25rem;
    color: #d1d5db;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.go-brand {
    color: #fff;
    font-weight: 700;
}

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

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

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: 0.9rem;
    transition: background 0.15s ease, color 0.15s ease;
}

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

.sidebar-nav a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
    position: relative;
}

.sidebar-nav a.active::before {
    content: "";
    position: absolute;
    left: -0.75rem;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--sidebar-accent);
}

.sidebar-user {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.user-email {
    font-size: 0.8rem;
    color: var(--sidebar-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    width: 100%;
    padding: 0.45rem 0.75rem;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-logout:hover {
    background: var(--color-danger);
    border-color: var(--color-danger);
    color: #fff;
}

/* --------------------------------------------------------------------------
   Topbar (barre de titre en haut de chaque page)
   -------------------------------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.topbar-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text);
}

/* --------------------------------------------------------------------------
   Contenu principal
   -------------------------------------------------------------------------- */

.main-page {
    flex: 1;
    padding: 1.5rem;
}

/* --------------------------------------------------------------------------
   Composants génériques réutilisables (cartes façon Ploi)
   -------------------------------------------------------------------------- */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

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

.card-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.card-header a {
    font-size: 0.8rem;
    color: var(--color-accent);
}

.card-header a:hover {
    color: var(--color-accent-hover);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.status-dot {
    display: inline-block;
    width: 6px;
    border-radius: 999px;
    align-self: stretch;
    background: var(--color-success);
}

.btn,
button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--color-accent);
    color: #fff;
    transition: background 0.15s ease;
    margin-top: 1rem;
    line-height: 1;
}

.btn:hover {
    background: var(--color-accent-hover);
}

.btn-secondary {
    background: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text);
}

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

/* --------------------------------------------------------------------------
   Messages flash (erreur / succès / avertissement / info)
   -------------------------------------------------------------------------- */

.flash {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
}

.flash-icon {
    width: 8px;
    height: 8px;
    margin-top: 0.4rem;
    border-radius: 999px;
    flex-shrink: 0;
}

.flash-error {
    background: var(--color-danger-bg);
    border-color: var(--color-danger-border);
    color: #991b1b;
}
.flash-error .flash-icon {
    background: var(--color-danger);
}

.flash-success {
    background: var(--color-success-bg);
    border-color: var(--color-success-border);
    color: #166534;
}
.flash-success .flash-icon {
    background: var(--color-success);
}

.flash-warning {
    background: var(--color-warning-bg);
    border-color: var(--color-warning-border);
    color: #92400e;
}
.flash-warning .flash-icon {
    background: var(--color-warning);
}

.flash-info {
    background: var(--color-info-bg);
    border-color: var(--color-info-border);
    color: #1e40af;
}
.flash-info .flash-icon {
    background: var(--color-info);
}

/* --------------------------------------------------------------------------
   Page d'erreur pleine page (404, 403, 500, ...)
   -------------------------------------------------------------------------- */

.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.75rem;
    padding: 4rem 1.5rem;
    max-width: 480px;
    margin: 3rem auto;
}

.error-code {
    font-size: 3rem;
    font-weight: 800;
    color: var(--color-accent);
    line-height: 1;
}

.error-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.error-message {
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}

/* --------------------------------------------------------------------------
   Responsive : sidebar en overlay sous 900px
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar + .space {
        width: 0 !important
    }

    .app-content {
        margin-left: 0;
    }
}

/* Container parent */
.toggle-container {
    width: 100%; /* S'adapte à la largeur disponible */
}

/* Cacher la checkbox native */
.toggle-input {
    display: none;
}

/* Style du bouton plein largeur (état OFF / Inactif par défaut) */
.toggle-button {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 6px 16px;
    background-color: var(--color-surface); /* Gris (Inactive) */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.1s ease, color 0.1s ease;
    box-sizing: border-box;
}

/* Gestion du texte ON / OFF */
.toggle-button .state-on {
    display: none; /* Caché quand décoché */
}
.toggle-button .state-off {
    display: inline; /* Visible quand décoché */
}

/* --- ÉTAT CHECKED (ON / Actif) --- */

/* Changement de couleur de fond au clic */
.toggle-input:checked + .toggle-button {
    background-color: var(--color-accent);
    color: var(--color-bg);
}

/* Inversion du texte ON / OFF */
.toggle-input:checked + .toggle-button .state-off {
    display: none;
}
.toggle-input:checked + .toggle-button .state-on {
    display: inline;
}

.desactive {
    opacity: .6;
}