/* ==========================================================================
   Comprehensive Mobile & Tablet Responsive Design System
   ========================================================================== */

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

button, a, input, select, textarea {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.table-scroll, .module-table-wrap, .table-tabs {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.content {
  width: 100%;
}

/* --- Large Displays (1500px+) --- */
@media (min-width: 1500px) {
  .content {
    padding-left: 42px;
    padding-right: 42px;
  }
  .metrics {
    gap: 18px;
  }
  .dashboard-grid {
    gap: 18px;
  }
  .metric-card {
    min-height: 150px;
  }
  .stock-chart {
    min-height: 320px;
  }
}

/* --- Laptops & Small Desktops (1100px) --- */
@media (max-width: 1100px) {
  .topbar {
    padding-inline: 22px;
  }
  .content {
    padding-inline: 22px;
  }
  .global-search {
    width: min(390px, 40vw);
  }
  .donut-wrap {
    gap: 16px;
  }
  .category-list {
    min-width: 145px;
  }
}

/* --- Tablets & Mobile Landscape (900px) --- */
@media (max-width: 900px) {
  .sidebar {
    width: min(84vw, 290px);
    transform: translateX(-105%);
    transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1), visibility .25s;
    box-shadow: 14px 0 42px rgba(0, 0, 0, .28);
    visibility: hidden;
    height: 100dvh;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .sidebar.open {
    transform: translateX(0);
    visibility: visible;
  }
  .sidebar-overlay.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(7, 17, 12, .56);
    backdrop-filter: blur(3px);
    z-index: 19;
  }
  main {
    margin-left: 0;
  }
  .menu-btn {
    display: grid;
  }
  .topbar {
    height: 66px;
    padding-inline: 18px;
  }
  .content {
    padding: 24px 18px 36px;
  }
  .global-search {
    width: auto;
    flex: 1;
    margin: 0 12px;
  }
  .profile > div:nth-child(2) {
    display: none;
  }
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .category-panel {
    min-height: auto;
  }
  .module-two-col {
    grid-template-columns: 1fr;
  }
  .profile-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .nav {
    overscroll-behavior: contain;
  }
  .sidebar-bottom {
    padding-top: 8px;
    background: var(--sidebar);
  }
}

/* --- Smartphones & Small Tablets (680px) --- */
@media (max-width: 680px) {
  .topbar {
    gap: 6px;
    padding-inline: 12px;
    height: 62px;
  }
  .global-search {
    margin: 0 4px;
    height: 38px;
  }
  .global-search kbd {
    display: none;
  }
  .top-actions {
    gap: 4px;
  }
  .top-actions .profile,
  .top-actions .admin-badge {
    display: none;
  }
  .icon-btn {
    width: 38px;
    height: 38px;
  }
  .logout-btn {
    width: 38px;
    padding: 0;
    font-size: 0;
  }
  .logout-btn:after {
    content: "↪";
    font-size: 17px;
  }
  .content {
    padding: 18px 12px 32px;
  }
  .page-heading,
  .module-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .page-heading h1,
  .module-heading h1 {
    font-size: 21px;
    line-height: 1.25;
  }
  .page-heading > div > p:last-child,
  .module-heading > div > p:last-child {
    line-height: 1.45;
  }
  .page-heading .primary-btn,
  .module-heading > .primary-btn {
    width: 100%;
    min-height: 42px;
    justify-content: center;
    font-size: 13px;
  }
  .metrics {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .metric-card {
    min-height: 120px;
    padding: 15px 16px;
  }
  .metric-label {
    left: 60px;
    top: 17px;
  }
  .dashboard-grid {
    gap: 12px;
  }
  .panel {
    padding: 16px;
  }
  .panel-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .panel-head select {
    width: 100%;
    max-width: none;
    height: 38px;
  }
  .stock-chart {
    overflow: hidden;
  }
  .chart-wrap {
    height: 170px;
  }
  .chart-legend {
    justify-content: flex-start;
    margin: 10px 0 4px 20px;
  }
  .donut-wrap {
    flex-direction: column;
    padding: 10px 0;
  }
  .category-list {
    width: 100%;
  }
  .category-list > div {
    padding: 9px 0;
  }
  .table-title {
    padding: 14px 16px;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }
  .table-title > div:last-child {
    justify-content: space-between;
  }
  .table-tabs {
    padding-inline: 14px;
    gap: 18px;
  }
  .inventory-table table {
    min-width: 760px;
  }
  .module-table {
    min-width: 680px;
  }
  th, td {
    padding-inline: 11px;
    padding-block: 10px;
  }
  .table-footer {
    padding-inline: 14px;
  }
  .table-footer > span {
    display: none;
  }
  .form-grid {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 13px;
  }
  .form-grid .full {
    grid-column: auto;
  }
  dialog {
    width: 100%;
    max-height: 94dvh;
    border-radius: 16px 16px 0 0;
    overflow: auto;
  }
  .dialog-head {
    padding: 18px;
  }
  .dialog-actions {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    padding: 12px 18px max(12px, env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
  }
  .dialog-actions button {
    flex: 1;
    min-height: 44px;
  }
  .module-card {
    padding: 16px;
  }
  .category-grid,
  .warehouse-grid,
  .report-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .order-summary {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .inline-fields {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .product-tools {
    flex-direction: column;
    gap: 10px;
  }
  .product-tools select {
    height: 42px;
    width: 100%;
  }
  .profile-layout {
    grid-template-columns: 1fr;
  }
  .profile-summary {
    padding-bottom: 16px;
  }
  .profile-form-actions {
    flex-direction: column-reverse;
    gap: 10px;
  }
  .profile-form-actions button {
    width: 100%;
    min-height: 44px;
  }
  .toast {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: auto;
  }
}

/* --- Extra Small Screens (440px and below) --- */
@media (max-width: 440px) {
  .global-search input::placeholder {
    color: transparent;
  }
  .global-search {
    max-width: none;
    padding-inline: 10px;
  }
  .content {
    padding-inline: 10px;
  }
  .eyebrow {
    font-size: 9px;
  }
  .metric-card {
    padding: 14px;
  }
  .metric-label {
    left: 54px;
  }
  .panel {
    border-radius: 10px;
    padding: 14px;
  }
  .table-tabs {
    gap: 14px;
  }
  .donut {
    width: 115px;
    height: 115px;
  }
  .auth-panel {
    padding: 20px 16px;
  }
  .auth-card h2 {
    font-size: 24px;
  }
  .auth-intro {
    margin-bottom: 20px;
  }
  .auth-form {
    gap: 14px;
  }
  .auth-input, .auth-submit {
    height: 46px;
  }
  .auth-demo {
    margin-top: 16px;
  }
  .auth-footer {
    margin-top: 16px;
  }
  .profile-avatar-large {
    width: 66px;
    height: 66px;
  }
  .order-summary {
    grid-template-columns: 1fr;
  }
}

/* --- Orientation & Height Adjustments --- */
@media (max-height: 720px) and (min-width: 801px) {
  .auth-visual {
    padding: 32px 44px;
  }
  .auth-message h1 {
    font-size: 40px;
    margin: 12px 0;
  }
  .auth-card h2 {
    font-size: 26px;
  }
  .auth-intro {
    margin-bottom: 16px;
  }
  .auth-form {
    gap: 12px;
  }
  .auth-input {
    height: 44px;
  }
  .auth-submit {
    height: 44px;
  }
}

@media (max-width: 800px) {
  .auth-screen {
    min-height: 100dvh;
  }
  .auth-panel {
    min-height: 100dvh;
    align-items: center;
    overflow-y: auto;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
  .auth-card {
    max-width: 420px;
  }
  .auth-input, .auth-submit {
    min-height: 46px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *:before, *:after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}
