/* ==========================================================================
   MediFlow — Responsive Layout & Mobile Stylesheet
   Complete cross-device optimization: 320px, 360px, 375px, 390px, 414px,
   430px, 768px, 820px, 1024px, 1366px, 1440px, and 1920px viewports.
   ========================================================================== */

/* Universal Responsive Box Sizing & Fluid Media */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
  -webkit-text-size-adjust: 100%;
}

img, svg, canvas {
  max-width: 100%;
  height: auto;
}

/* Base Container */
.container {
  width: 100%;
  max-width: var(--max-width, 1280px);
  margin: 0 auto;
  padding: 0 1.5rem;
  box-sizing: border-box;
}

/* --- Desktop Navigation Scaling (1025px - 1240px) --- */
@media (min-width: 1025px) and (max-width: 1240px) {
  .main-header-container {
    padding: 0 1rem;
    gap: 0.75rem;
  }
  .hospital-brand-sub {
    display: none;
  }
  .hospital-nav {
    gap: 0.15rem;
  }
  .nav-item-link {
    padding: 0.5rem 0.65rem;
    font-size: 0.88rem;
  }
  .nav-item-link.active::after {
    left: 0.65rem;
    right: 0.65rem;
  }
  .btn-book-appointment {
    padding: 0.55rem 0.95rem;
    font-size: 0.86rem;
  }
}

/* --- Mobile / Tablet Navigation Breakpoint (max-width: 1024px) --- */
@media (max-width: 1024px) {
  .hospital-nav {
    display: none !important;
  }

  .mobile-menu-toggle {
    display: flex !important;
  }

  .hospital-brand-sub {
    font-size: 0.65rem;
  }

  /* 2-column main hero/content layouts stack cleanly on tablets */
  .hero-layout {
    grid-template-columns: 1fr !important;
    gap: 2rem !important;
  }
}

/* --- Tablet / Large Mobile Breakpoint (max-width: 768px: 768px, 820px) --- */
@media (max-width: 768px) {
  .utility-emergency,
  .utility-divider-dot {
    display: none !important;
  }

  .utility-container {
    padding: 0 1rem;
  }

  .main-header {
    height: 64px;
  }

  .main-header-container {
    padding: 0 1rem;
  }

  .hospital-brand-sub {
    display: none;
  }

  .hospital-brand-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .hospital-brand-icon svg {
    width: 20px;
    height: 20px;
  }

  .hospital-brand-name {
    font-size: 1.25rem;
  }

  /* Multi-column grid adjustments */
  .grid-4 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1.5rem !important;
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1.5rem !important;
  }

  .footer-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 2.5rem !important;
  }

  .hero-visual {
    max-width: 580px;
    margin: 0 auto;
    width: 100%;
    position: relative;
    overflow: hidden;
  }

  /* Constrain hero ambient glow to avoid horizontal scroll */
  .hero-visual > div[style*="border-radius: 50%"] {
    width: 220px !important;
    height: 220px !important;
    max-width: 100% !important;
    right: 0 !important;
    top: 5% !important;
  }

  /* Floating badges stack naturally to eliminate horizontal off-canvas overflow */
  .hero-floating-badge-1,
  .hero-floating-badge-2 {
    position: static !important;
    margin-top: 0.75rem !important;
    width: 100% !important;
    transform: none !important;
    animation: none !important;
    box-shadow: var(--shadow-sm) !important;
  }

  /* Patient Journey Timeline — Single-Column Vertical Layout on Tablets */
  .timeline-line {
    left: 20px !important;
    transform: none !important;
  }

  .timeline-step {
    flex-direction: row !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    margin-bottom: 2rem !important;
    gap: 1rem !important;
  }

  .timeline-body-left {
    display: none !important;
  }

  .timeline-marker {
    width: 40px !important;
    height: 40px !important;
    font-size: 0.95rem !important;
    box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.2) !important;
    flex-shrink: 0 !important;
    z-index: 2 !important;
  }

  .timeline-body-right {
    width: calc(100% - 56px) !important;
    padding-left: 0 !important;
    text-align: left !important;
  }

  .timeline-mobile-content {
    display: block !important;
    margin-bottom: 0.75rem !important;
  }
}

/* --- Standard Mobile Phones (max-width: 480px: 375px, 390px, 414px, 430px) --- */
@media (max-width: 480px) {
  .utility-bar {
    height: 34px;
    font-size: 0.75rem;
  }

  .utility-divider {
    display: none !important;
  }

  .utility-lang-wrapper {
    padding: 0.1rem 0.35rem;
  }

  .utility-lang-select {
    font-size: 0.75rem;
  }

  .utility-portal-btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
  }

  .utility-portal-btn span {
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main-header {
    height: 60px;
  }

  .main-header-container {
    padding: 0 0.85rem;
    gap: 0.5rem;
  }

  .hospital-brand {
    gap: 0.5rem;
  }

  .hospital-brand-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
  }

  .hospital-brand-name {
    font-size: 1.15rem;
  }

  .header-actions {
    gap: 0.5rem;
  }

  /* Compact icon Book CTA on mobile header */
  .btn-book-appointment {
    padding: 0.45rem 0.65rem;
    font-size: 0.8rem;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn-book-appointment span {
    display: none;
  }

  .btn-book-appointment svg {
    margin: 0;
    width: 16px;
    height: 16px;
  }

  .mobile-menu-toggle {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }

  /* Top announcement banner */
  .prototype-banner {
    font-size: 0.725rem;
    padding: 0.4rem 0.75rem;
  }

  .prototype-banner .banner-content {
    justify-content: center;
    text-align: center;
    flex-direction: column;
    gap: 0.35rem;
  }

  /* Section spacing */
  .section {
    padding: 2.75rem 0;
  }

  .section-sm {
    padding: 2rem 0;
  }

  .section-header {
    margin-bottom: 1.75rem;
  }

  /* All multi-column grids collapse to 1 column */
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 1.25rem !important;
  }

  /* Card padding override to eliminate cramped content */
  .card {
    padding: 1.25rem !important;
    border-radius: var(--radius-lg);
  }

  h1 {
    font-size: clamp(1.6rem, 6.5vw, 2.05rem) !important;
    line-height: 1.22;
  }

  h2 {
    font-size: clamp(1.25rem, 5vw, 1.55rem) !important;
    line-height: 1.28;
  }

  h3 {
    font-size: 1.15rem;
  }

  p {
    font-size: 0.9rem;
    line-height: 1.55;
  }

  /* Form inputs: 16px font-size to prevent mobile browser zoom-in on focus */
  .form-input, .form-select, .form-textarea {
    font-size: 16px !important;
    padding: 0.65rem 0.85rem;
    width: 100%;
  }

  .btn {
    padding: 0.7rem 1.15rem;
    font-size: 0.9rem;
  }

  .btn-lg {
    padding: 0.8rem 1.25rem;
    font-size: 0.95rem;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  /* Hero Section Mobile Polish */
  .hero-actions {
    flex-direction: column;
    width: 100%;
    gap: 0.75rem !important;
  }

  .hero-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .hero-token-actions {
    flex-direction: column;
    gap: 0.6rem !important;
  }

  .hero-token-actions .btn {
    width: 100% !important;
    justify-content: center;
  }

  /* Floor Map Interface Mobile */
  .floor-map-wrapper {
    border-radius: var(--radius-lg);
  }

  .cad-toolbar {
    padding: 0.65rem 0.85rem !important;
    gap: 0.6rem !important;
  }

  .cad-toolbar-left {
    width: 100% !important;
    justify-content: space-between !important;
  }

  .cad-toolbar-right {
    width: 100% !important;
    justify-content: space-between !important;
  }

  .cad-zoom-controls {
    height: 38px;
  }

  .cad-zoom-btn {
    width: 38px !important;
    height: 38px !important;
    font-size: 1.1rem !important;
  }

  .cad-legend-bar {
    padding: 0.65rem 0.85rem !important;
    font-size: 0.725rem !important;
  }

  .cad-legend-items {
    gap: 0.65rem !important;
  }

  .map-svg-container {
    height: auto !important;
    aspect-ratio: 1000 / 680;
    min-height: 280px;
    max-height: 360px;
    touch-action: pan-x pan-y;
  }

  #floorButtonContainer {
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    padding-bottom: 4px;
  }

  .floor-btn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 0.45rem 0.75rem !important;
    font-size: 0.8rem !important;
  }

  #floorUnitsGrid {
    grid-template-columns: 1fr !important;
  }

  .multi-floor-leg-bar {
    padding: 0.65rem 0.85rem !important;
    font-size: 0.75rem !important;
  }

  .leg-switcher-group {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.35rem !important;
    margin-top: 0.35rem;
  }

  .leg-switcher-btn {
    width: 100% !important;
    text-align: center;
    padding: 0.45rem 0.6rem !important;
    font-size: 0.775rem !important;
  }

  /* Appointment date slot picker */
  .slot-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  .doctor-preview-inner {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  .doctor-preview-inner > div:last-child {
    text-align: left !important;
    width: 100%;
    border-top: 1px dashed var(--teal-200);
    padding-top: 0.5rem;
    margin-top: 0.25rem;
  }

  /* Discharge checklist step stack */
  .discharge-step-card-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  .discharge-step-card-header > div:last-child {
    width: 100% !important;
  }

  .discharge-step-card-header .btn {
    width: 100% !important;
    justify-content: center;
  }

  /* Doctor card action stack */
  .doctor-card-actions {
    flex-direction: column !important;
    gap: 0.5rem !important;
  }

  .doctor-card-actions .btn {
    width: 100% !important;
    justify-content: center;
  }

  /* Search & Filter bar fluid sizing */
  .floor-selector-bar {
    width: 100%;
    padding-bottom: 0.5rem;
  }

  .filter-pill {
    padding: 0.4rem 0.8rem !important;
    font-size: 0.8rem !important;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Billing cards & invoice actions */
  .invoice-card-actions {
    flex-direction: column;
    width: 100%;
    gap: 0.5rem;
  }

  .invoice-card-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border-radius: var(--radius-md);
    width: 100%;
  }

  .table-responsive table {
    min-width: 460px;
  }

  /* Modals on Mobile */
  .modal-dialog {
    margin: 0.625rem auto !important;
    width: calc(100vw - 1.25rem) !important;
    max-height: 88vh !important;
    border-radius: var(--radius-xl) !important;
  }

  .modal-header {
    padding: 1.15rem 1.25rem;
  }

  .modal-body {
    padding: 1.15rem 1.25rem;
  }

  .modal-body .grid-2,
  .modal-body div[style*="grid-template-columns: repeat(2"] {
    grid-template-columns: 1fr !important;
    gap: 0.65rem !important;
  }

  .modal-footer {
    padding: 1rem 1.25rem;
    flex-direction: column;
    gap: 0.5rem;
  }

  .modal-footer .btn {
    width: 100% !important;
    justify-content: center;
  }

  /* Payment method tabs stack on mobile */
  #paymentMethodTabs {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
  }

  #paymentMethodTabs .method-tab {
    width: 100% !important;
    justify-content: center;
    padding: 0.65rem 1rem !important;
  }

  /* Footer Mobile */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 2rem !important;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: 1rem;
  }

  /* Toast notification on mobile */
  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }

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

/* --- Ultra Narrow Mobile Phones (max-width: 360px: 320px screens) --- */
@media (max-width: 360px) {
  .container {
    padding: 0 0.75rem !important;
  }

  .card {
    padding: 1rem !important;
  }

  .main-header-container {
    padding: 0 0.65rem !important;
    gap: 0.35rem !important;
  }

  .hospital-brand-name {
    font-size: 1.05rem !important;
  }

  .hospital-brand-icon {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
  }

  .slot-grid {
    grid-template-columns: 1fr !important;
  }

  #heroTokenBadge {
    font-size: 1.15rem !important;
    padding: 0.3rem 0.6rem !important;
  }

  .badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
  }

  .prototype-banner {
    font-size: 0.675rem;
  }

  .brand-logo,
  .footer-brand .brand-logo {
    font-size: 1.25rem;
  }

  .brand-icon,
  .footer-brand .brand-icon {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    max-width: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
  }

  .brand-icon svg,
  .footer-brand .brand-icon svg {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
    min-height: 20px !important;
    max-height: 20px !important;
  }

  .utility-portal-btn span {
    max-width: 80px !important;
  }

  /* Hero wait time / queue pos matrix on ultra narrow */
  .hero-status-matrix {
    gap: 0.35rem !important;
  }

  .hero-status-matrix > div {
    padding: 0.4rem 0.25rem !important;
  }
}
