/* =========================================================
   Global layout + mobile-first responsiveness
   ========================================================= */
:root{
  --sidebar-w: 280px;
  --gap: 1rem;

  /* chart heights by tier */
  --chart-h-sm: 260px;  /* <576 */
  --chart-h-md: 320px;  /* ≥576 */
  --chart-h-lg: 360px;  /* ≥992 */
  --chart-h-xl: 420px;  /* ≥1200 */
  --chart-h-xxl: 480px; /* ≥1400 */
}

.layout{ min-height: 100vh; }

/* ---------------- Sidebar ---------------- */
.sidebar{
  width: var(--sidebar-w);
  background: var(--bs-body-bg);
  border-right: 1px solid var(--bs-border-color);
  overflow: auto;
}

/* Desktop: sticky sidebar */
@media (min-width: 992px){
  .sidebar{
    position: sticky;
    top: 0;
    height: 100dvh;
  }
}

/* Mobile: off-canvas sidebar */
@media (max-width: 991.98px){
  .sidebar{
    width: 100%;
    position: fixed;
    z-index: 1040;
    top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 0 0 0 rgba(0,0,0,0);
  }
  .sidebar.show{
    transform: translateX(0);
    box-shadow: 0 .75rem 1.5rem rgba(0,0,0,.15);
  }
}

/* Optional overlay for mobile sidebar */
.sidebar-backdrop{
  display:none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.25);
  z-index: 1039;
}
.sidebar-backdrop.show{ display:block; }

/* Sidebar links (shared with SMME pages) */
.nav-link{ color: var(--bs-emphasis-color); padding: .5rem .75rem; border-radius: .5rem; }
.nav-link:hover{ background: var(--bs-secondary-bg); }
.nav-link.active{ background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text); }

.list-group-item{
  padding: .5rem .75rem;
  border: none;
  border-radius: .5rem;
}
.list-group-item:hover{ background: var(--bs-secondary-bg); }

/* On very small screens, make list items extra touch-friendly */
@media (max-width: 575.98px){
  .list-group-item{ padding: .65rem .85rem; }
}

/* ---------------- Top navbar ---------------- */
.navbar{ backdrop-filter: saturate(120%) blur(6px); }
.sidebar-toggle{ display:none; } /* show only on mobile */
@media (max-width: 991.98px){
  .sidebar-toggle{ display:inline-flex; }
}

/* ---------------- Cards / KPIs ---------------- */
.card{ border-radius: 1rem; }
.card-header{
  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
}
.kpi .value{
  font-weight: 700;
  font-size: clamp(1.1rem, 2.5vw, 2rem);
}
.kpi .label{ color: var(--bs-secondary-color); }

/* smaller gutters on phones */
@media (max-width: 575.98px){
  .row.g-3 { --bs-gutter-x: .75rem; --bs-gutter-y: .75rem; }
}

/* ---------------- Charts ---------------- */
.card canvas{
  /* Default chart height (phones) */
  height: var(--chart-h-sm);
}
/* ≥576 */
@media (min-width: 576px){
  .card canvas{ height: var(--chart-h-md); }
}
/* ≥768 (MD) — keep height but allow a bit more padding */
@media (min-width: 768px){
  .card .card-body{ padding: 1.25rem; }
}
/* ≥992 (LG) */
@media (min-width: 992px){
  .card canvas{ height: var(--chart-h-lg); }
}
/* ≥1200 (XL) */
@media (min-width: 1200px){
  .card canvas{ height: var(--chart-h-xl); }
}
/* ≥1400 (XXL) */
@media (min-width: 1400px){
  .card canvas{ height: var(--chart-h-xxl); }
}

/* ---------------- Leaflet Map ---------------- */
#map{
  height: 320px;
  border-radius: 0 0 1rem 1rem;
}
/* ≥576 */
@media (min-width: 576px){ #map{ height: 380px; } }
/* ≥768 */
@media (min-width: 768px){ #map{ height: 420px; } }
/* ≥992 */
@media (min-width: 992px){ #map{ height: 440px; } }
/* ≥1200 */
@media (min-width: 1200px){ #map{ height: 500px; } }
/* ≥1400 */
@media (min-width: 1400px){ #map{ height: 560px; } }

/* ---------------- Tables ---------------- */
.table-responsive{ border-radius: 1rem; }
table thead th{ white-space: nowrap; }
@media (max-width: 575.98px){
  .table{ font-size: .9rem; }
  .table td, .table th{ white-space: nowrap; }
}
/* Sticky header (DataTables or long tables) */
table.dataTable thead th{
  position: sticky;
  top: 0;
  background: var(--bs-body-bg);
  z-index: 1;
}

/* ---------------- Headings / spacing ---------------- */
.section-title{ margin: 20px !important; }

/* ---------------- Utilities ---------------- */
.small-muted{ color: var(--bs-secondary-color); }

/* ---------------- Print ---------------- */
@media print{
  .navbar, .sidebar, .sidebar-backdrop, .offcanvas, .modal { display: none !important; }
  .card{ box-shadow: none !important; }
  body{ color: #000; }
}

/* =========================================================
   Explicit breakpoint blocks with real rules
   ========================================================= */

/* ≥576px (sm) ------------------------------------------------*/
@media (min-width: 576px) {
  .row.g-3 { --bs-gutter-x: 1rem; --bs-gutter-y: 1rem; }
  .kpi .value { font-size: clamp(1.1rem, 2vw, 1.6rem); }
  .card .card-body { padding: 1rem; }
  .list-group-item { padding: .6rem .9rem; }
  .section-title { margin: .75rem 0 1rem !important; }
  /* charts + map heights handled earlier but kept here for clarity */
  .card canvas { height: var(--chart-h-md); }
  #map { height: 380px; }
}

/* ≥768px (md) ------------------------------------------------*/
@media (min-width: 768px) {
  /* Slightly larger paddings/typography */
  .kpi .value { font-size: clamp(1.2rem, 2vw, 1.8rem); }
  .card .card-body { padding: 1.25rem; }
  .table { font-size: .95rem; }
  /* Sidebar list spacing a bit roomier */
  .list-group-item { padding: .7rem 1rem; }
}

/* ≥992px (lg) ------------------------------------------------*/
@media (min-width: 992px) {
  /* Sidebar becomes sticky; main stays fluid */
  .sidebar { position: sticky; top: 0; height: 100dvh; }
  .sidebar-toggle { display: none !important; }
  /* Give charts more breathing room */
  .card canvas { height: var(--chart-h-lg); }
  #map { height: 440px; }
  .kpi .value { font-size: clamp(1.2rem, 2vw, 1.9rem); }
  .list-group-item { padding: .65rem 1rem; }
  .table { font-size: 1rem; }
}

/* ≥1200px (xl) -----------------------------------------------*/
@media (min-width: 1200px) {
  .card .card-body { padding: 1.5rem; }
  .card canvas { height: var(--chart-h-xl); }
  #map { height: 500px; }
  .kpi .value { font-size: clamp(1.25rem, 1.8vw, 2.1rem); }
  .list-group-item { padding: .75rem 1.1rem; }
}

/* ≥1400px (xxl) ----------------------------------------------*/
@media (min-width: 1400px) {
  .card canvas { height: var(--chart-h-xxl); }
  #map { height: 560px; }
  .kpi .value { font-size: clamp(1.3rem, 1.6vw, 2.25rem); }
  .card .card-body { padding: 1.75rem; }
  .table { font-size: 1.05rem; }
}

/* --- Normalize sidebar width across all pages (SMMEs + index) --- */
@media (min-width: 992px) {
  /* Make the shell a flex layout on desktop */
  .layout { display: flex; }

  /* Force the sidebar to a fixed width even if it's inside a Bootstrap column */
  .layout > .sidebar {
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w) !important;
    max-width: var(--sidebar-w) !important;
    padding-right: 0; /* tidy up if sidebar had grid padding */
  }

  /* Neutralize any grid column sizing on the sidebar */
  .layout > .sidebar[class*="col-"] {
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w) !important;
    max-width: var(--sidebar-w) !important;
  }

  /* The main content takes the remaining space */
  .layout > .content {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }
}

/* Keep the mobile/off-canvas behavior exactly as before */
@media (max-width: 991.98px) {
  .layout { display: block; }
  .sidebar { width: 100%; } /* off-canvas full width on mobile */
}


/* Accordion wrapper */
.smme-accordion .accordion-button {
  font-weight: 600;
}
.smme-accordion .accordion-body {
  line-height: 1.55;
}

/* Map inside accordion */
.smme-map-wrap { position: relative; }
.smme-map {
  height: 280px;           /* default (phones) */
  border-radius: .75rem;
  overflow: hidden;
  border: 1px solid var(--bs-border-color);
}

/* ≥576 */
@media (min-width: 576px){
  .smme-map { height: 340px; }
}

/* ≥768 */
@media (min-width: 768px){
  .smmE-accordion .accordion-body { padding: 1.25rem 1.25rem 1rem; }
  .smme-map { height: 380px; }
}

/* ≥992 */
@media (min-width: 992px){
  .smme-map { height: 420px; }
}

/* ≥1200 */
@media (min-width: 1200px){
  .smme-map { height: 460px; }
}

/* ≥1400 */
@media (min-width: 1400px){
  .smme-map { height: 520px; }
}
