/* Capa responsiva del escritorio: ventanas angostas y formularios/modulos
   abiertos en el telefono dentro del chasis movil (includes/header.php). */
@media (max-width: 980px) {
  body,
  .app-shell {
    overflow-x: hidden;
  }

  .content,
  .card,
  .dashboard,
  .dashboard-card,
  .metric-card {
    min-width: 0;
    max-width: 100%;
  }

  .app-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    height: 100vh;
    width: min(82vw, 320px);
    transition: left 0.25s ease;
    z-index: 20;
    padding-top: 5rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-header {
    display: flex;
  }

  .app-shell.sidebar-open .sidebar {
    left: 0;
  }

  .app-shell.sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 15;
  }

  .content {
    padding: 1.25rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search {
    width: 100%;
  }

  .filter-advanced {
    grid-template-columns: 1fr;
    margin-top: 0.6rem;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .summary-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-controls {
    width: 100%;
    align-items: flex-start;
  }

  .summary-controls .btn {
    width: 100%;
  }

  .quick-filters-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-chips {
    gap: 0.6rem;
  }

  .installment-tabs {
    width: 100%;
    justify-content: space-between;
  }

  .installment-tab {
    flex: 1;
    text-align: center;
  }

  .installment-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      'hero'
      'actions'
      'summary'
      'client';
  }

  .installment-hero {
    grid-template-columns: 1fr;
  }

  .installment-actions-grid {
    grid-template-columns: 1fr;
  }

  .summary-cards {
    grid-template-columns: 1fr;
  }

  .client-actions {
    flex-direction: column;
  }

  .filter-chip {
    flex: 1 1 100%;
    padding: 0.7rem 1rem;
    justify-content: space-between;
  }

  .status-counts,
  .filter-group,
  .export-group {
    width: 100%;
    justify-content: flex-start;
  }

  .export-group .btn,
  .btn.primary {
    width: 100%;
  }

  .bulk-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .bulk-actions select,
  .bulk-actions .btn {
    width: 100%;
  }

  .column-toggles {
    display: none;
  }

  .bulk-actions {
    padding: 0.75rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--panel-soft);
  }

  .form-actions {
    flex-direction: column;
  }

  .topbar {
    gap: 0.5rem;
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem;
  }

  .brand-tag {
    display: none;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-direction: column;
    align-items: stretch;
  }

  .topbar .brand {
    width: 100%;
    text-align: center;
  }

  .menu-toggle {
    align-self: flex-start;
    padding: 0.55rem 0.95rem;
    font-size: 0.95rem;
  }

  .collector-only .menu-toggle {
    display: none !important;
  }

  .collector-only .sidebar,
  .collector-only .app-shell.sidebar-open .sidebar {
    display: none !important;
  }

  .collector-only .app-shell.sidebar-open::after {
    display: none !important;
  }

  .collector-only .collector-bottom-nav {
    display: flex !important;
  }

  .collector-only .collector-bottom-spacer {
    display: block !important;
  }

  .user-menu {
    width: 100%;
    position: static;
  }

  .user-trigger {
    width: 100%;
    justify-content: space-between;
  }

  .user-name {
    flex: 1;
    text-align: left;
  }

  .user-dropdown {
    position: static;
    width: 100%;
    margin-top: 0.5rem;
    box-shadow: none;
  }

  /* El landing publico ya no depende de este archivo: assets/css/landing.css
     trae sus propios breakpoints. */

  .stats {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .dashboard-page .content {
    padding: 1.5rem 1.25rem 2.5rem;
  }

  .dashboard-header {
    align-items: flex-start;
    gap: 0.75rem;
  }

  .dashboard-actions {
    align-items: flex-start;
  }

  .dashboard-quick-actions .card-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.4rem;
  }

  .quick-action-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-row {
    justify-content: flex-start;
  }

  .dashboard-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-card {
    padding: 1.1rem;
  }

  .metric-value {
    font-size: 1.4rem;
  }

  .dashboard-metrics {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .dashboard-panels,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .bar-chart {
    height: 180px;
  }

  .card-foot {
    flex-direction: column;
    gap: 0.4rem;
  }

  .card {
    padding: 1.25rem;
  }

  .table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .table th,
  .table td {
    padding: 0.65rem 0.5rem;
  }

  .table.responsive {
    display: block;
    width: 100%;
    white-space: normal;
    overflow: visible;
  }

  .table.responsive thead {
    display: none;
  }

  .table.responsive tbody {
    display: block;
    width: 100%;
  }

  .table.responsive tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--panel);
    width: 100%;
  }

  .table.responsive tbody tr.installment-row.is-paid {
    background: #f0fdf4;
    border-left: 4px solid #22c55e;
  }

  .table.responsive tbody tr.installment-row.is-on-way {
    background: #eff6ff;
    border-left: 4px solid #3b82f6;
  }

  .table.responsive tbody tr.installment-row.is-pending {
    background: #fff7ed;
    border-left: 4px solid #fb923c;
  }

  .table.responsive tbody tr.installment-row.is-paid-today {
    background: #ecfdf3;
    border-left: 4px solid #22c55e;
  }

  .table.responsive tbody tr.is-hidden {
    display: none;
  }

  .table.responsive tbody td {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    border: 0;
    white-space: normal;
    width: 100%;
  }

  .table.responsive tbody td.group-sep {
    margin-top: 0.4rem;
    padding-top: 0.6rem;
    border-top: 1px dashed var(--border);
  }

  .table.responsive tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.75rem;
  }

  .table.responsive tbody td:last-child {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .table.responsive.show-collector .col-collector,
  .table.responsive.show-phone .col-phone,
  .table.responsive.show-status .col-status,
  .table.responsive.show-last .col-last {
    display: flex;
  }

  .table.responsive .col-last,
  .table.responsive.show-last .col-last {
    display: none;
  }

  .bar-chart {
    min-width: 0;
  }

  .audit-actions {
    align-items: flex-start;
  }

  .audit-panel-card {
    width: 100%;
  }

  .audit-detail-actions {
    grid-template-columns: 1fr;
  }

  .date-range {
    flex-wrap: wrap;
  }

  .audit-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-card {
    margin: 10vh 1rem;
    padding: 1.25rem;
  }

  .toast-action {
    flex-direction: column;
    align-items: flex-start;
  }

  .toast-actions {
    width: 100%;
  }

  .fab {
    right: 1rem;
    bottom: 1rem;
  }
}

@media (max-width: 600px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .search {
    flex-direction: column;
  }

  .client-search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .client-search-btn {
    width: 100%;
  }

  .menu-toggle {
    padding: 0.35rem 0.6rem;
  }

  .dashboard-metrics {
    grid-template-columns: 1fr;
  }

  .quick-action-grid {
    grid-template-columns: 1fr;
  }

  .quick-action {
    padding: 0.85rem;
  }

  .quick-action-icon {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
  }

  .metric-card {
    padding: 1rem;
  }

  .metric-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .metric-icon {
    font-size: 1.2rem;
  }

  .metric-value {
    font-size: 1.35rem;
  }

  .metric-subtitle {
    font-size: 0.78rem;
  }

  .bar-chart {
    grid-template-columns: repeat(7, minmax(60px, 1fr));
    overflow-x: auto;
    padding-bottom: 0.5rem;
  }

  .bar {
    min-height: 70px;
  }

  .bar-value {
    font-size: 0.65rem;
  }

  .donut-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .donut {
    width: 120px;
    height: 120px;
  }

  .donut::after {
    inset: 18px;
  }

  .donut-legend {
    width: 100%;
  }

  .legend-row {
    font-size: 0.8rem;
  }

  .audit-cards {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .modal-grid {
    grid-template-columns: 1fr;
  }

  .table th,
  .table td {
    padding: 0.55rem 0.4rem;
    font-size: 0.78rem;
  }

  .users-table th:nth-child(2),
  .users-table td[data-label='Email'] {
    display: none;
  }

  .users-table td[data-label='Rol'] {
    display: none;
  }

  .users-table th:nth-child(5),
  .users-table td[data-label='Presencia'] {
    display: none;
  }

  .user-secondary {
    display: block;
  }

  .action-inline {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
  }

  .users-table .action-inline .action-secondary {
    display: none;
  }

  .action-inline .btn {
    width: auto;
    flex: 1;
    justify-content: center;
  }

  .action-inline .action-primary,
  .action-inline .action-secondary {
    padding: 0.7rem 0.85rem;
    font-size: 0.85rem;
  }

  .action-menu {
    display: inline-block;
  }

  .action-menu-item {
    padding: 0.6rem 0.7rem;
    min-height: 40px;
  }
}

@media (max-width: 600px) {
  .users-table th:nth-child(5),
  .users-table td[data-label='Presencia'] {
    display: flex;
  }

  .users-table td[data-label='Nombre'] {
    flex-direction: column;
    align-items: flex-start;
  }

  .users-table td[data-label='Nombre']::before {
    content: '';
  }

  .action-inline {
    display: flex;
  }

  .card-foot {
    flex-direction: column;
    gap: 0.5rem;
  }
}
