/* Responsive and Mobile-Specific Layout Adjustments */
@media (max-width: 640px) {
  .page {
    padding: 10px 10px 24px;
  }

  .masthead {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 6px 0 12px;
  }

  .masthead-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .masthead h1 {
    font-size: 20px;
    margin: 0;
    line-height: 1.2;
  }

  .masthead-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    width: 100%;
  }

  .action-btn-upload {
    height: 32px;
    padding: 0 9px;
    font-size: 11.5px;
    border-radius: 7px;
  }

  .action-btn-mapping {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 7px;
  }

  .upload-file-name {
    max-width: 85px;
  }

  .theme-switch {
    display: inline-flex;
    margin-left: auto;
    padding: 2px;
    border-radius: 20px;
    gap: 1px;
  }

  .theme-opt {
    padding: 4px 6px;
    font-size: 10.5px;
    gap: 2px;
  }

  .theme-opt svg {
    width: 13px;
    height: 13px;
  }

  /* Compact Mobile Dropzone & Mapping */
  .upload-bespoke {
    width: 100%;
    max-width: 100%;
  }

  .dropzone-content {
    width: 100%;
    max-width: 100%;
    gap: 8px;
    overflow: hidden;
  }

  .dropzone-icon-wrap {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    flex-shrink: 0;
  }

  .dropzone-icon-wrap svg {
    width: 16px;
    height: 16px;
  }

  .dropzone-text {
    min-width: 0;
    overflow: hidden;
  }

  .dropzone-title {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .dropzone-subtitle {
    display: none;
  }

  .dropzone-cta {
    flex-shrink: 0;
  }

  .pill-btn {
    padding: 4px 9px;
    font-size: 11px;
    white-space: nowrap;
  }

  .file-loaded-badge {
    max-width: 100%;
    overflow: hidden;
  }

  .file-loaded-badge span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Mapping form on mobile */
  .mapping-container {
    padding: 12px;
    border-radius: 10px;
  }

  .mapping-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .custom-select-menu {
    max-width: calc(100vw - 48px);
    width: 100%;
  }

  .mapping-actions {
    flex-direction: row;
    gap: 8px;
  }

  .calc-btn {
    flex: 1;
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
    justify-content: center;
  }

  .dimension-row {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
  }

  .dim-col-block,
  .dim-alias-block {
    flex: 1 1 calc(50% - 20px);
    min-width: 130px;
  }

  .mapping-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .mapping-actions {
    width: 100%;
  }

  .upload-summary-bar {
    width: 100%;
  }

  /* Tabs on mobile — smooth horizontal scrollable pill bar */
  .tabs {
    display: flex;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 1px solid var(--ux-line-2);
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    padding-bottom: 1px;
  }

  .tabs::-webkit-scrollbar {
    height: 3px;
  }

  .tab {
    flex: none;
    text-align: center;
    padding: 8px 12px;
    font-size: 12px;
    min-height: 38px;
    white-space: nowrap;
  }

  /* Export bar on mobile */
  .export-bar {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
  }

  .export-btn {
    flex: 1;
    justify-content: center;
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 6px;
  }

  .export-scope {
    display: none;
  }

  .section-title {
    font-size: 14px;
    margin: 16px 0 4px;
  }

  /* Dashboard mobile adjustments */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .kpi-card {
    padding: 12px 14px;
    border-radius: 10px;
  }

  .kpi-value {
    font-size: 20px;
  }

  .kpi-sub {
    font-size: 11px;
  }

  .dashboard-section {
    padding: 14px;
    border-radius: 12px;
  }

  .dash-heading {
    font-size: 14.5px;
  }

  .chart-viewport {
    height: 230px;
  }

  /* Followup & Category Retention Mobile Optimization */
  .followup-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-top: 12px;
  }

  .followup-search-wrap {
    width: 100%;
    min-width: 0;
  }

  .dash-header-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .dash-header-actions {
    width: 100%;
    flex-direction: row;
    gap: 8px;
  }

  .dash-header-actions .dash-controls {
    flex: 1;
    justify-content: center;
  }

  .dash-controls {
    width: 100%;
  }

  .dash-toggle-capsule {
    width: 100%;
    display: flex;
  }

  .dash-btn-toggle {
    flex: 1;
    justify-content: center;
    padding: 7px 10px;
    font-size: 11.5px;
  }

  .category-insights-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .cat-page-size-control {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .cat-page-size-control select.pagination-select {
    flex: 1;
    max-width: 100%;
  }

  .pagination-bar {
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding-top: 12px;
  }

  .pagination-info {
    font-size: 11.5px;
    text-align: center;
  }

  .pagination-nav {
    flex-wrap: wrap;
    justify-content: center;
  }

  .pagination-btn {
    min-width: 30px;
    height: 30px;
    padding: 0 6px;
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  .drilldown-modal-card {
    max-height: 92vh;
    border-radius: 10px;
  }

  .drilldown-modal-toolbar {
    padding: 8px 12px;
    gap: 8px;
  }

  .drilldown-search-wrap {
    width: 100%;
    min-width: 100%;
  }

  .drilldown-actions {
    width: 100%;
    display: flex;
    gap: 6px;
  }

  .modal-action-btn {
    flex: 1;
    justify-content: center;
    padding: 0 8px;
    font-size: 11px;
    height: 30px;
  }

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

  .cat-data-table th,
  .cat-data-table td {
    padding: 9px 10px;
    font-size: 11.5px;
  }

  .followup-data-table th,
  .followup-data-table td {
    padding: 8px 10px;
    font-size: 11.5px;
  }
}

@media (max-width: 640px) {
  /* Dashboard Insights Grid (Doctor Retention & Visit Frequency) */
  .dash-insights-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 14px;
  }

  .dash-doctor-card,
  .dash-frequency-card {
    padding: 12px;
    border-radius: 10px;
  }

  .dash-card-toolbar {
    padding-bottom: 10px;
    margin-bottom: 6px;
    gap: 8px;
  }

  .dash-card-title {
    font-size: 13px;
  }

  .dash-card-subtitle {
    font-size: 11px;
  }

  .dash-segment-btn {
    padding: 3px 7px;
    font-size: 10.5px;
  }

  .dash-doc-table-container,
  .dash-freq-table-container {
    margin: 0 -4px;
    -webkit-overflow-scrolling: touch;
  }

  .dash-bespoke-table thead th {
    padding: 7px 6px;
    font-size: 10px;
    letter-spacing: 0.2px;
  }

  .dash-bespoke-table tbody td {
    padding: 8px 6px;
    font-size: 11px;
  }

  .dash-bespoke-table .col-name .doc-primary-name,
  .dash-bespoke-table .col-name .freq-segment-name {
    font-size: 11.5px;
  }

  .table-rate-cell {
    gap: 6px;
  }

  .table-rate-cell .rate-track {
    width: 44px;
    height: 4px;
  }

  .table-rate-cell .rate-val {
    font-size: 11px;
    min-width: 28px;
  }
}

@media (max-width: 480px) {
  .dash-bespoke-table thead th.col-stat:nth-child(5),
  .dash-bespoke-table tbody td.col-stat:nth-child(5) {
    /* Hide Avg Visits column on very narrow mobile screens (<480px) so table auto-fits cleanly without scroll */
    display: none;
  }

  .dash-bespoke-table thead th {
    padding: 6px 4px;
    font-size: 9.5px;
  }

  .dash-bespoke-table tbody td {
    padding: 7px 4px;
  }

  .col-num {
    width: 22px !important;
  }

  .col-rate {
    width: 85px !important;
  }

  .table-rate-cell .rate-track {
    width: 36px;
  }

  .dash-card-footer {
    padding-top: 8px;
    margin-top: 4px;
  }
}

@media (max-width: 420px) {
  .theme-opt span {
    display: none;
  }
  .theme-opt {
    padding: 6px 9px;
  }
}
