/**
 * Roof Pitch Tools
 * Every colour and typeface is inherited from the active theme.
 * Nothing here hard-codes a brand colour or a font family.
 *
 * Resolution order for colour:
 *   1. --rpt-* override (set it in your theme if you want explicit control)
 *   2. theme.json presets exposed by WordPress as --wp--preset--color--*
 *   3. currentColor, i.e. whatever the surrounding text colour already is
 */

.rpt {
  /* Type comes straight from the theme. */
  font-family: inherit;
  font-size: inherit;
  line-height: 1.5;
  color: inherit;

  /* Colour tokens, all with a currentColor-based fallback. */
  --rpt-ink: var(--rpt-color-ink, var(--wp--preset--color--contrast, currentColor));
  --rpt-accent: var(--rpt-color-accent, var(--wp--preset--color--primary, var(--wp--preset--color--accent, currentColor)));
  --rpt-surface: var(--rpt-color-surface, var(--wp--preset--color--base, transparent));

  /* Derived tints. Solid fallbacks first for older browsers. */
  --rpt-line: rgba(128, 128, 128, 0.28);
  --rpt-soft: rgba(128, 128, 128, 0.07);
  --rpt-softer: rgba(128, 128, 128, 0.04);

  --rpt-gap: 1rem;
  --rpt-radius: var(--rpt-corner, 8px);

  display: block;
  margin: 0 0 1.5rem;
}

@supports (color: color-mix(in srgb, currentColor 10%, transparent)) {
  .rpt {
    --rpt-line: color-mix(in srgb, currentColor 22%, transparent);
    --rpt-soft: color-mix(in srgb, currentColor 6%, transparent);
    --rpt-softer: color-mix(in srgb, currentColor 3%, transparent);
  }
}

.rpt *,
.rpt *::before,
.rpt *::after { box-sizing: border-box; }

/* ---------- layout ---------- */

.rpt-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--rpt-gap);
}

@media (min-width: 720px) {
  .rpt-layout { grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.2fr); }
}

.rpt-side {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid var(--rpt-line);
  border-radius: var(--rpt-radius);
  background: var(--rpt-softer);
}

.rpt-main { min-width: 0; }

.rpt-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ---------- fields ---------- */

.rpt-field { display: flex; flex-direction: column; gap: 0.3rem; }

.rpt-field__label {
  font-size: 0.82em;
  font-weight: 600;
  letter-spacing: 0.01em;
  opacity: 0.75;
}

.rpt-field__row { display: flex; align-items: stretch; gap: 0; }

.rpt-input {
  font-family: inherit;
  font-size: 1em;
  color: inherit;
  background: var(--rpt-surface);
  border: 1px solid var(--rpt-line);
  border-radius: var(--rpt-radius);
  padding: 0.55em 0.7em;
  width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}

.rpt-field__row .rpt-input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 0;
}

.rpt-field__row .rpt-input:only-child {
  border-right: 1px solid var(--rpt-line);
  border-radius: var(--rpt-radius);
}

.rpt-input:focus-visible {
  outline: 2px solid var(--rpt-accent);
  outline-offset: 1px;
}

select.rpt-input {
  background-image: none;
  padding-right: 0.7em;
}

.rpt-field__suffix {
  display: flex;
  align-items: center;
  padding: 0 0.7em;
  font-size: 0.85em;
  opacity: 0.6;
  border: 1px solid var(--rpt-line);
  border-left: 0;
  border-radius: 0 var(--rpt-radius) var(--rpt-radius) 0;
  background: var(--rpt-soft);
  white-space: nowrap;
}

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

.rpt-btn {
  font-family: inherit;
  font-size: 0.9em;
  font-weight: 600;
  color: inherit;
  background: transparent;
  border: 1px solid var(--rpt-line);
  border-radius: var(--rpt-radius);
  padding: 0.6em 1.1em;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.rpt-btn:hover { background: var(--rpt-soft); }
.rpt-btn:focus-visible { outline: 2px solid var(--rpt-accent); outline-offset: 2px; }
.rpt-btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.rpt-btn--primary {
  border-color: var(--rpt-accent);
  color: var(--rpt-accent);
}

.rpt-btn--ghost { align-self: flex-start; opacity: 0.7; }

/* ---------- diagram ---------- */

.rpt-diagram { margin: 0 0 1rem; }

.rpt-svg { width: 100%; height: auto; display: block; overflow: visible; }

.rpt-svg-roof {
  stroke: var(--rpt-accent);
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
}

.rpt-svg-run,
.rpt-svg-rise {
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  opacity: 0.5;
  fill: none;
}

.rpt-svg-arc {
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
  opacity: 0.55;
}

.rpt-svg-label {
  fill: currentColor;
  font-family: inherit;
  font-size: 12px;
  opacity: 0.65;
}

.rpt-svg-angle {
  fill: var(--rpt-accent);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
}

/* ---------- results ---------- */

.rpt-primary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1px;
  background: var(--rpt-line);
  border: 1px solid var(--rpt-line);
  border-radius: var(--rpt-radius);
  overflow: hidden;
  margin-bottom: 1rem;
}

.rpt-primary__item {
  background: var(--rpt-surface);
  padding: 0.85rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.rpt-primary__label {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
}

.rpt-primary__value {
  font-size: 1.5em;
  font-weight: 700;
  line-height: 1.15;
  color: var(--rpt-accent);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.rpt-primary__sub { font-size: 0.78em; opacity: 0.6; }

.rpt-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1rem;
  font-size: 0.93em;
}

.rpt-table th,
.rpt-table td {
  text-align: left;
  padding: 0.55em 0.2em;
  border-bottom: 1px solid var(--rpt-line);
  vertical-align: top;
}

.rpt-table th { font-weight: 500; opacity: 0.78; width: 58%; }

.rpt-table td {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.rpt-table tr:last-child th,
.rpt-table tr:last-child td { border-bottom: 0; }

.rpt-subhead {
  font-family: inherit;
  font-size: 0.95em;
  font-weight: 700;
  margin: 1.25rem 0 0.5rem;
}

/* ---------- checklist (material checker) ---------- */

.rpt-checklist { list-style: none; margin: 0 0 1rem; padding: 0; }

.rpt-checklist__item {
  padding: 0.6em 0.7em;
  border: 1px solid var(--rpt-line);
  border-left-width: 3px;
  border-radius: var(--rpt-radius);
  margin-bottom: 0.4rem;
  background: var(--rpt-softer);
}

.rpt-checklist__item.is-ok { border-left-color: var(--rpt-accent); }
.rpt-checklist__item.is-cond { border-left-color: currentColor; opacity: 0.9; }
.rpt-checklist__item.is-no { opacity: 0.55; border-left-style: dashed; }

.rpt-checklist__top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}

.rpt-checklist__name { font-weight: 600; }

.rpt-checklist__val {
  font-size: 0.85em;
  opacity: 0.7;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.rpt-checklist__note {
  display: block;
  font-size: 0.82em;
  opacity: 0.65;
  margin-top: 0.25rem;
  line-height: 1.45;
}

/* ---------- notes and errors ---------- */

.rpt-notes {
  font-size: 0.85em;
  opacity: 0.7;
  line-height: 1.55;
  border-top: 1px solid var(--rpt-line);
  padding-top: 0.75rem;
}

.rpt-notes p { margin: 0 0 0.5rem; }
.rpt-notes p:last-child { margin-bottom: 0; }

.rpt-error {
  font-size: 0.9em;
  padding: 0.75em;
  border: 1px dashed var(--rpt-line);
  border-radius: var(--rpt-radius);
}

/* ---------- cut sheet ---------- */

.rpt-extras { margin-top: 1rem; }

.rpt-cutsheet {
  border: 1px solid var(--rpt-line);
  border-radius: var(--rpt-radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: var(--rpt-softer);
}

.rpt-cutsheet .rpt-subhead { margin-top: 0; }
.rpt-cutsheet__pitch { font-size: 0.85em; opacity: 0.65; margin: 0 0 0.75rem; }

/* ---------- clinometer gauge ---------- */

.rpt-gauge {
  border: 1px solid var(--rpt-line);
  border-radius: var(--rpt-radius);
  padding: 1.25rem;
}

.rpt-gauge__readout { text-align: center; margin-bottom: 1rem; }

.rpt-gauge__big {
  display: block;
  font-size: clamp(2.75rem, 14vw, 4.5rem);
  font-weight: 800;
  line-height: 1;
  color: var(--rpt-accent);
  font-variant-numeric: tabular-nums;
}

.rpt-gauge__sub { font-size: 0.8em; opacity: 0.6; margin-top: 0.35rem; }

.rpt-gauge__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 1px;
  background: var(--rpt-line);
  border: 1px solid var(--rpt-line);
  border-radius: var(--rpt-radius);
  overflow: hidden;
  margin-bottom: 1rem;
}

.rpt-gauge__cell {
  background: var(--rpt-surface);
  padding: 0.6rem 0.5rem;
  text-align: center;
}

.rpt-gauge__cell-label {
  display: block;
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
}

.rpt-gauge__cell-value {
  display: block;
  font-size: 1.05em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0.15rem;
}

.rpt-gauge__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.85rem;
}

.rpt-gauge__status {
  font-size: 0.85em;
  opacity: 0.7;
  text-align: center;
  line-height: 1.5;
  margin: 0 0 1rem;
}

.rpt-gauge__manual {
  border-top: 1px solid var(--rpt-line);
  padding-top: 0.75rem;
  font-size: 0.9em;
}

.rpt-gauge__manual summary { cursor: pointer; opacity: 0.75; margin-bottom: 0.5rem; }
.rpt-gauge__manual .rpt-field__row { max-width: 220px; }

/* ---------- static reference tables rendered by PHP ---------- */

.rpt-reference { margin: 1.5rem 0; overflow-x: auto; }

.rpt-reference table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
}

.rpt-reference th,
.rpt-reference td {
  padding: 0.5em 0.6em;
  border-bottom: 1px solid var(--rpt-line);
  text-align: right;
  white-space: nowrap;
}

.rpt-reference th:first-child,
.rpt-reference td:first-child { text-align: left; }

.rpt-reference thead th {
  font-weight: 700;
  border-bottom-width: 2px;
  position: sticky;
  top: 0;
  background: var(--rpt-surface);
}

.rpt-reference tbody tr.is-common { background: var(--rpt-soft); }

.rpt-faq { margin: 1.5rem 0; }
.rpt-faq__item { border-bottom: 1px solid var(--rpt-line); padding: 0.75rem 0; }
.rpt-faq__q { font-weight: 700; margin: 0 0 0.35rem; font-size: 1em; }
.rpt-faq__a { margin: 0; opacity: 0.8; font-size: 0.93em; line-height: 1.6; }

.rpt-answer {
  border-left: 3px solid var(--rpt-accent);
  padding: 0.25rem 0 0.25rem 1rem;
  margin: 0 0 1.25rem;
  font-size: 1.05em;
  line-height: 1.6;
}

/* ---------- accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  .rpt * { transition: none !important; animation: none !important; }
}

@media print {
  .rpt-side,
  .rpt-btn,
  .rpt-gauge__controls { display: none !important; }
  .rpt-layout { grid-template-columns: 1fr; }
}
