/* ===================================
   ENHANCED MOBILE-FIRST RESPONSIVE DESIGN
   =================================== */

/* Breakpoints */
/* xs: up to 575.98px */
/* sm: 576px and up */
/* md: 768px and up */
/* lg: 1024px and up */
/* xl: 1280px and up */
/* 2xl: 1536px and up */

/* Mobile First Approach - Start with mobile styles, then scale up */

/* ==== BASE MOBILE STYLES (Default, applies to all screens) ==== */

/* Ensure proper viewport handling */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

/* Touch-friendly interactive elements */
.btn, .nav-link, button, input[type="submit"], input[type="button"], 
input[type="reset"], .clickable, .action-card, .booking-card {
  min-height: 44px;
  min-width: 44px;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* ==== MOBILE DEVICES (all phones, up to 767.98px) ==== */
@media (max-width: 767.98px) {

  /* ----- Typography ----- */
  h1 {
    font-size: var(--text-2xl);
    line-height: 1.2;
    margin-bottom: var(--space-3);
  }
  h2 {
    font-size: var(--text-xl);
    margin-bottom: var(--space-3);
  }
  h3 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-2);
  }

  /* ----- NAVBAR: compact top bar ----- */
  .navbar {
    height: 56px;
    position: fixed;
    top: 0; left: 0; right: 0;
    width: 100%;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    z-index: var(--z-fixed);
    display: block;
    overflow: visible;
  }

  /* Show the mobile top bar */
  .nav-topbar {
    display: flex;
  }

  /* ----- HAMBURGER BUTTON — always visible on mobile ----- */
  .nav-toggle {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    z-index: 2;
  }

  .nav-toggle span {
    width: 22px;
    height: 2px;
    background-color: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
    display: block;
  }

  /* Hamburger → X animation */
  .nav-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
  }
  .nav-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
  }
  .nav-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
  }

  /* ----- NAVIGATION DRAWER (slides from left) ----- */
  .nav-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    background: var(--bg-primary);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1050;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .nav-drawer.open {
    transform: translateX(0);
  }

  /* Show close button inside drawer on mobile */
  .nav-drawer-close {
    display: flex;
  }

  /* Drawer header (brand + close) */
  .nav-brand {
    height: 64px;
    min-height: 64px;
    padding: 0 var(--space-3) 0 var(--space-4);
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
  }

  .nav-brand .brand-link {
    color: white;
  }

  .nav-brand .brand-text {
    color: white;
  }

  .nav-brand .brand-icon {
    color: rgba(255, 255, 255, 0.9);
  }

  .nav-brand .brand-logo {
    filter: brightness(0) invert(1);
  }

  .nav-drawer-close {
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
  }

  .nav-drawer-close:hover {
    color: white;
    background: rgba(255, 255, 255, 0.2);
  }

  /* Nav menu inside drawer — always visible (no animation needed) */
  .nav-menu {
    position: static !important;
    transform: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    display: flex !important;
    flex-direction: column;
    padding: var(--space-3);
    gap: var(--space-1);
    background: transparent;
    border: none;
    box-shadow: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: none;
  }

  /* Nav links in drawer */
  .nav-link {
    width: 100%;
    justify-content: flex-start;
    padding: 0.75rem var(--space-3);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    min-height: 2.75rem;
    margin-bottom: 0;
  }

  .nav-link i {
    font-size: 1rem;
    width: 1.25rem;
    flex-shrink: 0;
  }

  /* User section at bottom of drawer */
  .nav-user {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-color);
    gap: var(--space-2);
    flex-shrink: 0;
    background: var(--bg-secondary);
  }

  .user-info {
    flex-direction: row;
    width: 100%;
  }

  .user-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
  }

  .user-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
  }

  .nav-logout {
    width: 100%;
  }

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

  /* Hide desktop-only user dropdown chevron on mobile */
  .user-menu {
    display: none;
  }

  /* ----- MAIN CONTENT ----- */
  .main-content {
    margin-left: 0 !important;
    padding-top: 56px;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0));
  }

  .content-container {
    padding: var(--space-4) var(--space-3);
  }

  /* ----- MOBILE BOTTOM NAV ----- */
  .mobile-bottom-nav {
    display: flex;
  }

  /* ----- Flash Messages ----- */
  .flash-messages {
    top: 64px;
    right: var(--space-3);
    left: var(--space-3);
    max-width: none;
  }

  .alert {
    padding: var(--space-3);
    border-radius: var(--radius-lg);
  }

  /* ----- Cards ----- */
  .card {
    margin-bottom: var(--space-4);
    border-radius: var(--radius-lg);
  }

  .card-header,
  .card-body,
  .card-footer {
    padding: var(--space-4);
  }

  .card-title {
    font-size: var(--text-lg);
  }

  /* ----- Grids ----- */
  .grid,
  .grid-2,
  .grid-3,
  .grid-4,
  .grid-5,
  .grid-6 {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }

  .quick-actions-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .grid-auto,
  .grid-auto-sm,
  .grid-auto-lg {
    grid-template-columns: 1fr;
  }

  /* ----- Forms ----- */
  .form-control,
  .form-select {
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
    font-size: 16px;
    border-radius: var(--radius-lg);
  }

  .form-label {
    font-size: var(--text-sm);
    margin-bottom: var(--space-2);
  }

  .form-grid,
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .form-row {
    flex-direction: column;
    gap: var(--space-3);
  }

  .input-group {
    flex-direction: column;
  }

  .input-group .form-control {
    border-radius: var(--radius-lg);
  }

  /* ----- Buttons ----- */
  .btn {
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    width: 100%;
    justify-content: center;
    margin-bottom: var(--space-2);
  }

  .btn-sm {
    min-height: 36px;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
  }

  .btn-lg {
    min-height: 52px;
    padding: var(--space-4) var(--space-6);
  }

  .booking-actions .btn,
  .card-footer .btn,
  .inline-btn {
    width: auto;
    margin-bottom: 0;
    margin-right: var(--space-2);
  }

  .btn-group {
    flex-direction: column;
    gap: var(--space-2);
  }

  /* ----- Tables ----- */
  .table-container {
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  .table-responsive {
    font-size: var(--text-xs);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table {
    min-width: 600px;
  }

  .table th,
  .table td {
    padding: var(--space-2) var(--space-3);
    white-space: nowrap;
  }

  .table-responsive::-webkit-scrollbar { height: 4px; }
  .table-responsive::-webkit-scrollbar-track { background: var(--bg-tertiary); }
  .table-responsive::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

  /* ----- Modals ----- */
  .modal {
    width: 95%;
    margin: var(--space-3);
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-4);
  }

  .modal-footer {
    flex-direction: column-reverse;
    gap: var(--space-3);
  }

  .modal-footer .btn {
    width: 100%;
    margin-bottom: 0;
  }

  /* ----- Footer ----- */
  .footer-content {
    grid-template-columns: 1fr;
    gap: var(--space-6);
    text-align: center;
    padding: 0 var(--space-3);
  }

  /* ----- Stat Cards ----- */
  .stat-card {
    padding: var(--space-4);
    text-align: center;
  }

  .stat-number {
    font-size: var(--text-3xl);
    margin-bottom: var(--space-2);
  }

  .stat-label {
    font-size: var(--text-xs);
  }

  /* ----- Booking Cards ----- */
  .booking-card {
    padding: var(--space-4);
    margin-bottom: var(--space-3);
  }

  .booking-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .booking-details {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .booking-actions {
    flex-direction: column;
    gap: var(--space-2);
  }

  .booking-actions .btn {
    width: 100%;
  }

  /* ----- Dashboard Specific ----- */
  .dashboard-main {
    grid-template-columns: 1fr;
    gap: var(--space-6);
  }

  .hero-section {
    margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-3)) var(--space-6);
    padding: var(--space-6) 0;
  }

  .hero-title {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-3);
  }

  .hero-subtitle {
    font-size: var(--text-base);
    margin-bottom: var(--space-4);
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
  }

  .section-title {
    font-size: var(--text-xl);
  }

  /* ----- Status Badges ----- */
  .status-badge,
  .medical-badge {
    font-size: var(--text-xs);
    padding: var(--space-1) var(--space-2);
  }

  /* ----- Utility Classes ----- */
  .mobile-hidden  { display: none !important; }
  .mobile-only    { display: block !important; }
  .mobile-center  { text-align: center !important; }
  .mobile-full-width { width: 100% !important; }
}

/* ==== EXTRA SMALL phones (up to 400px) ==== */
@media (max-width: 400px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .bottom-nav-item span {
    font-size: 0.55rem;
  }
}

/* ==== SMALL DEVICES (landscape phones, 576px–767px) ==== */
@media (min-width: 576px) and (max-width: 767.98px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
  }

  .grid-auto {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }

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

  .modal {
    width: 88%;
  }

  .booking-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .booking-actions .btn {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
  }
}

/* ==== TABLET & DESKTOP (768px and up) — Sidebar layout ==== */
@media (min-width: 768px) {

  /* ----- SIDEBAR ----- */
  .navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    border-bottom: none;
    box-shadow: var(--shadow-md);
    z-index: var(--z-fixed);
    overflow: hidden;
    display: block;
  }

  /* Hide mobile top bar on desktop */
  .nav-topbar {
    display: none !important;
  }

  /* Overlay never shows on desktop */
  .nav-overlay {
    display: none !important;
  }

  /* Drawer is always visible as sidebar content */
  .nav-drawer {
    position: static;
    transform: none !important;
    width: 100%;
    height: 100vh;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
  }

  /* Sidebar brand header */
  .nav-brand {
    height: 64px;
    min-height: 64px;
    padding: 0 var(--space-4);
    justify-content: flex-start;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
  }

  .nav-brand .brand-logo {
    filter: none;
  }

  .nav-brand .brand-text {
    color: var(--primary);
  }

  /* Hide close button on desktop */
  .nav-drawer-close {
    display: none !important;
  }

  /* Nav menu as scrollable list in sidebar */
  .nav-menu {
    position: static !important;
    transform: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    display: flex !important;
    flex-direction: column;
    padding: var(--space-2);
    gap: var(--space-1);
    background: transparent;
    border: none;
    box-shadow: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: none;
    align-items: stretch;
  }

  .nav-link {
    width: 100%;
    justify-content: flex-start;
    padding: var(--space-3) var(--space-4);
    margin-bottom: 0;
    min-height: 2.75rem;
    border-radius: var(--radius-lg);
  }

  .nav-link span {
    flex: 1;
    text-align: left;
  }

  /* User section at bottom of sidebar */
  .nav-user {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-4);
    border-top: 1px solid var(--border-color);
    gap: var(--space-3);
    flex-shrink: 0;
    background: transparent;
  }

  .user-info {
    flex-direction: row;
    width: 100%;
  }

  .user-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
  }

  .nav-logout {
    width: 100%;
  }

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

  .user-menu {
    display: block;
    width: 100%;
    position: relative;
  }

  .user-menu-btn {
    width: 100%;
    justify-content: center;
    display: flex;
  }

  .user-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    top: auto;
    margin-bottom: var(--space-2);
    margin-top: 0;
    min-width: 100%;
  }

  /* ----- MAIN CONTENT OFFSET FOR SIDEBAR ----- */
  .main-content {
    margin-left: 260px;
    padding-top: 0;
    padding-bottom: 0;
  }

  .content-container {
    padding: var(--space-6) var(--space-6);
  }

  /* Flash messages */
  .flash-messages {
    right: var(--space-6);
    left: auto;
    max-width: 400px;
    top: var(--space-4);
  }

  /* Hide bottom nav on desktop */
  .mobile-bottom-nav {
    display: none !important;
  }

  /* Nav toggle hidden on desktop */
  .nav-toggle {
    display: none !important;
  }

  /* ----- Grids ----- */
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .grid-auto {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }

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

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

  /* ----- Forms ----- */
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-row {
    flex-direction: row;
    gap: var(--space-4);
  }

  .input-group {
    flex-direction: row;
  }

  /* ----- Buttons ----- */
  .btn {
    width: auto;
    margin-bottom: 0;
  }

  .btn-group {
    flex-direction: row;
    gap: var(--space-3);
  }

  /* ----- Modals ----- */
  .modal-footer {
    flex-direction: row;
    justify-content: flex-end;
    gap: var(--space-3);
  }

  .modal-footer .btn {
    width: auto;
  }

  /* ----- Footer ----- */
  .footer-content {
    grid-template-columns: repeat(2, 1fr);
    text-align: left;
  }

  /* ----- Tables ----- */
  .table-responsive {
    font-size: var(--text-sm);
  }

  .table th,
  .table td {
    padding: var(--space-3) var(--space-4);
  }

  /* ----- Dashboard ----- */
  .section-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

/* ==== LARGE DEVICES (desktops, 1024px and up) ==== */
@media (min-width: 1024px) {
  .navbar {
    width: 280px;
  }

  .main-content {
    margin-left: 280px;
  }

  .flash-messages {
    left: auto;
  }
  
  /* Grids */
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .grid-4 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .grid-5,
  .grid-6 {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .quick-actions-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  /* Forms */
  .form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  /* Footer */
  .footer-content {
    grid-template-columns: repeat(3, 1fr);
  }
  
  /* Dashboard */
  .dashboard-main {
    grid-template-columns: 2fr 1fr;
  }
}

/* ==== EXTRA LARGE DEVICES (large desktops, 1280px and up) ==== */
@media (min-width: 1280px) {
  /* Sidebar stays consistent */
  .navbar {
    width: 280px;
  }
  
  .main-content {
    margin-left: 280px;
  }
  
  /* Grids */
  .grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .grid-5 {
    grid-template-columns: repeat(5, 1fr);
  }
  
  .grid-6 {
    grid-template-columns: repeat(6, 1fr);
  }
  
  /* Content */
  .content-container {
    padding: var(--space-8) var(--space-6);
  }
  
  /* Footer */
  .footer-content {
    padding: 0 var(--space-6);
  }
}

/* ==== 2XL DEVICES (larger desktops, 1536px and up) ==== */
@media (min-width: 1536px) {
  /* Sidebar stays consistent */
  .navbar {
    width: 280px;
  }
  
  .main-content {
    margin-left: 280px;
  }
  
  .content-container {
    padding: var(--space-10) var(--space-8);
  }
  
  .footer-content {
    padding: 0 var(--space-8);
  }
}

/* ==== LANDSCAPE ORIENTATION ON MOBILE ==== */
@media (max-width: 767.98px) and (orientation: landscape) {
  .main-content {
    padding-top: 3rem;
  }
  
  .navbar {
    height: 3rem;
  }
  
  .nav-container {
    height: 100%;
  }
  
  .flash-messages {
    top: 3.5rem;
  }
  
  .hero-section {
    padding: var(--space-4) 0;
  }
  
  .modal {
    max-height: 95vh;
  }
}

/* ==== HIGH DPI DISPLAYS ==== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .card,
  .btn,
  .form-control {
    border-width: 0.5px;
  }
  
  .nav-toggle span {
    height: 1px;
  }
}

/* ==== PRINT STYLES ==== */
@media print {
  * {
    box-shadow: none !important;
    text-shadow: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .navbar,
  .footer,
  .flash-messages,
  .btn,
  .modal-overlay,
  .loading-overlay,
  .nav-toggle {
    display: none !important;
  }
  
  .main-content {
    padding-top: 0 !important;
  }
  
  .card {
    border: 1px solid #ddd !important;
    break-inside: avoid;
  }
  
  h1, h2, h3, h4, h5, h6 {
    break-after: avoid;
  }
  
  .table {
    border-collapse: collapse !important;
  }
  
  .table th,
  .table td {
    border: 1px solid #ddd !important;
    background: transparent !important;
  }
  
  .status-badge {
    border: 1px solid currentColor;
    background: transparent !important;
  }
}

/* ==== ACCESSIBILITY IMPROVEMENTS ==== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .nav-menu,
  .modal,
  .dropdown-menu {
    transition: none !important;
  }
  
  .nav-toggle span {
    transition: none !important;
  }
}

/* ==== HIGH CONTRAST MODE ==== */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
    --text-secondary: #000000;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f0;
  }
  
  .card,
  .btn,
  .form-control {
    border-width: 2px;
  }
}

/* ==== DARK MODE SUPPORT (Future Implementation) ==== */
@media (prefers-color-scheme: dark) and (max-width: 767.98px) {
  .nav-menu {
    background: #1f2937;
    border-color: #374151;
  }
  
  .modal {
    background: #1f2937;
  }
}

/* ==== RESPONSIVE UTILITY CLASSES ==== */
.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }
.d-grid { display: grid; }

@media (max-width: 575.98px) {
  .d-xs-none { display: none; }
  .d-xs-block { display: block; }
  .d-xs-flex { display: flex; }
  .d-xs-grid { display: grid; }
}

@media (min-width: 576px) {
  .d-sm-none { display: none; }
  .d-sm-block { display: block; }
  .d-sm-flex { display: flex; }
  .d-sm-grid { display: grid; }
}

@media (min-width: 768px) {
  .d-md-none { display: none; }
  .d-md-block { display: block; }
  .d-md-flex { display: flex; }
  .d-md-grid { display: grid; }
}

@media (min-width: 1024px) {
  .d-lg-none { display: none; }
  .d-lg-block { display: block; }
  .d-lg-flex { display: flex; }
  .d-lg-grid { display: grid; }
}

@media (min-width: 1280px) {
  .d-xl-none { display: none; }
  .d-xl-block { display: block; }
  .d-xl-flex { display: flex; }
  .d-xl-grid { display: grid; }
}

/* ==== SPACING UTILITIES ==== */
@media (max-width: 767.98px) {
  .p-mobile-0 { padding: 0 !important; }
  .p-mobile-2 { padding: var(--space-2) !important; }
  .p-mobile-3 { padding: var(--space-3) !important; }
  .p-mobile-4 { padding: var(--space-4) !important; }
  
  .m-mobile-0 { margin: 0 !important; }
  .m-mobile-2 { margin: var(--space-2) !important; }
  .m-mobile-3 { margin: var(--space-3) !important; }
  .m-mobile-4 { margin: var(--space-4) !important; }
  
  .text-mobile-center { text-align: center !important; }
  .text-mobile-left { text-align: left !important; }
}

/* ==== FIX iOS INPUT ZOOM ==== */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  select, textarea, input[type="text"], input[type="password"], 
  input[type="datetime"], input[type="datetime-local"], 
  input[type="date"], input[type="month"], input[type="time"], 
  input[type="week"], input[type="number"], input[type="email"], 
  input[type="url"], input[type="search"], input[type="tel"], 
  input[type="color"] {
    font-size: 16px !important;
  }
}

/* ==== COLLAPSIBLE SIDEBAR (desktop) ==== */
/* Hidden by default; only meaningful on desktop where the sidebar is fixed. */
.sidebar-collapse-btn,
.sidebar-expand-btn {
  display: none;
}

@media (min-width: 768px) {
  /* Animate the sidebar + content shift */
  .navbar { transition: transform 0.2s ease, width 0.2s ease; }
  .main-content { transition: margin-left 0.2s ease; }

  /* Collapse toggle sits at the right of the sidebar brand header */
  .sidebar-collapse-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-left: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .sidebar-collapse-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
  }

  /* Floating button to re-open the sidebar when collapsed */
  .sidebar-expand-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: calc(var(--z-fixed, 1000) + 5);
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    cursor: pointer;
  }
  .sidebar-expand-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
  }

  /* Collapsed state: slide sidebar off-screen, reclaim the space */
  body.sidebar-collapsed .navbar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  body.sidebar-collapsed .main-content {
    margin-left: 0 !important;
  }
  body.sidebar-collapsed .sidebar-collapse-btn { display: none; }
  body.sidebar-collapsed .sidebar-expand-btn { display: inline-flex; }
}