:root {
  --z-dropdown: 50;
  --z-header: 100;
  --z-modal: 1000;
  --z-alert: 1100;
  --z-loader: 2000;
  --color-primary: #6366f1;
  --color-primary-hover: #818cf8;
  --color-primary-muted: rgba(99, 102, 241, 0.15);
  --color-accent: #a855f7;
  --gradient-brand: linear-gradient(135deg, #6366f1 0%, #9333ea 100%);
  --color-bg: #111827;
  --color-bg-elevated: #1f2937;
  --color-surface: rgba(31, 41, 55, 0.72);
  --color-surface-deep: rgba(17, 24, 39, 0.78);
  --color-border: rgba(255, 255, 255, 0.06);
  --color-border-strong: rgba(255, 255, 255, 0.1);
  --color-text: #f3f4f6;
  --color-text-muted: #9ca3af;
  --color-text-dim: #6b7280;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --mobile-nav-h: 4.25rem;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  overflow-x: hidden;
  background: var(--color-bg);
  color: var(--color-text);
}

::selection {
  background: rgba(99, 102, 241, 0.35);
  color: #fff;
}

.glass-card {
  background: var(--color-surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.glass-panel {
  background: var(--color-surface-deep);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-color: var(--color-border);
}

.ambient-wrap {
  position: relative;
  isolation: isolate;
}

.ambient-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 100% 0%, rgba(99, 102, 241, 0.12), transparent 50%),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(147, 51, 234, 0.08), transparent 45%);
}

/* Contenu au-dessus du fond — ne pas cibler les enfants absolute (blobs décoratifs) */
.ambient-wrap > .ambient-layer {
  position: relative;
  z-index: 1;
}

.grain-overlay::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.kpi-card {
  transition: transform 0.35s var(--ease-out-expo), border-color 0.35s ease, box-shadow 0.35s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--color-border-strong);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(99, 102, 241, 0.08);
}

.kpi-card .kpi-glow {
  position: absolute;
  inset: -40% -20% auto auto;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  filter: blur(48px);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.kpi-card:hover .kpi-glow {
  opacity: 0.35;
}

.nav-item {
  position: relative;
  transition: color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.nav-item--active {
  color: #fff !important;
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.18), rgba(147, 51, 234, 0.08));
  box-shadow: inset 3px 0 0 var(--color-primary);
}

.nav-item--active i {
  color: var(--color-primary-hover) !important;
}

.input-premium {
  background: rgba(31, 41, 55, 0.6);
  border: 1px solid rgba(75, 85, 99, 0.6);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.input-premium:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-muted);
  background: rgba(31, 41, 55, 0.9);
}

.btn-brand {
  background: var(--gradient-brand);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease, filter 0.2s ease;
}

.btn-brand:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 28px rgba(99, 102, 241, 0.45);
}

.btn-brand:active {
  transform: scale(0.98);
}

.custom-scrollbar::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.25);
  border-radius: 999px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.45);
}

.anim-fade {
  animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  will-change: opacity;
}

.scale-in {
  animation: scaleIn 0.45s var(--ease-out-expo) forwards;
  opacity: 0;
  will-change: transform, opacity;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.97) translate3d(0, 12px, 0);
  }
  to {
    opacity: 1;
    transform: scale(1) translate3d(0, 0, 0);
  }
}

.loader {
  border-top-color: var(--color-primary);
  animation: spinner 0.85s linear infinite;
}

@keyframes spinner {
  to { transform: rotate(360deg); }
}

img {
  content-visibility: auto;
}

.content-fade-in {
  animation: contentIn 0.5s var(--ease-out-expo) forwards;
}

@keyframes contentIn {
  from {
    opacity: 0;
    transform: translate3d(0, 8px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

#loading-screen .loader-wrap {
  position: relative;
}

#loading-screen .loader-wrap::before {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.2), transparent 70%);
  animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

@keyframes blob {
  0% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(24px, -40px) scale(1.08); }
  66% { transform: translate(-16px, 16px) scale(0.94); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-14px); }
}

.blob-anim {
  animation: blob 18s infinite alternate ease-in-out;
}

.floating {
  animation: float 7s ease-in-out infinite;
}

/* ——— Page de connexion (layout explicite, ne dépend pas du purge Tailwind) ——— */
.login-page {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
  background: var(--color-bg);
}

.login-page__bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.login-page__form {
  position: relative;
  z-index: 1;
  width: 100%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem 1.5rem;
  background: rgba(17, 24, 39, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.login-page__form-inner {
  width: 100%;
  max-width: 24rem;
}

.login-page__quote {
  display: none;
  position: relative;
  z-index: 1;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  min-height: 0;
}

@media (min-width: 1024px) {
  .login-page {
    flex-direction: row;
    align-items: stretch;
  }

  .login-page__form {
    width: 38%;
    max-width: 28rem;
    min-height: 100%;
    border-bottom: none;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    padding: 3rem 2.5rem;
  }

  .login-page__quote {
    display: flex;
    flex: 1;
    padding: 3rem;
  }
}

@media (min-width: 1280px) {
  .login-page__form {
    width: 33.333%;
  }
}

/* ——— Menu principal ——— */
.main-menu-page {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
  padding: 2rem 1.5rem;
}

.main-menu-page__inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 56rem;
  margin-left: auto;
  margin-right: auto;
}

#app:empty {
  min-height: 100vh;
}

/* ——— Mobile & tactile ——— */
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.touch-target {
  min-height: 44px;
  min-width: 44px;
}

/* Évite le zoom iOS sur focus des champs */
@media (max-width: 767px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .form-grid-2 {
    grid-template-columns: 1fr !important;
  }
}

body.sidebar-open {
  overflow: hidden;
  touch-action: none;
}

/* Masquer blobs décoratifs fixes sur mobile (perf + lisibilité) */
@media (max-width: 767px) {
  .page-blob {
    display: none !important;
  }
}

/* Table → scroll horizontal avec indicateur */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.table-scroll table {
  min-width: 640px;
}

/* Liste cartes mobile */
.mobile-card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.mobile-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 1rem;
  border-radius: 1rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  transition: background 0.2s ease, border-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.mobile-card:active {
  background: rgba(255, 255, 255, 0.06);
}

.mobile-card + .mobile-card {
  margin-top: 0;
}

.desktop-table-only {
  display: none;
}

@media (min-width: 768px) {
  .mobile-only {
    display: none !important;
  }

  .desktop-table-only {
    display: block;
  }
}

@media (max-width: 767px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none !important;
  }
}

/* Modales type bottom-sheet sur mobile */
@media (max-width: 767px) {
  .modal-overlay-mobile {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .modal-sheet-mobile {
    max-height: min(92dvh, calc(100dvh - var(--safe-top) - 1rem));
    border-radius: 1.25rem 1.25rem 0 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .modal-sheet-mobile .modal-body-scroll {
    max-height: calc(92dvh - 8rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-actions-sticky {
    position: sticky;
    bottom: 0;
    padding-bottom: calc(1rem + var(--safe-bottom));
    background: linear-gradient(to top, rgba(17, 24, 39, 0.98) 85%, transparent);
  }
}

/* Barre de navigation basse (app shell) */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 767px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    height: calc(var(--mobile-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    background: rgba(17, 24, 39, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
  }

  .mobile-bottom-nav__btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.35rem 0.25rem;
    color: #6b7280;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: none;
    background: transparent;
    min-height: var(--mobile-nav-h);
    transition: color 0.2s ease;
  }

  .mobile-bottom-nav__btn i {
    font-size: 1.15rem;
  }

  .mobile-bottom-nav__btn--active {
    color: #a5b4fc;
  }

  .mobile-bottom-nav__btn--active i {
    color: #818cf8;
  }

  .layout-main-with-nav {
    padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 0.5rem) !important;
  }

  #main-sidebar {
    padding-top: var(--safe-top);
    padding-bottom: calc(var(--safe-bottom) + var(--mobile-nav-h));
  }

  .layout-header-mobile {
    padding-top: calc(0.5rem + var(--safe-top));
    min-height: calc(3.5rem + var(--safe-top));
  }

  #notif-dropdown {
    position: fixed !important;
    left: 0.5rem !important;
    right: 0.5rem !important;
    top: auto !important;
    bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 0.5rem) !important;
    width: auto !important;
    max-width: none !important;
    transform-origin: bottom center !important;
  }
}

/* Login / menu — safe areas */
@media (max-width: 767px) {
  .login-page__form {
    padding-top: calc(1.5rem + var(--safe-top));
    padding-bottom: calc(1.5rem + var(--safe-bottom));
  }

  .main-menu-page {
    padding-bottom: calc(2rem + var(--safe-bottom));
  }

  .main-menu-page__inner h1 {
    font-size: 2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scale-in,
  .content-fade-in,
  .anim-fade,
  .blob-anim,
  .floating {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .kpi-card:hover {
    transform: none;
  }
}
