/* ═══════════════════════════════════════════════════════════════════
   Docioo — Mobile responsiveness (≤768px)
   Targets phones/tablets in portrait. Desktop (≥769px) is unchanged.
   Test widths: 320, 375, 390, 414, 768
   ═══════════════════════════════════════════════════════════════════ */

/* ── Global foundations ─────────────────────────────────────────── */
@media (max-width: 768px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    overflow-x: hidden;
  }

  img,
  video,
  svg.docioo-logo {
    max-width: 100%;
    height: auto;
  }

  canvas {
    max-width: 100%;
  }

  /* Touch-friendly controls without changing desktop sizing */
  .btn:not(.btn-icon),
  .icon-btn,
  .nav-link,
  .sidebar-item,
  .nav-item,
  .page-link,
  .portal-bottom-nav a,
  .rs-slot-btn {
    min-height: 44px;
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    min-width: 18px;
    min-height: 18px;
  }

  /* Safe areas (iPhone notch / home indicator) */
  .app-header,
  .admin-header,
  .portal-topbar {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .portal-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--bottom-nav-h, 68px) + env(safe-area-inset-bottom));
  }

  .portal-main {
    padding-bottom: calc(var(--bottom-nav-h, 68px) + env(safe-area-inset-bottom) + 16px);
  }

  /* Prevent horizontal page scroll from wide children */
  .main-content,
  .admin-body,
  .portal-main,
  .page-view,
  .card,
  .card-body {
    max-width: 100%;
    min-width: 0;
  }
}

/* ── Clinic panel (app.css) ─────────────────────────────────────── */
@media (max-width: 768px) {
  .app-header {
    padding: 0 12px;
    gap: 8px;
  }

  .header-left,
  .header-right {
    gap: 6px;
    min-width: 0;
  }

  .header-logo .logo-img,
  .header-logo .docioo-logo {
    max-height: 32px;
  }

  .main-content {
    padding: 16px 12px 24px;
  }

  h1, .page-title { font-size: 1.35rem; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.05rem; }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 20px;
  }

  .page-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    white-space: normal;
    text-align: center;
  }

  .page-filters .card-body,
  .page-filters {
    overflow: visible;
  }

  .filter-form,
  .page-filters .filter-form,
  .card-body > .form-row.filter-form {
    flex-direction: column;
    align-items: stretch !important;
    width: 100%;
  }

  .filter-form .form-group,
  .page-filters .form-group {
    width: 100%;
    margin-bottom: 10px;
  }

  .filter-form .btn,
  .page-filters .btn {
    width: 100%;
  }

  .page-tabs {
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-tabs .btn,
  .page-tabs button {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }

  .card-header,
  .card-body,
  .card-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .stat-value { font-size: 1.5rem; }
  .stat-card { padding: 16px; }

  .table-wrapper,
  .table-card-scroll .table-wrapper {
    -webkit-overflow-scrolling: touch;
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
    width: calc(100% + 32px);
    max-width: calc(100% + 32px);
  }

  .data-table {
    font-size: 0.78rem;
    min-width: 560px;
  }

  .data-table thead th,
  .data-table tbody td {
    padding: 10px 12px;
  }

  /* Scroll-table pages: allow natural page scroll on phones */
  body:has(.page-view--scroll-table) {
    overflow: auto;
  }

  body:has(.page-view--scroll-table) .app-body {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  body:has(.page-view--scroll-table) .main-content {
    height: auto;
    min-height: calc(100vh - var(--header-h));
    overflow: visible;
    display: block;
  }

  .page-view--scroll-table,
  .page-view--scroll-table .scroll-table-panel,
  .page-view--scroll-table .table-card-scroll {
    overflow: visible;
    flex: none;
    min-height: 0;
  }

  .page-view--scroll-table .table-card-scroll .table-wrapper {
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
  }

  /* Modals — full-width sheet style on small screens */
  .modal-backdrop {
    padding: 12px;
    align-items: flex-end;
  }

  .modal,
  .modal-lg,
  .modal-xl,
  .discount-modal-dialog {
    max-width: calc(100vw - 16px);
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
  }

  .modal-header {
    padding: 18px 16px 0;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .modal-footer .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }

  /* Toasts & flash messages */
  #toast-container {
    left: 12px;
    right: 12px;
    top: calc(var(--header-h) + 8px);
  }

  .toast {
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  #flash-msg {
    left: 12px !important;
    right: 12px !important;
    max-width: none !important;
  }

  /* Dropdowns & panels — keep profile menu anchored; widen notification panel on small screens */
  .notification-dropdown .notification-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    top: calc(var(--header-h) + 8px);
    width: auto;
    max-width: none;
  }

  .profile-dropdown .dropdown-menu {
    right: 0;
    left: auto;
    min-width: 200px;
    max-width: calc(100vw - 24px);
  }

  .profile-btn {
    padding: 4px 8px 4px 4px;
  }

  /* Charts */
  .chart-wrap,
  .analytics-chart-card canvas {
    max-width: 100%;
  }

  /* Auth */
  .auth-right {
    padding: 24px 16px;
  }

  .auth-form-wrap {
    max-width: 100%;
  }

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

  /* OTP inputs scale down on narrow screens */
  .otp-inputs {
    gap: 6px;
  }

  .otp-input {
    width: 44px;
    height: 50px;
    font-size: 1.25rem;
  }

  /* Inline fixed-width controls in views */
  .form-control[style*="width:"],
  .form-control[style*="min-width:"],
  select.form-control[style*="max-width"] {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .flex.gap-3,
  .flex.gap-4 {
    flex-wrap: wrap;
  }

  .flex[style*="min-width"] {
    flex-direction: column;
    align-items: stretch !important;
    min-width: 0 !important;
    width: 100%;
  }

  .search-wrap {
    width: 100%;
    min-width: 0 !important;
    flex: 1 1 100%;
  }

  /* Payment & booking helpers */
  .payment-methods {
    grid-template-columns: 1fr;
  }

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

  .coupon-card__apply {
    align-self: stretch;
    width: 100%;
    margin-top: 8px;
  }

  .rs-slots-grid {
    max-height: none;
  }
}

@media (min-width: 769px) {
  /* Sidebar toggle only needed when sidebar is off-canvas */
  .sidebar-toggle {
    display: none !important;
  }
}

/* ── EMR (clinic) ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  body:has(#emr-page) {
    overflow: auto;
  }

  body:has(#emr-page) .app-body {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  body:has(#emr-page) .main-content {
    height: auto;
    min-height: calc(100vh - var(--header-h));
    overflow: visible;
  }

  #emr-page {
    min-height: calc(100vh - var(--header-h));
  }

  #emr-content {
    padding: 14px 12px;
  }

  #emr-picker-bar {
    padding: 10px 12px;
    gap: 8px;
  }

  #emr-picker-bar input {
    width: 100%;
    min-width: 0;
    flex: 1 1 140px;
  }

  #emr-header-actions {
    width: 100%;
    margin-left: 0;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
  }

  #emr-pt-list-dd {
    width: min(300px, calc(100vw - 24px));
  }

  .emr-hdr {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  #emr-page .g2,
  #emr-page .g3,
  #emr-page .form-row,
  #emr-page .form-row-2,
  #emr-page .vitals-grid,
  #emr-page .emr-print-kv-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  #emr-page .vitals-grid,
  #emr-page .form-row {
    grid-template-columns: 1fr 1fr !important;
  }
}

@media (max-width: 360px) {
  #emr-page .vitals-grid,
  #emr-page .form-row {
    grid-template-columns: 1fr !important;
  }
}

/* ── Master Admin (admin.css) ───────────────────────────────────── */
@media (max-width: 768px) {
  .admin-header {
    padding: 0 12px;
  }

  .admin-body {
    padding: 16px 12px 28px;
  }

  .breadcrumb {
    display: none;
  }

  .header-right .text-sm.text-muted {
    display: none;
  }

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

  .page-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .page-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  .filter-form,
  .analytics-filter-form,
  form.flex.filter-form,
  .card-body > form.flex {
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100%;
  }

  .filter-form .form-control,
  .filter-form select,
  .filter-form .search-wrap,
  .analytics-filter-form .form-control {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .filter-form .btn,
  .analytics-filter-form .btn {
    width: 100%;
  }

  .stat-grid-6 {
    grid-template-columns: repeat(2, 1fr);
  }

  .table-wrap,
  .card > .admin-table,
  .card-body > .admin-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
    width: calc(100% + 32px);
    max-width: calc(100% + 32px);
  }

  .admin-table {
    font-size: 0.78rem;
    min-width: 560px;
  }

  .admin-table thead th,
  .admin-table tbody td {
    padding: 10px 12px;
  }

  .card-header,
  .card-body,
  .card-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .credit-layout,
  .hospital-layout,
  .admin-form-layout {
    gap: 16px;
  }

  .form-row.cols-4 {
    grid-template-columns: 1fr;
  }

  .modal,
  .modal-lg {
    max-width: calc(100vw - 16px);
    width: 100%;
  }

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

  .flex[style*="min-width"] {
    flex-direction: column;
    align-items: stretch !important;
    min-width: 0 !important;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .stat-grid,
  .stat-grid-6 {
    grid-template-columns: 1fr;
  }

  .login-shell {
    padding: 16px;
    max-width: 100%;
  }

  .login-card {
    padding: 28px 20px;
  }
}

/* ── Patient portal (patient.css) ───────────────────────────────── */
@media (max-width: 768px) {
  .portal-topbar-inner {
    padding: 10px 12px;
  }

  .portal-brand-text span {
    max-width: 120px;
  }

  .portal-main {
    padding-left: 12px;
    padding-right: 12px;
  }

  .portal-hero {
    padding: 18px 16px;
  }

  .portal-main .card {
    padding: 16px;
  }

  .stat-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .stat-chip {
    width: 100%;
  }

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

  .btn-row .btn {
    width: 100%;
  }

  .detail-grid {
    gap: 8px;
  }

  .profile-tabs {
    -webkit-overflow-scrolling: touch;
  }

  .section-tabs {
    flex-wrap: wrap;
  }

  .section-tab {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }

  .apt-card {
    flex-wrap: wrap;
  }

  .login-form-panel {
    padding: 20px 16px;
  }

  .login-card {
    padding: 24px 18px;
  }

  .portal-main .form-row {
    grid-template-columns: 1fr !important;
  }

  .family-member-card {
    overflow: hidden;
  }
}

@media (max-width: 390px) {
  .portal-bottom-nav a {
    font-size: .62rem;
    padding: 6px 2px;
  }

  .portal-bottom-nav a svg {
    width: 20px;
    height: 20px;
  }
}

/* ── Marketing site (marketing.css) ─────────────────────────────── */
@media (max-width: 768px) {
  .container {
    padding-left: 16px;
    padding-right: 16px;
  }

  .hero {
    padding: 48px 0 40px;
  }

  .hero h1 {
    font-size: clamp(1.75rem, 8vw, 2.4rem);
  }

  .section {
    padding: 48px 0;
  }

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

  .pricing-grid,
  .features-grid {
    grid-template-columns: 1fr !important;
  }

  .nav-ctas .btn-login {
    padding: 8px 14px;
    font-size: .82rem;
  }

  .mobile-menu {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .footer-grid {
    gap: 24px;
  }
}

@media (max-width: 414px) {
  .home-stat {
    min-width: calc(50% - 6px);
    padding: 10px 12px;
  }

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

@media (max-width: 320px) {
  .hero-badge {
    font-size: .72rem;
    padding: 5px 12px;
  }

  .btn-primary,
  .btn-outline {
    padding-left: 16px;
    padding-right: 16px;
    font-size: .82rem;
  }
}

/* ── Public booking (public-booking.css) ────────────────────────── */
@media (max-width: 768px) {
  .booking-shell {
    padding: 16px 12px calc(80px + env(safe-area-inset-bottom));
    grid-template-columns: 1fr !important;
    gap: 16px;
  }

  .booking-shell .card,
  .booking-shell .summary-card {
    padding: 16px;
  }

  .booking-shell .form-row.cols-2,
  .booking-shell .form-row.cols-3 {
    grid-template-columns: 1fr !important;
  }

  .booking-progress-track {
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .booking-step {
    flex: 0 0 auto;
    min-width: 44px;
    font-size: .72rem;
  }

  .booking-shell .slot-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .booking-shell .doctor-grid,
  .booking-shell .branch-grid {
    grid-template-columns: 1fr !important;
  }

  .booking-shell .doctor-option,
  .booking-shell .branch-option {
    width: 100%;
  }

  .booking-footer {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    font-size: .78rem;
  }
}

@media (max-width: 360px) {
  .booking-shell .slot-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── Avatar crop modal (profile / doctor photo) ─────────────────── */
@media (max-width: 768px) {
  .avatar-crop-modal {
    padding: 12px;
    align-items: flex-end;
  }

  .avatar-crop-dialog {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .avatar-crop-footer {
    flex-wrap: wrap;
  }

  .avatar-crop-footer .btn {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
  }
}
