/* ========================================
   Polsia Responsive Design Framework
   Unified breakpoints & mobile patterns
   ======================================== */

:root {
  /* Unified breakpoints */
  --mobile: 640px;      /* ≤640px mobile */
  --tablet: 1024px;     /* 641-1024px tablet */
  --desktop: 1280px;    /* 1025-1279px desktop */
  --wide: 1280px;       /* 1280px+ wide */

  /* Common responsive spacing */
  --spacing-mobile: 1rem;
  --spacing-tablet: 1.5rem;
  --spacing-desktop: 2rem;
}

/* ========================================
   BREAKPOINT CONSOLIDATION
   Mobile: ≤640px
   Tablet: 641-1024px
   Desktop: 1025-1279px
   Wide: 1280px+
   ======================================== */

/* ========================================
   1. PRICING CARDS - Responsive Stack
   ======================================== */

.pricing-grid,
.pricing-cards,
.pricing-grid-3,
.pricing-grid-4 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  width: 100%;
}

/* Desktop adjustments */
@media (max-width: 1279px) {
  .pricing-grid-4 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Tablet: 2 columns */
@media (max-width: 1024px) {
  .pricing-grid,
  .pricing-cards,
  .pricing-grid-3,
  .pricing-grid-4 {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
}

/* Mobile: 1 column */
@media (max-width: 640px) {
  .pricing-grid,
  .pricing-cards,
  .pricing-grid-3,
  .pricing-grid-4 {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 0 1rem;
  }
}

/* ========================================
   2. CHANNEL PILLS - Horizontal Scroll
   ======================================== */

.channel-pills,
.pill-group,
.filter-tabs,
.tab-bar {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0.5rem 0;
}

/* Hide scrollbars on all browsers */
.channel-pills::-webkit-scrollbar,
.pill-group::-webkit-scrollbar,
.filter-tabs::-webkit-scrollbar,
.tab-bar::-webkit-scrollbar {
  display: none;
  height: 0;
}

.channel-pills > *,
.pill-group > *,
.filter-tabs > *,
.tab-bar > * {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Desktop: Normal flex wrap */
@media (min-width: 1025px) {
  .channel-pills,
  .pill-group,
  .filter-tabs,
  .tab-bar {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

/* ========================================
   3. COMPARISON TABLE - Mobile Stack
   ======================================== */

.comparison-table,
.feature-matrix,
.feat-matrix {
  width: 100%;
  border-collapse: collapse;
  overflow-x: auto;
}

/* Tablet & Desktop: Horizontal scroll wrapper */
@media (max-width: 1024px) {
  .comparison-table-wrapper,
  .table-scroll-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
  }

  .comparison-table,
  .feature-matrix,
  .feat-matrix {
    white-space: nowrap;
  }

  .comparison-table td,
  .comparison-table th,
  .feature-matrix td,
  .feature-matrix th,
  .feat-matrix td,
  .feat-matrix th {
    padding: 0.85rem 0.75rem;
    font-size: 0.9rem;
  }
}

/* Mobile: Full stack (rows become blocks) */
@media (max-width: 640px) {
  .comparison-table,
  .feature-matrix,
  .feat-matrix {
    display: block;
    border-radius: 12px;
    overflow: hidden;
  }

  .comparison-table thead,
  .feature-matrix thead,
  .feat-matrix thead {
    display: none;
  }

  .comparison-table tbody tr,
  .feature-matrix tbody tr,
  .feat-matrix tbody tr {
    display: block;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
  }

  .comparison-table td,
  .feature-matrix td,
  .feat-matrix td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    white-space: normal;
    border: none;
  }

  .comparison-table td::before,
  .feature-matrix td::before,
  .feat-matrix td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--gray-300);
    margin-right: 1rem;
  }
}

/* ========================================
   4. SIDEBAR / DRAWER - Hamburger Menu
   ======================================== */

/* Sidebar container */
.sidebar,
.app-sidebar,
.nav-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 280px;
  background: var(--gray-900);
  z-index: 150;
  transition: transform 0.3s ease-out;
  overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

/* Desktop: Always visible */
@media (min-width: 1025px) {
  .sidebar,
  .app-sidebar,
  .nav-sidebar {
    position: relative;
    height: auto;
    width: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    transform: translateX(0) !important;
  }
}

/* Tablet & Mobile: Hidden by default, slides in */
@media (max-width: 1024px) {
  .sidebar,
  .app-sidebar,
  .nav-sidebar {
    transform: translateX(-100%);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  }

  /* When menu is open */
  .sidebar.active,
  .sidebar.open,
  .app-sidebar.active,
  .app-sidebar.open,
  .nav-sidebar.active,
  .nav-sidebar.open {
    transform: translateX(0);
  }

  /* Overlay backdrop */
  .sidebar-overlay,
  .drawer-overlay,
  .menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 140;
  }

  .sidebar-overlay.active,
  .sidebar-overlay.show,
  .drawer-overlay.active,
  .drawer-overlay.show,
  .menu-overlay.active,
  .menu-overlay.show {
    opacity: 1;
    visibility: visible;
  }
}

/* Hamburger button */
.hamburger,
.menu-toggle,
.sidebar-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0.5rem;
  z-index: 160;
}

.hamburger span,
.menu-toggle span,
.sidebar-toggle span {
  width: 24px;
  height: 2px;
  background: var(--white);
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* Show hamburger on tablet & mobile */
@media (max-width: 1024px) {
  .hamburger,
  .menu-toggle,
  .sidebar-toggle {
    display: flex;
  }

  /* Hamburger animation: X on active */
  .hamburger.active span:nth-child(1),
  .menu-toggle.active span:nth-child(1),
  .sidebar-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translateY(10px);
  }

  .hamburger.active span:nth-child(2),
  .menu-toggle.active span:nth-child(2),
  .sidebar-toggle.active span:nth-child(2) {
    opacity: 0;
  }

  .hamburger.active span:nth-child(3),
  .menu-toggle.active span:nth-child(3),
  .sidebar-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translateY(-10px);
  }
}

/* ========================================
   5. RESPONSIVE ADJUSTMENTS - General
   ======================================== */

/* Typography: Clamp for fluid sizing */
h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
}

h2 {
  font-size: clamp(1.4rem, 4vw, 2.2rem);
}

/* Mobile padding adjustments */
@media (max-width: 640px) {
  body {
    padding-left: 0;
    padding-right: 0;
  }

  .container,
  .section,
  .content-wrapper {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.4rem; }
  h3 { font-size: 1.1rem; }
}

/* Mobile-first font overrides at 768px */
@media (max-width: 768px) {
  h1 { font-size: 1.5rem; }   /* 24px */
  h2 { font-size: 1.125rem; } /* 18px */
  /* body stays 14px - controlled by page */
}

/* Tablet padding */
@media (min-width: 641px) and (max-width: 1024px) {
  .container,
  .section,
  .content-wrapper {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

/* Desktop+ padding */
@media (min-width: 1025px) {
  .container,
  .section,
  .content-wrapper {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* ========================================
   6. UTILITY CLASSES
   ======================================== */

/* Hide on specific breakpoints */
.hide-sm { display: block; }  /* Show by default */
@media (max-width: 640px) { .hide-sm { display: none; } }

.hide-md { display: block; }
@media (max-width: 1024px) { .hide-md { display: none; } }

.hide-lg { display: block; }
@media (min-width: 1025px) { .hide-lg { display: none; } }

/* Show only on specific breakpoints */
.show-sm { display: none; }
@media (max-width: 640px) { .show-sm { display: block; } }

.show-md { display: none; }
@media (max-width: 1024px) and (min-width: 641px) { .show-md { display: block; } }

.show-lg { display: none; }
@media (min-width: 1025px) { .show-lg { display: block; } }

/* Flex direction responsive */
.flex-col-mobile {
  flex-direction: column;
}

@media (min-width: 641px) {
  .flex-col-mobile {
    flex-direction: row;
  }
}

/* ========================================
   7. CONTENT MAIN AREA - Sidebar Offset
   ======================================== */

.main-content,
.app-main,
.content-main {
  display: flex;
  flex-direction: column;
}

/* When sidebar is present and visible */
@media (min-width: 1025px) {
  .with-sidebar .main-content,
  .with-sidebar .app-main,
  .with-sidebar .content-main {
    margin-left: 280px;
    flex: 1;
  }
}

/* ========================================
   8. RESPONSIVE GRID PATTERNS
   ======================================== */

/* Auto-fit grids - flexible */
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

@media (max-width: 640px) {
  .grid-auto {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
  }
}

/* Fixed column grids */
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .grid-4,
  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* ========================================
   9. FORM ELEMENTS - Mobile Friendly
   ======================================== */

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  font-size: 16px;  /* Prevents iOS auto-zoom */
}

@media (max-width: 640px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  textarea,
  select {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
  }
}

/* ========================================
   10. IMAGE & MEDIA RESPONSIVE
   ======================================== */

img, video, iframe {
  max-width: 100%;
  height: auto;
  display: block;
}

@media (max-width: 640px) {
  .aspect-video {
    aspect-ratio: 16 / 9;
    width: 100%;
  }

  .aspect-square {
    aspect-ratio: 1 / 1;
    width: 100%;
  }
}

/* ========================================
   11. STAT CARDS - Responsive Grid
   ======================================== */

/* Auto-fit: 4 cols on wide, 2×2 on tight tablet, 1 col mobile */
.stats-grid,
.stat-cards-grid,
.stats-row,
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* Tight tablet (768-899px): force 2×2 */
@media (min-width: 768px) and (max-width: 899px) {
  .stats-grid,
  .stat-cards-grid,
  .stats-row,
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile: single column */
@media (max-width: 640px) {
  .stats-grid,
  .stat-cards-grid,
  .stats-row,
  .kpi-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

/* ========================================
   12. DATA TABLES - Responsive Scroll
   ======================================== */

/* Wrap any data table in .data-table-wrap for horizontal scroll */
.data-table-wrap,
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  border-radius: 10px;
  /* Inset shadow on right edge indicates more content */
  box-shadow: inset -10px 0 8px -8px rgba(0, 0, 0, 0.3);
}

.data-table-wrap table,
.table-responsive table {
  width: 100%;
  border-collapse: collapse;
}

/* Min column widths prevent text cramming */
.data-table-wrap table th,
.data-table-wrap table td,
.table-responsive table th,
.table-responsive table td {
  min-width: 100px;
  white-space: nowrap;
}

/* First column sticky */
.data-table-wrap table th:first-child,
.data-table-wrap table td:first-child,
.table-responsive table th:first-child,
.table-responsive table td:first-child {
  position: sticky;
  left: 0;
  background: #111616;
  z-index: 1;
}

/* Light mode sticky column bg */
html.light-mode .data-table-wrap table th:first-child,
html.light-mode .data-table-wrap table td:first-child,
html.light-mode .table-responsive table th:first-child,
html.light-mode .table-responsive table td:first-child {
  background: #ffffff;
}

/* Touch target min-height on table rows */
.data-table-wrap table tbody tr,
.table-responsive table tbody tr {
  min-height: 44px;
}

.data-table-wrap table tbody td,
.table-responsive table tbody td {
  height: 44px;
}

/* ========================================
   13. CHARTS - Tablet & Mobile
   ======================================== */

/* Full width on tablet */
@media (max-width: 1023px) {
  .chart-container,
  .chart-wrap,
  .chart-wrapper,
  .recharts-wrapper,
  canvas.chart-canvas {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Increase touch target sizes on chart interactive elements */
  .chart-container circle,
  .chart-container .dot,
  .chart-wrap circle,
  .chart-wrap .dot {
    r: 6;
  }
}

/* Legend below chart on narrow screens */
@media (max-width: 899px) {
  .chart-with-legend {
    flex-direction: column !important;
  }

  .chart-legend,
  .recharts-legend-wrapper {
    flex-direction: row !important;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 0.75rem !important;
    margin-left: 0 !important;
  }

  .chart-legend-item {
    margin: 0.25rem 0.5rem;
  }
}
