/* ===================================================================
   LAYOUT / UTILITIES (iOS-friendly, vertical-first)
   Mobile: Full-width cards, proper badge wrapping
   Desktop: Current hamburger menu + wider layout
   =================================================================== */

/* ---------- CSS Variables for Safe Areas ---------- */
:root {
  /* Safe area insets */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  
  /* Banner height */
  --as-banner-h: 56px;
  --mobile-dock-h: 68px;
  
  /* Control height for buttons */
  --ctl-h: 36px;
  
  /* Mobile vs Desktop spacing */
  --page-pad-mobile: 0px;
  --page-pad-desktop: 16px;
}

/* ---------- Flex & Grid helpers ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.center { justify-content: center; }

.col { display: grid; gap: 8px; }
.center { display: grid; place-items: center; }

.stack { display: grid; gap: 12px; }
.stack-sm { display: grid; gap: 8px; }
.stack-lg { display: grid; gap: 16px; }

/* ---------- Spacing helpers ---------- */
.pad-sm { padding: 8px; }
.pad    { padding: 16px; }
.pad-lg { padding: 24px; }

.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

/* ---------- Fullscreen/safe-area aware panels ---------- */
.fullscreen-panel {
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.scroll-y {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---------- Sticky, frosted headers ---------- */
.ms__hdr, .cs__hdr {
  position: sticky;
  top: 0;
  z-index: 1000;

  -webkit-backdrop-filter: blur(12px) saturate(1.05);
  backdrop-filter: blur(12px) saturate(1.05);
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  border-bottom: 1px solid rgba(255,255,255,.08);

  padding: 12px 16px;
}

/* Titles */
.ms__title, .cs__title {
  font-weight: 800;
  letter-spacing: .3px;
  font-size: 26px;
  margin: 0;
  text-align: center;
}

/* ---------- Z-layers ---------- */
.z-modal   { z-index: 15000; }
.z-overlay { z-index: 12000; }
.z-dock    { z-index: 11000; }
.z-header  { z-index: 1000; }

/* ---------- Toolbars ---------- */
.as-toolbar button,
.as-toolbar .as-btn,
.as-toolbar .as-btn--ghost,
.as-c-main__hdr .as-btn,
.as-c-main__hdr .as-btn--ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--ctl-h);
  padding: 0 12px;
  line-height: 1;
  border-radius: 999px;
}

/* ===================================================================
   MAIN CONTENT AREA - Responsive
   =================================================================== */

/* Module root - solid background */
#moduleRoot {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  background: #0f1522 !important;
  overflow-x: hidden;
}

/* Main content wrapper */
.ms-main,
.cs-main,
.as-c-main__body,
[class*="__main"] {
  position: relative;
  min-height: 100%;
  background: #0f1522;
}

/* ===================================================================
   COURSE BUILDER - Grid and Editor Container
   =================================================================== */

/* Main body: Relative positioning for children */
.as-c-main__body {
  position: relative;
  min-height: calc(100vh - 80px);
}

/* Grid: Takes full space when visible */
.as-grid {
  position: relative;
  z-index: 1;
}

/* Editor: Overlays grid when visible, hidden by default */
.as-editor {
  position: absolute;
  inset: 0;
  background: var(--bg, #0f1522);
  z-index: 10;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

/* When editor has [hidden] attribute, it's not displayed */
.as-editor[hidden] {
  display: none;
}

/* When grid has [hidden] attribute, it's not displayed */
.as-grid[hidden] {
  display: none;
}

/* Accordion inside editor */
.as-acc {
  max-width: 800px;
  margin: 0 auto;
}

/* Mobile: Extra bottom padding for editor toolbar */
@media (max-width: 720px) {
  .as-editor {
    padding-bottom: calc(var(--mobile-dock-h) + var(--safe-bottom) + 100px);
    /* Extra space for mobile editor toolbar buttons */
  }
}

/* ===================================================================
   COURSE CARDS - Mobile Full-Width, Desktop Grid
   =================================================================== */

/* Course grid container */
.ms__grid,
.cs__grid,
.as-grid,
[class*="__grid"] {
  display: grid;
  width: 100%;
}

/* Course cards - base styles */
.ms-card,
.cs-card,
.course-card,
.ms-row {
  width: 100%;
  box-sizing: border-box;
  border-radius: var(--radius, 12px);
  background: color-mix(in srgb, var(--panel-2, #1a2030) 92%, #000);
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Course card images */
.ms-card img,
.cs-card img,
.course-card img,
.ms-card__img,
.cs-card__img,
.ms-row__thumb {
  width: 100%;
  height: auto;
  object-fit: cover;
  flex-shrink: 0;
}

/* Course card content */
.ms-card__body,
.cs-card__body,
.ms-row__meta {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

/* Course card title */
.ms-card__title,
.cs-card__title,
.ms-row__name {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Course card metadata */
.ms-card__meta,
.cs-card__meta,
.ms-row__details {
  font-size: 13px;
  opacity: 0.8;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Course card tags */
.ms-card__tags,
.cs-card__tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
}

/* ===================================================================
   AUDIENCE BADGES - CRITICAL FIX for mobile wrapping
   =================================================================== */

/* Audience badge container - ✅ MUST WRAP on mobile */
.ms-row__audience-container {
  display: flex;
  gap: 6px;
  flex-wrap: wrap !important; /* CRITICAL: Allow wrapping */
  align-items: center;
  width: 100%;
}

/* Audience badges */
.ms-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  border: 1px solid;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Bronze - Beginner */
.ms-badge--beginner {
  background: linear-gradient(135deg, #cd7f32 0%, #b8722d 100%);
  color: #fff;
  border-color: rgba(255, 255, 255, .2);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

/* Silver - Intermediate */
.ms-badge--intermediate {
  background: linear-gradient(135deg, #c0c0c0 0%, #a8a8a8 100%);
  color: #1a1a1a;
  border-color: rgba(255, 255, 255, .3);
  text-shadow: 0 1px 1px rgba(255, 255, 255, .3);
}

/* Gold - Advanced */
.ms-badge--advanced {
  background: linear-gradient(135deg, #ffd700 0%, #ffb300 100%);
  color: #1a1a1a;
  border-color: rgba(255, 255, 255, .3);
  text-shadow: 0 1px 1px rgba(255, 255, 255, .3);
}

/* ===================================================================
   MOBILE LAYOUT (≤720px) - Full-width cards
   =================================================================== */

@media (max-width: 720px) {
  .mobile-hide { display: none !important; }
  
  /* Remove wallpaper on mobile */
  body::before {
    display: none !important;
  }
  
  body {
    background: #0f1522 !important;
    background-image: none !important;
  }
  
  /* Module root: Full-width, padding for dock */
  #moduleRoot {
    padding: 0 !important;
    padding-top: max(12px, var(--safe-top)) !important;
    padding-bottom: calc(var(--mobile-dock-h) + var(--safe-bottom) + 16px) !important;
  }
  
  /* Main content: No horizontal padding for grid, but editor needs it */
  .ms-main,
  .cs-main,
  [class*="__main"]:not(.as-c-main__body) {
    padding: 0 !important;
    padding-bottom: 24px !important;
  }
  
  /* Main body container keeps its structure */
  .as-c-main__body {
    padding: 0 !important;
  }
  
  /* Grid: Full-width with minimal gap */
  .ms__grid,
  .cs__grid,
  .as-grid:not(.is-list),
  [class*="__grid"] {
    gap: 12px !important;
    padding: 0 12px !important;
    grid-template-columns: 1fr !important;
  }
  
  /* List view: Full-width cards */
  .as-grid.is-list {
    display: block !important;
    padding: 0 12px 24px 12px !important;
  }
  
  /* Course cards on mobile: Full-width */
  .ms-card,
  .cs-card,
  .course-card,
  .ms-row {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 12px !important;
  }
  
  /* List row: Full-width with proper spacing */
  .ms-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    gap: 14px !important;
    padding: 14px !important;
    margin-bottom: 12px !important;
  }
  
  /* Row thumbnail: Compact on mobile */
  .ms-row__thumb {
    width: 120px !important;
    height: 90px !important;
    flex: 0 0 120px !important;
    border-radius: 10px !important;
  }
  
  /* Row metadata: Flex to fill space */
  .ms-row__meta {
    flex: 1 !important;
    min-width: 0 !important;
    padding: 0 !important;
    gap: 10px !important;
  }
  
  /* Row name: Smaller on mobile */
  .ms-row__name {
    font-size: 15px !important;
    line-height: 1.3 !important;
  }
  
  /* Row details: Wrap on mobile */
  .ms-row__details {
    font-size: 13px !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  
  /* Price: Slightly smaller */
  .ms-row__price {
    font-size: 14px !important;
  }
  
  /* Badges: Smaller but readable */
  .ms-badge {
    font-size: 9px !important;
    padding: 3px 8px !important;
  }
  
  /* Audience container: MUST wrap */
  .ms-row__audience-container {
    flex-wrap: wrap !important;
    max-width: 100% !important;
    overflow: visible !important;
  }
  
  /* Headers: Smaller font */
  .ms__title, .cs__title {
    font-size: 20px !important;
  }
  
  .ms__hdr, .cs__hdr {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
}

/* ===================================================================
   DESKTOP LAYOUT (>720px) - Current menu style persists
   =================================================================== */

@media (min-width: 721px) {
  /* Module root: Padding for banner + margins */
  #moduleRoot {
    padding: calc(var(--safe-top) + var(--as-banner-h)) var(--page-pad-desktop) 24px var(--page-pad-desktop);
  }
  
  /* Main content: Standard padding */
  .ms-main,
  .cs-main,
  [class*="__main"]:not(.as-c-main__body) {
    padding: 16px;
    padding-bottom: 24px;
  }
  
  /* Main body container */
  .as-c-main__body {
    padding: 6px 16px 18px;
  }
  
  /* Grid: Standard grid layout */
  .ms__grid,
  .cs__grid,
  .as-grid:not(.is-list),
  [class*="__grid"] {
    gap: 16px;
    padding: 0;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
  
  /* Course cards on desktop: Constrained */
  .ms-card,
  .cs-card,
  .course-card {
    max-height: 280px;
  }
  
  .ms-card img,
  .cs-card img,
  .course-card img {
    max-height: 140px;
  }
  
  /* List row: Wider on desktop */
  .ms-row {
    gap: 18px;
    padding: 16px 20px;
  }
  
  /* Row thumbnail: Larger on desktop */
  .ms-row__thumb {
    width: 180px;
    height: 135px;
    flex-basis: 180px;
  }
  
  /* Row name: Standard size */
  .ms-row__name {
    font-size: 17px;
  }
  
  /* Row details: Standard */
  .ms-row__details {
    font-size: 14px;
    gap: 10px;
  }
  
  /* Price: Standard */
  .ms-row__price {
    font-size: 15px;
  }
  
  /* Badges: Standard */
  .ms-badge {
    font-size: 10px;
    padding: 4px 10px;
  }
  
  /* Badges can scroll horizontally on desktop if needed */
  .ms-row__audience-container {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  
  .ms-row__audience-container::-webkit-scrollbar {
    display: none;
  }
}

/* ===================================================================
   SETTINGS PANEL - Responsive
   =================================================================== */

.as-settings {
  position: fixed;
  inset: 0;
  display: flex;
  gap: 24px;
  padding: 24px;
  background: var(--panel-2, #1a2030);
  z-index: 10000;
  overflow: hidden;
  color: var(--ink, #eef3ff);
  font-family: system-ui, sans-serif;
}

@media (max-width: 720px) {
  .as-settings {
    flex-direction: column;
    padding: 16px;
    padding-top: max(16px, var(--safe-top));
    padding-bottom: calc(var(--mobile-dock-h) + var(--safe-bottom) + 16px);
  }
  
  .as-settings__sidebar {
    min-width: auto;
    border-right: none;
    border-bottom: 1px solid var(--stroke, rgba(255,255,255,0.1));
    padding-right: 0;
    padding-bottom: 12px;
    flex-direction: row;
    overflow-x: auto;
  }
}

@media (min-width: 721px) {
  .as-settings {
    padding-left: max(24px, var(--safe-left));
    padding-right: max(24px, var(--safe-right));
    padding-top: max(24px, calc(var(--safe-top) + 24px));
    padding-bottom: max(24px, var(--safe-bottom));
  }
}

.as-settings__sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 8px;
  border-right: 1px solid var(--stroke, rgba(255,255,255,0.1));
}

.as-settings__tab {
  padding: 10px 14px;
  font-weight: 600;
  background: #101521;
  color: #eef3ff;
  border: 1px solid #2a3140;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}

.as-settings__tab:hover {
  background: rgba(255, 255, 255, 0.04);
}

.as-settings__tab.active {
  background: var(--blue, #3b82f6);
  color: #fff;
  border-color: var(--blue, #3b82f6);
}

.as-settings__content {
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.as-settings__content::-webkit-scrollbar {
  width: 8px;
}

.as-settings__content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* ===================================================================
   MODALS - Responsive
   =================================================================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: grid;
  place-items: center;
  z-index: 12000;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.modal__panel {
  background: var(--panel-2, #1a2030);
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  max-width: 320px;
  width: calc(100% - 32px);
  color: var(--ink, #eef3ff);
}

.modal__panel h3 {
  margin: 0 0 8px;
}

.modal__panel p {
  margin: 0 0 16px;
}

.modal .as-btn.danger {
  background: #ff3b30;
  color: #fff;
  border: none;
}

/* ===================================================================
   iOS OVERLAYS
   =================================================================== */

.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 12000;
}

.overlay-panel {
  position: fixed;
  inset: auto 0 0 0;
  max-height: min(86svh, 86dvh);
  background: var(--panel);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  box-shadow: 0 -8px 24px rgba(0,0,0,.4);
  z-index: 15000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: var(--safe-bottom);
}

.overlay-panel__body {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: max(16px, var(--safe-bottom));
} 