/* ===================================================================
   DEEPSTACK OS — Apple Refinement Layer (v1)
   Affinage typographique, motion et perf — applique au-dessus du design existant
   =================================================================== */

/* ===== Typographie & rendu ===== */
:root {
  --vd-font: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  --vd-mono: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
  --vd-easing: cubic-bezier(0.25, 1, 0.5, 1);
  --vd-easing-out: cubic-bezier(0.16, 1, 0.3, 1);
  --vd-easing-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

body {
  font-family: var(--vd-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv01', 'cv02', 'cv03', 'cv04', 'ss01', 'ss02';
}

/* Tabular numbers partout où c'est utile */
.tabnum, .data-table td, .kpi-card, .badge {
  font-variant-numeric: tabular-nums;
}

/* ===== Headings affinés ===== */
h1, .h1 { letter-spacing: -0.025em; font-weight: 800; }
h2, .h2 { letter-spacing: -0.02em; font-weight: 700; }
h3, .h3 { letter-spacing: -0.015em; font-weight: 700; }

/* ===== Surfaces ===== */
.kpi-card, .data-table, .modal, .slideover {
  border-radius: 14px;
}

.kpi-card {
  transition: transform 350ms var(--vd-easing), box-shadow 350ms var(--vd-easing);
}
.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

/* ===== Boutons : feedback tactile ===== */
button {
  transition: transform 150ms var(--vd-easing), background-color 200ms var(--vd-easing),
              box-shadow 200ms var(--vd-easing), color 200ms var(--vd-easing);
}
button:active {
  transform: scale(0.97);
}
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ===== Inputs : focus ring élégant ===== */
input, select, textarea {
  transition: border-color 200ms var(--vd-easing), box-shadow 200ms var(--vd-easing);
}
input:focus, select:focus, textarea:focus {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 12%, transparent);
  border-color: var(--primary);
  outline: none;
}

/* ===== Table : transitions de hover plus fluides ===== */
.data-table tr {
  transition: background 180ms var(--vd-easing);
}
.data-table tbody tr:hover td {
  background: color-mix(in srgb, var(--primary) 5%, var(--surface));
}

/* ===== Scrollbar : plus fine et discrète ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-muted) 30%, transparent);
  border-radius: 4px;
  transition: background 200ms;
}
::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text-muted) 50%, transparent);
}

/* ===== Badges : raffinement ===== */
.badge {
  font-feature-settings: 'tnum';
  letter-spacing: 0;
  border-radius: 7px;
  padding: 4px 9px;
  font-weight: 600;
  font-size: 11px;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 200ms var(--vd-easing);
}

/* ===== Animations d'entrée pour les écrans ===== */
@keyframes appleFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes appleFadeInScale {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

#main > * {
  animation: appleFadeIn 350ms var(--vd-easing) both;
}

/* Stagger pour les éléments de liste */
.data-table tbody tr {
  animation: appleFadeIn 300ms var(--vd-easing) both;
}
.data-table tbody tr:nth-child(1) { animation-delay: 0ms; }
.data-table tbody tr:nth-child(2) { animation-delay: 20ms; }
.data-table tbody tr:nth-child(3) { animation-delay: 40ms; }
.data-table tbody tr:nth-child(4) { animation-delay: 60ms; }
.data-table tbody tr:nth-child(5) { animation-delay: 80ms; }
.data-table tbody tr:nth-child(n+6) { animation-delay: 100ms; }

/* ===== KPI : amélioration visuelle ===== */
.kpi-card {
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, color-mix(in srgb, var(--primary) 6%, transparent), transparent 60%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 400ms var(--vd-easing);
}
.kpi-card:hover::before {
  opacity: 1;
}

/* ===== Modales : entrée plus naturelle ===== */
.modal {
  transition: transform 350ms var(--vd-easing-out), opacity 350ms var(--vd-easing-out);
}
.modal.open {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* ===== Sidebar : transitions ===== */
.sidebar-item {
  transition: background 200ms var(--vd-easing), color 200ms var(--vd-easing), transform 150ms var(--vd-easing);
}
.sidebar-item:active {
  transform: scale(0.97);
}

/* ===== Lazy loading images : placeholder élégant ===== */
img[loading="lazy"] {
  background: linear-gradient(110deg, var(--surface-2) 30%, var(--bg) 50%, var(--surface-2) 70%);
  background-size: 200% 100%;
  animation: appleShimmer 1.4s linear infinite;
}
img[loading="lazy"][src] {
  animation: none;
  background: var(--surface-2);
}
@keyframes appleShimmer {
  to { background-position: -200% 0; }
}

/* ===== Sélection texte : couleur de marque ===== */
::selection {
  background: color-mix(in srgb, var(--primary) 30%, transparent);
  color: var(--text);
}

/* ===== Toast : meilleure animation ===== */
.toast {
  transition: transform 400ms var(--vd-easing-out), opacity 250ms var(--vd-easing);
  border-radius: 12px;
}

/* ===== Header : densité plus aérée ===== */
#header {
  height: auto;
  padding: 14px 24px;
}

/* ===== Boutons icon-only : ronds parfaits ===== */
button.icon-only,
button[data-icon-only] {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===== Misc raffinements ===== */
* { -webkit-tap-highlight-color: transparent; }

/* Disable animations sur préférence reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Responsive : densité mobile ===== */
@media (max-width: 768px) {
  h1, .h1 { font-size: 22px; }
  .kpi-card { padding: 16px; }
  .data-table th, .data-table td { padding: 8px 12px; font-size: 12px; }
}
