/* ═══════════════════════════════════════════════════
   RESPONSIVE DESIGN — COMPLETE AUDIT & REWRITE
   Mobile-first, breakpoint-clean, fully tested
   ═══════════════════════════════════════════════════ */

/* ── RESET: Ensure box-sizing everywhere ── */
html, body, * {
  box-sizing: border-box;
}

/* ── BREAKPOINTS ── */
/* 320px: Extra small (old phones)
   480px: Small phones (iPhone SE)
   768px: Tablets portrait
   1024px: Tablets landscape / small desktop
   1440px: Desktop (1440p+)
*/

/* ═══════════════════════════════════════════════════
   MOBILE-FIRST (320px - 479px)
   ═══════════════════════════════════════════════════ */

/* Global mobile: remove overflow, set widths */
html {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

body {
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

/* Page content: full width, minimal padding */
.page-content {
  width: 100%;
  max-width: 100%;
  padding: 1rem 0.75rem;
  margin: 0;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* Dashboard shell: single column on small */
.dash-shell {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.dash-shell > div,
.dash-shell > aside {
  width: 100%;
  min-width: 0;
}

.dash-right {
  display: none !important;
}

/* KPI grid: 2 columns on mobile, tight */
.kpi-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
  padding: 0;
  margin: 0 0 1rem 0;
  box-sizing: border-box;
}

.kpi-card {
  width: 100%;
  min-width: 0;
  padding: 0.75rem;
  box-sizing: border-box;
}

.kpi-label {
  font-size: 0.65rem !important;
}

.kpi-val {
  font-size: 1.35rem !important;
}

/* Main container: full width */
.main-content {
  width: 100%;
  max-width: 100%;
  margin-left: 0;
  padding: 0;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* Sidebar: hidden by default, slide-in */
.sidebar {
  display: none;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

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

.sidebar-overlay {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Top bar: full width, no tricks */
.top-bar {
  width: 100%;
  padding: 0.75rem 0.75rem;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

/* ═══════════════════════════════════════════════════
   SMALL PHONES (480px - 767px)
   ═══════════════════════════════════════════════════ */

@media (min-width: 480px) {
  .page-content {
    padding: 1rem 1rem;
  }

  .kpi-card {
    padding: 0.875rem;
  }

  .kpi-label {
    font-size: 0.7rem !important;
  }

  .kpi-val {
    font-size: 1.5rem !important;
  }
}

/* ═══════════════════════════════════════════════════
   TABLETS PORTRAIT (768px - 1023px)
   ═══════════════════════════════════════════════════ */

@media (min-width: 768px) {
  .page-content {
    padding: 1.25rem 1.5rem;
  }

  .dash-shell {
    flex-direction: row;
    gap: 1.5rem;
  }

  .dash-shell > div:first-child {
    flex: 1;
    min-width: 0;
  }

  .dash-right {
    display: block !important;
    flex: 0 0 280px;
  }

  .sidebar {
    display: block;
    position: relative;
    width: 240px;
    transform: none;
    transition: none;
  }

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

  .kpi-strip {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
  }

  .kpi-card {
    padding: 1rem;
  }

  .kpi-label {
    font-size: 0.75rem !important;
  }

  .kpi-val {
    font-size: 1.6rem !important;
  }

  .top-bar {
    position: static;
    width: 100%;
    padding: 1rem;
  }
}

/* ═══════════════════════════════════════════════════
   TABLETS LANDSCAPE / SMALL DESKTOP (1024px - 1439px)
   ═══════════════════════════════════════════════════ */

@media (min-width: 1024px) {
  .page-content {
    padding: 1.5rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
  }

  .dash-shell {
    grid-template-columns: 1fr 300px;
    display: grid;
    gap: 1.5rem;
  }

  .sidebar {
    width: 256px;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
  }

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

  .kpi-strip {
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
  }

  .kpi-card {
    padding: 1.125rem;
  }
}

/* ═══════════════════════════════════════════════════
   DESKTOP (1440px+)
   ═══════════════════════════════════════════════════ */

@media (min-width: 1440px) {
  .page-content {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
  }

  .sidebar {
    width: 280px;
  }

  .main-content {
    margin-left: 280px;
  }

  .dash-right {
    flex: 0 0 320px;
  }
}

/* ═══════════════════════════════════════════════════
   UTILITIES — ensure nothing breaks responsive
   ═══════════════════════════════════════════════════ */

/* Prevent overflow on all flex/grid containers */
.platform-layout,
.dash-shell,
.kpi-strip,
.activity-wrap,
.ct-wrap {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* Text won't break layout */
img, video, iframe {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Tables scroll internally */
table {
  max-width: 100%;
}

.ct-wrap,
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

/* Remove all fixed widths that might overflow */
[style*="width: 520px"],
[style*="width: 600px"],
[style*="width: 800px"],
[style*="width: 1000px"] {
  max-width: 100% !important;
}
