/* ==========================================================================
   RESPONSIVE — el panel completo funciona en móvil y tablet
   - Barra superior compacta
   - La barra lateral pasa a "dock" inferior con scroll horizontal
   - Las tablas se convierten en tarjetas
   - Los modales se abren como hojas desde abajo
   ========================================================================== */

html, body { max-width: 100vw; overflow-x: hidden; }
img, svg, video { max-width: 100%; }

@media (max-width: 980px) {
  :root { --dock-h: 66px; }

  /* ---- Barra superior ---- */
  .panel-navbar { padding: 8px 12px; gap: 8px; flex-wrap: nowrap; min-width: 0; }
  .nav-left, .nav-right { min-width: 0; gap: 8px; }
  .nav-left { flex: 1 1 auto; }
  .nav-right { flex: 0 1 auto; justify-content: flex-end; }
  .brand-tag, .db-live-indicator { display: none !important; }
  .nav-brand { gap: 8px; }
  .brand-info { flex-direction: column; gap: 0; }
  .brand-name { font-size: 0.95rem; }

  .preview-selector-wrap { padding: 4px 10px; min-width: 0; max-width: 150px; }
  .preview-selector-wrap span { display: none; }
  .preview-selector-wrap select { max-width: 130px; text-overflow: ellipsis; font-size: 0.74rem; }

  .user-chip { padding: 3px 10px 3px 3px; max-width: 170px; }
  .user-meta { min-width: 0; }
  .user-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; }
  .user-role-badge { font-size: 0.55rem; padding: 1px 6px; }

  .preview-mode-bar { padding: 8px 12px; font-size: 0.74rem; flex-wrap: wrap; gap: 8px; }

  /* ---- Dock inferior ---- */
  #view-dashboard:not(.hidden) { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "banner" "main"; }
  .panel-tabs-bar {
    position: fixed !important;
    top: auto !important;
    left: 0; right: 0; bottom: 0;
    z-index: 90;
    height: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    flex-direction: row !important;
    align-items: stretch !important;
    gap: 2px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x proximity;
    border: 0 !important;
    border-top: 1px solid var(--border-medium) !important;
    background: rgba(18, 18, 20, 0.88) !important;
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    scrollbar-width: none;
  }
  .panel-tabs-bar::-webkit-scrollbar { display: none; }
  .tabs-group { flex-direction: row !important; gap: 2px !important; align-items: stretch; }
  .tabs-group-label, .tabs-group-divider, .tab-perm-badge, .tab-free-badge { display: none !important; }
  .panel-tab-btn {
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    width: auto !important;
    min-width: 68px;
    max-width: 92px;
    padding: 6px 8px !important;
    border-radius: 14px !important;
    font-size: 0.62rem !important;
    line-height: 1.1;
    text-align: center;
    scroll-snap-align: center;
    white-space: normal;
  }
  .panel-tab-btn:hover { transform: none; }
  .panel-tab-btn > span:not(.tab-badge) { flex: 0 0 auto !important; max-width: 80px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .panel-tab-btn.active::before { left: 28%; right: 28%; top: -6px; bottom: auto; width: auto; height: 3px; border-radius: 0 0 4px 4px; }
  .panel-tab-btn .tab-badge { position: absolute; top: 2px; right: 8px; margin: 0; padding: 0 5px; font-size: 0.55rem; }

  .panel-content { padding: 18px 14px calc(var(--dock-h) + 36px + env(safe-area-inset-bottom, 0px)); gap: 20px; }

  /* ---- Cabeceras de sección y herramientas ---- */
  .section-toolbar { flex-direction: column !important; align-items: stretch !important; gap: 12px !important; }
  .toolbar-actions { width: 100%; flex-wrap: wrap; gap: 8px; }
  .toolbar-actions > * { flex: 1 1 auto; }
  .search-input-wrap { width: 100%; max-width: none; }
  .section-title { font-size: 1.3rem; }

  .stats-grid { grid-template-columns: 1fr; gap: 12px; }
  .alert-grid-layout, .nerthia-grid, .reviews-workspace-grid, .notes-grid, .canned-responses-grid, .broadcast-presets-grid { grid-template-columns: 1fr !important; }
  .form-row-2, .input-row-2 { grid-template-columns: 1fr !important; }
  .support-subnav-bar { overflow-x: auto; flex-wrap: nowrap; max-width: 100%; scrollbar-width: none; }
  .support-subnav-bar::-webkit-scrollbar { display: none; }
  .support-subnav-btn { flex: 0 0 auto; white-space: nowrap; }
  .tool-card-header { flex-wrap: wrap; }
  .tool-search-row { flex-direction: column; align-items: stretch; }

  /* ---- Toasts ---- */
  .toast-container { left: 12px !important; right: 12px !important; top: 12px !important; bottom: auto !important; align-items: stretch; }
  .toast { max-width: none; }

  /* Controles táctiles cómodos */
  .btn-primary, .btn-secondary, .btn-table-action, .btn-mini, .sx-chip, .sx-tab { min-height: 40px; }
  input, select, textarea { font-size: 16px !important; } /* evita el zoom automático en iOS */
}

/* ---- Tablas -> tarjetas ---- */
@media (max-width: 760px) {
  .table-responsive { overflow: visible; }
  .apple-table, .apple-table tbody, .apple-table tr, .apple-table td { display: block; width: 100%; }
  .apple-table thead { display: none; }
  .apple-table tbody { display: grid; gap: 10px; padding: 10px; }
  .apple-table tbody tr {
    padding: 12px 14px;
    border: 1px solid var(--border-subtle) !important;
    border-radius: 16px;
    background: rgba(118, 118, 128, 0.1);
  }
  .apple-table tbody tr:hover { background: rgba(118, 118, 128, 0.16); }
  .apple-table td { padding: 6px 0 !important; border: 0 !important; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: right; min-width: 0; }
  .apple-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: left;
  }
  .apple-table td:first-child { justify-content: flex-start; padding-bottom: 8px !important; border-bottom: 1px solid var(--border-subtle) !important; margin-bottom: 4px; }
  .apple-table td:first-child::before { content: none; }
  .apple-table td.text-right { flex-direction: column; align-items: stretch; text-align: left; }
  .apple-table td.text-right::before { content: none; }
  .action-buttons-group { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-start; }
  .action-buttons-group > * { flex: 1 1 calc(50% - 6px); }
  .table-loading, .table-empty-state { text-align: center; justify-content: center; }
}

/* ---- Modales como hoja inferior ---- */
@media (max-width: 640px) {
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal-card, .modal-card-wide {
    max-width: none !important;
    width: 100% !important;
    max-height: 92vh !important;
    border-radius: 24px 24px 0 0 !important;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    animation: sheetUp 0.45s var(--spring-ease) both !important;
  }
  .modal-footer, .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-footer > *, .modal-actions > * { width: 100%; }
  .sx-tabs { display: flex; width: 100%; }
  .sx-tab { flex: 1 1 auto; padding: 8px 6px; font-size: 0.78rem; }
  .sx-detail-card { padding: 16px; }
}
@keyframes sheetUp { from { transform: translateY(100%); opacity: 0.6; } to { transform: none; opacity: 1; } }

/* Login en pantallas pequeñas */
@media (max-width: 480px) {
  .login-card { padding: 32px 20px 24px; border-radius: 24px; }
  .login-title { font-size: 1.45rem; }
}

@media (max-width: 620px) {
  .panel-navbar { padding: 8px 10px; }
  .nav-left { flex: 0 0 auto; }
  .brand-info { display: none; }
  .nav-right { flex: 1 1 auto; gap: 6px; }
  .preview-selector-wrap { flex: 1 1 auto; max-width: none; min-width: 0; }
  .preview-selector-wrap select { width: 100%; max-width: none; }
  .user-meta { display: none; }
  .user-chip { padding: 3px; max-width: none; }
  .stat-number-row { flex-wrap: wrap; row-gap: 2px; }
  .stat-number { font-size: 1.5rem; }
}
