/* ==========================================================================
   RESPONSIVE DESIGN & ERGONOMIE MOBILE - ANIME PODCAST STUDIO
   Adaptabilité mobile, tablette et grand écran
   Sidebar CRM sur PC & Bottom Navigation Bar sur Mobile (style application native)
   Protection absolue contre le zoom accidentel iOS/Android
   ========================================================================== */

/* Fix universel du zoom mobile sur focus des formulaires */
input, textarea, select {
  font-size: 16px !important;
  touch-action: manipulation;
}

/* ==========================================================================
   DESKTOP (>= 901px) : la sidebar affiche déjà le logo et le nom du site,
   on évite la répétition dans le header
   ========================================================================== */
@media (min-width: 901px) {
  .app-top-header .header-brand,
  .app-top-header .header-divider {
    display: none;
  }
}

/* ==========================================================================
   TABLETTE & GRANDS ÉCRANS INTERMÉDIAIRES (< 1120px)
   ========================================================================== */
@media (max-width: 1120px) {
  .studio-main {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 16px;
  }

  .config-sidebar {
    order: 2;
  }

  .preview-panel {
    order: 1;
  }
}

/* ==========================================================================
   MOBILE & PETITES TABLETTES (< 900px)
   Bascule de la Sidebar CRM vers la Bottom Navigation Bar (Application Native)
   ========================================================================== */
@media (max-width: 900px) {
  .app-container {
    flex-direction: column;
  }

  /* 1. Masquer la sidebar PC */
  .crm-sidebar {
    display: none !important;
  }

  /* 2. Header Top centré sur mobile (style Sukishort / AutoAMV) */
  .app-top-header {
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
    padding-bottom: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    overflow: hidden;
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 0;
    background-color: #09090b !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .app-top-header .header-left {
    gap: 10px;
    min-width: 0;
    width: 100%;
    justify-content: center;
  }

  .app-top-header .header-brand {
    gap: 10px;
    justify-content: center;
  }

  .app-top-header .header-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex-shrink: 0;
    border: none;
    background: transparent;
    box-shadow: none;
  }

  .app-top-header .header-title {
    font-family: var(--font-main) !important;
    font-weight: 800 !important;
    font-size: 1.5rem !important;
    letter-spacing: -0.01em;
    white-space: nowrap;
    line-height: 1;
    text-transform: none !important;
  }

  .app-top-header .header-badge,
  .app-top-header .header-divider,
  .app-top-header .header-tagline,
  .app-top-header .header-meta-item,
  .app-top-header .header-right {
    display: none !important;
  }

  /* 3. Ajuster le corps pour la barre du bas */
  .studio-main {
    padding: 14px 12px;
    gap: 16px;
    /* Dégagement pour ne jamais masquer les cartes sous la bottom bar */
    padding-bottom: calc(75px + env(safe-area-inset-bottom, 14px)) !important;
  }

  .studio-card {
    padding: 16px;
    border-radius: var(--radius-md);
  }

    /* 4. BARRE DE NAVIGATION DU BAS (Mobile Bottom Nav - Icônes uniquement) */
  .mobile-bottom-nav {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background-color: rgba(13, 13, 17, 0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle);
    z-index: 1000;
    align-items: center;
    justify-content: space-around;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.7);
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
    text-decoration: none;
    transition: all var(--transition-fast);
    touch-action: manipulation;
    user-select: none;
  }

  .mobile-nav-item span {
    display: none !important;
  }

  .mobile-nav-item svg {
    width: 24px;
    height: 24px;
    transition: transform var(--transition-fast), color var(--transition-fast);
  }

  .mobile-nav-item:active {
    transform: scale(0.9);
  }

  .mobile-nav-item.active {
    color: var(--gold-primary);
  }

  .mobile-nav-item.active svg {
    color: var(--gold-primary);
    transform: scale(1.15);
    filter: drop-shadow(0 0 10px var(--gold-glow));
  }

  /* Anti-débordement horizontal strict & Anti-zoom mobile */
  html, body, .app-container, .crm-main-content, .crm-page, .studio-main, .studio-card, .config-sidebar, .preview-panel {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  .card-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .card-header > div {
    width: 100%;
    display: flex !important;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* Cibles tactiles et retour à la ligne pour ne jamais déborder */
  .btn {
    min-height: 48px;
    font-size: 0.95rem;
    padding: 12px 14px;
    touch-action: manipulation;
    white-space: normal !important;
    text-align: center !important;
    word-break: break-word !important;
    line-height: 1.3 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .btn svg {
    flex-shrink: 0;
  }

  .btn-sm {
    min-height: 42px;
    padding: 8px 14px;
    font-size: 0.85rem;
  }

  .tab-btn {
    min-height: 46px;
    font-size: 0.88rem;
  }

  /* Pills d'attitudes tactiles et espacées */
  .poses-preview-bar {
    gap: 10px;
    max-height: 220px;
  }

  .pose-pill {
    min-height: 44px;
    padding: 8px 14px;
    font-size: 0.84rem;
  }

  /* Sélecteur de mascottes en 2 colonnes confortables */
  .mascot-picker {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .mascot-card {
    padding: 14px 10px;
    min-height: 140px;
  }

  .mascot-thumbnail {
    width: 80px;
    height: 80px;
  }

  /* Entrées de formulaire adaptées au toucher */
  .form-input,
  .form-select,
  .form-textarea {
    min-height: 48px;
    font-size: 16px !important;
    padding: 12px 14px;
  }

  .form-textarea {
    min-height: 120px;
  }

  /* Contrôles de lecture Canvas */
  .canvas-controls-bar {
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
    padding: 14px;
  }

  .playback-controls {
    justify-content: space-between;
    width: 100%;
  }

  .btn-play {
    width: 52px;
    height: 52px;
  }

  /* Bouton d'export plein écran mobile */
  #btn-export-video {
    width: 100%;
    min-height: 52px;
    font-size: 1rem;
  }

  /* Timeline & Segments adaptés aux doigts */
  .waveform-box {
    height: 70px;
  }

  .segment-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .segment-card > div:last-child {
    display: grid !important;
    grid-template-columns: 1fr 90px !important;
    gap: 8px !important;
    width: 100%;
  }

  .segment-pose-select {
    min-height: 44px;
    font-size: 16px !important;
    padding: 8px 10px;
    max-width: 100%;
  }

  /* Modale pleine largeur mobile */
  .modal-backdrop {
    padding: 10px;
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 12px));
  }

  .modal-card {
    padding: 18px 14px;
    max-height: 92vh;
    border-radius: var(--radius-md);
  }

  .bulk-upload-dropzone {
    padding: 24px 14px;
  }

  .bulk-dropzone-title {
    font-size: 0.95rem;
  }

  .bulk-review-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Nouvelles pages SPA - Adaptations mobile */
  .page-header {
    padding: 16px 14px 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .page-title {
    font-size: 1.15rem;
  }

  .mascots-full-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 14px 12px;
  }

  .mascot-full-card {
    padding: 14px;
  }

  .mascot-full-thumb {
    width: 72px;
    height: 72px;
  }

  .history-list {
    padding: 14px 12px;
  }

  .history-entry {
    flex-direction: column;
    align-items: flex-start;
    padding: 14px;
  }

  #page-settings .studio-card {
    margin: 0 12px 14px;
  }

  #page-settings .studio-card:first-of-type {
    margin-top: 14px;
  }

  .logs-console {
    max-height: 280px;
    font-size: 0.72rem;
  }

  /* Dégagement bas pour toutes les pages (bottom nav safe area) */
  .crm-page {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 14px));
  }
}

/* Écrans très étroits (< 380px) */
@media (max-width: 380px) {
  .mascot-picker {
    grid-template-columns: 1fr;
  }

  .brand-title {
    font-size: 0.95rem;
  }

  .btn {
    font-size: 0.88rem;
    padding: 10px 14px;
  }

  .mobile-nav-item span {
    font-size: 0.68rem;
  }
}
