/* =====================================================================
   Espace Client API Studio — Design System
   Base partagée par tous les écrans. Inspiré de la maquette de référence.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
    /* Couleurs de marque */
    --brand-600: #2563eb;
    --brand-700: #1d4ed8;
    --brand-500: #3b82f6;
    --brand-50:  #eff6ff;

    /* Neutres */
    --ink-900: #0f172a;   /* titres */
    --ink-700: #334155;
    --ink-600: #475569;
    --ink-500: #64748b;   /* texte secondaire */
    --ink-400: #94a3b8;   /* labels */
    --line:    #e5e7eb;   /* bordures */
    --surface: #ffffff;   /* cartes */
    --bg:      #f4f6fa;   /* fond appli */
    --bg-soft: #f8fafc;

    /* Sémantique */
    --green-bg: #d1fae5; --green-tx: #065f46; --green-dot: #22c55e;
    --blue-bg:  #dbeafe; --blue-tx:  #1e40af;
    --amber:    #f59e0b;
    --danger:   #dc2626; --danger-bg: #fef2f2; --danger-bd: #fecaca;
    --success:  #16a34a; --success-bg: #f0fdf4; --success-bd: #bbf7d0;

    /* Élévation & rayons */
    --radius:    16px;
    --radius-sm: 10px;
    --shadow:    0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
    --shadow-sm: 0 1px 2px rgba(16,24,40,.06);

    --sidebar-w: 248px;
    --topbar-h:  64px;

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

/* ---------- Reset léger ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink-900);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-size: 15px;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }

/* ---------- Layout applicatif ---------- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar__logo { height: 75px; width: auto; display: block; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--ink-600); font-weight: 500; font-size: 14.5px;
    transition: background .15s, color .15s;
}
.nav__item:hover { background: var(--bg-soft); color: var(--ink-900); }
.nav__item.is-active { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.nav__item svg { width: 20px; height: 20px; flex: none; }

.sidebar__spacer { flex: 1; }
.sidebar__footer { display: flex; flex-direction: column; gap: 2px; padding-top: 10px; }

/* ---------- Topbar ---------- */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    display: flex; align-items: center;
    padding: 0 32px; gap: 16px;
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 5;
}
.topbar__title { color: var(--ink-500); font-size: 14.5px; font-weight: 500; }
.topbar__spacer { flex: 1; }
.topbar__icons { display: flex; align-items: center; gap: 14px; }
.icon-btn {
    position: relative; width: 38px; height: 38px;
    display: grid; place-items: center; border-radius: 10px;
    color: var(--ink-500); background: transparent; border: none;
}
.icon-btn:hover { background: #eef1f7; color: var(--ink-700); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn__dot {
    position: absolute; top: 8px; right: 9px; width: 7px; height: 7px;
    background: var(--danger); border-radius: 50%; border: 2px solid var(--surface);
}
.topbar__sep { width: 1px; height: 28px; background: var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip__meta { text-align: right; line-height: 1.2; }
.user-chip__name { font-weight: 700; font-size: 14px; color: var(--ink-900); }
.user-chip__role { font-size: 12px; color: var(--ink-500); }
.user-chip__avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.avatar-fallback {
    width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--brand-600); color: #fff; font-weight: 700; font-size: 14px;
}

/* ---------- Zone de contenu ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.content { padding: 32px; flex: 1; }
.page-head { margin: 4px 0 28px; }
.page-title {
    font-size: 30px; font-weight: 800; letter-spacing: -.02em;
    display: inline-block; padding-bottom: 10px;
    border-bottom: 3px solid var(--brand-600);
}

/* ---------- Cartes ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 22px 26px; border-bottom: 1px solid var(--line);
}
.card__title { font-size: 19px; font-weight: 700; }
.card__body { padding: 26px; }

/* ---------- Grille de la page compte ---------- */
.account-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    align-items: start;
}

/* Carte profil */
.profile { padding: 30px 26px; text-align: center; }
.profile__avatar-wrap { position: relative; width: 116px; margin: 6px auto 18px; }
.profile__avatar {
    width: 116px; height: 116px; border-radius: 50%;
    object-fit: cover; border: 4px solid var(--brand-500);
    box-shadow: 0 0 0 4px var(--surface);
}
.profile__status {
    position: absolute; right: 6px; bottom: 6px;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--green-dot); border: 3px solid var(--surface);
    display: grid; place-items: center;
}
.profile__status svg { width: 12px; height: 12px; color: #fff; }
.profile__name { font-size: 22px; font-weight: 800; margin: 0; }
.profile__role { color: var(--brand-600); font-weight: 700; margin: 4px 0 2px; }
.profile__company { color: var(--ink-500); font-size: 14px; }
.profile__badges { display: flex; gap: 8px; justify-content: center; margin: 16px 0 0; }
.profile__divider { height: 1px; background: var(--line); margin: 22px 0; }
.profile__stats { display: flex; justify-content: center; gap: 56px; }
.stat { text-align: center; }
.stat__num { font-size: 20px; font-weight: 800; }
.stat__label { font-size: 13px; color: var(--ink-500); }

/* Badges */
.badge {
    display: inline-flex; align-items: center;
    padding: 5px 12px; border-radius: 999px;
    font-size: 12px; font-weight: 700; letter-spacing: .03em;
}
.badge--green { background: var(--green-bg); color: var(--green-tx); }
.badge--blue  { background: var(--blue-bg);  color: var(--blue-tx); }

/* Champs coordonnées */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 26px 32px; }
.field__label {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--ink-400); margin-bottom: 6px;
}
.field__label svg { width: 15px; height: 15px; }
.field__value { font-size: 15.5px; color: var(--ink-900); font-weight: 500; }
.field--full { grid-column: 1 / -1; }

/* Carte sécurité */
.security {
    margin-top: 24px;
    display: flex; align-items: center; gap: 18px;
    padding: 22px 26px;
    background: #eef2fb;
    border: 1px solid #dce4f5;
    border-radius: var(--radius);
}
.security__icon {
    width: 46px; height: 46px; border-radius: 12px; flex: none;
    background: var(--amber); color: #fff; display: grid; place-items: center;
}
.security__icon svg { width: 24px; height: 24px; }
.security__title { font-weight: 700; font-size: 16px; }
.security__text { color: var(--ink-500); font-size: 14px; }
.security__link {
    margin-left: auto; color: var(--brand-700); font-weight: 700;
    display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
    font-weight: 600; font-size: 14.5px; transition: background .15s, box-shadow .15s;
}
.btn svg { width: 17px; height: 17px; }
.btn--primary { background: var(--brand-600); color: #fff; }
.btn--primary:hover { background: var(--brand-700); }
.btn--ghost { background: #fff; border-color: var(--line); color: var(--ink-700); }
.btn--ghost:hover { background: var(--bg-soft); }
.btn--block { width: 100%; justify-content: center; }

/* ---------- Footer ---------- */
.footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 32px; border-top: 1px solid var(--line);
    color: var(--ink-500); font-size: 13.5px; background: var(--bg);
}
.footer a:hover { color: var(--ink-700); }
.footer__brand strong { color: var(--brand-600); }
.footer__links { display: flex; gap: 22px; }
.footer__links a { text-decoration: underline; }

/* ---------- Messages flash ---------- */
.alert {
    padding: 13px 16px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500; margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert--error   { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger-bd); }
.alert--success { background: var(--success-bg); color: var(--success); border-color: var(--success-bd); }

/* ---------- Page d'authentification ---------- */
.auth {
    min-height: 100vh;
    display: grid; place-items: center;
    background:
        radial-gradient(1200px 500px at 80% -10%, #e7eefc 0%, transparent 60%),
        var(--bg);
    padding: 24px;
}
.auth__card {
    width: 100%; max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 38px 34px;
}
.auth__brand { text-align: center; margin-bottom: 26px; }
.auth__logo { width: auto; display: inline-block; }
.auth__brand-name { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.auth__brand-sub { font-size: 13px; color: var(--ink-400); font-weight: 600; }
.auth__title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.auth__subtitle { color: var(--ink-500); font-size: 14px; margin: 0 0 24px; }

.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 7px; color: var(--ink-700); }
.form-control {
    width: 100%; padding: 12px 14px; font-size: 15px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff;
    color: var(--ink-900); transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none; border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-hint { font-size: 12.5px; color: var(--ink-400); margin-top: 14px; text-align: center; }

/* ---------- Page de connexion (split-screen) ---------- */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background-color: #fbfcfe;
    background-image: radial-gradient(circle, #dfe5ef 1px, transparent 1.4px);
    background-size: 22px 22px;
}
.login {
    width: 100%;
    max-width: 1040px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #fff;
    border: 1.5px solid #c7d2fe;
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(30, 58, 138, .10);
}

/* Panneau gauche illustré */
.login__left {
    position: relative;
    padding: 60px 52px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
    background: linear-gradient(160deg, #3b5bdb 0%, #2f6bed 55%, #1d4ed8 100%);
    overflow: hidden;
}
.login__left::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: url(/assets/img/login-pattern.svg);
    background-size: 64px auto;
    pointer-events: none;
}
.login__left > * { position: relative; z-index: 1; }
.login__headline { font-size: 38px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 18px; }
.login__lead {
    font-size: 15.5px; line-height: 1.7;
    color: rgba(255, 255, 255, .85); max-width: 430px; margin: 0;
}

/* Illustration "mockup" en verre */
.mock {
    margin-top: 44px; max-width: 380px;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .20);
    border-radius: 16px; padding: 20px 22px;
    backdrop-filter: blur(3px);
}
.mock__dots { display: flex; gap: 7px; margin-bottom: 20px; }
.mock__dots span { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .5); }
.mock__bar { height: 12px; border-radius: 6px; background: rgba(255, 255, 255, .26); margin-bottom: 12px; }
.mock__bar--80 { width: 80%; }
.mock__bar--65 { width: 65%; }
.mock__bar--72 { width: 72%; }
.mock__row { display: flex; align-items: center; justify-content: space-between; margin-top: 24px; }
.mock__circle { width: 58px; height: 58px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .4); }
.mock__btn { width: 110px; height: 36px; border-radius: 9px; background: rgba(255, 255, 255, .20); }

/* Panneau droit (formulaire) */
.login__right { display: flex; align-items: center; justify-content: center; padding: 56px 48px; }
.login__panel { width: 100%; max-width: 360px; }
.login__brand { display: flex; align-items: center; justify-content: center; margin-bottom: 26px; }
.login__brand-img { width: auto; display: block; }
.login__title { text-align: center; font-size: 24px; font-weight: 800; margin: 0 0 6px; }
.login__subtitle { text-align: center; color: var(--ink-500); font-size: 14px; margin: 0 0 28px; }

.login__options {
    display: flex; align-items: center; justify-content: space-between;
    margin: 4px 0 20px; gap: 12px;
}
.remember { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-600); font-size: 14px; cursor: pointer; }
.remember input { width: 16px; height: 16px; accent-color: var(--brand-600); cursor: pointer; }
.login__magic { color: var(--brand-600); font-weight: 600; font-size: 14px; }
.login__magic:hover { text-decoration: underline; }
.remember--center { display: flex; justify-content: center; margin: 0 0 18px; }

@media (max-width: 860px) {
    .login { grid-template-columns: 1fr; max-width: 440px; }
    .login__left { display: none; }
    .login__right { padding: 44px 30px; }
}

/* ---------- Modale ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: none; }
.modal.is-open { display: block; }
body.modal-open { overflow: hidden; }
.modal__overlay { position: absolute; inset: 0; background: rgba(15, 23, 42, .5); }
.modal__dialog {
    position: relative; z-index: 1;
    width: min(560px, calc(100% - 32px));
    max-height: calc(100vh - 48px); overflow: auto;
    margin: 40px auto; background: #fff;
    border-radius: var(--radius); box-shadow: 0 20px 60px rgba(15, 23, 42, .28);
    animation: modalIn .18s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to   { opacity: 1; transform: none; }
}
.modal__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--line);
}
.modal__title { font-size: 18px; font-weight: 700; margin: 0; }
.modal__close {
    width: 34px; height: 34px; display: grid; place-items: center;
    border: none; background: transparent; border-radius: 8px; color: var(--ink-500);
}
.modal__close:hover { background: var(--bg-soft); color: var(--ink-700); }
.modal__close svg { width: 20px; height: 20px; }
.modal__body { padding: 24px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; }
.modal__error { color: var(--danger); font-size: 14px; margin: 0; }

/* Grille de formulaire */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.form-group--full { grid-column: 1 / -1; }
.field-error { color: var(--danger); font-size: 12.5px; margin: 6px 0 0; }
.field-hint { color: var(--ink-400); font-size: 12px; margin: 6px 0 0; }
.form-control--readonly { background: var(--bg-soft); color: var(--ink-500); }
.form-control.has-error {
    border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, .12);
}

/* Édition d'avatar */
.avatar-edit { display: flex; align-items: center; gap: 18px; margin-bottom: 22px; }
.avatar-edit__preview {
    width: 76px; height: 76px; border-radius: 50%; overflow: hidden;
    flex: none; border: 3px solid var(--brand-500);
}
.avatar-edit__preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-edit__fallback { width: 76px; height: 76px; font-size: 26px; }
.avatar-edit__hint { font-size: 12px; color: var(--ink-400); margin: 8px 0 0; }

/* Toast */
.toast {
    position: fixed; right: 24px; bottom: 24px; z-index: 60;
    background: var(--ink-900); color: #fff; padding: 13px 18px;
    border-radius: 10px; font-size: 14px; font-weight: 500;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
    opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s;
}
.toast.is-visible { opacity: 1; transform: none; }
.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }

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

/* ---------- Page Sécurité ---------- */
.security-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
    max-width: 1248px;
}
.security-col { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
@media (max-width: 860px) {
    .security-grid { grid-template-columns: 1fr; }
}
.muted-text { color: var(--ink-500); font-size: 14px; line-height: 1.6; margin: 0 0 18px; }
.table-wrap { overflow-x: auto; }
.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history th {
    text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--ink-400); font-weight: 700; padding: 0 14px 10px 0; border-bottom: 1px solid var(--line);
}
.history td { padding: 11px 14px 11px 0; border-bottom: 1px solid var(--line); color: var(--ink-700); }
.history tr:last-child td { border-bottom: none; }

/* Champ code OTP + lien de renvoi */
.otp-input { letter-spacing: 10px; text-align: center; font-size: 24px; font-weight: 700; }
.otp-resend { text-align: center; margin-top: 14px; }
.link-button {
    background: none; border: none; color: var(--brand-600);
    font-weight: 600; font-size: 14px; cursor: pointer; padding: 0;
}
.link-button:hover { text-decoration: underline; }

/* ---------- Utilitaires ---------- */
.text-muted  { color: var(--ink-400); }
.text-center { text-align: center; }

/* Variantes ponctuelles (évitent tout style inline, CSP stricte) */
.profile__avatar.avatar-fallback { width: 116px; height: 116px; font-size: 38px; }
.security__link svg { width: 16px; height: 16px; }
.topbar__logout { margin-left: 8px; }
.welcome-title { margin: 0 0 8px; font-size: 20px; }
.welcome-text  { color: var(--ink-500); margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .account-grid { grid-template-columns: 1fr; }
    .fields { grid-template-columns: 1fr; }
}
