/* ============================================================
   Storia Mundi — CSS global
   Complément de StoriaMundiTheme.cs pour tout ce que MudBlazor
   ne peut pas exprimer via son système de thème.
   ============================================================ */

/* ─── 1. Tokens CSS ──────────────────────────────────────────
   Miroir des valeurs de StoriaMundiTheme.cs.
   UNE SEULE couleur sombre : --sm-color-dark (#18243A bleu nuit).
   ──────────────────────────────────────────────────────────── */
:root {
    --sm-color-primary:         #8d5062;
    --sm-color-primary-dark:    #6b3a49;
    --sm-color-primary-light:   #d4a0ac;
    --sm-color-dark:            #18243A;   /* bleu nuit — header, drawer, bottom nav */
    --sm-color-background:      #F8F5EF;   /* ivoire */
    --sm-color-surface:         #ffffff;
    --sm-color-text-primary:    #1C1A18;
    --sm-color-text-secondary:  #6B5D52;
    --sm-color-divider:         rgba(26, 18, 18, 0.10);

    --sm-font-heading:          'Playfair Display', serif;
    --sm-font-body:             'Inter', sans-serif;

    --sm-radius:                4px;
    --sm-appbar-height:         64px;
    --sm-bottom-nav-height:     72px;
    --sm-transition:            0.2s ease;
}

/* ─── 2. Base ────────────────────────────────────────────────*/
html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--sm-font-body);
    color: var(--sm-color-text-primary);
    background-color: var(--sm-color-background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Playfair Display pour les titres éditoriaux uniquement */
h1, h2, h3, h4, h5, h6,
.mud-typography-h1, .mud-typography-h2, .mud-typography-h3,
.mud-typography-h4, .mud-typography-h5, .mud-typography-h6 {
    font-family: var(--sm-font-heading);
}

/* Inter pour tous les éléments d'interface */
.mud-button-root,
.mud-button-root *,
.mud-chip,
.mud-chip *,
.mud-nav-link,
.mud-nav-link * {
    font-family: var(--sm-font-body);
}

/* Pas de text-transform uppercase sur les boutons */
.mud-button-root {
    text-transform: none !important;
}

/* ─── 3. AppBar — 64px, bleu nuit ───────────────────────────*/
.mud-appbar {
    height: var(--sm-appbar-height) !important;
    min-height: var(--sm-appbar-height) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
}

.mud-main-content {
    padding-bottom: 24px;
}

/* ─── 4. Logo ────────────────────────────────────────────────
   max-height strict pour rester dans les 64px de l'AppBar.
   max-width pour éviter que le logo ne prenne toute la place.
   ──────────────────────────────────────────────────────────── */
.sm-logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
    margin-right: 8px;
}

.sm-logo {
    height: 48px;
    max-height: 48px;
    width: auto;
    max-width: 160px;
    object-fit: contain;
    display: block;
}

/* ─── 5. Navigation desktop ──────────────────────────────────
   Visible par défaut (desktop). Cachée sur mobile.
   ──────────────────────────────────────────────────────────── */
.sm-desktop-nav {
    display: flex;
    align-items: center;
    height: 100%;
    margin: 0 8px;
}

@media (max-width: 959px) {
    .sm-desktop-nav { display: none; }
}

.sm-nav-link {
    display: flex;
    align-items: center;
    height: var(--sm-appbar-height);
    padding: 0 16px;
    font-family: var(--sm-font-body);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: color var(--sm-transition), border-color var(--sm-transition);
    white-space: nowrap;
}

.sm-nav-link:hover {
    color: #ffffff;
    border-bottom-color: var(--sm-color-primary-light);
}

.sm-nav-link.active {
    color: #ffffff;
    border-bottom-color: var(--sm-color-primary);
}

/* ─── 6. Hamburger et boutons desktop-only ───────────────────*/
.sm-hamburger {
    display: none;
}

@media (max-width: 959px) {
    .sm-hamburger { display: flex !important; }
}

.sm-auth-desktop {
    display: flex;
}

@media (max-width: 959px) {
    .sm-auth-desktop { display: none !important; }
}

/* ─── 7. Drawer (mobile) ─────────────────────────────────────
   Fond bleu nuit — même couleur que l'AppBar.
   ──────────────────────────────────────────────────────────── */
.mud-drawer,
.mud-drawer-content,
aside.mud-drawer {
    background-color: var(--sm-color-dark) !important;
}

.mud-navmenu,
.mud-navmenu-content {
    background-color: var(--sm-color-dark) !important;
}

.mud-nav-link {
    color: rgba(255, 255, 255, 0.85) !important;
    min-height: 52px !important;
    font-size: 0.95rem !important;
}

.mud-nav-link:hover {
    background-color: rgba(255, 255, 255, 0.08) !important;
}

.mud-nav-link.active {
    background-color: rgba(141, 80, 98, 0.20) !important;
    color: #ffffff !important;
    border-left: 3px solid var(--sm-color-primary);
}

.mud-nav-link .mud-nav-link-text,
.mud-nav-link span,
.mud-nav-link svg {
    color: inherit !important;
}

/* ─── 8. Bottom navigation bar (mobile) ─────────────────────
   Hors de MudLayout dans le template — position:fixed fonctionne.
   Cachée sur desktop, visible sur mobile (< 960px).
   ──────────────────────────────────────────────────────────── */
.sm-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--sm-bottom-nav-height);
    background-color: var(--sm-color-dark);
    border-top: 1px solid rgba(255, 255, 255, 0.10);
    z-index: 1200;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

@media (max-width: 959px) {
    .sm-bottom-nav {
        display: flex;
        align-items: stretch;
    }

    /* Espace pour que le contenu ne soit pas caché par la barre */
    .mud-main-content {
        padding-bottom: calc(var(--sm-bottom-nav-height) + 16px) !important;
    }
}

.sm-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    font-family: var(--sm-font-body);
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    padding: 8px 4px;
    transition: color var(--sm-transition);
    position: relative;
    -webkit-tap-highlight-color: transparent;
    min-width: 44px;   /* cible tactile minimum */
}

.sm-bottom-nav-item .mud-icon-root {
    font-size: 1.5rem !important;
    width: 1.5rem !important;
    height: 1.5rem !important;
}

.sm-bottom-nav-item:hover,
.sm-bottom-nav-item.active {
    color: var(--sm-color-primary-light);
}

/* Trait bordeaux en haut de l'item actif */
.sm-bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 2px;
    background-color: var(--sm-color-primary);
    border-radius: 0 0 2px 2px;
}

/* ─── 9. Bandeau de page (.sm-page-header) ──────────────────
   Utilisé sur toutes les pages de listing comme header visuel.
   Fond bleu nuit, texte blanc, coins arrondis.
   ──────────────────────────────────────────────────────────── */
.sm-page-header {
    background-color: var(--sm-color-dark);
    color: #ffffff;
    padding: 2rem;
    border-radius: var(--sm-radius);
}

/* ─── 9b. Contenu riche HTML (.sm-rich-content) ─────────────
   Appliqué aux descriptions HTML injectées via MarkupString
   (conférences, séries). Remplace les blocs <style> inline.
   ──────────────────────────────────────────────────────────── */
.sm-rich-content {
    line-height: 1.8;
    text-align: justify;
}

.sm-rich-content p { margin-bottom: 1rem; }

.sm-rich-content h1,
.sm-rich-content h2,
.sm-rich-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-family: var(--sm-font-heading);
}

.sm-rich-content ul,
.sm-rich-content ol {
    margin-left: 2rem;
    margin-bottom: 1rem;
}

.sm-rich-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--sm-radius);
    margin: 1rem 0;
}

/* ─── 10. Cards (MudCard) ────────────────────────────────────
   Hover subtil sur toutes les cards MudBlazor.
   ──────────────────────────────────────────────────────────── */
.mud-card {
    transition: box-shadow var(--sm-transition), transform var(--sm-transition);
}

.mud-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(141, 80, 98, 0.15) !important;
}

/* ─── 10. Formulaires ────────────────────────────────────────*/
.valid.modified:not([type=checkbox]) {
    outline: 2px solid #2a7a4a;
    outline-offset: 1px;
}

.invalid {
    outline: 2px solid #c0392b;
    outline-offset: 1px;
}

.validation-message {
    color: #c0392b;
    font-size: 0.85rem;
    margin-top: 4px;
}

/* ─── 11. Focus (accessibilité) ─────────────────────────────*/
:focus-visible {
    outline: 3px solid var(--sm-color-primary);
    outline-offset: 2px;
    border-radius: var(--sm-radius);
}

:focus:not(:focus-visible) {
    outline: none;
}

/* ─── 12. Erreur Blazor ──────────────────────────────────────*/
#blazor-error-ui {
    background: var(--sm-color-dark);
    color: rgba(255, 255, 255, 0.9);
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.4);
    display: none;
    left: 0;
    padding: 12px 20px;
    position: fixed;
    width: 100%;
    z-index: 9999;
    font-size: 0.875rem;
    font-family: var(--sm-font-body);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 16px;
    top: 12px;
}

/* ─── 13. Écran de chargement ────────────────────────────────*/
#app {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sm-loading-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.sm-loading-spinner {
    width: 52px;
    height: 52px;
    border: 5px solid rgba(141, 80, 98, 0.15);
    border-top: 5px solid var(--sm-color-primary);
    border-radius: 50%;
    animation: sm-spin 0.9s linear infinite;
}

@keyframes sm-spin {
    to { transform: rotate(360deg); }
}

.sm-loading-text {
    color: var(--sm-color-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.03em;
}

.loading-progress {
    position: relative;
    display: block;
    width: 64px;
    height: 64px;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: rgba(141, 80, 98, 0.15);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--sm-color-primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 600;
    inset: calc(50% - 0.75rem) 0 auto 0;
    font-size: 0.75rem;
    font-family: 'Inter', sans-serif;
    color: var(--sm-color-primary);
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Chargement");
}

/* ─── 14. Sidebar utilisateur — desktop authentifié ─────────
   Panneau latéral gauche visible uniquement sur desktop (≥ 960px)
   quand l'utilisateur est connecté. Sur mobile, le drawer
   hamburger + la bottom nav gèrent la navigation.
   ──────────────────────────────────────────────────────────── */
.sm-with-sidebar {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - var(--sm-appbar-height));
}

.sm-user-sidebar {
    display: none;
    width: 240px;
    flex-shrink: 0;
    background-color: var(--sm-color-dark);
    min-height: calc(100vh - var(--sm-appbar-height));
    position: sticky;
    top: var(--sm-appbar-height);
    flex-direction: column;
    overflow-y: auto;
    padding-top: 8px;
}

.sm-sidebar-main {
    flex: 1;
    min-width: 0;
}

@media (min-width: 960px) {
    .sm-user-sidebar { display: flex; }
}

/* Titre de section dans le sidebar — même style que le DrawerHeader mobile */
.sm-user-sidebar .sm-sidebar-title {
    color: var(--sm-color-primary);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 16px 16px 8px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Bouton déconnexion — aligné avec les nav-links sombres */
.sm-sidebar-logout {
    justify-content: flex-start !important;
    color: rgba(255, 255, 255, 0.85) !important;
    min-height: 52px !important;
    padding: 0 16px !important;
    font-size: 0.95rem !important;
}

.sm-sidebar-logout:hover {
    background-color: rgba(255, 255, 255, 0.08) !important;
}

.sm-sidebar-logout * {
    color: inherit !important;
}

/* ─── 15. Card grid à taille fixe ───────────────────────────
   Flex-wrap : les cards ont une largeur fixe et laissent un espace
   blanc sur la droite quand la ligne n'est pas remplie.
   Sur mobile (< 600px), chaque card prend toute la largeur.
   ──────────────────────────────────────────────────────────── */
.sm-card-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.sm-card-grid-item {
    width: 320px;
    flex-shrink: 0;
}

@media (max-width: 599px) {
    .sm-card-grid-item {
        width: 100%;
    }
}
