/* ============================================================
   RJSOL PRO — MOBILE GLOBAL STYLESHEET v4 (mobile-first)
   Layout only (no theme colors — dark theme preserved).
   Base styles = mobile. Desktop overrides via min-width queries.
   ============================================================ */

/* ── Reset body — stop horizontal scroll, allow vertical ── */
html {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  height: auto !important;
}
body {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  height: auto !important;
  padding-bottom: var(--bottom-nav-height, 56px) !important;
}

/* ── Root / shell viewport lock ── */
#root {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
}
#mobileShell {
  width: 100% !important;
  max-width: 100vw !important;
  overflow-x: hidden !important;
}

/* ── Solar Design Tool: preserve full-height flex layout ── */
body.solar-design-page {
  height: 100% !important;
  overflow: hidden !important;
}
body.solar-design-page #map {
  height: 100% !important;
  min-height: 0 !important;
}

/* ── JJ Chat: preserve full-height flex layout for chat interface ── */
body.jj-chat-page {
  height: 100% !important;
  overflow: hidden !important;
}

/* ── App Layout: stack sidebar above main content (mobile base) ── */
.app-layout {
  flex-direction: column !important;
  width: 100% !important;
  max-width: 100vw !important;
  height: auto !important;
}

/* ── Hide sidebar on mobile (base state) ── */
.sidebar,
#sidebar,
.sidebar.collapsed {
  display: none !important;
  width: 0 !important;
  min-width: 0 !important;
  flex-shrink: 0 !important;
}

/* ── Main content: full width (mobile base) ── */
.main-content {
  width: 100% !important;
  max-width: 100vw !important;
  min-height: calc(100vh - var(--bottom-nav-height, 56px)) !important;
  margin: 0 !important;
  padding: 14px !important;
  flex: 1 1 auto !important;
  overflow-y: auto !important;
}

/* ── Desktop overrides: restore sidebar + layout ── */
@media (min-width: 769px) {
  .app-layout {
    flex-direction: row !important;
    height: 100% !important;
  }
  .sidebar,
  #sidebar {
    display: flex !important;
    width: 248px !important;
    min-width: auto !important;
    flex-shrink: 0 !important;
  }
  .sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    display: flex !important;
    opacity: 0;
  }
  .main-content {
    min-height: 100vh !important;
    margin: 0 !important;
    padding: 24px !important;
  }
  body {
    padding-bottom: 0 !important;
  }
}

/* ── Topbar: proper height, no background override ── */
.topbar {
  height: auto !important;
  min-height: var(--bottom-nav-height, 56px) !important;
  padding: 8px 14px !important;
  flex-wrap: nowrap !important;
}

/* ── Sidebar toggle (hamburger): hidden on mobile (bottom nav replaces it) ── */
#sidebarToggle,
.sidebar-toggle {
  display: none !important;
}
@media (min-width: 769px) {
  #sidebarToggle,
  .sidebar-toggle {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 36px !important;
    height: 36px !important;
    background: transparent !important;
    border: none !important;
    border-radius: 8px !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
  }
}

/* ── Sidebar mobile-open overlay (slide-in drawer) ── */
.sidebar.mobile-open {
  width: 100% !important;
  max-width: 100vw !important;
  border-right: none !important;
  display: block !important;
  padding: 8px !important;
  overflow-y: visible !important;
}

.sidebar.mobile-open .sidebar-section {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 8px !important;
  margin-bottom: 16px !important;
  padding: 6px 0 !important;
}

.sidebar.mobile-open .sidebar-logo-header { display: none !important; }
.sidebar.mobile-open .sidebar-divider { display: none !important; }
.sidebar.mobile-open .sidebar-footer { display: none !important; }

.sidebar.mobile-open .sidebar-item {
  border-radius: 12px !important;
  padding: 16px 10px !important;
  text-align: center !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 100px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  margin: 2px 4px !important;
}

.sidebar.mobile-open .sidebar-icon { margin-bottom: 6px !important; }
.sidebar.mobile-open .sidebar-icon svg {
  stroke: currentColor !important;
  fill: none !important;
  width: 22px !important;
  height: 22px !important;
}

.sidebar.mobile-open .sidebar-label {
  font-weight: 600 !important;
  font-size: 12px !important;
  line-height: 1.3 !important;
}

.sidebar.mobile-open .active-badge {
  font-size: 0.6rem !important;
  padding: 2px 6px !important;
  border-radius: 10px !important;
  margin-top: 4px !important;
  font-weight: 700 !important;
}

/* ── Main content panels (tool-panel, etc.) ── */
.tool-panel {
  width: 100% !important;
  padding: 14px !important;
  min-height: auto !important;
}

/* ── Forms and inputs ── */
input, select, textarea {
  font-size: 16px !important;
  max-width: 100% !important;
  border-radius: 8px !important;
  padding: 12px !important;
  min-height: var(--touch-min, 44px);
}
input[type="range"] { width: 100% !important; min-height: auto; }

/* ── Buttons ── */
button, .btn, a.button, .ss-btn {
  min-height: var(--touch-min, 44px) !important;
  font-size: 14px !important;
  border-radius: 8px !important;
}

/* ── Modals: full width slide-up (mobile), centered (desktop) ── */
.modal, .dialog, [class*="modal-"],
.modal-overlay, .modal-box {
  width: 100vw !important;
  max-width: 100vw !important;
  margin: 0 !important;
  border-radius: 12px 12px 0 0 !important;
  left: 0 !important;
  right: 0 !important;
}
@media (min-width: 769px) {
  .modal, .dialog, .modal-box {
    width: auto !important;
    max-width: 560px !important;
    border-radius: 12px !important;
    margin: auto !important;
  }
}

/* ── Maps (exclude solar-design-page which needs full-height flex) ── */
body:not(.solar-design-page) #map,
body:not(.solar-design-page) .map,
.map-container, .leaflet-container,
[class*="map-"], .dt-map, .dt2-map {
  height: 45vh !important;
  min-height: 250px !important;
  width: 100% !important;
}

/* ── Tables ── */
table { width: 100% !important; font-size: 12px !important; overflow-x: auto !important; display: block !important; }
.table-wrap, [class*="table-"] { overflow-x: auto !important; display: block !important; }

/* ── Stats / KPI grid: 2 columns (mobile), 4 columns (desktop) ── */
.stats, .stats-row, .stat-grid, .kpi-row,
.dashboard-cards, [class*="stat-grid"], [class*="kpi-"],
.ss-metrics {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 10px !important;
}
@media (min-width: 769px) {
  .stats, .stats-row, .stat-grid, .kpi-row,
  .dashboard-cards, [class*="stat-grid"], [class*="kpi-"],
  .ss-metrics {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

.stat-box, .stat-card, .kpi-box,
[class*="stat-card"], .ss-metric {
  padding: 14px 10px !important;
  min-height: 90px !important;
}

/* ── Welcome modal ── */
.welcome-modal {
  width: calc(100vw - 32px) !important;
  max-width: 420px !important;
  padding: 24px !important;
  border-radius: 16px !important;
}

/* ── Notification badge ── */
#notifBadge, #sidebarNotifBadge {
  display: inline-block !important;
}

/* ── Home page — remove empty space below content ── */
.msh-screens {
  display: flex !important;
  flex-direction: column !important;
}
.msh-screen.active {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
}
#mshScreenHome > * {
  flex-shrink: 0 !important;
}

/* ── Phone viewport — full-width cards, single-col grids ── */
@media (max-width: 600px) {
  .app,
  .mobile-app,
  .page,
  .dashboard,
  .home-page,
  .main-content {
    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  .content,
  .dashboard-content {
    padding-left: 14px !important;
    padding-right: 14px !important;
    box-sizing: border-box !important;
  }

  .stats-grid,
  .button-row {
    grid-template-columns: 1fr !important;
    width: 100% !important;
  }

  .lead-card,
  .survey-card {
    width: 100% !important;
    max-width: 100% !important;
  }

  .msh-screens,
  .msh-screen {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }
  .msh-screen {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  .msh-stat-row {
    grid-template-columns: 1fr 1fr !important;
    width: 100% !important;
  }
  .msh-stat-card,
  .msh-job-card,
  .msh-sched-card,
  .msh-home-lead-card {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  table {
    max-width: 100% !important;
  }

  .tool-card,
  .msh-tool-tile {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .msh-home-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
    width: 100% !important;
  }
}

/* ── Mobile tools grid — 2 cols (mobile), 3 cols (tablet), 4 cols (desktop) ── */
.msh-tools-grid,
.msh-tools-cats .msh-tools-grid,
.msh-tools-sheet .msh-tools-grid {
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 10px !important;
}
@media (min-width: 769px) {
  .msh-tools-grid,
  .msh-tools-cats .msh-tools-grid,
  .msh-tools-sheet .msh-tools-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}
@media (min-width: 1025px) {
  .msh-tools-grid,
  .msh-tools-cats .msh-tools-grid,
  .msh-tools-sheet .msh-tools-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* Very narrow phones — sidebar 2 cols, smaller headings */
@media (max-width: 380px) {
  .sidebar.mobile-open .sidebar-section {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  h1, .page-title { font-size: 20px !important; }
}

/* ============================================================
   END OF MOBILE GLOBAL STYLESHEET v4
   ============================================================ */
