/* =====================================================================
   IkoDrive — styles applicatifs
   Source de vérité : docs/DESIGN.md (design system du 19/07/2026).
   Deux registres : l'UI utilitaire sur papier chaud (tables, formulaires),
   et la surface Blueprint (grille sombre) pour les moments de marque.
   ===================================================================== */

:root {
    /* ---- Couleurs (DESIGN.md, un-pour-un) ---- */
    --bg: #f5f4f0;
    --surface: #ffffff;
    --ink: #171a21;
    --muted: #6b7280;
    --line: #e4e2db;
    --accent: #3452e1;
    --accent-hover: #2a44c4;
    --accent-soft: #eef1fd;
    --accent-secondary: #e8b93c;
    --danger: #b3261e;
    --danger-soft: #fdecea;
    --success: #1e7d43;
    --success-soft: #e9f6ee;
    --warning: #8a6d1a;
    --warning-soft: #f7f0dc;

    /* ---- Rayons, ombres ---- */
    --radius: 10px;
    --radius-sm: 6px;
    --radius-pill: 999px;
    --shadow: 0 1px 2px rgba(23, 26, 33, 0.05), 0 8px 24px rgba(23, 26, 33, 0.06);
    --shadow-sm: 0 1px 2px rgba(23, 26, 33, 0.06);
    --shadow-lg: 0 4px 12px rgba(23, 26, 33, 0.08), 0 24px 48px rgba(23, 26, 33, 0.10);

    /* ---- Gabarit ---- */
    --topbar-h: 56px;
    --sidebar-w: 250px;
    --container-max: 1060px;

    /* ---- Typographie ---- */
    --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

    /* ---- Blueprint (surface de marque) ---- */
    --bp-bg: #10131a;
    --bp-grid: rgba(52, 82, 225, 0.14);
    --bp-edge: #6f8cf5;
    --bp-ink: #c9d4fb;
    --bp-grid-size: 32px;

    --focus-ring: 2px solid var(--accent);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    letter-spacing: -0.01em;
}

:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 1px;
}

/* ---------- Marque ---------- */

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: block;
    flex: none;
}

.brand--compact .brand-mark {
    width: 28px;
    height: 28px;
}

.brand-name {
    font-size: 1.6rem;
    font-weight: 300;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.brand--compact .brand-name {
    font-size: 1.1rem;
}

.brand-name strong {
    font-weight: 700;
}

/* ---------- Blueprint : la surface de marque ----------
   Grille sombre + ticks de repérage + annotations mono. Pour la landing,
   les couvertures de rapport et les en-têtes — JAMAIS derrière les tables. */

.bp {
    position: relative;
    background-color: var(--bp-bg);
    background-image:
        linear-gradient(var(--bp-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--bp-grid) 1px, transparent 1px);
    background-size: var(--bp-grid-size) var(--bp-grid-size);
    color: var(--bp-ink);
}

.bp-tick {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 0 solid var(--bp-edge);
    pointer-events: none;
}

.bp-tick.tl { top: 10px; left: 10px; border-top-width: 2px; border-left-width: 2px; }
.bp-tick.tr { top: 10px; right: 10px; border-top-width: 2px; border-right-width: 2px; }
.bp-tick.bl { bottom: 10px; left: 10px; border-bottom-width: 2px; border-left-width: 2px; }
.bp-tick.br { bottom: 10px; right: 10px; border-bottom-width: 2px; border-right-width: 2px; }

.bp-cross {
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--bp-edge);
    pointer-events: none;
}

.bp-titleblock {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
    border-top: 1px solid rgba(159, 178, 248, 0.3);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--bp-edge);
}

.bp-titleblock span {
    padding: 0.55rem 1rem;
    border-right: 1px solid rgba(159, 178, 248, 0.3);
    white-space: nowrap;
}

.bp-titleblock span:first-child {
    color: #ffffff;
    flex: 1;
}

.bp-titleblock span:last-child {
    border-right: 0;
}

/* Le kicker mono : la langue Blueprint sur les écrans propres. */
.kicker {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.05em;
    color: var(--accent);
    margin: 0 0 0.3rem;
}

/* ---------- Landing (backdrop Blueprint) ---------- */

body.landing {
    background: var(--bp-bg);
}

.landing-wrap {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem 4rem;
}

.landing-panel {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
    position: relative;
}

.landing-brand {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.landing-brand .brand-name {
    color: #ffffff;
}

.baseline {
    margin: 0;
    color: var(--bp-ink);
    font-size: 0.98rem;
}

.login-card {
    color: var(--ink);
}

/* ---------- Cartes, alertes ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.alert {
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.9rem;
    font-size: 0.92rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
}

.alert-success {
    background: var(--success-soft);
    color: var(--success);
}

.alert-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

/* ---------- Sélecteur de langue ---------- */

.locale-switch {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.locale-switch a {
    color: var(--bp-ink);
    text-decoration: none;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-pill);
    transition: background-color 120ms cubic-bezier(0.2, 0, 0, 1), color 120ms cubic-bezier(0.2, 0, 0, 1);
}

.locale-switch a:hover,
.locale-switch a:focus {
    text-decoration: none;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.locale-switch a.active {
    color: #ffffff;
    background: rgba(111, 140, 245, 0.25);
    font-weight: 600;
}

.locale-sep {
    color: var(--bp-edge);
}

/* ---------- Formulaires ---------- */

.form-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 1rem;
}

.form-row label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink);
}

.form-row .help,
.form-row .form-help {
    font-size: 0.8rem;
    color: var(--muted);
    margin: 0;
}

.form-row input[type='text'],
.form-row input[type='email'],
.form-row input[type='password'],
.form-row input[type='number'],
.form-row select {
    appearance: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.75rem;
    font: inherit;
    color: var(--ink);
    width: 100%;
}

.form-row input:focus,
.form-row select:focus {
    outline: var(--focus-ring);
    outline-offset: -1px;
    border-color: var(--accent);
}

.form-errors,
.form-row ul {
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--danger);
    font-size: 0.85rem;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.35rem 1rem;
}

.checkbox-grid label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 400;
    font-size: 0.92rem;
}

/* Arbre org cochable : guides d'arborescence dessinés par des spans
   (.tree-guide) — un par niveau, le dernier porte le coude. */
.checkbox-tree {
    display: flex;
    flex-direction: column;
}

.checkbox-tree[hidden] {
    display: none;
}

.checkbox-tree label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.18rem 0;
    font-weight: 400;
    font-size: 0.92rem;
}

.tree-guide {
    flex: none;
    width: 1.15rem;
    align-self: stretch;
    position: relative;
}

.tree-guide::before {
    content: '';
    position: absolute;
    left: 0.55rem;
    top: -0.18rem;
    bottom: -0.18rem;
    border-left: 1px solid var(--line);
}

.tree-guide-elbow::after {
    content: '';
    position: absolute;
    left: 0.55rem;
    top: 50%;
    width: 0.45rem;
    border-top: 1px solid var(--line);
}

/* Nœud impliqué par un ancêtre coché : inclus d'office, non modifiable. */
.checkbox-tree label.implied {
    color: var(--muted);
}

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

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

/* ---------- Onglets (page compte, extensible) ---------- */

.tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 1.25rem;
}

.tabs a {
    padding: 0.55rem 0.9rem;
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 120ms cubic-bezier(0.2, 0, 0, 1), border-color 120ms cubic-bezier(0.2, 0, 0, 1);
}

.tabs a:hover,
.tabs a:focus {
    text-decoration: none;
    color: var(--ink);
}

.tabs a.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ---------- Boutons & liens stylisés ----------
   Règle maison : jamais de text-decoration au survol d'un lien stylisé en
   bouton/carte — le feedback passe par la couleur et l'élévation. */

.btn,
a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.55rem 1rem;
    font: inherit;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 120ms cubic-bezier(0.2, 0, 0, 1), border-color 120ms cubic-bezier(0.2, 0, 0, 1), box-shadow 120ms cubic-bezier(0.2, 0, 0, 1);
}

.btn:hover,
.btn:focus,
.btn:active,
a.btn:hover,
a.btn:focus,
a.btn:active {
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--accent-hover);
    color: #fff;
}

.btn-ghost {
    background: transparent;
    color: var(--ink);
    border-color: var(--line);
}

.btn-ghost:hover,
.btn-ghost:focus {
    background: var(--surface);
    border-color: var(--muted);
    color: var(--ink);
}

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

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

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
}

/* ---------- Shell admin : sidebar + topbar ---------- */

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

.nav-toggle {
    display: none;
}

.sidebar {
    width: var(--sidebar-w);
    flex: none;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
}

/* Le bloc marque de la sidebar a exactement la hauteur de la topbar :
   les deux hairlines se rejoignent au pixel. */
.sidebar .brand-link {
    height: var(--topbar-h);
    flex: none;
    display: flex;
    align-items: center;
    padding: 0 18px;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid var(--line);
}

.sidebar .brand-link:hover,
.sidebar .brand-link:focus,
.topbar-brand:hover,
.topbar-brand:focus {
    text-decoration: none;
}

.side-nav {
    padding: 0.9rem 0.7rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.nav-group-label {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 0.5rem 0.35rem;
}

.side-nav a {
    display: block;
    color: var(--ink);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.93rem;
    padding: 0.42rem 0.6rem;
    border-radius: var(--radius-sm);
    transition: background-color 120ms cubic-bezier(0.2, 0, 0, 1), color 120ms cubic-bezier(0.2, 0, 0, 1);
}

.side-nav a:hover,
.side-nav a:focus {
    text-decoration: none;
    background: var(--bg);
}

.side-nav a.active {
    color: var(--accent);
    background: var(--accent-soft);
}

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

.topbar {
    height: var(--topbar-h);
    flex: none;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: none;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink);
    font-size: 16px;
    cursor: pointer;
    user-select: none;
}

/* Le logo dans la topbar : uniquement quand la sidebar est repliée (mobile). */
.topbar-brand {
    display: none;
    color: inherit;
    text-decoration: none;
    flex: none;
}

.workspace-label {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.workspace-label strong {
    color: var(--ink);
    font-weight: 600;
}

/* ---------- Menu utilisateur (avatar + dropdown, sans JS) ---------- */

.user-menu {
    position: relative;
    flex: none;
}

.user-menu summary {
    display: flex;
    align-items: center;
    gap: 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    padding: 4px 10px 4px 4px;
    cursor: pointer;
    list-style: none;
    transition: border-color 120ms cubic-bezier(0.2, 0, 0, 1), background-color 120ms cubic-bezier(0.2, 0, 0, 1);
}

.user-menu summary::-webkit-details-marker {
    display: none;
}

.user-menu summary:hover {
    border-color: var(--muted);
}

.user-menu[open] summary {
    background: var(--bg);
}

.avatar {
    width: 28px;
    height: 28px;
    flex: none;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.user-menu .user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
    white-space: nowrap;
}

.user-menu .chevron {
    color: var(--muted);
    font-size: 11px;
}

@keyframes ikd-pop {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: none; }
}

.user-menu .menu {
    position: absolute;
    top: 46px;
    right: 0;
    width: 210px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 20;
    animation: ikd-pop 120ms cubic-bezier(0.2, 0, 0, 1);
}

.user-menu .menu-email {
    padding: 8px 10px 6px;
    font-size: 12px;
    color: var(--muted);
    font-family: var(--font-mono);
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu .menu-link {
    display: block;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--ink);
    text-decoration: none;
    transition: background-color 120ms cubic-bezier(0.2, 0, 0, 1);
}

.user-menu .menu-link:hover,
.user-menu .menu-link:focus {
    text-decoration: none;
    background: var(--bg);
}

.user-menu .menu-divider {
    height: 1px;
    background: var(--line);
    margin: 6px 4px;
}

.user-menu .menu-signout {
    display: block;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--danger);
    text-decoration: none;
    transition: background-color 120ms cubic-bezier(0.2, 0, 0, 1);
}

.user-menu .menu-signout:hover,
.user-menu .menu-signout:focus {
    text-decoration: none;
    background: var(--danger-soft);
}

.admin-main {
    max-width: var(--container-max);
    width: 100%;
    margin: 0 auto;
    padding: 1.75rem 1.25rem 3rem;
}

.nav-overlay {
    display: none;
}

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform 160ms cubic-bezier(0.2, 0, 0, 1);
        box-shadow: var(--shadow);
    }

    .nav-toggle:checked ~ .sidebar {
        transform: translateX(0);
    }

    .nav-toggle:checked ~ .nav-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(23, 26, 33, 0.35);
        cursor: pointer;
    }

    .hamburger {
        display: inline-flex;
    }

    /* Sidebar repliée : le logo prend la priorité dans la topbar. */
    .topbar-brand {
        display: inline-flex;
    }
}

@media (max-width: 640px) {
    /* Le logo garde la priorité : le libellé workspace s'efface d'abord… */
    .workspace-label {
        display: none;
    }
}

@media (max-width: 480px) {
    /* …puis le nom d'utilisateur — l'avatar reste. */
    .user-menu .user-name {
        display: none;
    }
}

/* ---------- Têtes de page ---------- */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-head h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.page-head .sub {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 0.15rem 0 0;
}

/* ---------- Tables ---------- */

.table-card {
    padding: 0;
    overflow-x: auto;
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.93rem;
}

table.data th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--line);
    background: #faf9f6;
}

table.data td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

table.data tr:last-child td {
    border-bottom: none;
}

table.data td.actions {
    text-align: right;
    white-space: nowrap;
}

.tree-indent {
    color: var(--line);
    margin-right: 0.25rem;
}

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    border-radius: var(--radius-pill);
    padding: 0.1rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-group {
    background: var(--ink);
    color: #fff;
}

.badge-region {
    background: var(--accent-soft);
    color: var(--accent);
}

.badge-site {
    background: var(--success-soft);
    color: var(--success);
}

.badge-code {
    background: var(--warning-soft);
    color: var(--warning);
    font-family: var(--font-mono);
    font-weight: 500;
}

.muted {
    color: var(--muted);
}

.mono {
    font-family: var(--font-mono);
}

.inline-form {
    display: inline;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.row-form {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.row-form .form-row {
    margin-bottom: 0;
    flex: 1 1 140px;
}

.form-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    margin-top: 1.25rem;
}
