/* Admin Panel Responsive Design */

/* ============================================
   Mobile-First Base Styles
   ============================================ */

:root {
  --sidebar-width: 16rem; /* 256px */
  --header-height: 3.5rem; /* 56px */
  --transition-duration: 300ms;
}

/* Touch-friendly targets (minimum 44px) */
button, a[role="button"], [role="button"] {
  min-height: 2.75rem; /* 44px */
  min-width: 2.75rem; /* 44px */
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   Sidebar Responsive Enhancements
   ============================================ */

@media (max-width: 1023px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 16rem;
    box-shadow: -4px 0 6px rgba(0, 0, 0, 0.1);
    z-index: 50;
    overflow-y: auto;
  }

  #sidebar-overlay {
    transition: opacity var(--transition-duration) ease-in-out;
  }

  /* Prevent body scroll when sidebar is open */
  body.sidebar-open {
    overflow: hidden;
  }
}

@media (max-width: 640px) {
  #sidebar {
    width: 14rem;
  }

  #sidebar > div:first-child {
    padding: 1rem;
  }

  #sidebar h1 {
    font-size: 1.25rem;
  }

  #sidebar p {
    font-size: 0.75rem;
  }
}

/* ============================================
   Table Responsive Wrapper
   ============================================ */

.table-responsive-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive-wrapper table {
  min-width: 100%;
}

/* Scrollbar styling for better UX */
.table-responsive-wrapper::-webkit-scrollbar {
  height: 6px;
}

.table-responsive-wrapper::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

.table-responsive-wrapper::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 10px;
}

.table-responsive-wrapper::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* ============================================
   Forms - Mobile Optimizations
   ============================================ */

form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="date"],
form input[type="time"],
form input[type="number"],
form textarea,
form select {
  /* Increase font size to prevent zoom on iOS */
  font-size: 16px !important;
  padding: 0.75rem !important;
  min-height: 2.75rem !important;
}

/* Better spacing for form labels */
label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

/* ============================================
   Cards - Mobile Optimizations
   ============================================ */

.card-shadow {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.card-shadow:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

@media (max-width: 640px) {
  .card-shadow {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  }

  .card-shadow:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  }
}

/* ============================================
   Button Groups - Responsive Stacking
   ============================================ */

.button-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .button-group {
    flex-direction: column;
  }

  .button-group > * {
    width: 100%;
  }
}

/* ============================================
   Modal/Dialog Responsiveness
   ============================================ */

@media (max-width: 640px) {
  .modal, dialog {
    width: 90vw !important;
    max-width: 90vw !important;
    margin: auto !important;
    max-height: 90vh !important;
    border-radius: 0.75rem !important;
  }

  .modal-header {
    padding: 1.5rem !important;
  }

  .modal-body {
    padding: 1.5rem !important;
    max-height: calc(90vh - 200px) !important;
    overflow-y: auto !important;
  }

  .modal-footer {
    padding: 1.5rem !important;
    flex-direction: column !important;
  }

  .modal-footer > * {
    width: 100%;
  }
}

/* ============================================
   Header/Navbar Responsiveness
   ============================================ */

@media (max-width: 640px) {
  header {
    position: sticky;
    top: 0;
    z-index: 40;
  }

  header .px-4 {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  header h2 {
    font-size: 1rem;
    max-width: calc(100vw - 100px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  header .hidden.sm\:inline {
    display: none !important;
  }
}

/* ============================================
   Grid Responsiveness
   ============================================ */

@media (max-width: 768px) {
  .grid-auto-responsive {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================
   Calendar Responsive Fixes
   ============================================ */

.calendar-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
  .calendar-container .grid-cols-7 {
    grid-template-columns: repeat(7, minmax(50px, 1fr)) !important;
  }

  .calendar-container .text-sm {
    font-size: 0.75rem !important;
  }

  .calendar-container .p-2 {
    padding: 0.25rem !important;
  }
}

/* ============================================
   Action Buttons - Responsive Layout
   ============================================ */

.action-button-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.5rem;
}

@media (max-width: 640px) {
  .action-button-grid {
    grid-template-columns: 1fr;
  }

  .action-button-grid > button,
  .action-button-grid > a {
    width: 100%;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
}

/* ============================================
   Typography - Mobile Scaling
   ============================================ */

@media (max-width: 640px) {
  h1 {
    font-size: calc(1.875rem - 0.5rem) !important; /* Scale down from 1.875rem */
  }

  h2 {
    font-size: calc(1.5rem - 0.25rem) !important; /* Scale down from 1.5rem */
  }

  h3 {
    font-size: calc(1.25rem - 0.125rem) !important; /* Scale down from 1.25rem */
  }
}

/* ============================================
   Sidebar with Smooth Scroll on Mobile
   ============================================ */

@supports (scroll-behavior: smooth) {
  #sidebar nav {
    scroll-behavior: smooth;
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  #sidebar,
  header,
  .no-print {
    display: none;
  }

  body {
    margin: 0;
    padding: 0;
  }

  main {
    margin: 0;
    padding: 0;
  }
}

/* ============================================
   Support for Safe Areas (Notch)
   ============================================ */

@supports (padding: max(0px)) {
  #sidebar {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  header {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  main {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}
