/*
 * Fire Stopping — Tested Systems page styles (page-specific only).
 *
 * Loaded only on ?page=fire-stopping-systems. The shared FS shell (page header,
 * stats strip, table, chips, .fss-modal base, filter count badge) lives in
 * fire-stopping.css. This file holds ONLY what's unique to the systems page:
 * the filter column count, the applies-to chips, and the add/edit modal's form
 * grid + checkbox/toggle rows. Built against the GLOBAL :root tokens.
 */

/* ---- Filter: search + item type + cert status + sort + clear ------------- */
.fire-stopping-page .ipi-filter-bar {
  grid-template-columns: minmax(200px, 1fr) auto auto auto auto;
}

/* ---- Editable rows (managers click a row to edit) ------------------------ */
.fss-sys-row--editable {
  cursor: pointer;
}

/* ---- "Applies to" chips in the table ------------------------------------- */
.fss-sys-typechips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 5px;
}

.fss-sys-typechip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-inset);
  color: var(--ink-3);
  border: 1px solid var(--rule-strong);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* ==========================================================================
   Add / edit modal — tabbed (Identity / Certification / Scope)
   Stable dialog height so switching tabs doesn't resize the modal. Mobile is
   full-screen (canonical), so the desktop height only applies above 900px.
   ========================================================================== */
.fss-sys-modal .fss-modal__dialog {
  width: min(720px, calc(100vw - 32px));
  height: min(78vh, 540px);
}

/* Tab bar reuses the shared .fss-tabs/.fss-tab pills. flex-shrink:0 stops the
   body's flex column from squishing the pills when a taller step (Certification)
   overflows — the body scrolls instead. */
.fss-sys-modal__tabs {
  flex-shrink: 0;
  max-width: 100%;
}

.fss-sys-tabpanel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
}

.fss-sys-modal .fss-modal__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.fss-sys-modal .fss-modal__field--full {
  grid-column: 1 / -1;
}

/* Applies-to checkbox group */
.fss-sys-checkboxes {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.fss-sys-checkboxes legend {
  padding: 0;
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.fss-sys-checkboxes__row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

/* Checkbox rows: override the shared column-stacked label layout so the box
   sits beside its text, with normal (non-uppercase) label text. */
.fss-sys-modal .fss-modal__body label.fss-sys-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.fss-sys-modal .fss-modal__body label.fss-sys-checkbox > span {
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-2);
}

.fss-sys-checkbox input[type="checkbox"] {
  width: auto;
  min-height: 0;
  flex-shrink: 0;
  margin: 0;
  accent-color: var(--accent);
}

/* ---- Quick-start picker (manufacturer → product, pre-fills the basics) ---- */
.fss-sys-quickpick {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border: 1px dashed var(--rule-strong);
  border-radius: 10px;
  background: var(--surface-subtle);
}

.fss-sys-quickpick__head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.fss-sys-quickpick__title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.fss-sys-quickpick__opt {
  font-size: 10px;
  color: var(--ink-4);
}

.fss-sys-quickpick__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.fss-sys-quickpick__hint {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-4);
}

/* ---- Mandatory "confirm accurate" attestation (Scope step) ---------------- */
.fss-sys-modal .fss-modal__body label.fss-sys-confirm {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  background: var(--surface-subtle);
}

.fss-sys-modal .fss-modal__body label.fss-sys-confirm > span {
  font-size: 12.5px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-2);
  line-height: 1.45;
}

.fss-sys-confirm input[type="checkbox"] {
  width: auto;
  min-height: 0;
  flex-shrink: 0;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

/* ==========================================================================
   Expandable detail row — datasheet + the fields not shown in columns
   (available to all roles, including inspectors who can't edit).
   ========================================================================== */
.fss-sys-expand-cell {
  width: 36px;
  text-align: center;
}

.fss-sys-expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--ink-4);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.fss-sys-expand-btn:hover {
  background: var(--surface-inset);
  color: var(--ink-2);
}

.fss-sys-expand-btn svg {
  width: 13px;
  height: 13px;
  transition: transform 0.15s ease;
}

.fss-sys-expand-btn.is-open svg {
  transform: rotate(90deg);
}

.fss-sys-expand-btn__text {
  display: none; /* desktop: chevron only; the label shows on mobile */
}

.fss-sys-detail-row > .fss-sys-detail-cell {
  padding: 0 20px 16px 56px;
  background: var(--surface-subtle);
}

.fss-sys-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 24px;
  margin: 0;
  padding: 14px 0 2px;
}

.fss-sys-detail__item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.fss-sys-detail__item dt {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-4);
}

.fss-sys-detail__item dd {
  margin: 0;
  font-size: 13px;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

/* Audit trail line (who added / last confirmed). */
.fss-sys-detail__audit {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px dashed var(--rule-strong);
  font-size: 11.5px;
  color: var(--ink-4);
}

/* Datasheet link (compact in-row + in the detail panel) */
.fss-sys-datasheet-link {
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: none;
}

.fss-sys-datasheet-link:hover {
  text-decoration: underline;
}

/* ---- Certificate validity chips ------------------------------------------ */
.fss-sys-validity-chip {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  margin-top: 3px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}

.fss-sys-validity-chip--expired {
  background: var(--danger-soft);
  color: var(--danger);
}

.fss-sys-validity-chip--soon {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* Rich empty state styles now live in fire-stopping.css (.fss-empty-rich*) so
   both the systems and surveys lists can share them. */

/* ==========================================================================
   Responsive (≤900px)
   ========================================================================== */
@media (max-width: 900px) {
  .fss-sys-modal .fss-modal__grid {
    grid-template-columns: 1fr;
  }

  .fss-sys-quickpick__row {
    grid-template-columns: 1fr;
  }

  /* Narrow screens: let the pill bar scroll sideways rather than overflow. */
  .fss-sys-modal__tabs {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .fss-sys-modal__tabs::-webkit-scrollbar {
    display: none;
  }

  /* Expander becomes a labelled toggle button on the card. */
  .fss-sys-expand-cell {
    justify-content: flex-start !important;
    width: auto;
  }

  .fss-sys-expand-cell::before {
    content: none !important;
  }

  .fss-sys-expand-btn {
    width: auto;
    height: 34px;
    padding: 0 12px;
    border-color: var(--rule-strong);
    color: var(--ink-2);
  }

  .fss-sys-expand-btn__text {
    display: inline;
    font-size: 12.5px;
    font-weight: 600;
  }

  /* Detail: a card tucked flush under its (grid) row when expanded — joins the
     new main card's bottom edge (closes the 12px tbody gap, no top border). */
  [data-fss-systems-page] .fss-sys-table tbody tr.fss-sys-detail-row {
    margin-top: -12px;
    padding: 0;
    border: 1px solid rgba(26, 24, 21, 0.1);
    border-top: 0;
    border-radius: 0 0 14px 14px;
    background: var(--surface-card);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.05);
  }

  html[data-theme="dark"] [data-fss-systems-page] .fss-sys-table tbody tr.fss-sys-detail-row {
    background: var(--card);
    border-color: var(--border);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
  }

  .fss-sys-detail-row > .fss-sys-detail-cell {
    display: block;
    text-align: left;
    padding: 12px 14px;
  }

  .fss-sys-detail-cell::before {
    content: none !important;
  }

  .fss-sys-detail {
    grid-template-columns: 1fr;
    padding: 0;
  }

  /* --- Tested Systems library: native card on mobile/tablet (grid layout) ---
     Scoped to [data-fss-systems-page] (on the real + /demo/fs systems index,
     absent on the FS setup wizard that also loads this file) so it overrides the
     shared .fss-table flex-card (fire-stopping.css) WITHOUT touching any other
     .fss-table. Only the MAIN row (.fss-row) becomes a grid card via `tr.fss-row
     > td`; the expandable .fss-sys-detail-row keeps its own card (below). System
     is the title; applies-to + the two-up standard/cert sit below; the Details
     toggle + manage actions form a footer. Matches the fire-door card. Desktop
     untouched. */
  [data-fss-systems-page] .fss-table-wrap {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }

  [data-fss-systems-page] .fss-sys-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0;
  }

  [data-fss-systems-page] .fss-sys-table tbody tr.fss-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "system    system"
      "appliesto appliesto"
      "standard  cert"
      "details   actions";
    column-gap: 12px;
    row-gap: 11px;
    align-items: start;
    padding: 14px 16px;
    border: 1px solid rgba(26, 24, 21, 0.1);
    border-radius: 14px;
    background: var(--surface-card);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 16px rgba(15, 23, 42, 0.05);
  }

  [data-fss-systems-page] .fss-sys-table tbody tr.fss-row > td {
    display: block;
    padding: 0;
    border: 0;
    min-width: 0;
    gap: 0;
    text-align: left;
  }

  [data-fss-systems-page] .fss-sys-table tbody tr.fss-row > td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--ink-4);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    text-align: left;
  }

  [data-fss-systems-page] .fss-sys-table td[data-label="System"] { grid-area: system; }
  [data-fss-systems-page] .fss-sys-table td[data-label="Applies to"] { grid-area: appliesto; }
  [data-fss-systems-page] .fss-sys-table td[data-label="Standard / classification"] { grid-area: standard; }
  [data-fss-systems-page] .fss-sys-table td[data-label="Certification"] { grid-area: cert; }
  [data-fss-systems-page] .fss-sys-table td.fss-sys-expand-cell { grid-area: details; }
  [data-fss-systems-page] .fss-sys-table td.fss-td-actions { grid-area: actions; }

  /* Title + the label-less actions cell carry no pseudo-label (the expander cell
     already has content:none from the relabel rule above). */
  [data-fss-systems-page] .fss-sys-table tr.fss-row > td[data-label="System"]::before,
  [data-fss-systems-page] .fss-sys-table tr.fss-row > td.fss-td-actions::before {
    display: none;
  }

  /* Title block: left-aligned (the shared @900 rule right-aligns .fss-td-main) */
  [data-fss-systems-page] .fss-sys-table td[data-label="System"] .fss-td-main {
    align-items: flex-start;
  }

  [data-fss-systems-page] .fss-sys-table td[data-label="System"] .fss-td-name {
    font-size: 15px;
    font-weight: 700;
  }

  /* Footer: divider across both bottom cells; Details toggle left, actions right */
  [data-fss-systems-page] .fss-sys-table tr.fss-row > td.fss-sys-expand-cell,
  [data-fss-systems-page] .fss-sys-table tr.fss-row > td.fss-td-actions {
    margin-top: 2px;
    padding-top: 12px;
    border-top: 1px solid rgba(26, 24, 21, 0.1);
  }

  [data-fss-systems-page] .fss-sys-table tr.fss-row > td.fss-td-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
  }

  [data-fss-systems-page] .fss-sys-table tr.fss-row > td.fss-td-actions .btn {
    min-height: 40px;
  }

  /* Dark mode */
  html[data-theme="dark"] [data-fss-systems-page] .fss-sys-table tbody tr.fss-row {
    background: var(--card);
    border-color: var(--border);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
  }

  html[data-theme="dark"] [data-fss-systems-page] .fss-sys-table tbody tr.fss-row > td {
    color: var(--text);
  }

  html[data-theme="dark"] [data-fss-systems-page] .fss-sys-table tbody tr.fss-row > td::before {
    color: var(--text-muted);
  }

  html[data-theme="dark"] [data-fss-systems-page] .fss-sys-table td[data-label="System"] .fss-td-name {
    color: var(--text);
  }

  html[data-theme="dark"] [data-fss-systems-page] .fss-sys-table tr.fss-row > td.fss-sys-expand-cell,
  html[data-theme="dark"] [data-fss-systems-page] .fss-sys-table tr.fss-row > td.fss-td-actions {
    border-top-color: var(--border);
  }
}
