/* ==========================================================================
   css/responsive.css — Règles Responsive (>=1280px, 768-1279px, <768px Mobile)
   Garantie d'absence de scroll horizontal de 320px à 1920px+
   ========================================================================== */

/* Structure Desktop (>= 768px) avec Nav enfant direct de <body> */
@media (min-width: 768px) {
  body {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "topbar topbar"
      "nav    main";
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    position: relative;
  }

  .app-topbar {
    grid-area: topbar;
    width: 100%;
    max-width: 100%;
    margin: 0;
    box-sizing: border-box;
    left: 0;
    right: 0;
  }

  .app-nav {
    grid-area: nav;
    margin: 24px 0 24px 20px;
    position: sticky;
    top: 24px;
    align-self: start;
    height: auto;
  }

  .app-main-wrapper {
    grid-area: main;
    min-width: 0;
    padding: 24px 20px 48px 16px;
    box-sizing: border-box;
  }

  .app-shell {
    max-width: 1480px;
    width: 100%;
    box-sizing: border-box;
  }
}

/* ==========================================================================
   ÉCRANS LARGES (>= 1280px)
   ========================================================================== */
@media (min-width: 1280px) {
  .dashboard-grid,
  html[data-theme="lusamine"] .dashboard-grid {
    grid-template-columns: minmax(0, 1.42fr) minmax(0, 1.15fr) minmax(0, 1.1fr);
    gap: var(--gap-grid);
  }

  /* Chips de filtres : sur une seule ligne aux largeurs >= 1280px */
  .filter-chips-row {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .filter-chip-btn {
    padding: 5px 10px;
    font-size: 11px;
    flex-shrink: 0;
  }
}

/* Point 11 : À 1600px+, centrage horizontal du cadre principal dans Ichika et Diantha (margin-inline: auto)
   Réserve de la place à droite (padding-right) uniquement dans Lusamine pour son perso latéral */
@media (min-width: 1600px) {
  html[data-theme="ichika"] .app-main-wrapper,
  html[data-theme="diantha"] .app-main-wrapper {
    padding-left: 20px;
    padding-right: 20px;
  }

  html[data-theme="ichika"] .app-shell,
  html[data-theme="diantha"] .app-shell {
    margin-inline: auto;
  }

  html[data-theme="lusamine"] .app-main-wrapper {
    padding-right: 380px;
  }
}

/* Point 7 : À >= 2000px, centrage aussi du shell dans LUSAMINE et ancrage du perso latéral au bord droit du shell */
@media (min-width: 2000px) {
  html[data-theme="lusamine"] .app-main-wrapper {
    padding-left: 20px;
    padding-right: 20px;
  }

  html[data-theme="lusamine"] .app-shell {
    margin-inline: auto;
  }

  html[data-theme="lusamine"] .lusamine-side-character {
    right: auto;
    left: var(--lusamine-side-left, auto);
  }
}


/* ==========================================================================
   TABLETTES (768px à 1279px) : 2 Colonnes, Sidebar en icônes, Perso latéral masqué
   ========================================================================== */
@media (min-width: 768px) and (max-width: 1279px) {
  /* Réduire la sidebar Lusamine en icônes comme la pilule pour gagner de la place */
  html[data-theme="lusamine"] .app-nav {
    width: 72px;
    padding: 20px 10px;
    border-radius: var(--radius-pill);
    align-items: center;
  }

  html[data-theme="lusamine"] .app-nav .nav-brand-block,
  html[data-theme="lusamine"] .app-nav .nav-label,
  html[data-theme="lusamine"] .app-nav .nav-footer-extra {
    display: none;
  }

  html[data-theme="lusamine"] .app-nav .sidebar-avatar-wrapper {
    display: block;
  }

  html[data-theme="lusamine"] .app-nav .nav-btn {
    width: 44px;
    height: 44px;
    justify-content: center;
    padding: 0;
  }

  /* Grille 2 Colonnes */
  .dashboard-grid {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.15fr);
    gap: var(--gap-grid);
  }

  /* La 3ème colonne (Météo, Notifications, Vocal Radio) passe sous les deux colonnes principales */
  .grid-col:nth-child(3) {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--gap-grid);
    margin-top: 0;
  }

  /* Masquer le perso latéral en dessous de 1600px */
  .lusamine-side-character {
    display: none !important;
  }
}

/* Lusamine Hero Titre & Mode buttons ajustement 900-1150px */
@media (min-width: 850px) and (max-width: 1150px) {
  html[data-theme="lusamine"] .hero-main-title {
    font-size: 15px;
    -webkit-line-clamp: 4;
    line-height: 1.25;
  }
}

/* ==========================================================================
   MOBILES (< 768px) : 1 Colonne, Barre Nav Fixe en Bas
   ========================================================================== */
@media (max-width: 767px) {
  body {
    display: block;
    overflow-x: hidden;
    width: 100%;
  }

  .app-topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .topbar-center {
    order: 3;
    width: 100%;
    max-width: 100%;
    margin: 4px 0 0;
  }

  .topbar-kanji {
    display: none; /* Simplifier sur très petits écrans */
  }

  .theme-tab-btn {
    padding: 4px 8px;
    font-size: 10px;
  }

  /* Shell sur mobile */
  .app-main-wrapper {
    padding: 12px 10px calc(80px + env(safe-area-inset-bottom));
    width: 100%;
    box-sizing: border-box;
  }

  .app-shell {
    padding: 16px 12px;
    border-radius: 24px;
    width: 100%;
    box-sizing: border-box;
  }

  .shell-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .shell-header-left, .shell-header-right {
    width: 100%;
    justify-content: space-between;
  }

  /* 1 Seule Colonne pour la grille */
  .dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
  }

  .grid-col {
    width: 100%;
  }

  /* Hero Mobile : Adapté sans recouvrir le texte */
  .hero-card-container {
    margin-top: 24px;
    min-height: 180px;
    width: 100%;
  }

  .hero-card-content {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 16px calc(35% + 14px) 16px 16px;
    box-sizing: border-box;
  }

  .hero-main-title {
    font-size: 15px;
    line-height: 1.25;
    width: 100%;
    min-width: 0;
  }

  .hero-cta-btn {
    padding: 7px 14px;
    font-size: 11.5px;
    white-space: nowrap;
    max-height: 44px;
    align-self: flex-start;
  }

  .hero-character-wrapper {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 35%;
    max-width: 130px;
    height: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    pointer-events: none;
    z-index: 4;
    -webkit-mask-image: linear-gradient(to right, transparent 0%, black 16px, black 100%);
    mask-image: linear-gradient(to right, transparent 0%, black 16px, black 100%);
  }

  .hero-character-img {
    width: 100%;
    height: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: bottom right;
  }

  /* Modules row passe en 1 colonne ou flex défilant */
  .modules-cards-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Barre Nav Mobile FIXE EN BAS (Enfant direct de <body>) */
  .app-nav {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 62px;
    background-color: var(--surface);
    border-top: 1px solid var(--card-border);
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    margin: 0;
    border-radius: 0;
    backdrop-filter: blur(16px);
    box-sizing: border-box;
  }

  /* Masquer tous les éléments desktop dans la barre mobile */
  .sidebar-avatar-wrapper,
  .nav-brand-block,
  .nav-footer-extra,
  .nav-spacer,
  .nav-tooltip {
    display: none !important;
  }

  .nav-links-list {
    display: flex;
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
    gap: 2px;
    align-items: center;
    margin: 0;
    padding: 0;
  }

  .nav-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    justify-content: center;
  }

  .nav-btn {
    flex: 1 1 0;
    min-width: 0;
    height: 48px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 2px;
    border-radius: var(--radius-xs);
    color: var(--muted);
  }

  .nav-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .nav-label {
    display: block !important;
    font-size: 10px !important;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .nav-btn[aria-current="page"] {
    background-color: var(--input-bg);
    color: var(--accent);
    box-shadow: none;
  }

  /* Masquer le perso latéral sur mobile */
  .lusamine-side-character {
    display: none !important;
  }

  /* Rétablissement de la largeur mobile stricte et suppression de tout scroll horizontal */
  html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }

  .app-shell {
    max-width: 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    padding: 16px !important;
    border-radius: 18px !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  .app-main-wrapper {
    padding: 12px 8px 72px 8px !important;
    max-width: 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  .dashboard-view {
    max-width: 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  .builder-form-card {
    max-width: 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    padding: 16px !important;
  }

  .config-subnav {
    display: flex !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    max-width: 100% !important;
    padding-bottom: 8px;
  }

  .config-nav-btn {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    font-size: 11.5px !important;
    padding: 8px 12px !important;
  }

  .grid-2-col,
  .form-row-2,
  .rules-grid,
  .security-rules-grid,
  .color-editor-grid {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    gap: 14px !important;
  }

  .audit-table-wrapper {
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box !important;
  }

  .color-picker-item,
  .form-group {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  .modern-table {
    display: block !important;
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
  }

  .theme-presets-row {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .tag-input-row {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .tag-input-row input {
    flex: 1 1 140px !important;
    min-width: 0 !important;
  }

  #cfg-pane-themes div[style*="display:flex"] {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
}
