/*
 * Advanced Projector Screen Calculator — styles scoped entirely under the
 * "advcalc" prefix (and the shared global primitives .btn/.form-row/
 * .form-grid/.form-hint/.section/.container, which are already used
 * site-wide and are safe to reuse). Nothing here redefines or overrides any
 * class used by the original /screen-calculator/ page (".calculator…"),
 * so the two calculators cannot visually or behaviourally collide.
 * Loaded only on /advanced-projector-screen-calculator/ via a <link> tag
 * in pages/advanced-projector-screen-calculator.php — assets/css/main.css
 * is not touched.
 */

.advcalc {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
  margin-top: 28px;
  padding: 24px;
  background: var(--color-paper-soft);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-lg);
}

@media (min-width: 900px) {
  .advcalc { grid-template-columns: 360px 1fr; align-items: start; }
}

.advcalc__panel {
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
}

/* --- App-style form controls: segmented pill groups, custom-chevron
   selects, and a numeric stepper — replace a few plain <select>/<input>
   controls with a more native-app feel. Fully namespaced; nothing here
   touches the global .form-row/input/select rules in main.css. --------- */

.advcalc-segmented {
  display: flex;
  gap: 6px;
  background: var(--color-paper-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.advcalc-segmented__input {
  position: absolute;
  width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}

.advcalc-segmented__option {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: normal;
  line-height: 1.15;
  padding: 9px 6px;
  margin: 0;
  border-radius: calc(var(--radius-sm) - 2px);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
  transition: background-color .18s var(--ease), color .18s var(--ease), box-shadow .18s var(--ease), transform .12s var(--ease);
}

.advcalc-segmented__input:checked + .advcalc-segmented__option {
  background: var(--color-paper);
  color: var(--color-accent-dark);
  box-shadow: var(--shadow-xs);
}

.advcalc-segmented__input:focus-visible + .advcalc-segmented__option {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.advcalc-segmented__option:active {
  transform: scale(0.96);
}

.advcalc-select-wrap {
  position: relative;
}

.advcalc-select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 38px;
  cursor: pointer;
}

.advcalc-select-wrap::after {
  content: "";
  position: absolute;
  right: 15px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.advcalc-stepper {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.advcalc-stepper input[type="number"] {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
}

.advcalc-stepper__btn {
  flex: 0 0 auto;
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1;
  color: var(--color-ink);
  background: var(--color-paper-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color .15s var(--ease), transform .12s var(--ease);
}

.advcalc-stepper__btn:hover { background: var(--color-accent-soft); color: var(--color-accent-dark); }
.advcalc-stepper__btn:active { transform: scale(0.92); }

.advcalc__results {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.advcalc__result-block {
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
}

.advcalc__result-heading {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-ink);
  margin: 0 0 14px;
}

.advcalc__stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

@media (min-width: 560px) {
  .advcalc__stat-grid { grid-template-columns: repeat(3, 1fr); }
  .advcalc__stat-grid--fabric { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .advcalc__stat-grid--fabric { grid-template-columns: repeat(3, 1fr); }
}

.advcalc__stat { min-width: 0; }

.advcalc__stat-label {
  font-size: 0.74rem;
  color: var(--color-text-muted);
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.advcalc__stat-value {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-ink);
  margin: 0;
  overflow-wrap: break-word;
  border-radius: 6px;
}

.advcalc__stat-value.is-updated {
  animation: advcalc-pulse .5s var(--ease);
}

@keyframes advcalc-pulse {
  0% { background: var(--color-accent-soft); color: var(--color-accent-dark); transform: scale(1.04); }
  100% { background: transparent; color: var(--color-ink); transform: scale(1); }
}

/* --- Technical diagram + tables --------------------------------------- */

.advcalc__diagram-section {
  margin-top: 32px;
}

.advcalc__diagram-wrap {
  display: flex;
  justify-content: center;
  padding: 20px;
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.advcalc__diagram {
  width: 100%;
  max-width: 480px;
  height: auto;
}

.advcalc__diagram-rect {
  fill: var(--color-accent-soft);
  stroke: var(--color-accent-2);
  stroke-width: 2;
}

.advcalc__diagram-border-rect {
  fill: none;
  stroke: var(--color-ink);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}

.advcalc__diagram-diagonal {
  stroke: var(--color-ink);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
}

.advcalc__diagram-label {
  font-family: var(--font-body);
  font-size: 13px;
  fill: var(--color-ink);
  font-weight: 600;
}

.advcalc__diagram-label--muted {
  fill: var(--color-text-muted);
  font-weight: 500;
  font-size: 11px;
}

.advcalc__tables {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-top: 20px;
}

@media (min-width: 720px) {
  .advcalc__tables { grid-template-columns: 1fr 1fr; }
}

.advcalc__table-wrap h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  margin: 0 0 10px;
  color: var(--color-ink);
}

.advcalc__table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.advcalc__table th,
.advcalc__table td {
  text-align: left;
  padding: 9px 12px;
  font-size: 0.86rem;
  border-bottom: 1px solid var(--color-border-soft);
}

.advcalc__table th {
  font-weight: 500;
  color: var(--color-text-muted);
  width: 55%;
}

.advcalc__table td {
  font-weight: 600;
  color: var(--color-ink);
}

.advcalc__table tr:last-child th,
.advcalc__table tr:last-child td {
  border-bottom: none;
}

/* --- Action buttons ----------------------------------------------------- */

.advcalc__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 26px;
}

.advcalc__actions .btn { flex: 1 1 200px; }

/* Tap/press feedback — scoped to this page's own buttons only, never the
   sitewide .btn class elsewhere. */
.advcalc .btn:active,
.advcalc__actions .btn:active,
.advcalc-panel .btn:active {
  transform: scale(0.97);
}

/* Gentle entrance animation for first paint — respects prefers-reduced-
   motion by only existing inside this media query, so a reduced-motion
   user simply sees the fully-visible page with no fade/slide at all. */
@media (prefers-reduced-motion: no-preference) {
  .advcalc,
  .advcalc__diagram-section,
  .advcalc__actions {
    animation: advcalc-fade-up .5s var(--ease) both;
  }
  .advcalc__diagram-section { animation-delay: .08s; }
  .advcalc__actions { animation-delay: .14s; }
}

@keyframes advcalc-fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Send / Order side panel (mirrors the sitewide quick-enquiry panel's
   interaction language — slide-in overlay — but fully namespaced, its own
   markup, and not reused from templates/partials/footer.php) ------------ */

.advcalc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 14, 20, 0.45);
  /* Must clear .site-header's z-index:100 (sticky header) — matched to the
     existing sitewide quick-enquiry panel's overlay/panel z-index values
     (.enquire-overlay/.enquire-panel in main.css) for consistency. */
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}

.advcalc-overlay.is-open { opacity: 1; }

.advcalc-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 420px;
  background: var(--color-paper);
  z-index: 1001;
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.25s var(--ease);
  overflow-y: auto;
  padding: 24px;
}

.advcalc-panel.is-open { transform: translateX(0); }

.advcalc-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.advcalc-panel__head h2 {
  font-size: 1.1rem;
  margin: 0;
}

.advcalc-panel__close {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px 8px;
}

.advcalc-panel__close:hover { color: var(--color-ink); }

.advcalc-panel__spec-preview {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  background: var(--color-paper-soft);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 16px;
  white-space: pre-line;
}

.advcalc-panel__notice {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}

.advcalc-panel__notice--success {
  background: #ecfdf3;
  color: #087443;
  border: 1px solid #bbf0d3;
}

.advcalc-panel__notice--error {
  background: #fef2f2;
  color: #b42318;
  border: 1px solid #fecdca;
}

/* --- Print-only spec sheet for "Save as PDF" ---------------------------- */

.advcalc-print-sheet { display: none; }

@media print {
  /* Hide absolutely everything on the page except the print sheet: the
     whole calculator body (h1, intro, form panel, live results, diagram,
     tables, action buttons) is wrapped in .advcalc-page-body for exactly
     this purpose, plus every other piece of page/site chrome. The print
     sheet (.advcalc-print-sheet, populated by JS right before printing)
     lives outside that wrapper so it's the only thing left visible. */
  .header-utility,
  .site-header,
  .breadcrumb,
  .footer-cta,
  .site-footer,
  .float-stack,
  .enquire-tab,
  .enquire-overlay,
  .enquire-panel,
  .advcalc-page-body,
  .advcalc-overlay,
  .advcalc-panel,
  .advcalc-stickybar,
  .skip-link,
  section.section--soft {
    display: none !important;
  }

  .advcalc-print-sheet.is-printing {
    display: block;
    font-family: var(--font-body), sans-serif;
    color: #10131a;
    padding: 20px;
  }

  .advcalc-print-sheet h1 {
    font-family: var(--font-display), sans-serif;
    font-size: 1.4rem;
    margin: 0 0 4px;
  }

  .advcalc-print-sheet .advcalc-print-sheet__brand {
    font-weight: 700;
    color: #c2410c;
    margin-bottom: 18px;
  }

  .advcalc-print-sheet table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 18px;
  }

  .advcalc-print-sheet th,
  .advcalc-print-sheet td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid #ddd;
    font-size: 0.9rem;
  }
}

/* --- Sticky bottom action bar (mobile only) — mirrors the three buttons
   in .advcalc__actions so Save/Send/Order are always one tap away while
   scrolling, the way a native app's bottom bar works. Completely hidden
   above 768px; uses :has() to nudge the sitewide WhatsApp/Call float
   buttons and add page bottom padding ONLY when this bar is present and
   visible — pure CSS, no edits to main.css or footer.php needed. -------- */

.advcalc-stickybar {
  display: none;
}

@media (max-width: 768px) {
  .advcalc-stickybar {
    display: flex;
    gap: 8px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    background: var(--color-paper);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -4px 16px rgba(11, 14, 20, 0.12);
  }

  body:has(.advcalc-stickybar) {
    padding-bottom: 68px;
  }

  body:has(.advcalc-stickybar) .float-stack {
    bottom: 80px;
  }
}

.advcalc-stickybar__btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color .15s var(--ease), color .15s var(--ease), transform .12s var(--ease);
}

.advcalc-stickybar__btn:active { transform: scale(0.94); }
.advcalc-stickybar__btn:hover { background: var(--color-accent-soft); color: var(--color-accent-dark); }

.advcalc-stickybar__btn--primary {
  background: var(--gradient-accent);
  color: #fff;
}

.advcalc-stickybar__btn--primary:hover { color: #fff; }

/* --- Mobile tightening ---------------------------------------------------*/

@media (max-width: 480px) {
  .advcalc { padding: 16px; }
  .advcalc__panel { padding: 16px; }
  .advcalc__result-block { padding: 14px 16px; }
  .advcalc__stat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .advcalc-panel { max-width: 100%; padding: 18px; }
  .advcalc-stepper__btn { width: 40px; }
}
