/* ============================================================
   layout.css — DOCUMENT SCROLL MODEL (RECOMMENDED)
   Compatible with floating modals (#floating-modals)
   ============================================================ */

/* ---------- Variables ---------- */
:root{
--header-h: 52px;
  --footer-h: 0px;
  --gap: 12px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --fig-heading: #111827;
  --fig-subtle:  #374151;
}

/* ---------- Root / Body: page scrolls normally ---------- */
html, body{
  margin: 0;
  padding: 0;
  height: auto;
  min-height: 100%;
}

/* Safari / Android compatibility */
html{
  height: -webkit-fill-available;
  -webkit-text-size-adjust: 100%;
}

body{
  min-height: 100vh;
  min-height: -webkit-fill-available;

  /* ✅ Normal website scroll */
  overflow-y: auto;
  overflow-x: hidden;

  background: #f7f7f8;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Main content flows in document ---------- */
body > main,
#app-main{
  position: relative;
  display: block;

  height: auto;
  min-height: 0;
  overflow: visible;

  /* header spacing (fixed header) */
  padding-top: var(--header-h);

  /* safe bottom spacing */
  padding-bottom: calc(var(--safe-bottom) + 8px);
}

/* ---------- Sidebar helpers ---------- */
.sidebar{ min-width: 260px; }
.main-panel{ overflow: visible; }
.sidebar-scroll{ overflow: visible; }

/* Off-canvas sidebar on phones */
@media (max-width: 768px){
  .sidebar{
    position: fixed;
    z-index: 1000;

    top: var(--header-h);
    bottom: calc(var(--footer-h) + var(--safe-bottom));
    left: 0;

    width: min(86vw, 340px);
    transform: translateX(-100%);
    transition: transform .25s ease;

    background: #fff;
    border-right: 1px solid #e5e7eb;

    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open{ transform: translateX(0); }

  .overlay{
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.28);
    z-index: 999;
    display: none;
  }
  .overlay.show{ display: block; }
}

/* ---------- Tables: stack into cards on small screens ---------- */
@media (max-width: 768px){
  .table-stacked{
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
  }
  .table-stacked thead{ display: none; }

  .table-stacked tr{
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 10px;
    padding: 8px;
  }

  .table-stacked tr:has(td:nth-child(2):last-child){
    grid-template-columns: 1fr;
  }

  .table-stacked td{
    display: flex;
    gap: 6px;
    padding: 6px 8px;
    border: 0 !important;
    min-width: 0;
  }

  .table-stacked td::before{
    content: attr(data-label);
    flex: 0 0 42%;
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Tablet/desktop guard */
@media (min-width: 820px){
  .table-stacked thead{ display: table-header-group !important; }
  .table-stacked tr{ display: table-row !important; }
  .table-stacked td{ display: table-cell !important; }
  .table-stacked td::before{ content: none !important; }
}

/* ---------- Utilities ---------- */

/* IMPORTANT: do not create scroll traps by default */
.scroll-y{ overflow: visible; }

/* Allow JS to lock scroll (sidebars, menus, etc.) */
.no-scroll{ overflow: hidden !important; }

/* Container spacing */
.container-responsive{ padding: 8px; }
@media (min-width: 1024px){
  .container-responsive{ padding: 12px var(--gap); }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce){
  *{ animation: none !important; transition: none !important; }
}

/* Headings */
h1, h2, h3,
.heading, .panel-title,
.modal h1, .modal h2, .modal h3{
  color: var(--fig-heading) !important;
  font-weight: 700 !important;
}

label span, .form-label, .text-muted{
  color: var(--fig-subtle) !important;
}

/* Calendar events */
.fc-event,
.fc-daygrid-event,
.fc-timegrid-event{
  color: #111827 !important;
  font-weight: 500;
}
.fc-event.fc-is-done{ color: #374151 !important; }

/* Buttons */
button, .btn{ color: var(--fig-heading); }
.btn-primary, .bg-figurella{ color: #fff !important; }

/* ============================================================
   FORCE DOCUMENT SCROLL — but NEVER fight modal lock
   ============================================================ */

/* ✅ Only enforce document scroll when modal is NOT open */
html:not(.modal-open),
body:not(.modal-open):not(.leads-pin-open){
  overflow-y: auto !important;
  overflow-x: hidden !important;
}


html:not(.modal-open){ overflow-y: auto !important; }
body:not(.modal-open):not(.leads-pin-open){
  overflow-y: auto !important;
  overflow-x: hidden !important;
}


/* If any wrapper was locking scroll, unlock it (except during modal open) */
html:not(.modal-open) body > main,
html:not(.modal-open) #app-main{
  height: auto !important;
  overflow: visible !important;
}
