/* ═══════════════════════════════════════════════════════════════════
   Responsive — global responsive baseline for all pages.
   Loaded after components.css, before bookings-mobile.css.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Anti-scroll-x guard (global) ──────────────────────────── */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
.main, .view { min-width: 0; max-width: 100%; }
.view > * { min-width: 0; max-width: 100%; }

/* Tables always get horizontal scroll container */
.data-table, .se-table, .mg-table, .rd-table {
  max-width: 100%;
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* ── Container fluid ───────────────────────────────────── */
.container-fluid { width: 100%; max-width: 100%; padding-inline: var(--s-4); }
@media (min-width: 1024px) { .container-fluid { padding-inline: var(--s-5); } }

/* ── Responsive grid helper ────────────────────────────── */
.grid-auto {
  display: grid;
  gap: var(--s-3);
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
@media (max-width: 480px) { .grid-auto { grid-template-columns: 1fr; } }

/* ── Desktop large (≥1440) ─────────────────────────────── */
@media (min-width: 1440px) {
  .view { padding: var(--s-8) var(--s-6); }
}

/* ── Laptop (≤1280) ───────────────────────────────────── */
@media (max-width: 1280px) {
  .view-head { gap: var(--s-3); }
}

/* ── iPad horizontal (≤1024) ────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 208px; }
  .view { padding: var(--s-5) var(--s-4); }
  .view-actions { gap: 6px; }
  .view-actions input,
  .view-actions select {
    min-width: 0 !important;
    flex: 1 1 140px;
  }
}

/* ── iPad vertical & below (≤768) ──────────────────────── */
@media (max-width: 768px) {
  /* Anti iOS auto-zoom — all editable inputs 16px min */
  input, select, textarea,
  [contenteditable="true"] {
    font-size: 16px !important;
    max-width: 100%;
  }
  /* Touch targets 44px */
  button, .btn, .pin-key, .nav-item,
  .segmented button, .cm-tab, .sb-tab, .gm-btn,
  .ct-tab, .wa-pill, .ftab, .pu-tab {
    min-height: 40px;
  }
  .btn-sm, .btn-icon { min-height: 36px; }
  .view-head { flex-direction: column; align-items: stretch; }
  .view-actions { width: 100%; flex-wrap: wrap; }
  .view-title { font-size: var(--fs-xl); }
  .data-table { font-size: 13px; }
  .stat { padding: var(--s-3) var(--s-4); }

  /* Page-local grids default to single column */
  .two-col, .sb-form-row, .mg-form,
  .ct-body, .se-wrap {
    grid-template-columns: 1fr !important;
  }

  /* Segmented controls scroll instead of wrap */
  .segmented {
    overflow-x: auto;
    flex-wrap: nowrap;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }
  .segmented button,
  .segmented .cm-tab,
  .segmented .sb-tab { flex-shrink: 0; }
}

/* ── Mobile large (≤640) ──────────────────────────────── */
@media (max-width: 640px) {
  .view { padding: var(--s-3); }
  .view-title { font-size: var(--fs-lg); }
  .card { padding: var(--s-4); }

  /* KPIs 2 cols in narrow tablets */
  .kpi-grid,
  [id$="kpis"],
  .sb-kpis,
  .pu-kpis {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ── Mobile small (≤480) ──────────────────────────────── */
@media (max-width: 480px) {
  .view { padding: var(--s-3) var(--s-2); }
  .view-title { font-size: var(--fs-md); letter-spacing: -0.01em; }
  .kpi-grid,
  [id$="kpis"],
  .sb-kpis,
  .pu-kpis { grid-template-columns: 1fr !important; }
  .toast { min-width: 200px; max-width: calc(100vw - 32px); }
  .drawer { width: 100vw !important; }

  /* Modals become bottom sheets */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }

  /* Generic tables fallback when no per-page cards defined */
  .data-table:not(.no-stack) thead {
    position: absolute;
    left: -9999px;
    top: -9999px;
  }
  .data-table:not(.no-stack) tbody tr {
    display: block;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
  }
  .data-table:not(.no-stack) tbody td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    border: none;
    font-size: 13px;
    text-align: right;
  }
  .data-table:not(.no-stack) tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .04em;
    text-align: left;
  }
}

/* ── Safe area (iOS notch/home bar) ────────────────────── */
@supports (padding: max(0px)) {
  .topbar {
    padding-left: max(var(--s-5), env(safe-area-inset-left));
    padding-right: max(var(--s-5), env(safe-area-inset-right));
  }
  .sidebar { padding-bottom: max(var(--s-4), env(safe-area-inset-bottom)); }
  .toast-root { bottom: max(var(--s-5), env(safe-area-inset-bottom)); }
}

/* ── Reduce hover visual noise on touch devices ────────── */
@media (hover: none) {
  .card.is-interactive:hover { transform: none; }
  .nav-item:hover { background: transparent; }
}

/* ══════════════════════════════════════════════════════════
   Bottom nav (mobile only)
   ══════════════════════════════════════════════════════════ */
.bottom-nav { display: none; }

@media (max-width: 768px) {
  /* Topbar search collapses to icon-only */
  .topbar-search {
    flex: 0 0 auto;
    max-width: none;
    min-width: 0;
    padding: 8px 10px;
    gap: 0;
  }
  .topbar-search > span { display: none; }
  .topbar-search > svg { flex-shrink: 0; }

  /* Leave room for bottom nav */
  .view, .wa-wrap, #bd-drawer {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .bd-foot { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    background: color-mix(in srgb, var(--surface-raised) 92%, transparent);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid var(--border-subtle);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 0;
  }
  .bn-item {
    background: transparent;
    border: 0;
    padding: 6px 4px 4px;
    color: var(--text-tertiary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    font: inherit;
    min-height: auto;
    border-radius: 10px;
    transition: color .15s ease;
  }
  .bn-item .bn-ic {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
  }
  .bn-item .bn-lb {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: -0.005em;
    line-height: 1.1;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .bn-item.on { color: var(--brand-500); }
  .bn-item.on .bn-lb { font-weight: 700; }

  /* Centre FAB — AI chat */
  .bn-item.bn-fab {
    position: relative;
    top: -14px;
    background: var(--brand-500);
    color: #fff;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    justify-self: center;
    align-self: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 6px 18px rgba(14, 82, 89, 0.35);
  }
  .bn-item.bn-fab .bn-lb {
    position: absolute;
    bottom: -16px;
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 600;
  }
  .bn-item.bn-fab.on { background: var(--brand-600); color: #fff; }
  .bn-item.bn-fab.on .bn-lb { color: var(--brand-500); }
}

/* ══════════════════════════════════════════════════════════
   Bottom sheet (Reservas sub-menu)
   ══════════════════════════════════════════════════════════ */
.bn-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 210;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s ease;
}
.bn-sheet-backdrop.open { opacity: 1; }
.bn-sheet {
  width: 100%;
  max-width: 560px;
  background: var(--surface-raised);
  border-radius: 18px 18px 0 0;
  padding: 8px 12px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.25);
  transform: translateY(100%);
  transition: transform .24s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 80dvh;
  overflow-y: auto;
}
.bn-sheet-backdrop.open .bn-sheet { transform: translateY(0); }
.bn-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 6px auto 10px;
}
.bn-sheet-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 0 8px 8px;
}
.bn-sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 12px;
  background: transparent;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  color: var(--text-primary);
  font: inherit;
  min-height: 56px;
}
.bn-sheet-item:hover,
.bn-sheet-item:active { background: var(--surface-hover); }
.bn-sheet-ic {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--brand-50);
  color: var(--brand-500);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.bn-sheet-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bn-sheet-lb {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}
.bn-sheet-sub {
  font-size: 12px;
  color: var(--text-secondary);
}
.bn-sheet-chev {
  color: var(--text-tertiary);
  flex-shrink: 0;
}
