/* Glassco Customer Portal (invite-only, read-only bottle bank reporting) */
:root {
  --primary: #2fa84f;
  --primaryDark: #238a3f;
  --danger: #ef4444;
  --ok: #10b981;
  --warn: #f59e0b;

  --bg: #f1f5f9;
  --panel: #ffffff;
  --panelSoft: #f8fafc;
  --panelBorder: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.10);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 12px 14px 12px 14px;
}

.wrap { width: 100%; max-width: 1100px; margin: 0 auto; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px; padding: 8px 16px;
  border: 1px solid var(--panelBorder); border-radius: 16px; background: var(--panel);
  box-shadow: var(--shadow);
}
.brandMark {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  column-gap: 16px; align-items: center;
}
.brandMark img {
  grid-column: 1; grid-row: 1 / span 2; align-self: center;
  height: 40px; width: auto; max-width: 200px; object-fit: contain;
  display: block; padding-right: 16px; border-right: 1px solid var(--panelBorder);
}
.brandMark h1 { grid-column: 2; grid-row: 1; align-self: center; font-size: 17px; line-height: 1.15; margin: 0; letter-spacing: 0.2px; }
.brandMark p { grid-column: 2; grid-row: 2; align-self: center; margin: 2px 0 0; color: var(--muted); font-size: 13px; line-height: 1.2; }
/* A title with no subtitle (sign-in pages) sits level with the logo, not in
   the top half of the two rows the logo spans. */
.brandMark h1:last-child { grid-row: 1 / span 2; }

/* Sign-in, invite and magic-link pages: the same card as the invite and
   sign-in emails (backend/utils/branded-email.js), so the page a customer
   lands on from an email looks like the email. */
body.authPage { background: #F4F8F3; padding: 24px 16px; }
.authCard {
  max-width: 600px; margin: 0 auto; background: #fff; border-radius: 14px; overflow: hidden;
  box-shadow: 0 10px 30px rgba(23, 34, 27, 0.08); color: #17221B;
  font-family: Arial, Helvetica, sans-serif;
}
.authCard::before { content: ""; display: block; height: 6px; background: #55AC4E; }
.authCardBody { padding: 22px 32px 8px; }
.authLogo { display: block; width: 180px; max-width: 60%; height: auto; margin: 0 0 18px; }
.authCard h1 { margin: 0 0 16px; font-size: 22px; line-height: 28px; color: #1F6938; font-weight: bold; }
.authCard p { margin: 0 0 14px; font-size: 15px; line-height: 22px; }
.authCard .authSmall { font-size: 13px; line-height: 19px; color: #5F6D63; margin: 0 0 10px; }
.authCard label { font-size: 13px; color: #5F6D63; }
.authCard input[type="email"] { margin-bottom: 16px; }
.authCard input:focus { border-color: #1F6938; box-shadow: 0 0 0 3px rgba(31, 105, 56, 0.15); }
.authButton {
  appearance: none; display: inline-block; border: 0; border-radius: 10px; background: #1F6938; color: #fff;
  padding: 13px 26px; font: bold 15px/1.2 Arial, Helvetica, sans-serif; cursor: pointer; text-decoration: none;
  margin: 0 0 20px;
}
.authButton:hover { background: #18552D; }
.authButton:disabled { opacity: 0.5; cursor: not-allowed; }
.authFooter {
  padding: 16px 32px; background: #F4F8F3; border-top: 1px solid #E1EADF;
  font-size: 12px; line-height: 18px; color: #5F6D63;
}
.authFooter a { color: #1F6938; }
@media (max-width: 480px) {
  .authCardBody, .authFooter { padding-left: 20px; padding-right: 20px; }
}

/* Page nav: Dashboard / Sites / Account */
.portalNav {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 6px; border: 1px solid var(--panelBorder); border-radius: 999px;
  background: var(--panelSoft);
}
.portalNav a {
  display: inline-block; padding: 7px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 600; color: var(--muted); text-decoration: none;
}
.portalNav a:hover { background: #fff; color: var(--text); }
.portalNav a.active { background: var(--primary); color: #fff; }
.portalNav a[hidden] { display: none; }

/* Switcher between the parts of the portal one login has (Wheelie bin
   collections / Bottle banks / Sample results). Only drawn for 2 or more. */
.systemSwitch {
  margin-left: auto; display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); font-weight: 600;
}
.systemSwitch select {
  font: inherit; font-size: 14px; color: var(--text); font-weight: 600;
  padding: 7px 30px 7px 12px; border-radius: 999px;
  border: 1px solid var(--panelBorder); background: var(--panelSoft);
  cursor: pointer;
}
.systemSwitch select:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.card {
  background: var(--panel); border: 1px solid var(--panelBorder);
  border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; margin-bottom: 8px;
}
.cardHeader { padding: 9px 16px 0 16px; }
.cardBody { padding: 10px 16px; }

.grid { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .row2 { grid-template-columns: 1fr; } }
.actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="email"], input[type="text"], select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--panelBorder);
  border-radius: 12px; font-size: 15px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,168,79,0.15); }

.btn {
  appearance: none; border: 1px solid var(--panelBorder); background: #fff; color: var(--text);
  padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--panelSoft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btnPrimary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btnPrimary:hover { background: var(--primaryDark); border-color: var(--primaryDark); }
.btnGhost { background: transparent; }

.hint { color: var(--muted); font-size: 13px; margin: 0 0 6px; line-height: 1.5; }

/* Dashboard stat tiles */
.statTiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.statTile {
  background: var(--panelSoft); border: 1px solid var(--panelBorder); border-radius: 12px;
  padding: 12px 14px;
}
.statTileLabel { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 700; }
.statTileValue { font-size: 24px; font-weight: 800; margin-top: 4px; }
.statTileChange { font-size: 12px; margin-top: 4px; font-weight: 700; }
.statTileChange.up { color: var(--ok); }
.statTileChange.down { color: var(--danger); }
.statTileChange.flat { color: var(--muted); }

/* Table */
.tableWrap { overflow-x: auto; }
table.portal { width: 100%; border-collapse: collapse; font-size: 14px; }
table.portal th, table.portal td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--panelBorder); white-space: nowrap; }
table.portal th { background: var(--panelSoft); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; position: sticky; top: 0; }
table.portal tbody tr:hover { background: var(--panelSoft); }
table.portal tfoot td { font-weight: 700; background: var(--panelSoft); border-top: 2px solid var(--panelBorder); }
table.portal td.num, table.portal th.num { text-align: right; }
/* Site names are links. Underlined by default rather than on hover only, so a
   row that opens something is obvious without having to hover to find out. */
table.portal a { color: var(--primaryDark); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
table.portal a:hover { text-decoration-thickness: 2px; }
/* Second, non-colour cue that the row leads somewhere. */
.goChevron { color: var(--muted); font-weight: 700; margin-left: 6px; }
table.portal tbody tr:hover .goChevron { color: var(--primary); }
/* Zebra striping so a 111-row list stays readable across a row. */
table.portal tbody tr:nth-child(even) { background: rgba(148, 163, 184, 0.06); }

.searchRow { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.searchRow input[type="text"] { max-width: 320px; }

/* Photo gallery */
.photoGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photoGrid figure { margin: 0; background: var(--panelSoft); border: 1px solid var(--panelBorder); border-radius: 12px; overflow: hidden; }
.photoGrid img { width: 100%; height: 130px; object-fit: cover; display: block; }
.photoGrid figcaption { padding: 6px 8px; font-size: 11px; color: var(--muted); }

.muted { color: var(--muted); }
/* Sample results: Pass / Fail against spec */
.specPass { color: #166534; font-weight: 700; }
.specFail { color: #b91c1c; font-weight: 700; }
.right { text-align: right; }
.center { text-align: center; }

.skeleton { color: var(--muted); padding: 24px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px;
  background: #0f172a; color: #fff; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.toast.err .dot { background: var(--danger); }

.logoutFixed { position: fixed; right: 18px; bottom: 18px; z-index: 50; }

.pageFooter {
  text-align: center; color: var(--muted); font-size: 12px;
  margin: 10px 0 0; padding-top: 12px;
}

@media (max-width: 640px) {
  .topbar { gap: 12px; }
  .brandMark { column-gap: 12px; width: 100%; }
  .brandMark img { height: 34px; padding-right: 12px; }
  .brandMark h1 { font-size: 16px; }
  .portalNav { width: 100%; justify-content: space-between; }
  .systemSwitch { width: 100%; margin-left: 0; }
  .systemSwitch select { flex: 1; }
}

/* Dashboard tab bar (Weights / Lifts / Cleaning Events / Photos / Visits),
   matching the tab strip on the system this replaces. */
.tabBar { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 8px; border-bottom: 1px solid var(--panelBorder); }
.tabBtn {
  appearance: none; border: 1px solid var(--panelBorder); border-bottom: none;
  background: var(--panelSoft); color: var(--muted);
  padding: 9px 16px; border-radius: 10px 10px 0 0; cursor: pointer;
  font-size: 14px; font-weight: 600;
}
.tabBtn:hover { background: #fff; color: var(--text); }
.tabBtn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tabPanel { display: none; }
.tabPanel.active { display: block; }

/* Summary-grid total row: the figure the eye goes to first. */
table.portal tr.rowStrong td { font-weight: 800; background: var(--panelSoft); border-top: 2px solid var(--panelBorder); }

/* Expandable collection rows (Site Collection / Site Cleaning), matching the
   +/- tree on the system this replaces. */
table.portal tr.expandRow { cursor: pointer; }
table.portal tr.expandRow:hover { background: #eef6ff; box-shadow: inset 3px 0 0 var(--primary); }
table.portal tr.expandRow:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.expandCell { width: 1%; }
.expandIcon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 4px;
  border: 1px solid var(--panelBorder); background: #fff;
  font-weight: 700; line-height: 1; color: var(--muted);
}
table.portal tr.expandRow:hover .expandIcon { border-color: var(--primary); color: var(--primary); }
table.portal tr.childRow > td { background: var(--panelSoft); padding: 0 0 0 34px; }
table.portal table.childTable { margin: 8px 0; background: #fff; border: 1px solid var(--panelBorder); border-radius: 8px; }
table.portal table.childTable th { font-size: 11px; }
table.portal table.childTable td { font-size: 13px; }

/* Site Location panel */
.siteMap { padding: 4px 0 8px; }
.mapCoords { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
.mapLabel { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 700; }

/* ---- Period / site filter bar shared by the filtered list tabs ---------- */
.filterBar {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  margin: 0 0 12px; padding-bottom: 12px; border-bottom: 1px solid var(--panelBorder);
}
.filterField { display: flex; flex-direction: column; gap: 4px; }
.filterField label {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .4px; font-weight: 700;
}
.filterField input, .filterField select { min-width: 160px; }
.filterBar .spacer { flex: 1 1 auto; }
.filterActions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Total Performance / Total Tonnage are wide grids; keep the site column
   readable while the numeric columns compress. */
table.portal td.siteCol, table.portal th.siteCol { min-width: 180px; }
table.portal tbody tr.totalRow td { font-weight: 800; border-top: 2px solid var(--panelBorder); }

.photoFilters { margin-bottom: 12px; }

/* ---- Site detail header photo ------------------------------------------
   The photo leads the site's details where one exists; with no photo the slot
   is [hidden] and the details take the full width. */
.siteHeader { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.siteHeader > #siteInfo { flex: 1 1 320px; min-width: 0; }
.siteHero {
  flex: 0 0 auto; display: block; width: 190px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--panelBorder); background: var(--panelSoft);
}
.siteHero img { display: block; width: 100%; height: 130px; object-fit: cover; }
.siteHero:hover { border-color: var(--primary); }
@media (max-width: 560px) { .siteHero { width: 100%; } }

/* ---- Sortable column headings ------------------------------------------
   A heading only carries this class once its table has been wired up, so a
   column never looks clickable before it is. */
table.portal th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 20px; }
table.portal th.sortable:hover { color: var(--text); background: var(--panelSoft); }
table.portal th.sortable:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
/* A dim neutral marker on every sortable column, so the affordance is visible
   before any click; it sharpens into the direction actually applied. */
table.portal th.sortable::after {
  content: "\2195"; position: absolute; right: 6px; opacity: .35; font-weight: 700;
}
table.portal th.sortable:hover::after { opacity: .7; }
table.portal th.sortable[aria-sort="ascending"]::after { content: "\2191"; opacity: 1; color: var(--primary); }
table.portal th.sortable[aria-sort="descending"]::after { content: "\2193"; opacity: 1; color: var(--primary); }
@media print { body.printing table.portal th.sortable::after { content: ""; } }

/* ---- Print: the branded header plus only the panel being exported -------
   "Export to PDF" is the browser's own print-to-PDF, so the printed sheet is
   this page minus the chrome: no tab bar, no buttons, no other tab's data. */
@media print {
  body.printing .portalNav,
  body.printing .tabBar,
  body.printing .logoutFixed,
  body.printing .filterActions,
  body.printing .searchRow .btn,
  body.printing .pageFooter,
  body.printing .toast { display: none !important; }

  body.printing .tabPanel { display: none !important; }
  body.printing .printTarget { display: block !important; }

  body.printing { background: #fff; }
  body.printing .card { box-shadow: none; border: 1px solid #ccc; }
  body.printing .tableWrap { overflow: visible; }
  body.printing table.portal { font-size: 10px; }
  /* Repeat the header on every printed page of a long site list. */
  body.printing table.portal thead { display: table-header-group; }
  body.printing table.portal tr { break-inside: avoid; }
  /* The filter values caption the report -- keep the values, drop the control
     styling, so a printed report says what period it covers. */
  body.printing .filterBar input,
  body.printing .filterBar select { border: 0; padding: 0; font-weight: 700; }
}
