/* =========================================================================
   az-student — Design system (mobile-first, PWA, thème clair + sombre)
   Couche moderne posée au-dessus de Bootstrap. Tout est piloté par des
   tokens CSS : changer la marque = changer quelques variables ci-dessous.
   ========================================================================= */

:root {
    /* Marque */
    --brand: #8B4513;
    --brand-600: #7a3d11;
    --brand-700: #632f0b;
    --brand-ink: #ffffff;
    --brand-soft: rgba(139, 69, 19, .10);

    /* Surfaces & texte (clair) */
    --bg: #f5f3f1;
    --surface: #ffffff;
    --surface-2: #efece9;
    --text: #1b1613;
    --text-muted: #7c7169;
    --border: rgba(27, 22, 19, .09);

    /* Sémantique */
    --success: #17835a;
    --success-soft: rgba(23, 131, 90, .12);
    --danger: #c53b2f;
    --danger-soft: rgba(197, 59, 47, .12);
    --warning: #b07d10;
    --warning-soft: rgba(176, 125, 16, .14);
    --info: #2b6cb0;

    /* Rayons */
    --r-sm: 10px;
    --r: 16px;
    --r-lg: 22px;
    --r-pill: 999px;

    /* Ombres */
    --shadow-sm: 0 1px 2px rgba(27, 22, 19, .06), 0 1px 3px rgba(27, 22, 19, .04);
    --shadow: 0 4px 16px rgba(27, 22, 19, .08);
    --shadow-lg: 0 12px 32px rgba(27, 22, 19, .14);

    /* Divers */
    --nav-h: 64px;
    --content-max: 640px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --brand: #c98a56;
        --brand-600: #b97b48;
        --brand-700: #a86a3a;
        --brand-ink: #1a1108;
        --brand-soft: rgba(201, 138, 86, .16);

        --bg: #141110;
        --surface: #1e1a17;
        --surface-2: #292320;
        --text: #f3eeea;
        --text-muted: #a99c92;
        --border: rgba(255, 255, 255, .10);

        --success: #46c088;
        --success-soft: rgba(70, 192, 136, .16);
        --danger: #ef6a5f;
        --danger-soft: rgba(239, 106, 95, .16);
        --warning: #e0ad4c;
        --warning-soft: rgba(224, 173, 76, .18);

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

/* ---- Base ------------------------------------------------------------- */
* { -webkit-tap-highlight-color: transparent; }

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

a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4, h5, h6 { color: var(--text); }

/* ---- App shell -------------------------------------------------------- */
.app-shell {
    max-width: var(--content-max);
    margin-inline: auto;
    padding: 0 16px;
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 24px);
    min-height: 100vh;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 2px calc(14px + env(safe-area-inset-top, 0px));
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: saturate(150%) blur(12px);
}

.app-topbar .brand {
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -.02em;
    color: var(--text);
}
.app-topbar .brand span { color: var(--brand); }

.topbar-avatar {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--r-pill);
    background: var(--brand-soft); color: var(--brand);
    border: 1px solid var(--border);
}

/* ---- Bottom navigation (mobile-first) --------------------------------- */
.bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(160%) blur(14px);
    border-top: 1px solid var(--border);
}

.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: .68rem;
    font-weight: 600;
    padding-top: 6px;
    transition: color .15s ease;
}
.bottom-nav a svg { width: 24px; height: 24px; }
.bottom-nav a.active { color: var(--brand); }
.bottom-nav a.active svg { transform: translateY(-1px); }

/* ---- Cards ------------------------------------------------------------ */
.card-soft {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow-sm);
    padding: 18px;
}

.section-title {
    font-size: .82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin: 24px 2px 10px;
}

/* ---- Balance card ----------------------------------------------------- */
.balance-card {
    position: relative;
    overflow: hidden;
    border-radius: var(--r-lg);
    padding: 22px;
    color: #fff;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-700) 100%);
    box-shadow: var(--shadow);
}
.balance-card::after {
    content: "";
    position: absolute;
    right: -40px; top: -60px;
    width: 180px; height: 180px;
    background: rgba(255, 255, 255, .12);
    border-radius: 50%;
}
.balance-card .label { font-size: .8rem; opacity: .85; letter-spacing: .04em; }
.balance-card .amount { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; margin-top: 4px; }
.balance-card .amount small { font-size: 1rem; font-weight: 600; opacity: .8; }
.balance-card .meta { position: relative; margin-top: 14px; font-size: .8rem; opacity: .9; }

/* ---- Quick actions ---------------------------------------------------- */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 16px;
}
.quick-actions.cols-3 { grid-template-columns: repeat(3, 1fr); }
.quick-action {
    display: flex; flex-direction: column; align-items: center; gap: 7px;
    padding: 14px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-size: .74rem; font-weight: 600; text-align: center;
    transition: transform .12s ease, box-shadow .12s ease;
}
.quick-action:active { transform: scale(.96); }
.quick-action .ico {
    width: 42px; height: 42px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--r-pill);
    background: var(--brand-soft); color: var(--brand);
}
.quick-action .ico svg { width: 22px; height: 22px; }

/* ---- Transactions list ------------------------------------------------ */
.tx-list { display: flex; flex-direction: column; gap: 2px; }
.tx-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: 0; }
.tx-ico {
    flex: 0 0 auto;
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--r-pill);
}
.tx-ico svg { width: 20px; height: 20px; }
.tx-ico.credit { background: var(--success-soft); color: var(--success); }
.tx-ico.debit { background: var(--danger-soft); color: var(--danger); }
.tx-body { flex: 1; min-width: 0; }
.tx-body .t { font-weight: 600; font-size: .92rem; }
.tx-body .s { font-size: .76rem; color: var(--text-muted); }
.tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amount.credit { color: var(--success); }
.tx-amount.debit { color: var(--text); }

/* ---- Buttons ---------------------------------------------------------- */
.btn-brand {
    background: var(--brand); color: var(--brand-ink);
    border: none; border-radius: var(--r-pill);
    font-weight: 700; padding: 13px 22px;
    box-shadow: var(--shadow-sm);
    transition: filter .15s ease, transform .1s ease;
}
.btn-brand:hover { color: var(--brand-ink); filter: brightness(1.05); }
.btn-brand:active { transform: scale(.98); }
.btn-ghost {
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--r-pill);
    font-weight: 700; padding: 13px 22px;
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-block { display: block; width: 100%; text-align: center; }

/* ---- Chips / badges --------------------------------------------------- */
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 11px; border-radius: var(--r-pill);
    font-size: .74rem; font-weight: 700;
    background: var(--surface-2); color: var(--text-muted);
}
.chip.ok { background: var(--success-soft); color: var(--success); }
.chip.warn { background: var(--warning-soft); color: var(--warning); }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--brand-soft); color: var(--brand); }

/* ---- Forms ------------------------------------------------------------ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 7px; color: var(--text); }
.input, .select, textarea.input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 13px 14px;
    color: var(--text);
    font-size: 1rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .select:focus, textarea.input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.amount-field {
    display: flex; align-items: baseline; gap: 8px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r); padding: 16px 18px;
}
.amount-field input {
    border: none; background: transparent; outline: none;
    font-size: 2rem; font-weight: 800; color: var(--text);
    width: 100%; font-variant-numeric: tabular-nums;
}
.amount-field .cur { font-weight: 700; color: var(--text-muted); }

.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.preset {
    padding: 11px; border-radius: var(--r-sm);
    border: 1px solid var(--border); background: var(--surface);
    font-weight: 700; color: var(--text); text-align: center; cursor: pointer;
}
.preset.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

/* ---- QR display ------------------------------------------------------- */
.qr-frame {
    display: inline-block;
    padding: 16px;
    background: #fff;
    border-radius: var(--r);
    box-shadow: var(--shadow);
}
.qr-frame img { display: block; width: 240px; height: 240px; }

/* ---- Auth (connexion, activation, code secret) ------------------------ */
.auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    padding-top: calc(32px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
}

.auth-shell { width: 100%; max-width: 420px; }

.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-brand img {
    width: auto; height: 76px;
    border-radius: 22px;
    
}
.auth-brand .name {
    font-size: 1.5rem; font-weight: 800;
    letter-spacing: -.02em; margin-top: 14px;
}
.auth-brand .name span { color: var(--brand); }
.auth-brand .tagline { color: var(--text-muted); font-size: .87rem; margin-top: 2px; }

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    padding: 26px 22px;
}
.auth-title { font-size: 1.18rem; font-weight: 700; margin: 0 0 4px; }
.auth-sub { color: var(--text-muted); font-size: .86rem; margin: 0 0 22px; }

.auth-alert {
    display: flex; gap: 9px; align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--r-sm);
    font-size: .85rem; line-height: 1.4;
    margin-bottom: 18px;
}
.auth-alert svg { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 1px; }
.auth-alert.err { background: var(--danger-soft); color: var(--danger); }
.auth-alert.ok { background: var(--success-soft); color: var(--success); }
.auth-alert ul { margin: 0; padding-left: 16px; }

.auth-links {
    display: flex; justify-content: space-between; gap: 12px;
    margin-top: 16px; font-size: .85rem; font-weight: 600;
}
.auth-foot {
    text-align: center;
    color: var(--text-muted);
    font-size: .78rem;
    margin-top: 26px;
}

/* Champ mot de passe avec bascule d'affichage */
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 48px; }
.pw-toggle {
    position: absolute; right: 5px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none; padding: 9px;
    color: var(--text-muted); cursor: pointer;
    display: inline-flex; align-items: center;
}
.pw-toggle:hover { color: var(--text); }

.field-err { color: var(--danger); font-size: .8rem; margin-top: 6px; }

/* ---- Empty state ------------------------------------------------------ */
.empty {
    text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty svg { width: 56px; height: 56px; opacity: .5; margin-bottom: 12px; }

/* ---- Helpers ---------------------------------------------------------- */
.text-muted-2 { color: var(--text-muted); }
.stack > * + * { margin-top: 12px; }
.hide-mobile { display: none; }
@media (min-width: 768px) {
    .hide-mobile { display: initial; }
    .bottom-nav { display: none; }
    .app-shell { padding-bottom: 40px; }
}
