/* =========================================================================
   A M Water Services — Integrated Management System
   Brand palette (AMWS navy, ISO-grade corporate feel).
   Pulled from the Obsidian publish.css so both sites share the same brand.

   AMWS brand palette:
     --amw-navy:         #1e3a5f  (primary)
     --amw-navy-dark:    #0f1f33
     --amw-navy-light:   #2c4f7c
     --amw-accent:       #4a7ba7
     --amw-highlight:    #6499c7
     --amw-sidebar-blue: #3b5998
     --amw-bg-light:     #f0f4f8
   ========================================================================= */

/* --- Palette override --------------------------------------------------- */
[data-md-color-scheme="default"] {
  --amw-navy:         #1e3a5f;
  --amw-navy-dark:    #0f1f33;
  --amw-navy-light:   #2c4f7c;
  --amw-accent:       #4a7ba7;
  --amw-highlight:    #6499c7;
  --amw-sidebar-blue: #3b5998;
  --amw-bg-light:     #f0f4f8;
  --amw-border:       #d4dce4;

  --md-primary-fg-color:              var(--amw-navy);
  --md-primary-fg-color--light:       var(--amw-navy-light);
  --md-primary-fg-color--dark:        var(--amw-navy-dark);
  --md-primary-bg-color:              #ffffff;
  --md-primary-bg-color--light:       rgba(255, 255, 255, 0.7);

  /* IMS accent: brand mid-blue (keeps the corporate feel — no hi-vis
     orange here, that's the Van Packs identity) */
  --md-accent-fg-color:               var(--amw-highlight);
  --md-accent-fg-color--transparent:  rgba(100, 153, 199, 0.1);
  --md-accent-bg-color:               #ffffff;
  --md-accent-bg-color--light:        rgba(255, 255, 255, 0.7);

  --md-typeset-a-color:               var(--amw-sidebar-blue);
}

[data-md-color-scheme="slate"] {
  --amw-navy:         #2c4f7c;
  --amw-navy-dark:    #1e3a5f;
  --amw-navy-light:   #4a7ba7;
  --amw-highlight:    #6499c7;
  --amw-bg-light:     #1a2330;
  --amw-border:       #2a3a50;

  --md-primary-fg-color:              var(--amw-navy-dark);
  --md-primary-fg-color--light:       var(--amw-navy);
  --md-primary-fg-color--dark:        #0f1f33;
  --md-accent-fg-color:               var(--amw-highlight);
  --md-accent-fg-color--transparent:  rgba(100, 153, 199, 0.15);
  --md-typeset-a-color:               var(--amw-highlight);
}

:root {
  --md-text-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --- Material 'grid cards' — corporate polish --------------------------- */
.md-typeset .grid.cards > :is(ol, ul) > li {
  border-radius: 8px !important;
  border: 1px solid var(--amw-border, var(--md-default-fg-color--lightest));
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  padding: 1.25rem !important;
}

.md-typeset .grid.cards > :is(ol, ul) > li:hover {
  border-color: var(--md-primary-fg-color);
  box-shadow: 0 4px 14px rgba(30, 58, 95, 0.15);
  transform: translateY(-2px);
}

.md-typeset .grid.cards .twemoji.lg svg {
  height: 2em;
  width:  2em;
  color: var(--md-primary-fg-color);
  fill:  var(--md-primary-fg-color);
}

/* --- ISO badges on home --------------------------------------------------- */
.iso-badges {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1.5rem 0;
}

.iso-badge {
  background: var(--amw-bg-light);
  color: var(--amw-navy-dark);
  border: 1px solid var(--amw-border);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

[data-md-color-scheme="slate"] .iso-badge {
  background: var(--amw-navy-dark);
  color: var(--amw-highlight);
  border-color: var(--amw-navy);
}

/* --- Document control header ------------------------------------------- */
/* =========================================================================
   .doc-control — compact document-control table.
   Behaves like a normal markdown table inside a subtly-styled wrapper.
   Header row above, data row(s) below, soft horizontal rules. Content wraps
   naturally. On mobile, collapses to label/value list via ::before.
   ========================================================================= */

.doc-control {
  border-left: 4px solid var(--md-primary-fg-color);
  padding: 0.4rem 0.9rem 0.5rem;
  margin: 0 0 1.5rem 0;
  border-radius: 0 4px 4px 0;
  background: rgba(30, 58, 95, 0.02);
  max-width: 100%;
  overflow: hidden;
}

.doc-control table {
  margin: 0;
  width: 100% !important;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 0.85rem;
}

.doc-control th,
.doc-control td {
  padding: 0.35rem 0.6rem;
  text-align: left;
  vertical-align: top;
  word-break: normal;
  overflow-wrap: break-word;
  min-width: 0;
  border: none;
  border-bottom: 1px solid var(--md-default-fg-color--lightest, #e5e8ec);
}

.doc-control thead th {
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--md-default-fg-color--light);
  background: transparent;
  border-bottom: 1px solid var(--md-default-fg-color--lighter, #d4dce4);
}

.doc-control tbody td {
  font-weight: 500;
  color: var(--md-default-fg-color);
  line-height: 1.45;
}

/* No bottom border on the last data row */
.doc-control tbody tr:last-child td {
  border-bottom: none;
}

/* Ref + Rev tabular numerics (only nowrap if the cell is short — content
   that's a single token like "MAN_01" or "3" stays inline; longer values
   wrap naturally because we don't force nowrap globally). */
.doc-control tbody td:nth-child(1),
.doc-control tbody td:nth-child(2) {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Mobile: collapse to stacked label/value list */
@media (max-width: 50em) {
  .doc-control table,
  .doc-control thead,
  .doc-control tbody,
  .doc-control tr,
  .doc-control th,
  .doc-control td {
    display: block;
    width: 100% !important;
  }
  .doc-control thead { display: none; }
  .doc-control tbody td {
    border: none;
    padding: 0.15rem 0;
    white-space: normal !important;
  }
  .doc-control tbody td::before {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--md-default-fg-color--light);
    margin-bottom: 1px;
  }
  .doc-control tbody td:nth-child(1)::before { content: "Reference"; }
  .doc-control tbody td:nth-child(2)::before { content: "Revision"; }
  .doc-control tbody td:nth-child(3)::before { content: "Issue date"; }
  .doc-control tbody td:nth-child(4)::before { content: "Next review"; }
  .doc-control tbody td:nth-child(5)::before { content: "Controlled by"; }
  .doc-control tbody td:nth-child(6)::before { content: "Approved by"; }
  .doc-control tbody tr {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--md-default-fg-color--lightest, #e5e8ec);
  }
  .doc-control tbody tr:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
  }
}

/* Catch-all for other markdown tables — let cells wrap rather than force
   horizontal overflow on the whole table. */
.md-typeset__scrollwrap { max-width: 100%; }
.md-typeset table:not([class]) {
  table-layout: auto;
  word-break: normal;
  overflow-wrap: anywhere;
}

/* --- Risk-rating swatches (used in home-office RAs) -------------------- */
.risk-low,
.risk-moderate,
.risk-high,
.risk-very-high {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.9em;
  white-space: nowrap;
}
.risk-low       { background: #92D050; color: #1B5E20; }
.risk-moderate  { background: #FFC000; color: #5D4037; }
.risk-high      { background: #ED7D31; color: #ffffff; }
.risk-very-high { background: #C00000; color: #ffffff; }

/* --- Mobile table scroll fallback --------------------------------------- */
@media (max-width: 600px) {
  .md-typeset__table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* --- Footer motto ------------------------------------------------------ */
.motto {
  font-style: italic;
  color: var(--md-primary-fg-color);
  text-align: center;
  padding: 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

/* --- Print rules ------------------------------------------------------- */
@media print {
  .md-header, .md-tabs, .md-sidebar, .md-footer, .md-top {
    display: none !important;
  }
  .md-main__inner, .md-content {
    margin: 0 !important;
    max-width: 100% !important;
  }
  .md-content__inner { padding: 1cm !important; }
  body::before {
    content: "UNCONTROLLED WHEN PRINTED — A M Water Services Ltd";
    position: fixed;
    top: 0.5cm;
    right: 0.5cm;
    font-size: 9pt;
    color: #999;
    font-weight: 600;
  }
  a { text-decoration: none; color: inherit; }
  h1, h2, h3 { page-break-after: avoid; }
  table, pre, blockquote { page-break-inside: avoid; }
}

/* =========================================================================
   COLLAPSIBLE SIDEBARS — floating FAB controls (see widescreen.js)
   Three buttons bottom-right: Wide / Nav / TOC.
   Adapted from gauge-mkdocs-v2; AMWS navy palette.
   ========================================================================= */

/* Toggle buttons container — fixed bottom-right */
.sidebar-toggles {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-toggle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--amw-navy);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
  font-size: 20px;
  font-family: sans-serif;
}

.sidebar-toggle:hover {
  background-color: var(--amw-navy-dark);
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.sidebar-toggle:focus {
  outline: 2px solid var(--amw-highlight);
  outline-offset: 2px;
}

.sidebar-toggle.active {
  background-color: #424242;
}

.sidebar-toggle.active:hover {
  background-color: #333333;
}

/* Smooth transitions for sidebars */
.md-sidebar {
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

/* Hide left sidebar (navigation) */
body.hide-nav .md-sidebar--primary {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-100%);
  width: 0 !important;
  min-width: 0 !important;
}

/* Hide right sidebar (TOC) */
body.hide-toc .md-sidebar--secondary {
  opacity: 0;
  visibility: hidden;
  transform: translateX(100%);
  width: 0 !important;
  min-width: 0 !important;
}

/* ----- Desktop layout reflow (>1220px) ----- */
@media screen and (min-width: 76.25em) {
  body.hide-nav .md-grid,
  body.hide-toc .md-grid,
  body.hide-nav.hide-toc .md-grid {
    max-width: 100% !important;
  }

  body.hide-nav .md-main__inner,
  body.hide-toc .md-main__inner,
  body.hide-nav.hide-toc .md-main__inner {
    max-width: 100% !important;
  }

  body.hide-nav .md-content { margin-left: 0 !important; }
  body.hide-toc .md-content { margin-right: 0 !important; }

  body.hide-nav.hide-toc .md-content {
    margin-left: 1rem !important;
    margin-right: 1rem !important;
    max-width: calc(100% - 2rem) !important;
  }

  body.hide-nav.hide-toc .md-content__inner {
    max-width: 100% !important;
    margin: 0 auto;
  }

  body.hide-nav .md-sidebar--primary { position: absolute; left: -9999px; }
  body.hide-toc .md-sidebar--secondary { position: absolute; right: -9999px; }
}

/* ----- Tablet layout reflow (960-1220px) ----- */
@media screen and (min-width: 60em) and (max-width: 76.24em) {
  body.hide-nav .md-grid,
  body.hide-toc .md-grid,
  body.hide-nav.hide-toc .md-grid {
    max-width: 100% !important;
  }
  body.hide-toc .md-sidebar--secondary { display: none !important; }
  body.hide-nav.hide-toc .md-content {
    margin: 0 1rem !important;
    max-width: calc(100% - 2rem) !important;
  }
}

/* Mobile: hide the FABs entirely (Material already gives full width) */
@media screen and (max-width: 60em) {
  .sidebar-toggles { display: none; }
}

/* Print: hide the FABs */
@media print {
  .sidebar-toggles { display: none !important; }
}
