/* Roofing Sheet Calculator
   Scoped under .src-modal (browser) and .src-print-root (print).
   Uses the project's existing CSS variables (--bg, --fg, --accent, --emerald, --emerald-light).
*/

/* ─── Modal overlay ─────────────────────────────────────────────── */
.src-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
  padding: var(--space-md);
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease-out;
}
.src-modal-overlay.is-open {
  opacity: 1; pointer-events: auto;
}

.src-modal {
  background: var(--bg);
  border: 1px solid var(--emerald);
  border-radius: 6px;
  width: 100%; max-width: 720px; max-height: 90vh;
  overflow-y: auto;
  color: var(--fg);
  box-shadow: 0 0 32px rgba(80, 220, 100, 0.15);
}

.src-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.src-modal-title { margin: 0; font-size: 1.25rem; }
.src-modal-close {
  background: none; border: none; color: var(--fg);
  font-size: 1.5rem; cursor: pointer; padding: 0 var(--space-xs);
  line-height: 1;
}
.src-modal-close:hover { color: var(--white); }

.src-modal-body { padding: var(--space-md); }
.src-modal-footer {
  display: flex; gap: var(--space-sm); justify-content: flex-end;
  padding: var(--space-md); border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-wrap: wrap;
}

/* ─── Units toggle ─────────────────────────────────────────────── */
.src-units-row {
  display: flex; align-items: center; gap: var(--space-sm);
  margin-bottom: var(--space-md);
  font-size: 0.85rem;
  color: var(--white);
}
.src-units-toggle {
  display: inline-flex; gap: var(--space-xs);
}
.src-units-toggle label {
  cursor: pointer; padding: 2px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 4px;
  color: var(--fg);
}
.src-units-toggle input { display: none; }
.src-units-toggle input:checked + label {
  background: var(--emerald); color: #000; border-color: var(--emerald);
}

/* ─── Pill button groups (profile, shape) ─────────────────────── */
.src-pill-group {
  display: flex; flex-wrap: wrap; gap: var(--space-xs);
  margin-bottom: var(--space-md);
}
.src-pill-group label {
  cursor: pointer; padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 999px;
  font-size: 0.85rem; color: var(--fg);
}
.src-pill-group input { display: none; }
.src-pill-group input:checked + label {
  background: var(--emerald); color: #000; border-color: var(--emerald);
}
.src-field-label {
  display: block; font-size: 0.85rem;
  color: var(--field-text, #fff); font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  margin-bottom: 6px;
}

/* ─── Form fields ──────────────────────────────────────────────── */
.src-field {
  display: grid; grid-template-columns: 1fr auto; gap: var(--space-sm);
  align-items: center; margin-bottom: var(--space-sm);
}
.src-field input[type="number"], .src-field select {
  background: var(--field-bg, #2E2E2E); color: var(--field-text, #fff);
  border: 1.5px solid var(--field-border, #fff); border-radius: 6px;
  padding: 10px 12px; font-size: 0.95rem; font-weight: 600;
  min-width: 80px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.src-field input[type="number"]:focus, .src-field select:focus {
  outline: none;
  border-color: var(--warning, #34D399);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25);
}
.src-field-suffix {
  font-size: 0.8rem; color: var(--field-text, #fff); font-weight: 600;
  width: 40px; text-align: left;
}
.src-checkbox-row {
  display: flex; align-items: center; gap: 10px;
  margin: var(--space-xs) 0 var(--space-sm);
  cursor: pointer; font-size: 0.9rem; font-weight: 600;
  color: var(--field-text, #fff);
}
.src-checkbox-row input[type="checkbox"] { accent-color: var(--field-text, #fff); width: 18px; height: 18px; }
.src-hint {
  margin: 6px 0 0 28px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--field-text, #fff);
  line-height: 1.5;
}

/* ─── Pitch warning ────────────────────────────────────────────── */
.src-warning {
  background: rgba(255, 100, 60, 0.15);
  border: 1px solid rgba(255, 100, 60, 0.4);
  color: #ffbfa8;
  padding: var(--space-sm) var(--space-md);
  border-radius: 4px;
  margin: var(--space-md) 0;
  font-size: 0.9rem;
}

/* ─── Live roof-plan schematic (always visible in modal) ──────── */
.src-schematic-slot {
  margin: var(--space-md) 0;
  padding: var(--space-sm) var(--space-md);
  background: rgba(80, 220, 100, 0.04);
  border: 1px solid rgba(80, 220, 100, 0.2);
  border-radius: 4px;
  text-align: center;
  color: var(--fg);
}
.src-schematic-slot.is-hidden { display: none; }
.src-schematic-slot svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 360px;
  margin: 0 auto;
}
.src-schematic-empty {
  margin: 0;
  padding: var(--space-md);
  font-size: 0.85rem;
  color: var(--white);
}

/* ─── Results panel ────────────────────────────────────────────── */
.src-results {
  background: rgba(80, 220, 100, 0.06);
  border: 1px solid rgba(80, 220, 100, 0.2);
  border-radius: 4px;
  padding: var(--space-md);
  margin-top: var(--space-md);
}
.src-results-title {
  font-size: 0.8rem; color: var(--white);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: var(--space-sm);
}
.src-result-line {
  display: grid; grid-template-columns: 1fr auto; gap: var(--space-sm);
  align-items: center; padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.src-result-line:last-child { border-bottom: none; }
.src-result-line input[type="checkbox"] { transform: scale(1.2); cursor: pointer; }

/* ─── Disclaimer note ──────────────────────────────────────────── */
.src-disclaimer {
  margin: var(--space-md) 0 0;
  padding: var(--space-sm) var(--space-md);
  background: rgba(80, 220, 100, 0.06);
  border-left: 3px solid var(--emerald);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.8rem;
  line-height: 1.5;
}

/* ─── Buttons ──────────────────────────────────────────────────── */
.src-btn {
  background: #000; color: var(--fg);
  border: 1px solid var(--fg); border-radius: 4px;
  padding: 8px 18px; cursor: pointer; font-size: 0.95rem;
  transition: all 0.15s ease;
}
.src-btn:hover {
  background: var(--bg); border-color: var(--emerald);
  color: var(--white); box-shadow: 0 0 12px rgba(80, 220, 100, 0.3);
}
.src-btn-primary { background: var(--emerald); color: #000; border-color: var(--emerald); }
.src-btn-primary:hover { background: var(--emerald-light); border-color: var(--emerald-light); color: #000; }

/* ─── Toast ────────────────────────────────────────────────────── */
.src-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9); color: var(--fg);
  border: 1px solid var(--emerald);
  padding: var(--space-sm) var(--space-md);
  border-radius: 4px; font-size: 0.9rem;
  z-index: 10000;
  animation: src-fade-out 3s forwards;
}
@keyframes src-fade-out {
  0% { opacity: 0; }
  10% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ─── Print preview overlay (in-modal) ─────────────────────────── */
.src-preview {
  background: #fff; color: #000; padding: var(--space-md);
  border-radius: 4px; margin-top: var(--space-md);
  font-family: var(--ff-sans);
}
.src-preview svg { display: block; margin: 0 auto var(--space-md); max-width: 100%; }
.src-preview-title { font-size: 1.1rem; margin: 0 0 var(--space-sm); }

/* ─── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .src-modal { max-height: 100vh; border-radius: 0; max-width: 100%; }
  .src-modal-overlay { padding: 0; }
  .src-field { grid-template-columns: 1fr; gap: 4px; }
  .src-field-suffix { display: none; }
  .src-modal-footer { flex-direction: column-reverse; }
  .src-modal-footer .src-btn { width: 100%; }
}

/* ─── Print stylesheet ─────────────────────────────────────────── */
@page {
  size: A4 portrait;
  margin: 15mm 15mm 15mm 15mm;
}

@media print {
  /* Hide everything except the print root */
  body > *:not(.src-print-root) { display: none !important; }

  html, body {
    background: #fff !important;
    color: #000 !important;
  }

  .src-print-root {
    display: block !important;
    position: static !important;
    background: #fff !important;
    color: #000 !important;
    font-family: Helvetica, Arial, sans-serif;
  }

  /* The whole document lives inside one outer table so that the thead and
     tfoot repeat at the top and bottom of every printed page (the most
     reliable cross-browser way to get running headers/footers). */
  .src-print-page-table {
    width: 100%;
    border-collapse: collapse;
  }
  .src-print-page-table thead { display: table-header-group; }
  .src-print-page-table tfoot { display: table-footer-group; }

  .src-print-running-header {
    text-align: center;
    padding: 0 0 4mm;
    border-bottom: 0.5pt solid #000;
  }
  .src-print-running-header img {
    max-height: 14mm;
    max-width: 60mm;
    width: auto;
    height: auto;
  }

  .src-print-running-footer {
    text-align: center;
    padding: 4mm 0 0;
    border-top: 0.5pt solid #000;
    font-size: 8pt;
    line-height: 1.4;
    color: #000;
  }
  .src-print-running-footer .src-print-footer-line {
    display: block;
  }

  /* Each top-level section becomes its own page */
  .src-print-page {
    page-break-after: always;
    break-after: page;
    padding-top: 6mm;
  }
  .src-print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .src-print-page h1 {
    font-size: 16pt;
    margin: 0 0 4pt;
    color: #000;
  }
  .src-print-meta {
    font-size: 9pt;
    color: #000;
    margin: 0 0 10pt;
  }

  /* Roof plan — center the SVG, scale to fit the available area */
  .src-print-svg {
    text-align: center;
    margin: 8pt 0;
  }
  .src-print-svg svg {
    color: #000; /* makes inline currentColor strokes/fills resolve to black */
    max-width: 100%;
    max-height: 220mm;
    width: auto;
    height: auto;
  }
  .src-print-svg svg text { fill: #000; stroke: none; }

  /* Cutlist — each category group stays together on a page when possible */
  .src-print-group {
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 12pt;
  }
  .src-print-group h2 {
    font-size: 11pt;
    margin: 0 0 4pt;
    color: #000;
    border-bottom: 0.5pt solid #000;
    padding-bottom: 2pt;
  }
  .src-print-group table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9.5pt;
  }
  .src-print-group th, .src-print-group td {
    text-align: left;
    padding: 3pt 6pt 3pt 0;
    vertical-align: top;
    color: #000;
    font-weight: normal;
  }
  .src-print-group td.qty {
    text-align: right;
    white-space: nowrap;
    width: 22%;
    font-weight: 600;
  }
  .src-print-group .pieces {
    display: block;
    margin-top: 1pt;
    font-size: 8.5pt;
    color: #000;
  }

  .src-modal-overlay { display: none !important; }
}

/* ─── Launch button (on quote.html) ────────────────────────────── */
.src-launcher-row {
  text-align: center; margin-top: var(--space-lg);
}
.src-launcher-eyebrow {
  font-size: 0.85rem; color: var(--white); margin-bottom: var(--space-xs);
}
.src-launcher-hint {
  font-size: 0.8rem; color: var(--white); margin-top: var(--space-xs);
}

/* ─── Prefill banner (on quote-materials.html) ─────────────────── */
.src-prefill-banner {
  background: rgba(80, 220, 100, 0.1);
  border: 1px solid var(--emerald);
  color: var(--fg); padding: var(--space-sm) var(--space-md);
  border-radius: 4px; margin-bottom: var(--space-md);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.9rem;
}
.src-prefill-banner a {
  color: var(--white); text-decoration: underline;
  cursor: pointer;
}
