/*
 * R Creative Uptime — print / "Save as PDF".
 * Link AFTER app.css:  <link rel="stylesheet" href="{% static 'css/print.css' %}" media="print">
 * Output: white paper, black text, no navigation or controls, tables that
 * repeat headers and never split a row. Unlayered, so it beats app.css layers. Wrapped in @media print
 * as a guard in case the link is ever included without media="print".
 */

@media print {
  @page {
    size: auto;
    margin: 14mm 12mm 16mm;
  }

  :root,
  :root[data-theme] {
    /* Force the light palette regardless of screen theme. */
    --c-page: #FFFFFF;
    --c-surface: #FFFFFF;
    --c-surface-2: #FFFFFF;
    --c-sunken: #F1F2F4;
    --c-line: #B8BEC6;
    --c-line-strong: #5B6270;
    --c-text: #000000;
    --c-muted: #3A414C;
    --c-accent: #000000;
    --c-up: #146C35;
    --c-down: #B3261E;
    --c-warn: #8A4B00;
    --c-unknown: #4A5361;
    --c-paused: #3D4F66;
    --c-down-tint: #FFFFFF;
    --c-warn-tint: #FFFFFF;
    --shadow-1: none;
    --strip-bg: #FFFFFF;
    --strip-tile: #FFFFFF;
    --strip-tile-alert: #FFFFFF;
    --strip-tile-warn: #FFFFFF;
    --strip-line: #B8BEC6;
    --strip-text: #000000;
    --strip-muted: #3A414C;
    --strip-rule: #000000;
    --strip-up: #146C35;
    --strip-down: #B3261E;
    --strip-warn: #8A4B00;
    --strip-unknown: #4A5361;
    --strip-paused: #3D4F66;
    color-scheme: light;
  }

  html, body {
    background: #FFFFFF !important;
    color: #000000 !important;
  }
  body {
    font-size: 10pt;
    line-height: 1.4;
    min-height: 0;
  }

  /* Hide chrome and interactive controls. */
  .skip-link,
  .app-header,
  .nav,
  .header-tools,
  .theme-switch,
  .app-footer,
  .page-head__actions,
  .form__actions,
  .range-form,
  .btn,
  button,
  .no-print,
  [data-theme-control] {
    display: none !important;
  }
  .print-only { display: block !important; }

  .app-main {
    max-width: none;
    padding: 0;
    gap: 6mm;
  }
  .grid-2 { display: block; }
  .grid-2 > * + * { margin-top: 6mm; }

  /* Flat surfaces, hairline borders. */
  .panel,
  .callout,
  .secret,
  .strip,
  .tile,
  .messages > li {
    background: #FFFFFF !important;
    box-shadow: none !important;
    border-color: #B8BEC6;
  }
  .strip { border: 1px solid #B8BEC6; border-top: 2px solid #000000; padding: 3mm; }
  .tile::before { animation: none !important; }

  /* Keep state colours, lamps, marks and meters (browsers drop backgrounds otherwise). */
  .status__mark,
  .tile::before,
  .meter,
  .meter svg,
  .logo-full,
  .brand__tile {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Logo stays on a white field. */
  .report__brand .logo-full { width: 26mm; height: 26mm; border: 0; }

  /* Headings stay with their content. */
  h1, h2, h3, h4,
  .panel__head,
  .report__head,
  .callout__title {
    break-after: avoid;
    page-break-after: avoid;
  }
  .panel, .callout, .figures, .kv, .precision-note {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  /* Long panels holding tables may break; the table rows will not. */
  .panel:has(.table) { break-inside: auto; page-break-inside: auto; }

  /* Tables: no clipping, repeat headers, never split a row. */
  .table-wrap { overflow: visible !important; }
  .table { width: 100%; max-width: 100%; table-layout: auto; font-size: 9pt; }
  /* Screen nowrap (codes, times, statuses, numbers, headers) must not push
     cells past the paper edge: allow wrapping and emergency breaks. */
  .table th,
  .table td,
  .table .num,
  .table .code,
  .table .status,
  .table .nowrap,
  .table time,
  .table thead th {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .table .status { display: inline-flex; flex-wrap: wrap; }
  .table thead { display: table-header-group; }
  .table tfoot { display: table-footer-group; }
  .table tr,
  .table td,
  .table th {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .table th, .table td { padding: 1.6mm 2.4mm; }
  .table thead th { background: #FFFFFF !important; color: #000000; border-bottom: 1.5px solid #000000; }
  .table tr[data-state] { background: #FFFFFF !important; }
  /* Undo small-screen stacking if the print viewport is narrow. */
  .table--stack thead { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
  .table--stack { display: table; }
  .table--stack tbody { display: table-row-group; }
  .table--stack tr { display: table-row; padding: 0; }
  .table--stack td, .table--stack th[scope="row"] { display: table-cell; width: auto; padding: 1.6mm 2.4mm; border-bottom: 1px solid #B8BEC6; }
  .table--stack td[data-label]::before { content: none; }

  .code { background: none; border: 1px solid #B8BEC6; white-space: normal; overflow-wrap: anywhere; }
  .kv dd, .feed__meta, .figure__value, .meta, time { white-space: normal; overflow-wrap: anywhere; }
  /* Severity stripe on rows is a box-shadow; keep it, but the status text in the row carries meaning. */
  .table tr[data-state] > :first-child { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Show external destinations in reports. */
  .report a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 8pt;
    color: #3A414C;
    overflow-wrap: anywhere;
  }
  a { color: #000000; text-decoration: none; }

  .precision-note { color: #3A414C; font-size: 8pt; }
}
