/* ═══════════════════════════════════════════════════
   RESPONSIVE DESIGN OPTIMIZATIONS
   Mobile-first approach for all screen sizes
   ═══════════════════════════════════════════════════ */

/* ─────────────────────────────────────
   MOBILE (320px - 640px)
───────────────────────────────────── */
@media (max-width: 640px) {
  /* Layout adjustments */
  .platform-layout {
    flex-direction: column;
  }

  /* Sidebar - Hidden on mobile, full width when open */
  .sidebar {
    width: 100%;
    max-width: none;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: none;
    border-right: none;
    border-left: 1px solid var(--sb-border);
  }

  /* Main content */
  .main-content {
    margin-left: 0;
    margin-top: 56px;
  }

  /* Top bar optimizations */
  .top-bar {
    height: 52px;
    padding: 0 0.875rem;
    gap: 0.5rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
  }

  .menu-toggle {
    display: flex !important;
    width: 32px;
    height: 32px;
  }

  /* Search bar - Hide on mobile, show only as icon */
  .top-search {
    display: none;
  }

  .top-search.mobile-visible {
    display: flex;
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    border-radius: 0;
    padding: 0.75rem;
    z-index: 39;
  }

  /* Top actions - Stack vertically */
  .top-actions {
    gap: 0.25rem;
  }

  /* Page content */
  .page-content {
    padding: 1rem 0.875rem;
    width: 100%;
    overflow-x: hidden;
  }

  /* Buttons - Full width or optimized */
  button.btn-primary,
  button.btn-secondary {
    width: 100%;
    max-width: none;
  }

  /* Cards - Full width */
  .card {
    width: 100%;
    border-radius: 8px;
    padding: 1rem;
  }

  /* Grid layouts - Single column */
  .grid-2,
  .grid-3,
  .grid-auto {
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }

  /* Forms */
  .form-group {
    margin-bottom: 1rem;
  }

  .form-row {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .form-row input,
  .form-row select,
  .form-row textarea {
    width: 100%;
  }

  /* Tables - Responsive */
  table {
    font-size: 0.75rem;
  }

  /* Headers - Reduce size */
  h1 {
    font-size: 1.5rem;
    margin: 0.75rem 0;
  }

  h2 {
    font-size: 1.25rem;
    margin: 0.5rem 0;
  }

  h3 {
    font-size: 1rem;
    margin: 0.5rem 0;
  }

  /* Text - Slightly larger for readability */
  body {
    font-size: 14px;
  }

  .text-sm {
    font-size: 0.8125rem;
  }

  /* Padding and spacing - Reduce */
  .sidebar .sb-brand {
    padding: 1rem 0.75rem;
  }

  .sidebar .sb-nav {
    padding: 0.5rem 0.5rem;
  }

  .sidebar .sb-nav-item {
    padding: 0.5rem;
    border-radius: 6px;
  }

  /* Icons - Slightly smaller */
  .icon-sm {
    width: 16px;
    height: 16px;
  }

  .icon-md {
    width: 20px;
    height: 20px;
  }

  /* Modals - Full width on mobile */
  .modal {
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0;
    max-width: none;
  }

  .modal-content {
    border-radius: 12px 12px 0 0;
  }

  /* Hide elements on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Show elements only on mobile */
  .show-mobile {
    display: block !important;
  }

  /* Dropdowns - Full width on mobile */
  .dropdown-panel {
    width: calc(100vw - 1.75rem) !important;
    max-width: none !important;
  }
}

/* ─────────────────────────────────────
   TABLET (641px - 1024px)
───────────────────────────────────── */
@media (641px <= width <= 1024px) {
  /* Sidebar - Collapsible */
  .sidebar {
    width: 240px;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Main content */
  .main-content {
    margin-left: 0;
  }

  /* Top bar */
  .top-bar {
    height: 56px;
    padding: 0 1.25rem;
  }

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

  /* Search bar - Medium width */
  .top-search {
    max-width: 280px;
  }

  /* Page content */
  .page-content {
    padding: 1.25rem;
  }

  /* Grid layouts - 2 columns */
  .grid-3 {
    grid-template-columns: 1fr 1fr !important;
  }

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

  /* Cards */
  .card {
    padding: 1.25rem;
  }

  /* Forms */
  .form-row {
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  /* Text sizes */
  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.4rem;
  }

  h3 {
    font-size: 1.1rem;
  }
}

/* ─────────────────────────────────────
   DESKTOP (1025px+)
───────────────────────────────────── */
@media (min-width: 1025px) {
  /* Sidebar - Always visible */
  .sidebar {
    transform: translateX(0) !important;
    position: fixed;
    width: 256px;
  }

  .menu-toggle {
    display: none !important;
  }

  /* Main content */
  .main-content {
    margin-left: 256px;
  }

  /* Top bar */
  .top-bar {
    padding: 0 1.5rem;
  }

  .top-search {
    max-width: 360px;
  }

  /* Page content */
  .page-content {
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
  }

  /* Grid layouts */
  .grid-3 {
    grid-template-columns: 1fr 1fr 1fr !important;
  }

  .grid-auto {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
  }

  /* Forms */
  .form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.25rem;
  }

  /* Hide mobile elements */
  .show-mobile {
    display: none !important;
  }

  .hide-mobile {
    display: block !important;
  }
}

/* ─────────────────────────────────────
   UNIVERSAL IMPROVEMENTS
───────────────────────────────────── */

/* Ensure images don't overflow */
img,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Make inputs responsive */
input,
select,
textarea {
  font-size: 16px; /* Prevent zoom on iOS */
  width: 100%;
  max-width: 100%;
}

/* Improve touch targets on mobile */
@media (pointer: coarse) {
  button,
  a,
  .clickable {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1rem;
  }
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Fix overflow issues */
body {
  overflow-x: hidden;
}

.page-content {
  overflow-x: hidden;
}

/* Flexible containers */
.container {
  width: 100%;
  padding: 0 1rem;
  margin: 0 auto;
}

@media (min-width: 641px) {
  .container {
    padding: 0 1.5rem;
  }
}

@media (min-width: 1025px) {
  .container {
    max-width: 1400px;
    padding: 0 2rem;
  }
}

/* Prevent text selection issues */
* {
  -webkit-user-select: text;
  user-select: text;
}

button,
[role="button"],
a {
  -webkit-user-select: none;
  user-select: none;
}

/* Print styles */
@media print {
  .sidebar,
  .top-bar,
  .menu-toggle {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
  }
}
