/* ===========================================
   RESPONSIVE.CSS - Media Queries
   =========================================== */

/* ===========================================
   DESKTOP LARGE (> 1400px)
   =========================================== */

@media (min-width: 1400px) {
  :root {
    --sidebar-width: 480px;
  }

  .kpis-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* ===========================================
   DESKTOP (1024px - 1400px)
   =========================================== */

@media (min-width: 1024px) and (max-width: 1399px) {
  .kpis-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ===========================================
   TABLET (640px - 1023px)
   =========================================== */

@media (max-width: 1023px) {
  :root {
    --sidebar-width: 100%;
    --header-height: 60px;
  }

  .app-main {
    flex-direction: column;
    padding: var(--space-md);
  }

  .params-sidebar {
    width: 100%;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .mobile-tabs {
    display: block;
  }

  .mobile-tabs-list {
    display: flex;
  }

  /* Sections cachées par défaut sur tablette/mobile */
  .tab-section {
    display: none;
  }

  .tab-section.active {
    display: block;
  }

  .kpis-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-container {
    height: 250px;
  }

  /* Header compact */
  .header-logo h1 {
    font-size: var(--font-size-lg);
  }

  .header-actions {
    gap: var(--space-sm);
  }

  .btn span.hide-tablet {
    display: none;
  }

  /* Modale pleine largeur */
  .modal {
    max-width: 100%;
    margin: var(--space-md);
    max-height: calc(100vh - var(--space-lg) * 2);
  }

  /* Toast repositionné */
  .toast-container {
    left: var(--space-md);
    right: var(--space-md);
    bottom: var(--space-md);
  }

  .toast {
    width: 100%;
  }
}

/* ===========================================
   MOBILE (< 640px)
   =========================================== */

@media (max-width: 639px) {
  :root {
    --header-height: 56px;
    --space-lg: 16px;
    --space-xl: 24px;
  }

  html {
    font-size: 14px;
  }

  .app-header {
    padding: 0 var(--space-md);
  }

  .header-logo img {
    width: 32px;
    height: 32px;
  }

  .header-logo h1 {
    font-size: var(--font-size-base);
  }

  .header-actions .btn span {
    display: none;
  }

  .app-main {
    padding: var(--space-sm);
    gap: var(--space-sm);
  }

  /* KPIs en grille 2 colonnes */
  .kpis-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }

  .kpi-card {
    padding: var(--space-sm);
    min-height: 120px;
  }

  .kpi-value {
    font-size: 1.25rem;
  }

  .kpi-icon {
    width: 28px;
    height: 28px;
  }

  .kpi-icon i {
    width: 14px;
    height: 14px;
  }

  .kpi-info {
    width: 18px;
    height: 18px;
    font-size: 10px;
  }

  .kpi-label {
    font-size: 10px;
  }

  .kpi-subtext {
    font-size: 10px;
  }

  /* Grilles en 1 colonne */
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  /* Cards */
  .glass-card {
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  /* Charts */
  .chart-container {
    height: 200px;
  }

  /* Sections paramètres plus compactes */
  .param-section-header {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
  }

  .param-section-body {
    padding: var(--space-sm) var(--space-md);
  }

  /* Form groups */
  .form-group {
    margin-bottom: var(--space-sm);
  }

  .form-label {
    font-size: var(--font-size-xs);
  }

  .form-input,
  .form-select {
    padding: var(--space-sm);
    font-size: var(--font-size-sm);
  }

  .slider-value {
    font-size: var(--font-size-xs);
    padding: 2px var(--space-xs);
  }

  /* Boutons */
  .btn {
    padding: var(--space-sm);
    font-size: var(--font-size-sm);
  }

  .btn-lg {
    padding: var(--space-sm) var(--space-md);
  }

  /* Tables */
  .data-table {
    font-size: var(--font-size-xs);
  }

  .data-table th,
  .data-table td {
    padding: var(--space-xs) var(--space-sm);
  }

  /* Table responsive - scroll horizontal */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(var(--space-md) * -1);
    padding: 0 var(--space-md);
  }

  .table-wrapper .data-table {
    min-width: 600px;
  }

  /* Modale */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 85vh;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-md);
  }

  /* Tabs */
  .tabs {
    flex-wrap: wrap;
  }

  .tab-btn {
    flex: 1 1 45%;
    padding: var(--space-sm);
    font-size: var(--font-size-xs);
  }

  /* Mobile tabs */
  .mobile-tab-btn {
    padding: var(--space-sm);
  }

  .mobile-tab-btn span {
    display: none;
  }

  /* Comparaison */
  .comparison-grid {
    grid-template-columns: 1fr;
  }

  /* Personnalisation */
  .customize-grid {
    grid-template-columns: 1fr;
  }

  .customize-item {
    padding: var(--space-sm);
    font-size: var(--font-size-xs);
  }

  /* Simulation list */
  .simulation-item {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .simulation-actions {
    width: 100%;
    justify-content: flex-end;
  }

  /* Footer */
  .app-footer {
    padding: var(--space-sm);
    font-size: var(--font-size-xs);
  }

  /* Hide non-essential elements */
  .hide-mobile {
    display: none !important;
  }

  /* Tooltip repositionné pour mobile */
  .tooltip::after {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    max-width: calc(100vw - 32px);
    font-size: 12px;
  }

  .kpi-info.tooltip::after {
    left: auto;
    right: 0;
    bottom: auto;
    top: 100%;
    transform: none;
    width: 180px;
    max-width: 180px;
    font-size: 10px;
  }
}

/* ===========================================
   TRÈS PETIT ÉCRAN (< 360px)
   =========================================== */

@media (max-width: 359px) {
  :root {
    --space-md: 12px;
  }

  html {
    font-size: 13px;
  }

  .kpis-grid {
    grid-template-columns: 1fr;
  }

  .header-logo h1 {
    display: none;
  }

  .mobile-tab-btn i {
    font-size: 1rem;
  }
}

/* ===========================================
   ORIENTATIONS
   =========================================== */

/* Paysage sur mobile */
@media (max-width: 896px) and (orientation: landscape) {
  .app-main {
    flex-direction: row;
  }

  .params-sidebar {
    width: 40%;
    max-height: calc(100vh - var(--header-height) - var(--space-md) * 2);
    overflow-y: auto;
  }

  .results-area {
    width: 60%;
  }

  .mobile-tabs {
    display: none;
  }

  .tab-section {
    display: block !important;
  }

  .chart-container {
    height: 180px;
  }
}

/* ===========================================
   PRÉFÉRENCES UTILISATEUR
   =========================================== */

/* Réduction des animations */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  body {
    animation: none;
    background-size: 100% 100%;
  }

  .kpi-card:hover,
  .glass-card:hover {
    transform: none;
  }
}

/* Mode contraste élevé */
@media (prefers-contrast: high) {
  :root {
    --glass-bg: rgba(0, 0, 0, 0.8);
    --glass-border: rgba(255, 255, 255, 0.5);
  }

  .form-input,
  .form-select {
    border-width: 2px;
  }

  .btn {
    border-width: 2px;
  }
}

/* ===========================================
   PRINT
   =========================================== */

@media print {
  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  body {
    font-size: 12pt;
    line-height: 1.4;
  }

  .app-header,
  .mobile-tabs,
  .params-sidebar,
  .btn,
  .toast-container,
  .modal-overlay {
    display: none !important;
  }

  .app-main {
    display: block;
    padding: 0;
  }

  .results-area {
    width: 100%;
  }

  .glass-card {
    border: 1px solid #ddd;
    page-break-inside: avoid;
    margin-bottom: 1rem;
  }

  .kpis-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .kpi-card {
    border: 1px solid #ddd;
  }

  .chart-container {
    height: auto;
    max-height: 300px;
  }

  .data-table {
    border: 1px solid #ddd;
  }

  .data-table th,
  .data-table td {
    border: 1px solid #ddd;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
}
