/* ==========================================================================
   Portail ALM Group - feuille de style unique
   Aucune dependance externe : polices systeme, icones SVG en ligne.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Jetons de theme
   Le mode clair est la valeur par defaut. Le mode sombre s'applique via la
   preference systeme, ou via data-theme pose par l'interrupteur (le choix
   manuel l'emporte dans les deux sens).
   -------------------------------------------------------------------------- */

:root {
    color-scheme: light;

    --brand: #AA1717;
    --brand-strong: #54030F;
    --brand-on: #FFFFFF;
    --brand-text: #AA1717;   /* 7.38:1 sur blanc */

    --bg: #F4F4F6;
    --surface: #FFFFFF;
    --surface-2: #FAFAFB;
    --surface-3: #F0F0F2;
    --border: #DFDFE4;
    --border-strong: #C6C6CE;

    --text: #17171A;
    --text-muted: #5C5C66;

    --ok-bg: #DCFCE7;
    --ok-text: #14532D;
    --warn-bg: #FEF3C7;
    --warn-text: #854D0E;
    --danger-bg: #FEE2E2;
    --danger-text: #991B1B;
    --neutral-bg: #ECECEF;
    --neutral-text: #45454E;

    --ring: #AA1717;
    --shadow-sm: 0 1px 2px rgba(2, 1, 1, .06);
    --shadow: 0 4px 16px rgba(2, 1, 1, .08);
    --shadow-lg: 0 16px 40px rgba(2, 1, 1, .12);

    /* Echelle d'espacement 4/8 */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;
    --sp-7: 48px;

    --r-sm: 6px;
    --r: 10px;
    --r-lg: 14px;
    --r-full: 999px;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --header-h: 64px;
    --speed: 180ms;
}

/* Bloc sombre : duplique volontairement, une regle @media et un selecteur
   d'attribut ne peuvent pas etre fusionnes en CSS natif. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --brand-text: #E88A8A;   /* 5.9:1 sur fond sombre */

        --bg: #101013;
        --surface: #1A1A1F;
        --surface-2: #212128;
        --surface-3: #2A2A32;
        --border: #33333D;
        --border-strong: #46464F;

        --text: #F2F2F5;
        --text-muted: #A8A8B4;

        --ok-bg: rgba(74, 222, 128, .14);
        --ok-text: #86EFAC;
        --warn-bg: rgba(251, 191, 36, .14);
        --warn-text: #FCD34D;
        --danger-bg: rgba(248, 113, 113, .14);
        --danger-text: #FCA5A5;
        --neutral-bg: rgba(255, 255, 255, .07);
        --neutral-text: #C9C9D3;

        --ring: #E88A8A;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow: 0 4px 16px rgba(0, 0, 0, .45);
        --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --brand-text: #E88A8A;

    --bg: #101013;
    --surface: #1A1A1F;
    --surface-2: #212128;
    --surface-3: #2A2A32;
    --border: #33333D;
    --border-strong: #46464F;

    --text: #F2F2F5;
    --text-muted: #A8A8B4;

    --ok-bg: rgba(74, 222, 128, .14);
    --ok-text: #86EFAC;
    --warn-bg: rgba(251, 191, 36, .14);
    --warn-text: #FCD34D;
    --danger-bg: rgba(248, 113, 113, .14);
    --danger-text: #FCA5A5;
    --neutral-bg: rgba(255, 255, 255, .07);
    --neutral-text: #C9C9D3;

    --ring: #E88A8A;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 4px 16px rgba(0, 0, 0, .45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.25;
    letter-spacing: -.01em;
    font-weight: 700;
}

h1 { font-size: clamp(22px, 2.4vw, 28px); }
h2 { font-size: clamp(17px, 1.8vw, 20px); }

p { margin: 0; }

a { color: var(--brand-text); }

img, svg { max-width: 100%; }

:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: var(--sp-3);
    top: -100px;
    z-index: 100;
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    transition: top var(--speed) ease-out;
}

.skip-link:focus { top: var(--sp-3); }

.icon {
    width: 20px;
    height: 20px;
    flex: none;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon--sm { width: 16px; height: 16px; }

/* --------------------------------------------------------------------------
   3. En-tete
   -------------------------------------------------------------------------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    min-height: var(--header-h);
    padding: var(--sp-2) var(--sp-4);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.brand {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    gap: var(--sp-3);
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    min-width: 0;
}

/* Le logo est insere en SVG : "currentColor" lui donne la couleur du texte,
   ce qui le rend lisible en mode clair comme en mode sombre. */
.brand__logo { height: 30px; width: auto; color: var(--text); }

.brand__name {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-nav {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.app-nav__link {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: 44px;
    padding: 0 var(--sp-3);
    border-radius: var(--r);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: background var(--speed) ease-out, color var(--speed) ease-out;
}

.app-nav__link:hover { background: var(--surface-3); color: var(--text); }

.app-nav__link[aria-current="page"] {
    color: var(--brand-text);
    background: var(--surface-3);
}

/* Actions dangereuses separees visuellement de la navigation normale. */
.app-nav__link--exit { color: var(--text-muted); margin-left: var(--sp-2); }
.app-nav__link--exit:hover { background: var(--danger-bg); color: var(--danger-text); }

.app-nav__sep {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 var(--sp-1);
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0 var(--sp-3);
    min-height: 36px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 13px;
    max-width: 220px;
}

.user-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.theme-toggle {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--speed) ease-out, color var(--speed) ease-out;
}

.theme-toggle:hover { background: var(--surface-3); color: var(--text); }
.theme-toggle .icon--moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon--sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon--moon { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon--sun { display: none; }
    :root:not([data-theme="light"]) .theme-toggle .icon--moon { display: block; }
}

/* --------------------------------------------------------------------------
   4. Mise en page
   -------------------------------------------------------------------------- */

.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--sp-6) var(--sp-4) var(--sp-7);
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
}

.page-head__text { min-width: 0; flex: 1 1 260px; }

.page-head__sub {
    margin-top: var(--sp-1);
    color: var(--text-muted);
    font-size: 14px;
}

.section { margin-top: var(--sp-6); }

.section__title {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-bottom: var(--sp-3);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   5. Boutons
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: 44px;
    padding: 0 var(--sp-5);
    border: 1px solid transparent;
    border-radius: var(--r);
    background: var(--surface-3);
    color: var(--text);
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--speed) ease-out, border-color var(--speed) ease-out, color var(--speed) ease-out;
}

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

.btn--primary { background: var(--brand); color: var(--brand-on); }
.btn--primary:hover { background: var(--brand-strong); }

.btn--ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn--ghost:hover { background: var(--surface-3); }

.btn--block { width: 100%; }

.btn[disabled], .btn[aria-disabled="true"] {
    opacity: .45;
    cursor: not-allowed;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   6. Cartes et messages
   -------------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}

.card__body { padding: var(--sp-5); }

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r);
    font-size: 14px;
    margin-bottom: var(--sp-4);
}

.alert--error { background: var(--danger-bg); color: var(--danger-text); }
.alert--ok { background: var(--ok-bg); color: var(--ok-text); }
.alert--warn { background: var(--warn-bg); color: var(--warn-text); }

.alert__body { min-width: 0; }
.alert__title { font-weight: 700; }
.alert__hint { opacity: .9; }

.empty {
    padding: var(--sp-7) var(--sp-5);
    text-align: center;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-lg);
}

.empty__title { color: var(--text); font-weight: 700; margin-bottom: var(--sp-2); }

/* --------------------------------------------------------------------------
   7. Formulaires
   -------------------------------------------------------------------------- */

.field { margin-bottom: var(--sp-4); }

.label {
    display: block;
    margin-bottom: var(--sp-2);
    font-size: 14px;
    font-weight: 600;
}

.input {
    width: 100%;
    min-height: 44px;
    padding: var(--sp-3) var(--sp-4);
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px; /* evite le zoom automatique sur iOS */
    transition: border-color var(--speed) ease-out, box-shadow var(--speed) ease-out;
}

.input::placeholder { color: var(--text-muted); opacity: .8; }

.input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(170, 23, 23, .18);
}

/* Reste a 44px : meme dans une liste dense, un champ doit pouvoir etre
   touche au doigt sans erreur. */
.input--sm { min-height: 44px; padding: var(--sp-2) var(--sp-3); font-size: 14px; }

/* Lecture seule : visiblement different d'un champ desactive, qui lui
   serait grise et non selectionnable. */
.input[readonly] {
    background: var(--surface-3);
    border-style: dashed;
    color: var(--text-muted);
    cursor: default;
}

.help {
    margin-top: var(--sp-2);
    color: var(--text-muted);
    font-size: 13px;
}

.field-error {
    margin-top: var(--sp-2);
    color: var(--danger-text);
    font-size: 13px;
    font-weight: 600;
}

.search {
    position: relative;
    flex: 0 1 320px;
}

.search .icon {
    position: absolute;
    left: var(--sp-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search .input { padding-left: 42px; }

/* --------------------------------------------------------------------------
   8. Badges d'etat
   Le badge "Public" est volontairement en ambre : il signale une exposition
   sur Internet, ce n'est pas une reussite mais un etat a surveiller.
   -------------------------------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 3px var(--sp-2);
    border-radius: var(--r-full);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge--public { background: var(--warn-bg); color: var(--warn-text); }
.badge--private { background: var(--neutral-bg); color: var(--neutral-text); }
.badge--new { background: var(--danger-bg); color: var(--danger-text); }

/* Les deux icones sont presentes : le CSS affiche celle qui correspond a
   l'etat, ce qui permet au script de ne changer qu'une classe. */
.icon--if-public, .icon--if-private { display: none; }
.badge--public .icon--if-public { display: block; }
.badge--private .icon--if-private { display: block; }

/* --------------------------------------------------------------------------
   9. Grille des projets
   -------------------------------------------------------------------------- */

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--sp-4);
}

.project-card {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    padding: var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    color: var(--text);
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--speed) ease-out, box-shadow var(--speed) ease-out, transform var(--speed) ease-out;
}

.project-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.project-card:active { transform: translateY(0); }

.project-card__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
}

.project-card__icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--r);
    background: var(--surface-3);
    color: var(--brand-text);
}

.project-card__title {
    font-size: 16px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.project-card__desc {
    color: var(--text-muted);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.project-card__meta {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-top: auto;
    padding-top: var(--sp-2);
    color: var(--text-muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.project-card__path {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
   10. Console d'administration
   -------------------------------------------------------------------------- */

.rows {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}

.row {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: start;
    gap: var(--sp-3) var(--sp-4);
    padding: var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--speed) ease-out;
}

.row:focus-within { border-color: var(--border-strong); }

.row__icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--r);
    background: var(--surface-3);
    color: var(--text-muted);
}

.row__main { min-width: 0; }

.row__head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-bottom: var(--sp-3);
}

.row__key {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.row__fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    gap: var(--sp-3);
}

.row__control {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 132px;
}

/* Interrupteur accessible : vraie case a cocher, jamais un div. */
.switch {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-3);
    min-height: 44px;
    cursor: pointer;
    user-select: none;
}

.switch__input {
    position: absolute;
    opacity: 0;
    width: 44px;
    height: 26px;
    margin: 0;
    cursor: pointer;
}

.switch__track {
    position: relative;
    width: 44px;
    height: 26px;
    flex: none;
    border-radius: var(--r-full);
    background: var(--border-strong);
    transition: background var(--speed) ease-out;
}

.switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: var(--shadow-sm);
    transition: transform var(--speed) ease-out;
}

.switch__input:checked + .switch__track { background: var(--brand); }
.switch__input:checked + .switch__track::after { transform: translateX(18px); }
.switch__input:focus-visible + .switch__track {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
}

.switch__text {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 52px;
}

.switch__input:checked ~ .switch__text { color: var(--warn-text); }

/* Marge basse pour que la derniere ligne puisse defiler au-dessus de la
   barre d'enregistrement collee en bas. */
#liste-acces { padding-bottom: var(--sp-6); }

/* Barre d'enregistrement collee en bas */
.savebar {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sp-3);
    margin-top: var(--sp-5);
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
}

.savebar__status {
    color: var(--text-muted);
    font-size: 14px;
    margin-right: auto;
}

/* --------------------------------------------------------------------------
   11. Page de connexion
   -------------------------------------------------------------------------- */

.auth {
    min-height: 100dvh;
    display: grid;
    grid-template-rows: 1fr auto;
    padding: var(--sp-5) var(--sp-4);
}

.auth__inner {
    width: min(100%, 420px);
    margin: auto;
    align-self: center;
}

.auth__logo {
    display: block;
    height: 40px;
    width: auto;
    margin: 0 auto var(--sp-5);
    color: var(--text);
}

.auth__title { text-align: center; }

.auth__sub {
    margin: var(--sp-2) 0 var(--sp-5);
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.auth__foot {
    margin-top: var(--sp-5);
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.theme-float {
    position: fixed;
    top: var(--sp-4);
    right: var(--sp-4);
    z-index: 30;
}

.password-wrap { position: relative; }
.password-wrap .input { padding-right: 52px; }

.password-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: var(--r);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.password-toggle:hover { color: var(--text); }
.password-toggle .icon--eye-off { display: none; }
.password-toggle[aria-pressed="true"] .icon--eye { display: none; }
.password-toggle[aria-pressed="true"] .icon--eye-off { display: block; }

/* --------------------------------------------------------------------------
   12. Adaptatif
   -------------------------------------------------------------------------- */

@media (max-width: 860px) {
    .row {
        grid-template-columns: 36px minmax(0, 1fr);
    }

    .row__control {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .row__fields { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .page { padding: var(--sp-5) var(--sp-3) var(--sp-7); }

    .app-header {
        flex-wrap: wrap;
        padding: var(--sp-2) var(--sp-3);
    }

    .app-nav { width: 100%; justify-content: flex-start; margin-left: 0; }
    .app-nav__sep { display: none; }
    .user-chip { display: none; }
    .search { flex-basis: 100%; }
    .project-grid { grid-template-columns: 1fr; }
    .savebar__status { width: 100%; margin-right: 0; }
    .savebar .btn { flex: 1 1 auto; }
}

/* --------------------------------------------------------------------------
   13. Preferences d'accessibilite
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }

    .project-card:hover { transform: none; }
}

@media print {
    .app-header, .savebar, .theme-toggle { display: none; }
    body { background: #FFFFFF; }
}
