/* ===== MOBILE FIRST (DEFAULT) ===== */
@media (max-width: 767px) {
  .nav-sidebar {
    transform: translateX(-100%);
  }
  .nav-sidebar.open {
    transform: translateX(0);
  }
  .grid-2 { grid-template-columns: 1fr; }
  .otp-input input {
    width: clamp(38px, 12vw, 46px);
    height: clamp(46px, 14vw, 54px);
    font-size: var(--font-xl);
  }
  .btn {
    max-width: 100% !important;
    white-space: normal !important;
    text-align: center !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
    box-sizing: border-box !important;
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.35;
  }
  .btn-sm {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 12px;
    line-height: 1.25;
  }
  .card-glass, .card {
    padding: 14px;
  }
  /* Modal & dialog action buttons automatically wrap cleanly on mobile without clipping */
  .modal div[style*="display:flex"],
  .modal div[style*="display: flex"] {
    flex-wrap: wrap !important;
  }
  .modal div[style*="display:flex"] > .btn,
  .modal div[style*="display: flex"] > .btn {
    flex: 1 1 120px !important;
    min-width: 0 !important;
  }
}

/* ===== TABLET (768px+) ===== */
@media (min-width: 768px) {
  /* Offset the content area past the fixed 260px sidebar so .screen's
     margin:0 auto centers it in the remaining space (not against the left edge). */
  body.app-shell #app {
    padding-left: 260px;
  }

  .screen {
    padding: var(--space-lg);
    padding-bottom: var(--space-lg);
    max-width: 720px;
    margin: 0 auto;
  }

  .screen.with-sidebar {
    max-width: 960px;
  }

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

  .nav-bottom {
    display: none;
  }

  .modal {
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-lg);
    max-width: 520px;
  }

  .otp-input input { width: 56px; height: 64px; }
}

/* ===== DESKTOP (1024px+) ===== */
@media (min-width: 1024px) {
  body.app-shell #app {
    padding-left: 280px;
  }

  .nav-sidebar {
    width: 280px;
  }

  .screen {
    max-width: 1240px;
    padding: var(--space-xl) 36px;
  }

  .screen.with-sidebar {
    max-width: 1400px;
    padding: var(--space-xl) 36px;
  }

  /* Home Desktop Layout */
  .action-grid,
  #home-action-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 16px;
  }

  .action-card {
    height: 140px;
  }

  .specialty-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }

  .specialty-tile {
    min-height: 150px;
  }

  .cat-row#home-categories {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
    gap: 14px;
    overflow-x: visible;
    padding-bottom: 0;
  }

  .cat-tile {
    flex: none;
    width: auto;
    height: 110px;
  }

  #home-concerns {
    gap: 12px;
  }

  #home-concerns .tab {
    padding: 10px 20px;
    font-size: 14px;
  }

  /* Catalog Screen Desktop Layout */
  #catalog-list {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px !important;
  }

  .search-box {
    max-width: 600px;
  }

  /* Admin Dashboard & Operations Desktop Layout */
  #admin-stats {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 16px !important;
  }

  .admin-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 16px;
  }

  .admin-tile {
    min-height: 112px;
    padding: 18px 20px;
  }

  .admin-tile .tile-ico {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }

  .admin-tile .tile-label {
    font-size: 16px;
    font-weight: 700;
  }

  /* Desktop Data Tables */
  .table-container {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.05);
  }

  .data-table th {
    padding: 14px 20px;
    font-size: 13px;
    font-weight: 700;
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: 2px solid var(--border);
  }

  .data-table td {
    padding: 14px 20px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
  }

  .data-table tr:hover td {
    background: var(--surface-hover);
  }

  /* Modal on Desktop */
  .modal {
    max-width: 640px;
    border-radius: var(--radius-xl);
  }

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

  .stat-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
  }

  .list-card {
    padding: var(--space-lg);
  }

  .list-card-img {
    width: 80px;
    height: 80px;
    font-size: 40px;
  }
}

/* ===== LARGE DESKTOP (1440px+) ===== */
@media (min-width: 1440px) {
  .screen {
    max-width: 1440px;
    padding: var(--space-xl) 48px;
  }

  .screen.with-sidebar {
    max-width: 1680px;
    padding: var(--space-xl) 48px;
  }

  .action-grid,
  #home-action-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 20px;
  }

  .action-card {
    height: 150px;
  }

  .specialty-row {
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
  }

  .specialty-tile {
    min-height: 160px;
  }

  #catalog-list {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 20px !important;
  }

  #admin-stats {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 20px !important;
  }

  .admin-grid {
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 18px;
  }

  .modal {
    max-width: 720px;
  }
}

/* ===== TOUCH TARGETS ===== */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .tab { min-height: 44px; }
  .nav-item { min-width: 44px; min-height: 44px; }
  .qty-btn { width: 44px; height: 44px; }
  .list-card { min-height: 44px; }
  .profile-item { min-height: 44px; }
}

/* ===== TYPOGRAPHY SCALING ===== */
@media (min-width: 768px) {
  body {
    font-size: 16px;
  }
}

/* ===== HIGH DPI ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .input, .form-input {
    border-width: 0.5px;
  }
}

/* ===== PORTRAIT/LANDSCAPE ON TABLETS ===== */
@media (min-width: 768px) and (orientation: landscape) {
  .screen.with-sidebar {
    padding-top: var(--space-lg);
  }
}

/* ===== PRINT ===== */
@media print {
  .nav-bottom, .nav-sidebar, .install-banner, .toast {
    display: none !important;
  }
  .screen {
    padding: 0;
    max-width: 100%;
  }
  body {
    background: white;
    color: black;
  }
  .card, .card-glass, .stat-card, .cart-item {
    border: 1px solid #ccc;
    background: white;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

