/* Mobile: lock the frame */
@media (max-width: 820px) {
  html, body {
    overflow-x: hidden;
  }
}

/* Desktop: do NOT override overflow at all */



:root{
  --border: rgba(0,0,0,.12);
  --muted: rgba(0,0,0,.65);
  --bg:#fafafa;
}

/* Base */
body{
  margin:0;
  font-family: system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background:var(--bg);
  color:#111;
}

label{
  font-size:12px;
  color:var(--muted);
}

input,select{
  border:1px solid var(--border);
  border-radius:12px;
  padding:10px 12px;
  background:#fff;
  font-size:14px;
}

/* Header */
header{
  position:sticky;
  top:0;
  z-index:20;
  background:#fff;
  border-bottom:1px solid var(--border);
}

.bar{
  max-width:none;
  margin:0;
  padding:12px;
  display:flex;
  gap:12px;
  align-items:center;
  justify-content:space-between;
  flex-wrap:wrap;
}

.title{ font-weight:900; }
.sub{ color:var(--muted); font-size:13px; }

/* Layout */
main{
  width:100%;
  max-width:none;
  margin:0;
  padding:12px;
  display:grid;
  gap:12px;
}

.row{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:end;
}

.card{
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px;
  background:#fff;
}

.field{
  display:flex;
  flex-direction:column;
  gap:6px;
  min-width:180px;
}

/* Pills */
.pill{
  border:1px solid var(--border);
  border-radius:999px;
  padding:6px 10px;
  background:#fff;
  font-size:12px;
}

.pill.ok{
  border-color: rgba(0,160,70,.30);
  background: rgba(0,160,70,.08);
}

.pill.no{
  border-color: rgba(180,0,32,.30);
  background: rgba(180,0,32,.07);
}

/* Buttons */
.btn{
  border:1px solid var(--border);
  border-radius:12px;
  padding:10px 12px;
  background:#fff;
  font-size:14px;
  cursor:pointer;
}

.btn-primary{
  border-color:transparent;
  background:#111;
  color:#fff;
}

.btn-secondary{
  border-color:var(--border);
  background:#fff;
  color:#111;
}

/* Table */
.tablewrap{
  overflow:auto;
  border:1px solid var(--border);
  border-radius:16px;
  background:#fff;
}

table{
  border-collapse:separate;
  border-spacing:0;
  width:100%;
  min-width:980px;
  font-size:14px;
}

thead th{
  position:sticky;
  top:0;
  background:#fff;
  border-bottom:1px solid var(--border);
  padding:10px;
  text-align:left;
  white-space:nowrap;
}

tbody td{
  padding:10px;
  border-bottom:1px solid rgba(0,0,0,.06);
  vertical-align:top;
}

tbody tr:nth-child(2n) td{
  background: rgba(0,0,0,.02);
}

/* Mobile cards */
#cardsSection{ display:none; }

.mcard{
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px;
  background:#fff;
}

.mcardTop{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
}

.mcardName{
  font-weight:800;
  line-height:1.2;
}

.mcardSub{
  margin-top:6px;
  color:var(--muted);
  font-size:13px;
}

.mcardRight{
  display:flex;
  gap:8px;
  align-items:center;
}

/* Drawer */
.drawerBackdrop{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.35);
  z-index:50;
}

.drawer{
  position:fixed;
  left:0;
  right:0;
  bottom:0;
  max-height:80vh;
  background:#fff;
  border-top-left-radius:18px;
  border-top-right-radius:18px;
  z-index:51;
  overflow:auto;
  box-shadow: 0 -12px 32px rgba(0,0,0,.20);
}

.drawerHeader{
  position:sticky;
  top:0;
  background:#fff;
  border-bottom:1px solid rgba(0,0,0,.08);
  padding:12px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
}

.drawerTitle{ font-weight:900; }
.drawerBody{ padding:12px; }

.drawerGrid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}

.k{ color:var(--muted); font-size:12px; }
.v{ font-size:14px; word-break:break-word; }

/* Utilities */
.hidden{ display:none !important; }

}

/* --- Desktop toolbar: keep buttons pinned left even when editor filters expand --- */
.card > .row {
  align-items: center; /* nicer than align-items:end for buttons */
}

/* Put the filtersRow on its own line under the buttons */
#filtersRow.desktop-only {
  order: 50;
  flex: 1 1 100%;
  width: 100%;
  min-width: 0;

  overflow-x: auto;
  flex-wrap: nowrap !important;
  white-space: nowrap;
  padding-bottom: 4px;
  gap: 8px;
}

/* Keep each filter compact so it doesn't force width */
#filtersRow.desktop-only .field {
  flex: 0 0 auto !important;
  min-width: 160px;
}

/* Keep buttons from stretching */
.card > .row > button {
  flex: 0 0 auto;
}

/* =========================================================
   Mobile Accordion Filters (optional upgrade)
   ========================================================= */

.desktop-only { display: flex !important; }
.mobile-only  { display: none !important; }

@media (max-width: 820px) {
  .desktop-only { display: none !important; }
  .mobile-only  { display: block !important; }
}


/* Accordion container */
.accordion {
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 14px;
  background: rgba(255,255,255,.75);
  padding: 10px 12px;
}

/* Accordion title row */
.accordion-title {
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 13px;

  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Accordion body */
.accordion-body {
  margin-top: 12px;
}

/* Chevron rotate */
details[open] .chev {
  transform: rotate(180deg);
}

.starBtn {
  touch-action: manipulation;
}

.star-saving {
  opacity: 0.55;
  pointer-events: none;
}

.star-saving::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(0,0,0,.3);
  border-top-color: rgba(0,0,0,.8);
  border-radius: 50%;
  margin-left: 6px;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =========================================================
   Editor mode: prevent filters from pushing buttons away
   ========================================================= */

#filtersRow {
  flex: 1 1 auto;
  min-width: 0;              /* critical: allow flex item to shrink */
  overflow-x: auto;
  flex-wrap: nowrap !important;
  white-space: nowrap;
  gap: 8px;
  padding-bottom: 4px;
}

#filtersRow .field {
  flex: 0 0 auto !important;
  min-width: 160px;
}

/* Enable sticky columns */
table th,
table td {
  position: relative; /* baseline */
}

/* Pinned (left) columns */
.pinned {
  position: sticky !important;
  left: 0;
  z-index: 2;
  background: #fff; /* MUST be solid */
}

/* Header cells need higher stacking */
thead .pinned {
  z-index: 4;
}

/* =========================================================
   Mobile: remove main horizontal padding (fix left gutter)
   NOTE: bump dashboard.css?v=... to bust cache after deploying
   ========================================================= */
@media (max-width: 820px) {
  main {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
}

/* =========================================================
   Desktop: window owns horizontal scroll (not .tablewrap)
   ========================================================= */
@media (min-width: 821px) {
  .tablewrap {
    overflow-x: visible !important;
    overflow-y: visible !important;
  }

  html, body {
    overflow-x: auto !important;
  }
}

#tableSection{ display:block; }


/* Responsive switch: table -> cards (mobile) */
@media (max-width: 820px){
  #tableSection{ display:none; }
  #cardsSection{ display:block; }
}

/* Desktop: table visible, cards hidden */
@media (min-width: 821px){
  #tableSection{ display:block; }
  #cardsSection{ display:none; }
}


/* =========================================================
   Desktop: real scrolling restored (page + table work correctly)
   ========================================================= */
@media (min-width: 821px){

  /* Let the page scroll normally */
  html, body {
    height: auto;
    overflow: auto;
  }

  /* Do NOT lock main — allow natural page flow */
  main {
    height: auto;
    overflow: visible;
  }

  /* The table wrapper owns real scrolling near the data */
  .tablewrap {
    overflow: auto;                 /* vertical + horizontal both work */
    max-height: calc(100vh - 260px);/* keeps scrollbar near headers */
    -webkit-overflow-scrolling: touch;
  }

  /* Force horizontal overflow so right columns exist */
  #resultsTable {
    width: max-content;
    min-width: 980px;
  }

  /* Sticky column headers inside the scrolling wrapper */
  #resultsTable thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #fff;
  }
}



  /* Make main a full-height layout with a fixed top area and scrollable content */
  main {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Everything above the table stays fixed by virtue of main's flex layout.
     The table section becomes the scroll container. */
  #tableSection {
    flex: 1 1 auto;
    min-height: 0; /* critical for flex scroll containers */
    overflow: hidden;
  }

  /* The tablewrap owns both vertical + horizontal scroll on desktop */
  .tablewrap {
    height: 100%;
    max-height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: auto;
  }

  /* Keep table header visible while scrolling inside tablewrap */
  #resultsTable thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #fff;
  }

@media (min-width: 821px){
  /* Force horizontal scroll to be owned by the table wrapper */
  #tableSection { overflow: visible !important; }
  .tablewrap { overflow-x: auto !important; }
}
/* =========================================================
   Desktop: force real horizontal overflow for wide tables
   (so the horizontal scrollbar actually moves columns)
   ========================================================= */
@media (min-width: 821px) {

  /* Make the table size to content instead of squeezing into 100% */
  .tablewrap table {
    table-layout: auto !important;
    width: max-content !important;
    min-width: 100% !important; /* still fills when narrow */
  }

  /* Prevent cells from wrapping (creates true width/overflow) */
  .tablewrap th,
  .tablewrap td {
    white-space: nowrap !important;
  }

  /* Ensure wrapper owns the scroll */
  .tablewrap {
    overflow-x: auto !important;
    overflow-y: auto !important;
  }
}

/* =========================================================
   GLOBAL SCROLL RESET (fix frozen page on desktop + mobile)
   ========================================================= */

/* Always allow vertical scrolling */
html, body {
  height: auto !important;
  overflow-y: auto !important;
}

/* Allow horizontal scrolling ONLY where intended */
html, body {
  overflow-x: hidden; /* page itself should not drift */
}

/* Table wrapper owns horizontal scrolling */
.tablewrap {
  overflow-x: auto !important;
  overflow-y: auto !important;
}

/* Never trap scroll on containers */
main,
#tableSection,
#cardsSection {
  overflow: visible !important;
  height: auto !important;
}
@media (max-width: 820px){
  html, body {
    overflow-x: hidden !important;
  }
}

/* =========================================================
   Desktop: keep scrollbars near the table (not at page bottom)
   - page scroll stays normal above the table
   - tablewrap becomes the scroll viewport for the results table
   - enables sticky header row
   ========================================================= */
@media (min-width: 821px) {

  /* Give tablewrap a viewport height so it can scroll vertically */
  .tablewrap {
    max-height: calc(100vh - 260px);
    overflow: auto !important;   /* vertical + horizontal live here */
  }

  /* Sticky header row inside the tablewrap scroller */
  #resultsTable thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
  }

  /* Keep columns wide enough to require horizontal scroll (prevents squeeze) */
  #resultsTable {
    width: max-content;
    min-width: 100%;
  }

  #resultsTable th,
  #resultsTable td {
    white-space: nowrap;
  }
}
/* =========================================================
   Desktop: fix header/left-freeze overlap (z-index + backgrounds)
   ========================================================= */
@media (min-width: 821px){

  /* Base sticky header should sit above normal cells */
  #resultsTable thead th{
    z-index: 5;
    background: #fff;
  }

  /* Left-frozen cells (applyPinnedLeft should add .pinned) */
  #resultsTable .pinned{
    z-index: 6;
    background: #fff;
  }

  /* Top-left intersection (header + pinned) must be highest */
  #resultsTable thead th.pinned{
    z-index: 10;
    background: #fff;
  }
}
/* =========================================================
   Desktop: limit table viewport to ~15 rows
   ========================================================= */
@media (min-width: 821px){

  /* Approx row height = 36px (your current table) */
  .tablewrap{
    max-height: calc(36px * 15 + 40px); /* rows + header buffer */
    overflow: auto;
  }
}


/* =========================================================
   Disabled button styling (so disabled looks "grayed out")
   ========================================================= */
button:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(40%);
}


@media (max-width: 820px) {
  #exportCsvBtn { display: none !important; }
}

/* Disabled buttons — visual feedback */
.btn:disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
/* Disabled buttons — visual feedback */
.btn:disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
