/*
 * Couche de convergence web → app.
 * La palette et les dimensions de primitives suivent mobile/src/theme.
 * Ce fichier reste chargé après style.css afin de ne pas disperser les overrides.
 */

:root {
    color-scheme: dark;
    --bg: #0d0e13;
    --bg-card: #16181f;
    --bg-card-hover: #1c1f28;
    --bg-input: #1c1f28;
    --bg-elevated: #1a1c24;
    --sidebar-bg: #111318;
    --border: #22252e;
    --border-light: #2a2d38;
    --text: #e8e9ed;
    --text-secondary: #8b8fa3;
    --text-muted: #565a6e;
    --accent: #c9a55c;
    --accent-light: #dbb86e;
    --accent-bg: rgba(201, 165, 92, 0.12);
    --accent-glow: rgba(201, 165, 92, 0.06);
    --accent-ink: #111111;
    --green: #2dd4a0;
    --green-bg: rgba(45, 212, 160, 0.12);
    --red: #f06060;
    --red-bg: rgba(240, 96, 96, 0.10);
    --orange: #f5a623;
    --orange-bg: rgba(245, 166, 35, 0.12);
    --blue: #5b9fe6;
    --shadow: rgba(0, 0, 0, 0.45);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --focus-ring: 0 0 0 3px var(--accent-bg);
    --bottomnav-h: 62px;
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-card-hover: #f7f7f9;
    --bg-input: #f3f3f6;
    --bg-elevated: #ffffff;
    --sidebar-bg: #ffffff;
    --border: #e3e3e8;
    --border-light: #ececf1;
    --text: #1a1a1f;
    --text-secondary: #5b5e6e;
    --text-muted: #8d91a3;
    --accent: #a8853b;
    --accent-light: #c9a55c;
    --accent-bg: rgba(168, 133, 59, 0.10);
    --accent-glow: rgba(168, 133, 59, 0.06);
    --accent-ink: #ffffff;
    --green: #0f8466;
    --green-bg: rgba(15, 132, 102, 0.10);
    --red: #d7423c;
    --red-bg: rgba(215, 66, 60, 0.08);
    --orange: #c9740d;
    --orange-bg: rgba(201, 116, 13, 0.10);
    --blue: #3174c2;
    --shadow: rgba(15, 17, 28, 0.10);
}

html {
    background: var(--bg);
    scroll-padding-top: 68px;
}

body {
    min-height: 100dvh;
    background: var(--bg);
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
summary,
a {
    -webkit-tap-highlight-color: transparent;
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

:where(input, select, textarea):focus-visible {
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
    outline: none;
}

::selection {
    color: var(--text);
    background: var(--accent-bg);
}

/* Primitives partagées */
.card,
.kpi-card,
.account-card,
.bank-card {
    border-color: var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
}

.card {
    padding: 16px;
}

:where(.input-field, .form-group input, .form-group select, .form-group textarea, .search-input) {
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-size: 15px;
}

:where(.input-field, .form-group input, .form-group select, .form-group textarea)::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

:where(.pill, .filter-pill, .scope-pill, .forecast-pill) {
    border-color: var(--border);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-weight: 600;
}

:where(.pill, .filter-pill, .scope-pill, .forecast-pill).active,
:where(.pill, .filter-pill, .scope-pill, .forecast-pill)[aria-current="true"],
:where(.pill, .filter-pill, .scope-pill, .forecast-pill)[aria-pressed="true"] {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: var(--accent-light);
}

:where(.badge, .card-badge, .status-badge) {
    border-radius: 999px;
}

.badge {
    padding: 3px 8px;
    font-size: 0.7rem;
    font-weight: 700;
}

.btn {
    min-height: 44px;
    border-radius: var(--radius);
}

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

[data-theme="light"] .btn-primary,
[data-theme="light"] .top-bar-avatar,
[data-theme="light"] .user-avatar {
    color: var(--accent-ink);
}

/* Shell et barre supérieure */
.app-layout {
    padding-bottom: calc(96px + var(--safe-bottom));
}

.top-bar {
    min-height: 52px;
    padding: 8px 16px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
}

.page-title {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-bar-actions {
    gap: 8px;
}

.top-notif-btn,
.top-bar-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 999px;
}

.top-notif-btn {
    border-color: var(--border);
    background: var(--bg-card);
}

.top-bar-avatar,
.user-avatar {
    background: var(--accent);
    color: var(--accent-ink);
}

.top-company-switcher {
    display: none;
}

.top-user-menu-header {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.top-user-menu-company,
.top-user-menu-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-user-menu-company {
    color: var(--text);
    font-size: 0.84rem;
    font-weight: 700;
}

.top-user-menu-email {
    color: var(--text-secondary);
    font-size: 0.74rem;
}

.top-user-menu-link {
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 600;
}

/* Barre de navigation flottante, calée sur BottomNav.tsx */
.bottom-nav {
    --active-center: 10%;
    height: var(--bottomnav-h);
    bottom: calc(16px + var(--safe-bottom));
    padding: 8px 6px;
    overflow: visible;
    background: rgba(255, 255, 255, 0.55);
    border-color: rgba(0, 0, 0, 0.06);
    box-shadow: 0 10px 20px var(--shadow);
}

[data-theme="dark"] .bottom-nav {
    background: rgba(22, 24, 31, 0.68);
    border-color: rgba(255, 255, 255, 0.10);
    box-shadow: 0 10px 20px var(--shadow);
}

.bottom-nav::before {
    content: "";
    position: absolute;
    z-index: -1;
    top: 8px;
    left: calc(var(--active-center) - 26px);
    width: 52px;
    height: 30px;
    border-radius: 14px;
    background: var(--accent-bg);
}

.bottom-nav.shell-nav-ready::before {
    transition: left 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bottom-nav-item {
    position: relative;
    z-index: 1;
    min-height: 46px;
    padding: 0 2px;
    gap: 3px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
}

.bottom-nav-item svg {
    width: 20px;
    height: 20px;
    padding: 4px 14px;
    border-radius: 13px;
    transition: none;
}

.bottom-nav-item.active,
.bottom-nav-item[aria-current="page"] {
    color: var(--accent);
}

.bottom-nav-item.active svg,
.bottom-nav-item[aria-current="page"] svg {
    color: var(--accent);
    background: transparent;
}

/* Plus : navigation secondaire uniquement, sous forme de feuille d'accès rapides */
.mobile-more {
    position: static;
}

.mobile-more-backdrop {
    display: none;
}

.mobile-more[open] .mobile-more-backdrop {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(0, 0, 0, 0.45);
}

.mobile-more-panel {
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 140;
    padding: 8px 10px calc(22px + var(--safe-bottom));
    border-radius: 20px 20px 0 0;
    background: var(--bg-card);
}

.mobile-more[open] .mobile-more-panel {
    display: block;
}

.mobile-more-handle {
    display: block;
    width: 42px;
    height: 5px;
    margin: 0 auto 8px;
    border-radius: 3px;
    background: var(--border);
}

.mobile-more-title {
    display: block;
    margin: 0 8px 12px;
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
}

.mobile-more-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
    gap: 8px;
    padding: 0 4px;
}

.mobile-more-panel .mobile-more-grid a {
    min-height: 92px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 6px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-card-hover);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

.mobile-more-panel .mobile-more-grid a:hover,
.mobile-more-panel .mobile-more-grid a:focus-visible,
.mobile-more-panel .mobile-more-grid a[aria-current="page"] {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: var(--text);
}

.mobile-more-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--accent-bg);
    color: var(--accent);
}

/* Menu compte : feuille mobile, menu ancré sur grand écran */
@media (max-width: 899px) {
    .top-user-menu[open]::before {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 118;
        pointer-events: none;
        background: rgba(0, 0, 0, 0.45);
    }

    .top-user-menu-panel {
        position: fixed;
        inset: auto 0 0;
        z-index: 120;
        min-width: 0;
        padding: 0 8px calc(20px + var(--safe-bottom));
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -12px 30px var(--shadow);
    }
}

/* Sidebar desktop : adaptation de densité, sans toucher aux routes/permissions */
@media (min-width: 900px) {
    :root {
        --sidebar-width: 240px;
    }

    .app-layout {
        padding-bottom: 0;
    }

    .sidebar {
        background: var(--sidebar-bg);
        border-color: var(--border);
    }

    .sidebar::before {
        display: none;
    }

    .sidebar-header {
        min-height: 68px;
        padding: 18px 20px;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-nav {
        gap: 4px;
        padding: 14px 10px;
    }

    .nav-item {
        min-height: 42px;
        border-radius: var(--radius);
        color: var(--text-secondary);
    }

    .nav-item:hover {
        background: var(--bg-card-hover);
        color: var(--text);
    }

    .nav-item.active,
    .nav-item[aria-current="page"] {
        background: var(--accent-bg);
        color: var(--accent-light);
        font-weight: 700;
    }

    .sidebar-footer {
        background: var(--sidebar-bg);
    }

    .user-menu {
        background: var(--bg-card);
    }

    .top-bar {
        min-height: 60px;
        padding: 10px 28px;
    }

    .top-company-switcher {
        display: block;
    }

    .page-title {
        font-size: 22px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto !important;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0ms !important;
    }
}

@supports not (background: color-mix(in srgb, white, black)) {
    .top-bar {
        background: var(--bg);
    }
}
