/* ==========================================================================
   SWP Calculator — Stylesheet
   Minimal, generous-spacing aesthetic. Green accent (#16b99a).
   Optimized: fluid clamp()-based sizing (fewer breakpoint jumps), larger
   touch targets on coarse-pointer devices, render-containment hints, and
   guards against horizontal overflow on small screens.
   ========================================================================== */

:root {
  --accent: #16b99a;
  --accent-dark: #0f9c81;
  --accent-light: #e5f8f2;
  --accent-alt: #2f6fed;
  --danger: #e5484d;
  --danger-light: #fdecec;

  --navy-900: #0b1f3a;
  --navy-800: #12294a;
  --navy-700: #1c3a63;
  --navy-100: #eaeff5;

  --ink-900: #101c2c;
  --ink-700: #3c4a5c;
  --ink-500: #7c8b9c;
  --ink-300: #b7c2ce;
  --ink-100: #edf1f5;

  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --border: #e6eaf0;

  --shadow-sm: 0 1px 2px rgba(11, 31, 58, 0.06);
  --shadow-md: 0 10px 30px rgba(11, 31, 58, 0.07);
  --shadow-lg: 0 24px 60px rgba(11, 31, 58, 0.12);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  /* Manrope/Inter are intentionally NOT fetched from a font host — no extra
     network round-trip, no render-blocking @font-face swap. The stack falls
     back straight to the platform's native UI font, which is both fastest
     and matches each OS's look. */
  --font-display: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink-900);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
  min-height: 100vh;
}

img, svg { display: block; max-width: 100%; }

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 24px) 64px;
}

/* ---------- Header (full-bleed navy letterhead) ---------- */

.site-header {
  background: linear-gradient(120deg, var(--navy-900) 0%, var(--navy-700) 100%);
  padding: clamp(20px, 4vw, 30px) 0;
  margin-bottom: clamp(24px, 5vw, 40px);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 24px);
}

.brand { display: flex; align-items: center; gap: 16px; }

.brand-mark {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--navy-900);
  background: var(--accent);
  box-shadow: var(--shadow-md);
  contain: strict;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(20px, 2.8vw, 28px);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.subtitle { margin: 5px 0 0; font-size: 13.5px; color: #a9bad4; }

/* ---------- Layout ---------- */

.calculator-grid {
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
  gap: 24px;
  align-items: start;
}

.panel {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: clamp(20px, 4vw, 40px);
  padding-top: clamp(24px, 4vw, 44px);
  transition: box-shadow 0.25s ease;
  overflow: hidden;
  /* Isolate layout/paint to this subtree so slider-drag and counter
     animations elsewhere on the page don't force this panel to repaint. */
  contain: layout style;
}

.panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--navy-900) 0%, var(--accent) 100%);
}

.panel:hover { box-shadow: var(--shadow-lg); }

.inputs-panel { position: sticky; top: 24px; }

.panel-title {
  margin: 0 0 34px;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 800;
  color: var(--navy-900);
}

/* ---------- Input groups (generous spacing, pill value, thin slider) ---------- */

.input-group { margin-bottom: 40px; }
.input-group:last-of-type { margin-bottom: 24px; }

.input-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.input-group-head label {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink-700);
  display: flex;
  align-items: center;
  gap: 7px;
}

.required-mark {
  color: var(--danger);
  font-weight: 700;
  font-size: 13px;
}

.info-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.4px solid var(--ink-300);
  background: transparent;
  color: var(--ink-500);
  font-size: 10px;
  font-style: italic;
  font-family: Georgia, serif;
  line-height: 1;
  cursor: help;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

/* Comfortable ~44px tap target on touch devices without visually
   enlarging the 16px dot (uses an invisible pseudo-element hit area). */
@media (pointer: coarse) {
  .info-icon::after {
    content: '';
    position: absolute;
    inset: -14px;
  }
}

.info-icon:hover, .info-icon:focus-visible {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: var(--accent-light);
  outline: none;
}

.value-box {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-light);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  width: clamp(112px, 32vw, 150px);
  flex-shrink: 0;
  transition: box-shadow 0.15s ease;
}

.value-box:focus-within { box-shadow: 0 0 0 3px rgba(22, 185, 154, 0.25); }

.value-box .prefix, .value-box .suffix {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-700);
  flex-shrink: 0;
}

.value-box .suffix { margin-left: 3px; }

.value-input {
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--font-display);
  /* 16px minimum keeps iOS Safari from auto-zooming the page on focus */
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-900);
  width: 100%;
  text-align: right;
  padding: 0;
}

/* Fields whose value should read in accent green (rate / duration) */
.value-box.accent .value-input,
.value-box.accent .suffix { color: var(--accent-dark); }

/* Thin, minimal range slider — track is 4px visually but the interactive
   hit area is a full 44px tall on touch devices for reliable dragging. */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  outline: none;
  margin: 0;
  padding: 0;
  cursor: pointer;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

@media (pointer: coarse) {
  .slider { height: 44px; }
}

.slider::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--fill, 50%), var(--ink-100) var(--fill, 50%), var(--ink-100) 100%);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--navy-900);
  box-shadow: 0 2px 6px rgba(11, 31, 58, 0.28);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  margin-top: -8px;
}

@media (pointer: coarse) {
  .slider::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -11px; }
}

.slider::-webkit-slider-thumb:hover,
.slider:focus-visible::-webkit-slider-thumb { transform: scale(1.15); border-color: var(--accent-dark); }

.slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: #ffffff; border: 3px solid var(--navy-900);
  box-shadow: 0 2px 6px rgba(11, 31, 58, 0.28);
  cursor: pointer; transition: transform 0.12s ease, border-color 0.12s ease;
}
@media (pointer: coarse) {
  .slider::-moz-range-thumb { width: 26px; height: 26px; }
}
.slider::-moz-range-thumb:hover { transform: scale(1.15); border-color: var(--accent-dark); }
.slider::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--accent); }
.slider::-moz-range-track { height: 4px; border-radius: 999px; background: var(--ink-100); }

.field-error {
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  display: none;
}
.field-error.visible { display: block; }

.global-error {
  display: none;
  margin: 4px 0 24px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-light);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}
.global-error.visible { display: block; }

/* ---------- Buttons ---------- */

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 12px 16px;
  min-height: 44px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.65; cursor: progress; transform: none; }

.btn-ghost { background: #f6f8f7; border-color: var(--border); color: var(--ink-700); }
.btn-ghost:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent-dark); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: 0 8px 20px rgba(22, 185, 154, 0.35); }
.btn:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 2px; }

/* ---------- Results panel ---------- */

.results-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px; margin-bottom: 8px;
}
.results-head .panel-title { margin: 0; }

/* Plain list rows — no boxes, no dividers, generous vertical rhythm */
.stats-list { margin: 8px 0 36px; }

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 4px;
}

.stat-row .stat-label { font-size: 14.5px; font-weight: 500; color: var(--ink-500); }
.stat-row .stat-value {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 800;
  color: var(--ink-900);
  text-align: right;
  /* Value text changes every frame during the counter animation; promoting
     it avoids repainting neighboring rows on each tick. */
  will-change: contents;
}

/* ---------- Tooltip popup ---------- */

.tooltip-popup {
  position: fixed;
  z-index: 999;
  max-width: min(240px, 80vw);
  background: var(--ink-900);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.45;
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.tooltip-popup.visible { opacity: 1; transform: translateY(0); }

/* ---------- Footer ---------- */

.site-footer { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); }
.site-footer p { font-size: 12px; color: var(--ink-300); margin: 0; }

/* ---------- Animations ---------- */

@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.pulse { animation: pulseAnim 0.4s ease; }
@keyframes pulseAnim { 0% { transform: scale(1); } 40% { transform: scale(1.015); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .calculator-grid { grid-template-columns: 1fr; }
  .inputs-panel { position: static; }
}

@media (max-width: 720px) {
  .site-header { padding: 22px 0; margin-bottom: 28px; }
  .action-buttons { flex-direction: column; }
  .btn { width: 100%; }
  .brand-mark { width: 80px; height: 80px; border-radius: 20px; }
}

@media (max-width: 360px) {
  .value-box { width: 100%; }
  .input-group-head { flex-direction: column; align-items: stretch; }
}

/* ---------- Print ---------- */

@media print {
  .site-header, .action-buttons, .inputs-panel, .tooltip-popup, .site-footer { display: none !important; }
  body { background: #fff; }
  .calculator-grid { grid-template-columns: 1fr; }
  .panel { box-shadow: none; border: 1px solid #ddd; }
}