/* ==========================================================================
   HKS Dashboard — version mobile / tablette (1.54.0)
   Tablette : ≤ 1024px · Smartphone : ≤ 640px
   ========================================================================== */

/* ---------- Tablette et smartphone ---------- */
@media (max-width: 1024px) {
  .hksdi-shell { display: block; }
  .hksdi-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 100; width: 272px; max-width: 86vw; transform: translateX(-105%); transition: transform .22s ease; box-shadow: 20px 0 50px rgba(25,32,51,.22); overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .hksdi-shell.is-menu-open .hksdi-sidebar { transform: translateX(0); }
  .hksdi-mobile-toggle { position: fixed; left: 12px; top: 12px; z-index: 110; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 12px; background: #111318; color: #fff; font-size: 17px; cursor: pointer; }
  .hksdi-shell.is-menu-open .hksdi-mobile-toggle { left: 284px; }
  .hksdi-mobile-backdrop { position: fixed; inset: 0; z-index: 95; background: rgba(15,23,42,.5); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .hksdi-shell.is-menu-open .hksdi-mobile-backdrop { opacity: 1; pointer-events: auto; }
  .hksdi-sidebar-toggle { display: none !important; }
  .hksdi-sidebar .hksdi-nav-link { min-height: 44px; }

  .hksdi-topbar { position: sticky; top: 0; z-index: 90; padding: 10px 12px 10px 66px; min-height: 64px; gap: 8px; background: rgba(255,255,255,.96); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid #e5e7eb; }
  .hksdi-topbar-title { display: block !important; min-width: 0; flex: 1 1 0%; }
  .hksdi-top-actions { flex: 0 0 auto !important; width: auto !important; max-width: 60%; margin-left: auto; order: 2; justify-content: flex-end; }
  .hksdi-search { order: 3; }
  .hksdi-topbar-title strong { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hksdi-topbar-title small { display: none; }
  .hksdi-content { padding: 16px 14px 96px; }
  .hksdi-kpi-grid, .hksdi-relations { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .hksdi-page-heading { gap: 10px; }
  .hksdi-page-heading h1 { font-size: 24px; }
  .hksdi-heading-actions { flex-wrap: wrap; }
  .hksdi-card { border-radius: 12px; }
  .hksdi-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .hksdi-shortcode-panel { padding: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .hksdi-mini-button { min-width: 40px; min-height: 40px; }
  .hksdi-primary-button, .hksdi-outline-button { min-height: 42px; }
  button, input, select, textarea { font-size: 16px; } /* évite le zoom automatique iOS */
  .hks-pf-filter, [data-hksdi-filters] button { font-size: 13px; }

  /* Barre de navigation basse */
  .hksdi-bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 94; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #111318; color: #fff; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 24px rgba(15,23,42,.25); }
  .hksdi-bottom-nav a, .hksdi-bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; border: 0; background: transparent; color: #c7ccd6; font: 700 11px/1.1 inherit; text-decoration: none; border-radius: 10px; -webkit-tap-highlight-color: transparent; }
  .hksdi-bottom-nav i { font-size: 18px; }
  .hksdi-bottom-nav .is-active { color: #fff; background: #e4032e; }
  .hksdi-shell.is-menu-open .hksdi-bottom-nav { display: none; }
}

/* ---------- Smartphone ---------- */
@media (max-width: 640px) {
  .hksdi-topbar { flex-wrap: wrap; padding-right: 10px; }
  .hksdi-search { order: 3; flex-basis: 100%; width: 100%; margin: 2px 0 0; }
  .hksdi-search input { height: 38px; }
  .hksdi-topbar-user > summary > span { display: none; }
  .hksdi-topbar-usermenu-panel { position: fixed !important; left: 10px !important; right: 10px !important; top: 66px !important; width: auto !important; max-width: none !important; min-width: 0 !important; }
  .hksdi-content { padding: 12px 10px 96px; }
  .hksdi-page-heading { flex-direction: column; align-items: stretch; }
  .hksdi-page-heading h1 { font-size: 21px; }
  .hksdi-page-heading p { font-size: 13px; }
  .hksdi-heading-actions { width: 100%; }
  .hksdi-heading-actions > * { flex: 1 1 auto; }
  .hksdi-kpi .hksdi-kpi-icon { width: 36px; height: 36px; font-size: 15px; }
  .hksdi-kpi strong { font-size: 22px; }
  .hksdi-card-heading { flex-direction: column; align-items: stretch; gap: 10px; }
  .hksdi-card-heading > div:last-child { width: 100%; }
  .hksdi-card-heading input[type="search"] { width: 100%; min-width: 0 !important; }
  [data-hks-pf-filters], [data-hksdi-filters] { display: flex; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; scrollbar-width: none; }
  [data-hks-pf-filters]::-webkit-scrollbar { display: none; }
  [data-hks-pf-filters] button { flex: 0 0 auto; }
  .hks-pf-grid { grid-template-columns: 1fr !important; }
  small { font-size: 12px; }

  /* Tableaux du dashboard → cartes empilées (libellés injectés par dashboard-mobile.js) */
  .hksdi-table-scroll { overflow: visible; }
  .hksdi-table.is-cards { min-width: 0 !important; width: 100%; border-collapse: separate; border-spacing: 0; }
  .hksdi-table.is-cards thead { display: none; }
  .hksdi-table.is-cards, .hksdi-table.is-cards tbody, .hksdi-table.is-cards tr, .hksdi-table.is-cards td { display: block; width: 100%; box-sizing: border-box; }
  .hksdi-table.is-cards tr { margin: 0 0 10px; padding: 6px 12px; border: 1px solid #e5e7eb; border-radius: 12px; background: #fff; }
  .hksdi-table.is-cards tr[hidden] { display: none; }
  .hksdi-table.is-cards td { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 7px 0 !important; border: 0 !important; border-bottom: 1px dashed #eef0f3 !important; font-size: 13px !important; text-align: left !important; white-space: normal !important; }
  .hksdi-table.is-cards td:last-child { border-bottom: 0 !important; }
  .hksdi-table.is-cards td::before { content: attr(data-label); flex: 0 0 38%; max-width: 38%; font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: #6b7280; padding-top: 1px; }
  .hksdi-table.is-cards td[data-label=""]::before, .hksdi-table.is-cards td.hksdi-cards-full::before { display: none; }
  .hksdi-table.is-cards td.hksdi-cards-full { justify-content: flex-end; flex-wrap: wrap; }
  .hksdi-table.is-cards td.hksdi-cards-empty { display: none; }
  .hksdi-table.is-cards .hksdi-cards-value { flex: 1 1 auto; min-width: 0; text-align: right; }
  .hksdi-table.is-cards td:first-child .hksdi-cards-value { text-align: left; }
  .hksdi-table.is-cards .hksdi-cards-value small { display: block; white-space: normal; }
  .hksdi-table.is-cards .hksdi-cards-value .hks-pf-tag-envoye { white-space: normal; }
  .hksdi-table.is-cards .hksdi-cards-value > div { width: 100%; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .hksdi-table.is-cards .hksdi-cards-value form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; width: 100%; }
  .hksdi-table.is-cards .hksdi-cards-value form span { text-align: right; }
  .hksdi-table.is-cards td[colspan] { display: block; text-align: center !important; }
  .hksdi-table.is-cards td[colspan]::before { display: none; }

  /* Fenêtres (modales) plein écran */
  .hksdi-modal { padding: 0; align-items: stretch; }
  .hksdi-modal-panel { max-width: 100% !important; width: 100%; min-height: 100%; border-radius: 0; }
  .hksdi-modal-head { position: sticky; top: 0; background: #fff; z-index: 2; }
  .hksdi-modal-body { padding: 16px 14px; }
}

/* ---------- Très petits écrans ---------- */
@media (max-width: 360px) {
  .hksdi-kpi-grid, .hksdi-relations { grid-template-columns: 1fr; }
  .hksdi-bottom-nav a, .hksdi-bottom-nav button { font-size: 10px; }
}

/* ---------- Grand écran : rien ne change ---------- */
@media (min-width: 1025px) {
  .hksdi-bottom-nav, .hksdi-mobile-backdrop { display: none !important; }
}

/* ---------- Application installée (PWA) ---------- */
@media (display-mode: standalone) and (max-width: 1024px) {
  .hksdi-topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
}
