/**
 * Mortgage Calculators: Custom Styles (UIKit companion)
 *
 * UIKit handles layout, forms, cards, buttons, and responsive.
 * This file covers ONLY what UIKit doesn't provide:
 *   1. Accent color theming via --mcalc-color
 *   2. Range slider thumb
 *   3. Toggle switch
 *   4. Result hero display
 *   5. Honeypot hiding
 *   6. Focus-visible ring on accent-colored buttons (inline background
 *      can suppress UIKit's default focus outline on some browsers)
 *   7. uk-hidden-visually safety net (UIKit provides this, but a local
 *      copy makes the plugin work on themes that strip UIKit utilities)
 */

/* Visually hide content but keep it available to assistive tech. */
.mcalc .uk-hidden-visually,
.mcchart .uk-hidden-visually {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Inline `background-color: var(--mcalc-color)` on themed buttons can
   suppress UIKit's default :focus outline on Webkit. Pin a high-contrast
   focus ring so keyboard users always see where focus sits. */
.mcalc .uk-button:focus-visible,
.mcalc .uk-accordion-title:focus-visible {
  outline: 2px solid var(--mcalc-color);
  outline-offset: 2px;
}

/* Intro paragraph: sits above the form on every calculator. */
.mcalc-intro {
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ─── Smart (Tabbed) Calculator ──────────────────── */
/*
 * Wraps multiple per-type calculators in UIKit tabs. The outer card
 * provides the visual frame; each tab panel contains a full calculator
 * instance with its inner card wrapper suppressed (see MC_Smart).
 */
.mcalc-smart {
  --_color: var(--mcalc-color, #1a56db);
  container-type: inline-size;
  container-name: mcalc-smart;
  color: #111827;
  /* No baseline padding-bottom. When no card is set (default), the inner
     .mcalc already provides 16px. When a card IS set, the rule below
     adds breathing room outside the card's bottom edge so the card
     does not butt up against the section boundary. */
}

/* When the smart wrapper renders with a card_style other than "none",
   the card's visual bottom edge sits inside .mcalc-smart. Without this,
   the card ends right at .mcalc-smart's edge and visually sticks against
   the section's padding-bottom. */
.mcalc-smart:has(> .uk-card) {
  padding-bottom: 24px;
}

/* Defensive sizing for the YOOtheme element wrappers. Without these,
   the inner card + uk-overflow-hidden combination can resist shrinking
   inside narrow columns (left-side half-width column, sidebar, etc.)
   and the widget appears to ignore the parent column's width. min-width
   on the box content also lets the inner UIKit grid collapse properly
   in narrow contexts. */
.el-lfcalc-smart,
.el-lfchart {
  display: block;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.mcalc,
.mcalc-smart,
.mcchart {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.mcalc *,
.mcalc-smart *,
.mcchart * {
  box-sizing: border-box;
}

/* ─── Container-aware responsive layout ─────────────
 *
 * UIKit's `uk-width-expand@m` and `uk-width-1-3@m` use VIEWPORT media
 * queries. That means a narrow column on a desktop viewport (e.g. a
 * 1/2-width column at 1440px viewport = 600px column) still tries to
 * render the form and results panes side-by-side. The widget then
 * either overflows or compresses unreadably.
 *
 * Fix: when the calculator's own container is below ~700px, force the
 * panes to stack regardless of viewport. We name the container "mcalc"
 * (set up at .mcalc { container-type: inline-size; container-name: mcalc; })
 * and query its inline-size.
 *
 * Note the \@m escape: `@` is valid in CSS class names but must be
 * escaped with `\` in selectors.
 */
@container mcalc (max-width: 700px) {
  .mcalc .uk-width-expand\@m,
  .mcalc .uk-width-1-3\@m {
    width: 100%;
  }
}

/* Same treatment for the breakdown chart's side-by-side legend layout. */
@container mcchart (max-width: 540px) {
  .mcchart .uk-width-1-2\@s {
    width: 100%;
  }
}

.mcalc-smart-tabs {
  /* Make the tab nav inherit the accent so the active tab indicator
     matches the calculator's brand color instead of UIKit's default. */
  margin-bottom: 0;
}
.mcalc-smart-tabs > .uk-active > a {
  border-bottom-color: var(--_color);
  color: var(--_color);
}
.mcalc-smart-tabs > li > a:hover {
  color: var(--_color);
}

.mcalc-smart-switcher {
  /* Drop UIKit's default top padding so the active tab panel starts
     immediately under the tab nav, not after a UIKit list gap. */
  margin: 0;
  padding: 0;
  list-style: none;
}
.mcalc-smart-switcher > li {
  padding-top: 0;
}

/* Stack tabs to multiple lines on very narrow embeds, but keep them
   readable. UIKit's default wrap behavior handles this; we just trim
   the bottom margin so wrapped lines don't add visual gap. */
@container mcalc-smart (max-width: 540px) {
  .mcalc-smart-tabs > li > a {
    padding: 8px 12px;
    font-size: 13px;
  }
}

/* ─── Accent Color Token + Container Query Root ── */

.mcalc {
  --_color: var(--mcalc-color, #1a56db);
  /* Make .mcalc the container query root so the calculator
     adapts to the WIDTH OF ITS CONTAINER, not the viewport.
     This is what makes the calc work when it's embedded in a
     narrow column (hero side-by-side, sidebar, half-width grid). */
  container-type: inline-size;
  container-name: mcalc;
  /* Own our color scheme. Don't inherit from .uk-light, .uk-section-primary,
     .uk-section-secondary, or any other context that flips text white.
     The calculator is a self-contained component, readable in any section. */
  color: #111827;
  /* Internal bottom padding for the no-card case. The form and results
     panes have their own inner padding, but without a card_style there is
     no uk-card-body wrapping them, so the widget visually ends right at
     that boundary. 16px gives breathing room before the section's
     padding-bottom takes over. The with-card case is handled by the
     :has(> .uk-card) rule below. */
  padding-bottom: 16px;
}

/* Shortcode path: when calculator.php renders standalone (via [lfcalc]),
   the card (if any) is a direct child of .mcalc. Bump the bottom padding
   so the card has visible breathing room before the section ends. */
.mcalc:has(> .uk-card) {
  padding-bottom: 24px;
}

/* Share button: pin to the accent color in all states. UIKit's
   uk-button-text defaults to a dark color that becomes unreadable when
   the calculator is inside a Primary or Secondary card (dark background).
   Using the accent color keeps it readable and visually consistent with
   the hero result number, which also uses the accent. */
.mcalc-results .mcalc-share-btn,
.mcalc-results .mcalc-share-btn:hover,
.mcalc-results .mcalc-share-btn:focus,
.mcalc-results .mcalc-share-btn:active {
  color: var(--_color);
}

/* ─────────────────────────────────────────────────
 * Results Panel: Self-Contained Color Scheme
 *
 * The results panel has its own light gradient background. When it's
 * embedded inside a dark section, a Primary/Secondary card, or any
 * context where UIKit applies `.uk-light` text inversion, child text
 * inherits white, and white text on the light gradient is invisible.
 *
 * Fix: every text element inside `.mcalc-results` declares its own
 * color with !important. The panel becomes truly self-contained:
 * always readable regardless of parent section's color scheme.
 *
 * The form side intentionally is NOT locked down. It adapts to its
 * parent context (white labels on dark hero, dark labels on light card).
 * ───────────────────────────────────────────────── */

.mcalc-results {
  color: #111827;
}

/* Hero result value: always the accent color */
.mcalc-results .mcalc-result-hero-value {
  color: var(--_color) !important;
}

/* Hero result label ("Monthly Payment", etc.) */
.mcalc-results .mcalc-result-hero-label {
  color: #6b7280 !important;
}

/* Result row labels ("Principal & Interest", "Monthly Taxes", etc.) */
.mcalc-results .uk-text-meta,
.mcalc-results .mcalc-result-row .uk-text-meta {
  color: #6b7280 !important;
}

/* Result row values */
.mcalc-results .uk-text-bold,
.mcalc-results [data-result] {
  color: #111827 !important;
}

/* Disclaimer at the bottom of results panel. #6b7280 clears 4.5:1 on the
   light results gradient; #9ca3af did not. */
.mcalc-results .mcalc-disclaimer {
  color: #6b7280 !important;
}

/* Email gate heading inside results panel */
.mcalc-results .mcalc-email-gate p {
  color: var(--_color) !important;
}

/* Email gate status text: neutral by default, red on error */
.mcalc-results .mcalc-email-status {
  color: #6b7280 !important;
}

.mcalc-results .mcalc-email-status.mcalc-error {
  color: #dc2626 !important;
}

/* Email input inside results panel: force light bg + dark text
   so a parent dark section doesn't make it unreadable */
.mcalc-results .mcalc-email-input {
  background-color: #ffffff !important;
  color: #111827 !important;
  border-color: #e5e7eb !important;
}

.mcalc-results .mcalc-email-input::placeholder {
  color: #6b7280 !important;
  opacity: 1 !important;
}


/* ─── Container-Aware Stacking ──────────────────── */
/*
 * UIKit's default .uk-padding (40px) eats ~160px of horizontal room across
 * both panels. Trim it inside .mcalc so the form/results layout can stay
 * side-by-side at narrower container widths before we have to stack.
 *
 * The panes actually carry `uk-padding@m` (not bare `uk-padding`), so the
 * escaped `.uk-padding\@m` selector is required or these overrides never match.
 */
.mcalc .uk-padding,
.mcalc .uk-padding\@m {
  padding: 24px;
}

/* Intermediate width: tighten further before stacking, shrink the hero
   number, and compact the slider value gutter so the form column can
   contract without overflowing or pushing the results panel. */
@container mcalc (max-width: 720px) {
  .mcalc .uk-padding,
  .mcalc .uk-padding\@m {
    padding: 18px;
  }
  .mcalc-result-hero-value {
    font-size: 34px;
  }
  .mcalc-range-value {
    min-width: 44px;
    font-size: 13px;
    margin-left: 8px;
  }
}

/* Stack only when the container truly can't hold both columns. */
@container mcalc (max-width: 540px) {
  .mcalc [uk-grid] > * {
    width: 100% !important;
  }
  /* The stacked top-border is the base style now; the side-by-side left
     border is added only at >=701px, so nothing to override here. */
}

/* Very narrow (mobile or extremely squeezed embed) */
@container mcalc (max-width: 380px) {
  .mcalc .uk-padding,
  .mcalc .uk-padding\@m {
    padding: 14px;
  }
  .mcalc-result-hero-value {
    font-size: 30px;
  }
}

/* ─── Form Labels (override theme hiding) ──────── */

.mcalc .uk-form-label {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
  text-transform: none;
  letter-spacing: normal;
}

/* ─── Group Heading ─────────────────────────────── */

.mcalc-group-heading {
  color: var(--_color);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--_color);
  letter-spacing: 0.08em;
  font-size: 13px;
}

/* ─── Results Panel ─────────────────────────────── */

.mcalc-results {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  /* Stacked is the default (mobile / narrow embeds): divide with a top
     border. The left border is added back only when the panes are actually
     side by side (container is wide enough), by the min-width rule below. */
  border-top: 1px solid #e5e7eb;
  /* Critical: prevent overflow when narrow.
     The result hero number ($X,XXX) needs room to breathe. */
  min-width: 0;
  overflow-wrap: break-word;
}

/* Side-by-side layout: divide with a left border instead of a top one. */
@container mcalc (min-width: 701px) {
  .mcalc-results {
    border-top: none;
    border-left: 1px solid #e5e7eb;
  }
}

/* ─── Result Hero ───────────────────────────────── */

.mcalc-result-hero-value {
  display: block;
  font-size: 42px;
  font-weight: 800;
  color: var(--_color);
  letter-spacing: -1px;
  line-height: 1.1;
  /* Prevent the hero number from forcing horizontal overflow
     when the container is squeezed. */
  word-break: break-word;
}

/* ─── Result Rows ───────────────────────────────── */

.mcalc-result-row {
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
}

.mcalc-result-row:last-of-type {
  border-bottom: none;
}

/* ─── Hero sub-line + verdict semantics ─────────────
 * A benchmark line under the headline ("Target 1.25 · clears by +0.07",
 * "Buying wins by $47k over 10 years · break-even yr 6") and semantic color
 * on the qualify/decline and buy/rent verdicts. Scoped under .mcalc-results
 * so they out-specify the panel's black-text and accent-hero locks. */
.mcalc-results .mcalc-result-hero-sub {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.4;
  color: #6b7280 !important;
}
.mcalc-results .mcalc-result-hero-sub:empty {
  display: none;
}
.mcalc-results .mcalc-verdict-pass {
  color: #059669 !important;
}
.mcalc-results .mcalc-verdict-fail {
  color: #dc2626 !important;
}
.mcalc-results .mcalc-verdict-alt {
  color: var(--_color) !important;
}
.mcalc-results .mcalc-verdict-neutral {
  color: #6b7280 !important;
}

/* ─── Range Slider ──────────────────────────────── */

.mcalc-range {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: #e5e7eb;
  outline: none;
  cursor: pointer;
}

.mcalc-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--_color);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: grab;
  transition: transform 0.15s;
}

.mcalc-range::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.mcalc-range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--_color);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: grab;
}

.mcalc-range-value {
  min-width: 56px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  color: var(--_color);
  white-space: nowrap;
  margin-left: 12px;
}

/* ─── Toggle Switch ─────────────────────────────── */

.mcalc-toggle {
  width: 40px;
  height: 22px;
  -webkit-appearance: none;
  appearance: none;
  background: #d1d5db;
  border-radius: 11px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.mcalc-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.mcalc-toggle:checked {
  background: var(--_color);
}

.mcalc-toggle:checked::after {
  transform: translateX(18px);
}

/* ─── Honeypot ──────────────────────────────────── */

.mcalc-hp {
  position: absolute;
  left: -9999px;
  opacity: 0;
  height: 0;
  width: 0;
  overflow: hidden;
}

/* ─── Email Status ──────────────────────────────── */

.mcalc-success {
  color: #059669;
}

.mcalc-error {
  color: #dc2626;
}

/* ─── Focus Accent ──────────────────────────────── */

.mcalc .uk-input:focus,
.mcalc .uk-select:focus {
  border-color: var(--_color);
}

/* ─── Field Validation Errors ──────────────────── */

.mcalc-field-error {
  color: #dc2626;
  font-size: 12px;
  line-height: 1.4;
}

.mcalc .uk-form-danger,
.mcalc .uk-form-danger:focus {
  border-color: #dc2626 !important;
}

/* ─── Chart Widgets ─────────────────────────────── */

.mcchart {
  --_color: var(--mcalc-color, #1a56db);
  font-family: inherit;
  /* Container query root so the chart's donut + legend layout adapts
     to the column it lives in, not the viewport. Paired with the
     @container mcchart rule near the top of this file. */
  container-type: inline-size;
  container-name: mcchart;
  /* Internal bottom padding so the chart widget does not render flush
     against the next page element when there is no surrounding card. */
  padding-bottom: 16px;
}

.mcchart-donut-wrap {
  max-width: 260px;
  margin: 0 auto;
}

.mcchart-donut {
  width: 100%;
  height: auto;
  display: block;
}

.mcchart-slice {
  transition: stroke-dasharray 0.35s ease, stroke-dashoffset 0.35s ease;
}

.mcchart-total {
  font-family: inherit;
  fill: #0f172a;
}

.mcchart-total-value {
  font-size: 5px;
  font-weight: 700;
}

.mcchart-total-label {
  font-size: 2.5px;
  fill: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mcchart-row {
  position: relative;
  padding-left: 18px;
}

.mcchart-dot {
  position: absolute;
  left: 0;
  top: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.mcchart-label {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
}

.mcchart-pct {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  pointer-events: none;
}

/* ─── Accessibility: keyboard focus, reduced motion, forced colors ── */

/* Sliders and toggles are the primary controls; keyboard users must see
   focus. The slider drops the mouse-focus outline, so restore it for
   :focus-visible only. */
.mcalc-range:focus-visible,
.mcalc-toggle:focus-visible {
  outline: 2px solid var(--_color);
  outline-offset: 4px;
}

/* Respect reduced-motion: no thumb scale, slice sweep, or toggle slide. */
@media (prefers-reduced-motion: reduce) {
  .mcalc-range::-webkit-slider-thumb,
  .mcalc-toggle,
  .mcalc-toggle::after,
  .mcchart-slice {
    transition: none !important;
  }
  .mcalc-range::-webkit-slider-thumb:hover {
    transform: none;
  }
}

/* Windows High Contrast / forced-colors flattens background color, which is
   the only thing carrying the toggle's on/off state. Add a border and an
   inner marker so the state stays perceivable. */
@media (forced-colors: active) {
  .mcalc-toggle {
    border: 1px solid CanvasText;
  }
  .mcalc-toggle:checked {
    background: Highlight;
  }
  .mcalc-toggle::after {
    background: CanvasText;
  }
  .mcalc-range:focus-visible,
  .mcalc-toggle:focus-visible {
    outline-color: Highlight;
  }
}

/* ─── Touch targets & iOS zoom (coarse pointers) ─────────────────── */

@media (pointer: coarse) {
  /* 16px inputs stop iOS Safari auto-zooming the page on focus. */
  .mcalc .uk-input,
  .mcalc .uk-select,
  .mcalc .mcalc-email-input {
    font-size: 16px;
  }

  /* 44px-tall hit area for the slider while the visible track stays 6px. */
  .mcalc-range {
    height: 44px;
    background: transparent;
    touch-action: pan-y;
  }
  .mcalc-range::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
  }
  .mcalc-range::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
  }
  .mcalc-range::-webkit-slider-thumb {
    width: 30px;
    height: 30px;
    margin-top: -12px; /* center the 30px thumb on the 6px track */
  }
  .mcalc-range::-moz-range-thumb {
    width: 30px;
    height: 30px;
  }

  /* Comfortable tap size on the report / share buttons. */
  .mcalc .uk-button-small,
  .mcalc-share-btn,
  .mcalc-download-btn,
  .mcalc-send-btn {
    min-height: 44px;
  }
}

/* ─── Amortization table: sticky header, right-aligned figures ───── */

.mcalc-amort-table thead th {
  position: sticky;
  top: 0;
  background: #ffffff;
  z-index: 1;
}
.mcalc-amort-table th:not(:first-child),
.mcalc-amort-table td:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ─── Smart tabs: one scrollable row, not 3-5 stacked lines ──────── */

.mcalc-smart-tabnav {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.mcalc-smart-tabnav .mcalc-smart-tabs {
  flex-wrap: nowrap;
}
