/* ============================================================
   Finishes.pk cost calculator — component styles (scoped .fcalc)
   Reuses the site's global :root tokens (--accent, --bg, --text ...).
   Adds calculator-only tokens + the trade colour scale, theme-aware.
   ============================================================ */

.fcalc {
  /* surfaces — light (base definitions always live here) */
  --fc-surface: #FFFFFF;
  --fc-surface-2: #F7F3EE;
  --fc-surface-3: #F0E9E1;
  --fc-ink: #1C1410;
  --fc-ink-muted: #7A6E68;
  --fc-line: #E8E0D8;
  --fc-line-strong: #D8CCBF;
  --fc-accent: #C1521F;
  --fc-accent-hover: #A8421A;
  --fc-accent-pale: #F0E3D8;
  --fc-wa: #25D366;
  --fc-wa-hover: #1DA851;
  --fc-focus: #C1521F;
  --fc-shadow: 0 2px 16px rgba(28,20,16,0.07);
  --fc-shadow-hover: 0 8px 32px rgba(28,20,16,0.13);
  --fc-radius: 12px;
  --fc-radius-sm: 6px;

  /* trade colour scale — business encoded in colour.
     Grey structure recedes (muted stone). Finishing carries brand warmth. */
  --tc-grey-1: #C3B7AC;
  --tc-grey-2: #A2948A;
  --tc-grey-3: #82756B;
  --tc-finish-sage: #8A9A63;
  --tc-finish-walnut: #A9713E;
  --tc-finish-terracotta: #C1521F;
  --tc-finish-terracotta-light: #E07B45;
  --tc-finish-brass: #C09A3E;
  --tc-finish-walnut-dark: #7A4A28;
  --tc-finish-stone-warm: #B98A5E;
  --tc-finish-sage-deep: #5F7047;
  --tc-finish-stone-cool: #9E8A7C;

  color: var(--fc-ink);
  font-family: var(--font-body, 'DM Sans', Arial, sans-serif);
}

/* dark mode — system default (un-stamped) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .fcalc {
    --fc-surface: #241A15;
    --fc-surface-2: #2C211B;
    --fc-surface-3: #362A22;
    --fc-ink: #F4EEE8;
    --fc-ink-muted: #B7A99F;
    --fc-line: #3D2F27;
    --fc-line-strong: #4E3D33;
    --fc-accent: #E07B45;
    --fc-accent-hover: #EC8F5C;
    --fc-accent-pale: #3A2A20;
    --fc-focus: #E07B45;
    --fc-shadow: 0 2px 16px rgba(0,0,0,0.35);
    --fc-shadow-hover: 0 8px 32px rgba(0,0,0,0.5);
    /* lift trade bands for contrast on dark surfaces */
    --tc-grey-1: #C9BDB2;
    --tc-grey-2: #AC9E93;
    --tc-grey-3: #8E8177;
    --tc-finish-sage: #9DAE74;
    --tc-finish-walnut: #C3894F;
    --tc-finish-terracotta: #DA6A34;
    --tc-finish-terracotta-light: #F0925C;
    --tc-finish-brass: #D6AE4E;
    --tc-finish-walnut-dark: #A0663A;
    --tc-finish-stone-warm: #CD9E70;
    --tc-finish-sage-deep: #7B8C5C;
    --tc-finish-stone-cool: #B29E90;
  }
}
/* dark mode — explicitly stamped */
:root[data-theme="dark"] .fcalc {
  --fc-surface: #241A15;
  --fc-surface-2: #2C211B;
  --fc-surface-3: #362A22;
  --fc-ink: #F4EEE8;
  --fc-ink-muted: #B7A99F;
  --fc-line: #3D2F27;
  --fc-line-strong: #4E3D33;
  --fc-accent: #E07B45;
  --fc-accent-hover: #EC8F5C;
  --fc-accent-pale: #3A2A20;
  --fc-focus: #E07B45;
  --fc-shadow: 0 2px 16px rgba(0,0,0,0.35);
  --fc-shadow-hover: 0 8px 32px rgba(0,0,0,0.5);
  --tc-grey-1: #C9BDB2; --tc-grey-2: #AC9E93; --tc-grey-3: #8E8177;
  --tc-finish-sage: #9DAE74; --tc-finish-walnut: #C3894F;
  --tc-finish-terracotta: #DA6A34; --tc-finish-terracotta-light: #F0925C;
  --tc-finish-brass: #D6AE4E; --tc-finish-walnut-dark: #A0663A;
  --tc-finish-stone-warm: #CD9E70; --tc-finish-sage-deep: #7B8C5C;
  --tc-finish-stone-cool: #B29E90;
}

/* ---------- layout ---------- */
.fcalc * { box-sizing: border-box; }
.fcalc-grid {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 28px;
  align-items: start;
}
.fcalc-rail {
  position: sticky;
  top: calc(var(--nav-height, 72px) + 12px);
  background: var(--fc-surface);
  border: 1px solid var(--fc-line);
  border-radius: var(--fc-radius);
  box-shadow: var(--fc-shadow);
  padding: 20px;
  /* IMPORTANT: no fixed height, no overflow — never a nested scroll box */
}
.fcalc-results {
  min-height: 520px; /* reserve space → no CLS when results render */
}
@media (max-width: 860px) {
  .fcalc-grid { grid-template-columns: 1fr; }
  .fcalc-rail { position: static; }
  .fcalc-results { min-height: 460px; }
}

/* ---------- controls ---------- */
.fcalc-field { margin-bottom: 16px; }
.fcalc-field > label,
.fcalc-legend {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fc-ink);
  margin-bottom: 7px;
}
.fcalc-field .fcalc-hint { font-weight: 400; color: var(--fc-ink-muted); }

.fcalc select,
.fcalc input[type="number"] {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--fc-ink);
  background: var(--fc-surface-2);
  border: 1px solid var(--fc-line-strong);
  border-radius: var(--fc-radius-sm);
  padding: 10px 12px;
  min-height: 44px;
}
.fcalc-plot { display: grid; grid-template-columns: 1fr 120px; gap: 8px; }

/* segmented control */
.fcalc-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.fcalc-seg button {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--fc-ink);
  background: var(--fc-surface-2);
  border: 1px solid var(--fc-line-strong);
  border-radius: var(--fc-radius-sm);
  cursor: pointer;
  transition: background var(--transition, .3s ease), color var(--transition, .3s ease), border-color var(--transition, .3s ease);
}
.fcalc-seg button[aria-pressed="true"] {
  background: var(--fc-accent);
  border-color: var(--fc-accent);
  color: #fff;
}

/* sliders */
.fcalc-slider-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.fcalc-slider-val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--fc-accent);
  min-width: 3.2em;
  text-align: right;
}
.fcalc input[type="range"] {
  width: 100%;
  accent-color: var(--fc-accent);
  height: 40px; /* tap target */
}

/* checkboxes */
.fcalc-trades-group { margin-bottom: 10px; }
.fcalc-trades-group > span {
  display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--fc-ink-muted); margin: 6px 0 4px;
}
.fcalc-check {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 6px; min-height: 40px; cursor: pointer; border-radius: var(--fc-radius-sm);
}
.fcalc-check:hover { background: var(--fc-surface-2); }
.fcalc-check input { width: 18px; height: 18px; accent-color: var(--fc-accent); }
.fcalc-check .fcalc-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.fcalc-check span.lbl { font-size: 0.88rem; }
.fcalc-check .wesupply { font-size: 0.66rem; font-weight: 700; color: var(--fc-accent);
  background: var(--fc-accent-pale); padding: 1px 6px; border-radius: 20px; letter-spacing: .03em; }

/* more-options expander (pushes content down, no scroll box) */
.fcalc-more { border-top: 1px solid var(--fc-line); margin-top: 6px; padding-top: 12px; }
.fcalc-more-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: none; border: none; cursor: pointer; padding: 6px 0; min-height: 44px;
  font-family: inherit; font-size: 0.9rem; font-weight: 600; color: var(--fc-accent);
}
.fcalc-more-toggle .chev { transition: transform var(--transition, .3s ease); }
.fcalc-more-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.fcalc-more-panel[hidden] { display: none; }

/* ---------- results ---------- */
.fcalc-total-card {
  background: var(--fc-surface);
  border: 1px solid var(--fc-line);
  border-radius: var(--fc-radius);
  box-shadow: var(--fc-shadow);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.fcalc-total-label { font-size: 0.8rem; color: var(--fc-ink-muted); margin: 0 0 2px; }
.fcalc-total-value {
  font-family: var(--font-heading, 'Playfair Display', Georgia, serif);
  font-size: clamp(1.9rem, 5vw, 2.9rem);
  font-weight: 700; line-height: 1.05; color: var(--fc-accent); margin: 0;
}
.fcalc-total-sub { font-size: 0.9rem; color: var(--fc-ink-muted); margin: 6px 0 0; }
.fcalc-metrics { display: flex; flex-wrap: wrap; gap: 18px 28px; margin-top: 14px; }
.fcalc-metric .m-val { font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.fcalc-metric .m-lab { font-size: 0.76rem; color: var(--fc-ink-muted); }

/* stacked build-up bar */
.fcalc-bar-wrap { margin: 4px 0 14px; }
.fcalc-bar {
  display: flex; width: 100%; height: 34px; border-radius: 6px; overflow: hidden;
  background: var(--fc-surface-3); box-shadow: inset 0 0 0 1px var(--fc-line);
}
.fcalc-bar-seg { height: 100%; position: relative; }
.fcalc-bar-seg + .fcalc-bar-seg { box-shadow: -1px 0 0 rgba(255,255,255,.35); }
.fcalc-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 28px; margin-top: 14px; }
.fcalc-legend-item { display: flex; align-items: center; gap: 9px; font-size: 0.82rem; padding: 5px 0; border-bottom: 1px solid var(--fc-line); }
.fcalc-legend-item .fcalc-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.fcalc-legend-item > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fcalc-legend-item .amt { margin-left: auto; color: var(--fc-ink-muted); font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 12px; }

/* trade cards */
.fcalc-trades { display: flex; flex-direction: column; gap: 8px; }
.fcalc-trade {
  border: 1px solid var(--fc-line); border-radius: var(--fc-radius-sm);
  background: var(--fc-surface); overflow: hidden;
}
.fcalc-trade-head {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; background: none; border: none; cursor: pointer;
  font-family: inherit; text-align: left; color: var(--fc-ink); min-height: 52px;
}
.fcalc-trade-head .fcalc-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.fcalc-trade-head .t-name { font-weight: 600; font-size: 0.94rem; flex: 1; }
.fcalc-trade-head .t-cost { font-weight: 700; font-variant-numeric: tabular-nums; }
.fcalc-trade-head .chev { transition: transform var(--transition, .3s ease); color: var(--fc-ink-muted); }
.fcalc-trade-head[aria-expanded="true"] .chev { transform: rotate(180deg); }
.fcalc-trade .wesupply {
  font-size: 0.62rem; font-weight: 700; color: #fff; background: var(--fc-accent);
  padding: 2px 7px; border-radius: 20px; letter-spacing: .03em; white-space: nowrap;
}
.fcalc-trade-body[hidden] { display: none; }
.fcalc-trade-body { padding: 0 14px 14px; }
.fcalc-table-scroll { overflow-x: auto; }
.fcalc-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; min-width: 380px; }
.fcalc-table th, .fcalc-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--fc-line); }
.fcalc-table th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--fc-ink-muted); }
.fcalc-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.fcalc-table a { color: var(--fc-accent); font-weight: 600; }

/* CTAs */
.fcalc-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.fcalc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  font-family: inherit; font-size: 0.95rem; font-weight: 600; cursor: pointer;
  padding: 13px 20px; border-radius: var(--fc-radius-sm); border: 1px solid transparent;
  min-height: 48px; text-decoration: none; transition: background var(--transition, .3s ease);
}
.fcalc-btn-wa { background: var(--fc-wa); color: #fff; flex: 1 1 auto; }
.fcalc-btn-wa:hover { background: var(--fc-wa-hover); }
.fcalc-btn-print { background: var(--fc-surface-2); color: var(--fc-ink); border-color: var(--fc-line-strong); }
.fcalc-btn-print:hover { background: var(--fc-surface-3); }

.fcalc-disclaimer { font-size: 0.78rem; color: var(--fc-ink-muted); margin-top: 14px; line-height: 1.55; }
.fcalc-stamp { font-size: 0.78rem; color: var(--fc-ink-muted); margin-top: 6px; }
.fcalc-stamp b { color: var(--fc-ink); }

/* sticky mobile running total */
.fcalc-sticky-total {
  display: none;
  position: sticky; bottom: 0; z-index: 20;
  background: var(--fc-surface); border-top: 1px solid var(--fc-line-strong);
  box-shadow: 0 -4px 20px rgba(28,20,16,.12);
  padding: 10px 16px; align-items: center; justify-content: space-between; gap: 12px;
}
.fcalc-sticky-total .st-val { font-family: var(--font-heading, serif); font-weight: 700; font-size: 1.25rem; color: var(--fc-accent); }
.fcalc-sticky-total .st-lab { font-size: 0.72rem; color: var(--fc-ink-muted); }
.fcalc-sticky-total .fcalc-btn-wa { flex: 0 0 auto; padding: 10px 16px; min-height: 42px; }
@media (max-width: 860px) {
  .fcalc-sticky-total { display: flex; }
}

/* loading / error */
.fcalc-loading, .fcalc-error { padding: 40px 20px; text-align: center; color: var(--fc-ink-muted); }
.fcalc-error { color: var(--fc-accent); }

/* focus + motion */
.fcalc :focus-visible {
  outline: 3px solid var(--fc-focus);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  .fcalc *, .fcalc *::before, .fcalc *::after { transition: none !important; animation: none !important; }
}

/* print — clean estimate sheet */
@media print {
  body * { visibility: hidden; }
  .fcalc-print-area, .fcalc-print-area * { visibility: visible; }
  .fcalc-print-area { position: absolute; left: 0; top: 0; width: 100%; }
  .fcalc-rail, .fcalc-more-toggle, .fcalc-actions, .fcalc-sticky-total, .fcalc-trade-head .chev { display: none !important; }
  .fcalc-trade-body[hidden] { display: block !important; }
  .fcalc-total-value, .fcalc a { color: #000 !important; }
}

/* ============================================================
   Calculator PAGE layout (outside .fcalc widget scope)
   ============================================================ */
.page-hero-lead { font-size: 1.06rem; line-height: 1.65; max-width: 760px; color: var(--text-muted); }
.calc-article { max-width: 820px; }
.calc-article .article-content h2 { margin-top: 1.9rem; }
.calc-article .article-content p { line-height: 1.7; }

.toc-container {
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--border-radius-card); padding: 16px 20px; margin-bottom: 28px;
}
.toc-title { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 0 0 8px; }
.toc-container .toc-list ol { margin: 0; padding-left: 1.1rem; }
.toc-container .toc-list a { color: var(--accent); }

.calc-related { margin-top: 2.4rem; padding-top: 1.4rem; border-top: 1px solid var(--border); }
.calc-related h2 { font-size: 1.15rem; margin-bottom: 0.9rem; }
.calc-related-links { display: flex; flex-wrap: wrap; gap: 10px; }
.calc-related-links a {
  display: inline-block; padding: 8px 16px; border: 1px solid var(--border);
  border-radius: 40px; font-size: 0.86rem; color: var(--accent); background: var(--white);
  transition: all var(--transition);
}
.calc-related-links a:hover { background: var(--accent-pale); border-color: var(--accent); }

.calc-embed-box {
  width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem;
  padding: 12px; border: 1px solid var(--border); border-radius: var(--border-radius-btn);
  background: var(--bg-alt); color: var(--text); resize: vertical;
}

/* ============================================================
   Embed mode (?embed=1) — show only the calculator for iframes
   ============================================================ */
body.fcalc-embed .navbar,
body.fcalc-embed .mobile-menu,
body.fcalc-embed .footer,
body.fcalc-embed .page-hero,
body.fcalc-embed .calc-article,
body.fcalc-embed .faq-list,
body.fcalc-embed main > section:not(.fcalc-embed-keep) { display: none !important; }
body.fcalc-embed main > section.fcalc-embed-keep { padding: 16px !important; }
body.fcalc-embed .fcalc-embed-credit { display: block; text-align: center; font-size: 0.8rem; padding: 10px; color: var(--text-muted); }
.fcalc-embed-credit { display: none; }

/* rate index tables — tight, zebra-striped, aligned (uses GLOBAL site tokens,
   since these tables sit outside the .fcalc widget scope) */
.rate-table { font-size: 0.92rem; width: 100%; max-width: 760px; border-collapse: collapse; margin: 0 0 10px; color: var(--text, #1C1410); }
.rate-table thead th { background: var(--bg-alt, #F4F1EC); color: var(--text, #1C1410); font-weight: 700; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 2px solid var(--sand-dark, #C9B8AE); }
.rate-table th, .rate-table td { padding: 10px 16px; border-bottom: 1px solid var(--border, #E8E0D8); text-align: left; }
.rate-table th.num, .rate-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rate-table tbody tr:nth-child(even) { background: var(--bg-alt, #F4F1EC); }
.rate-table tbody tr:hover { background: var(--accent-pale, #F0E3D8); }
.rate-table td:first-child { font-weight: 600; }
.rate-table a { color: var(--accent, #C1521F); font-weight: 600; }
.rate-supply { font-size: 0.58rem; font-weight: 700; color: #fff; background: var(--accent); padding: 1px 6px; border-radius: 20px; margin-left: 6px; white-space: nowrap; }
.calc-article h2 { margin-top: 2rem; }
