/**
 * RADEXEL Design System - Responsive Breakpoints
 *
 * 4 breakpoints (mobile-first approach with max-width overrides):
 *   1024px - Tablet landscape / small desktop
 *   768px  - Tablet portrait
 *   640px  - Large phone
 *   480px  - Small phone (compact mode)
 */

/* ==========================================================================
   Breakpoint: <= 1024px (Tablet Landscape)
   Left sidebar becomes overlay drawer, right sidebar stays.
   ========================================================================== */

@media (max-width: 1024px) {
  :root {
    --left-sidebar-width: 280px;
  }

  /* Sidebar becomes an overlay drawer */
  .app-body {
    grid-template-columns: 0px 1fr var(--right-sidebar-width);
  }

  .left-sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--left-sidebar-width);
    z-index: var(--z-modal);
    transform: translateX(-100%);
    transition: transform var(--duration-slow) var(--ease-default);
    box-shadow: none;
  }

  .left-sidebar.drawer-open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  /* Show backdrop when drawer is open */
  .sidebar-backdrop.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  /* Content takes full width minus right sidebar */
  .main-content__inner {
    padding: var(--space-5);
  }

  /* Dashboard grid adjustments */
  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }
}


/* ==========================================================================
   Breakpoint: <= 768px (Tablet Portrait)
   Hide left sidebar by default, adjust topbar, stack more layouts.
   ========================================================================== */

@media (max-width: 768px) {
  :root {
    --topbar-height: 52px;
  }

  /* Remove right sidebar on tablet portrait */
  .app-body {
    grid-template-columns: 0px 1fr 0px;
  }

  .right-sidebar {
    display: none;
  }

  /* Show bottom navigation on mobile */
  .bottom-nav {
    display: flex;
  }

  /* Add bottom padding to content area for bottom nav */
  .content-area {
    padding-bottom: var(--bottom-nav-height);
  }

  /* Adjust toast position above bottom nav */
  .toast-container {
    bottom: calc(var(--bottom-nav-height) + var(--space-3));
  }

  /* Topbar compacts */
  .topbar__title {
    font-size: var(--font-size-base);
  }

  .topbar__subtitle {
    display: none;
  }

  /* Content area padding reduces */
  .main-content__inner {
    padding: var(--space-4);
  }

  /* Cards reduce padding */
  .card {
    padding: var(--space-4);
  }

  /* Dashboard grid single column fallback */
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

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

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .page-header__actions {
    width: 100%;
    justify-content: flex-start;
  }

  /* Container reduces side padding */
  .container {
    padding: 0 var(--space-4);
  }

  /* Tables become scrollable */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Modal adjustments */
  .modal {
    margin: var(--space-4);
    max-height: calc(100vh - var(--space-8));
    max-height: calc(100dvh - var(--space-8));
  }
}


/* ==========================================================================
   Breakpoint: <= 640px (Large Phone)
   Stack layouts, full-width content, simplified UI.
   ========================================================================== */

@media (max-width: 640px) {
  /* Sidebar drawer becomes full-width */
  .left-sidebar {
    width: 100%;
    max-width: 100%;
  }

  /* Content padding minimal */
  .main-content__inner {
    padding: var(--space-3);
  }

  /* Cards tight */
  .card {
    padding: var(--space-3);
    border-radius: var(--radius-md);
  }

  /* Stat grid single col */
  .stat-grid {
    grid-template-columns: 1fr;
  }

  /* Buttons full width in some contexts */
  .page-header__actions {
    flex-wrap: wrap;
  }

  .page-header__actions .btn {
    flex: 1;
    min-width: 0;
  }

  /* Modal becomes nearly full-screen */
  .modal {
    margin: var(--space-2);
    border-radius: var(--radius-md);
    max-width: 100%;
  }

  .modal-body {
    max-height: calc(100vh - 180px);
    max-height: calc(100dvh - 180px);
  }

  /* Form groups go full-width */
  .form-row {
    flex-direction: column;
  }

  .form-row > * {
    width: 100%;
  }

  /* Tab navigation scrollable */
  .tab-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tab-nav::-webkit-scrollbar {
    display: none;
  }

  /* Divider text smaller */
  .divider {
    font-size: var(--font-size-xs);
    margin: var(--space-4) 0;
  }

  /* Toast notifications full-width */
  .toast-container {
    left: var(--space-3);
    right: var(--space-3);
    bottom: var(--space-3);
  }

  .toast {
    width: 100%;
  }
}


/* ==========================================================================
   Breakpoint: <= 480px (Small Phone / Compact Mode)
   Minimal padding, smaller fonts, single-column everything.
   ========================================================================== */

@media (max-width: 480px) {
  :root {
    --topbar-height: 48px;
    --font-size-base: 0.8125rem;
    --font-size-md: 0.9375rem;
    --font-size-lg: 1rem;
    --font-size-xl: 1.125rem;
    --font-size-2xl: 1.25rem;
    --font-size-3xl: 1.5rem;
  }

  /* Minimal padding everywhere */
  .main-content__inner {
    padding: var(--space-2);
  }

  .card {
    padding: var(--space-3);
    border-radius: var(--radius-sm);
  }

  /* Page title smaller */
  .page-header h2 {
    font-size: var(--font-size-xl);
  }

  /* Topbar compact */
  .topbar {
    padding: 0 var(--space-3);
  }

  .topbar__logo-text {
    font-size: var(--font-size-base);
  }

  /* User menu minimal */
  .user-info {
    display: none;
  }

  /* Modal fullscreen on tiny screens */
  .modal {
    margin: 0;
    border-radius: 0;
    height: 100%;
    max-height: 100%;
    max-height: 100dvh;
  }

  .modal-body {
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px);
  }

  /* Container no side padding */
  .container {
    padding: 0 var(--space-3);
  }

  /* Buttons shrink */
  .btn {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
  }

  .btn-sm {
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
  }

  /* Dropdown menus full width */
  .dropdown-menu {
    position: fixed;
    left: var(--space-3);
    right: var(--space-3);
    max-width: none;
  }
}


/* ==========================================================================
   Hover-capable Device Detection
   Only show hover effects on devices that support hover.
   ========================================================================== */

@media (hover: none) {
  .card:hover {
    box-shadow: var(--shadow-sm);
  }

  .btn:hover {
    filter: none;
  }
}


/* ==========================================================================
   Touch Device Enhancements
   ========================================================================== */

@media (pointer: coarse) {
  /* Larger tap targets */
  .btn {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 36px;
  }

  .nav-item {
    min-height: 44px;
  }

  .dropdown-item {
    min-height: 44px;
  }

  /* Wider touch scrollbar */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
}


/* ==========================================================================
   Landscape Phone
   ========================================================================== */

@media (max-height: 500px) and (orientation: landscape) {
  .app-layout {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .modal {
    max-height: 90vh;
    max-height: 90dvh;
  }
}


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

@media print {
  .left-sidebar,
  .right-sidebar,
  .topbar,
  .sidebar-backdrop,
  .toast-container,
  .modal-overlay,
  .btn {
    display: none !important;
  }

  .app-body {
    display: block;
  }

  .main-content {
    overflow: visible;
  }

  .main-content__inner {
    padding: 0;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }

  body {
    color: #000;
    background: #fff;
  }

  a {
    color: #000;
    text-decoration: underline;
  }
}
