/* ===================================================================
   QME Combined Calculator — app.css
   Single consolidated stylesheet. "Clinical Precision" aesthetic.
   =================================================================== */

/* ===== 1. CSS CUSTOM PROPERTIES ===== */

:root {
  /* Colors — Light Theme (Editorial: warm paper + oxblood) */
  --color-bg-page: #F4EFE6;
  --color-bg-surface: #FBF8F1;
  --color-bg-elevated: #FFFFFF;
  --color-bg-inset: #EDE6D8;
  --color-text-primary: #23201A;
  --color-text-secondary: #5C564B;
  --color-text-muted: #6F6857; /* warm muted, AA-compliant on paper */
  --color-border: #DAD2C2;
  --color-border-focus: #7A2E2E;
  --color-accent: #7A2E2E;
  --color-accent-hover: #632323;
  --color-accent-subtle: rgba(122, 46, 46, 0.07);
  --color-accent-glow: rgba(122, 46, 46, 0.16);
  --color-success: #3F6B47;
  --color-success-subtle: rgba(63, 107, 71, 0.09);
  --color-error: #B0322B;
  --color-error-subtle: rgba(176, 50, 43, 0.08);
  --color-warning: #9A7B3F;
  --color-warning-subtle: rgba(154, 123, 63, 0.10);
  --color-result-bg: #F0E2DC;
  --color-result-accent: #7A2E2E;
  --color-overlay: rgba(35, 32, 26, 0.55);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(60, 48, 33, 0.05);
  --shadow-sm: 0 1px 3px rgba(60, 48, 33, 0.07), 0 1px 2px rgba(60, 48, 33, 0.05);
  --shadow-md: 0 4px 14px rgba(60, 48, 33, 0.09);
  --shadow-lg: 0 10px 28px rgba(60, 48, 33, 0.13);
  --shadow-xl: 0 18px 50px rgba(60, 48, 33, 0.17);

  /* Radii */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Typography */
  --font-heading: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', 'Consolas', monospace;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
  --transition-slow: 0.4s ease;
}

/* ===== DARK THEME ===== */

.dark-theme {
  --color-bg-page: #1B1813;
  --color-bg-surface: #232019;
  --color-bg-elevated: #2B271F;
  --color-bg-inset: #16130E;
  --color-text-primary: #EDE6D6;
  --color-text-secondary: #B3AA96;
  --color-text-muted: #958C76; /* warm muted, AA-compliant on dark paper */
  --color-border: #3A352B;
  --color-border-focus: #CB7B5E;
  --color-accent: #CB7B5E;
  --color-accent-hover: #DD9476;
  --color-accent-subtle: rgba(203, 123, 94, 0.10);
  --color-accent-glow: rgba(203, 123, 94, 0.22);
  --color-success: #7FB07F;
  --color-success-subtle: rgba(127, 176, 127, 0.10);
  --color-error: #E08B7E;
  --color-error-subtle: rgba(224, 139, 126, 0.10);
  --color-warning: #D4A857;
  --color-warning-subtle: rgba(212, 168, 87, 0.10);
  --color-result-bg: #2A2018;
  --color-result-accent: #DD9476;
  --color-overlay: rgba(0, 0, 0, 0.65);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 28px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 18px 50px rgba(0, 0, 0, 0.6);
}

/* Editorial dark: the accent (terracotta) and success (sage) are light, warm
   colors, so text on them must be dark ink — white would fail WCAG contrast
   (white on #CB7B5E is only 3.2:1; dark ink is 5.2:1). */
.dark-theme .auth-button,
.dark-theme .btn.primary,
.dark-theme .calculate-button,
.dark-theme .auth-btn-primary,
.dark-theme .success-feedback {
  color: #2A1A10;
}


/* ===== 2. CSS RESET & BASE ===== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-text-primary);
  background-color: var(--color-bg-page);
  transition: background-color var(--transition-base), color var(--transition-base);
  min-height: 100vh;
  position: relative;
}

/* ===== Atmospheric depth =====
   Soft radial illumination so the tool feels lit, not flat — like the focused
   light on a precision instrument. Plus fine film grain for tactile richness.
   Both sit behind all content (negative z-index), are theme-aware via the
   accent-glow tokens, and are GPU-cheap (no blur, no animation). */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(72% 55% at 50% -10%, var(--color-accent-glow), transparent 66%),
    radial-gradient(48% 45% at 90% 6%, var(--color-accent-subtle), transparent 58%);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.02;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
}

/* ===== Orchestrated page-load reveal =====
   One choreographed entrance: structural sections settle in top-to-bottom,
   like an instrument powering on. `backwards` fill keeps each section hidden
   only during its own delay; if animations are unsupported the elements simply
   render normally, and the reduced-motion guard neutralizes it entirely. */
@keyframes reveal-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.app-header,
.calculator-main,
.trust-bar,
.faq-section,
.app-footer {
  animation: reveal-up 0.62s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
.app-header      { animation-delay: 0.05s; }
.calculator-main { animation-delay: 0.15s; }
.trust-bar       { animation-delay: 0.26s; }
.faq-section     { animation-delay: 0.34s; }
.app-footer      { animation-delay: 0.42s; }

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--color-accent-hover); }

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  background: none;
  font-size: inherit;
  color: inherit;
}

input, select, textarea {
  font-family: var(--font-body);
  font-size: 16px; /* Prevents iOS zoom */
  color: var(--color-text-primary);
}

ul { list-style: none; }

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


/* ===== 3. TYPOGRAPHY ===== */

h1 {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--color-text-primary);
}

h2 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 400;
  line-height: 1.3;
  color: var(--color-text-primary);
}

h3 {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-text-primary);
}

.section-label {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}


/* ===== 4. LAYOUT ===== */

.app-shell {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-lg) var(--space-2xl);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.calculator-main {
  flex: 1;
}


/* ===== 5. HEADER ===== */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0 var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-lg);
  gap: var(--space-md);
}

.header-brand h1 {
  font-size: 1.5rem;
  margin-bottom: 2px;
}

.header-tagline {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.account-chip {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 13px;
}

.account-chip .user-email {
  color: var(--color-text-secondary);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-button,
.logout-button {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.auth-button {
  background: var(--color-accent);
  color: #fff;
}
.auth-button:hover {
  background: var(--color-accent-hover);
}

.logout-button {
  color: var(--color-text-muted);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
}
.logout-button:hover {
  color: var(--color-error);
  border-color: var(--color-error);
  background: var(--color-error-subtle);
}

.icon-button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
  font-size: 16px;
}
.icon-button:hover {
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}


/* ===== 6. SUBSCRIPTION BANNER ===== */

#subscriptionBanner {
  margin-bottom: var(--space-lg);
}

.subscription-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 10px var(--space-md);
  border-radius: var(--radius-md);
  font-size: 14px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  transition: all var(--transition-base);
}

/* Mobile toggle */
.subscription-toggle {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--space-md);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}
.subscription-toggle:hover {
  border-color: var(--color-accent);
}
.subscription-toggle i {
  font-size: 12px;
  transition: transform var(--transition-base);
}

.subscription-details {
  /* Default visible on desktop */
}

/* Free plan banner */
.plan-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 10px var(--space-md);
  border-radius: var(--radius-md);
  font-size: 14px;
  flex-wrap: wrap;
}

.plan-banner.free-plan {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
}

.plan-banner.free-plan-depleted {
  background: var(--color-warning-subtle);
  border: 1px solid var(--color-warning);
}

.plan-banner.paid-plan {
  background: var(--color-success-subtle);
  border: 1px solid var(--color-success);
}

.plan-banner h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.plan-banner p {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin: 2px 0 0 0;
}

.plan-info {
  flex: 1;
  min-width: 0;
}

.plan-action {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.plan-action p {
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.coffee-comparison {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.email-reminder {
  font-size: 11px;
  color: var(--color-text-muted);
}

.upgrade-prompt {
  font-size: 13px;
}

/* Subscription buttons */
.btn.primary,
.subscribe-button,
#subscribeButton {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: var(--color-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.btn.primary:hover,
.subscribe-button:hover,
#subscribeButton:hover {
  background: var(--color-accent-hover);
}

.btn.secondary,
.btn.grey {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: var(--color-bg-surface);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.btn.secondary:hover,
.btn.grey:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}


/* ===== 7. CALCULATOR FORM ===== */

#calculatorContainer {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-md);
}

.input-section {
  margin-bottom: var(--space-lg);
}

.input-fields,
.input-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md) var(--space-lg);
}

.additional-fields {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height var(--transition-slow), opacity var(--transition-base), margin var(--transition-base);
  margin-top: 0;
}

.additional-fields.expanded {
  max-height: 600px;
  opacity: 1;
  margin-top: var(--space-md);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.input-group label .optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  font-size: 11px;
  opacity: 0.7;
}

.input-group input[type="number"] {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 500;
  padding: 12px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  text-align: center;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -moz-appearance: textfield;
  width: 100%;
}

.input-group input[type="number"]::-webkit-outer-spin-button,
.input-group input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-group input[type="number"]::placeholder {
  color: var(--color-text-muted);
  font-weight: 400;
  font-size: 14px;
  opacity: 0.6;
}

.input-group input[type="number"]:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
  outline: none;
}

.input-group input[type="number"].valid {
  border-color: var(--color-success);
}

.input-group input[type="number"].invalid {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px var(--color-error-subtle);
}

/* Expand button */
.expand-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  padding: 12px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin: var(--space-md) 0 0;
}

.expand-button:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.expand-button i {
  font-size: 12px;
  transition: transform var(--transition-base);
}

.expand-button.expanded i {
  transform: rotate(180deg);
}


/* ===== 8. BUTTONS ===== */

.button-section {
  display: flex;
  gap: var(--space-md);
  margin: var(--space-lg) 0;
}

.calculate-button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 14px var(--space-lg);
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-md);
  /* Tactile primary action: subtle top sheen + ambient glow + inset highlight
     so the button reads as lit and physical. White overlays keep it correct in
     both themes (accent-hover is lighter in dark, darker in light). */
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 52%),
    var(--color-accent);
  color: #fff;
  transition: all var(--transition-fast);
  min-height: 48px;
  box-shadow: var(--shadow-sm), 0 6px 20px var(--color-accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.calculate-button:hover:not(:disabled) {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 52%),
    var(--color-accent-hover);
  box-shadow: var(--shadow-md), 0 9px 28px var(--color-accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.26);
  transform: translateY(-1px);
}

.calculate-button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: var(--shadow-xs);
}

.calculate-button:disabled,
.calculate-button.disabled-button {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--color-text-muted);
  box-shadow: none;
}

.reset-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 14px var(--space-lg);
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-md);
  background: var(--color-bg-elevated);
  color: var(--color-text-secondary);
  border: 1.5px solid var(--color-border);
  transition: all var(--transition-fast);
  min-height: 48px;
}

.reset-button:hover {
  border-color: var(--color-error);
  color: var(--color-error);
  background: var(--color-error-subtle);
}


/* ===== 9. RESULTS ===== */

.results-section {
  background: var(--color-result-bg);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-top: var(--space-lg);
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.results-header h2 {
  font-size: 1.1rem;
}

.results-actions {
  display: flex;
  gap: var(--space-sm);
}

.results-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  transition: all var(--transition-fast);
}

.results-actions button:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.results-actions button.copied {
  color: var(--color-success);
  border-color: var(--color-success);
  background: var(--color-success-subtle);
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-md);
}

.result-group,
.result-card {
  background: var(--color-bg-surface);
  border-radius: var(--radius-md);
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

/* Hero result: the Combined Value is the answer; UE/LE are derived. Give it an
   accent-tinted face and a soft glow on the number so it reads as the protagonist
   (no size change — that would re-introduce the mobile row overflow). */
.result-group:first-child,
.result-card:first-child {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-md);
  background: linear-gradient(180deg, var(--color-accent-subtle), var(--color-bg-surface) 58%);
}

.result-group:first-child input[readonly],
.result-card:first-child input[readonly] {
  text-shadow: 0 0 22px var(--color-accent-glow);
}

.result-group label,
.result-card label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

.result-group input[readonly],
.result-card input[readonly] {
  font-family: var(--font-heading);
  font-size: 3rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--color-result-accent);
  border: none;
  background: transparent;
  text-align: center;
  width: 100%;
  padding: 0;
  outline: none;
}

.result-unit {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

/* Result animation */
.result-group,
.result-card {
  opacity: 0;
  transform: translateY(12px);
}

.result-group.show-result,
.result-card.show-result,
.result-card.revealed {
  animation: resultReveal 0.4s ease-out forwards;
}
.result-group:nth-child(1).show-result,
.result-card:nth-child(1).show-result,
.result-card:nth-child(1).revealed { animation-delay: 0s; }
.result-group:nth-child(2).show-result,
.result-card:nth-child(2).show-result,
.result-card:nth-child(2).revealed { animation-delay: 0.1s; }
.result-group:nth-child(3).show-result,
.result-card:nth-child(3).show-result,
.result-card:nth-child(3).revealed { animation-delay: 0.2s; }

/* Timestamp */
.timestamp,
#calculationTimestamp {
  text-align: center;
  margin-top: var(--space-md);
  font-size: 12px;
  color: var(--color-text-muted);
}

/* Mobile close button for results */
.mobile-close-btn {
  display: none;
}


/* ===== 10. AUTH MODAL ===== */

.auth-overlay,
#directLoginOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.auth-overlay.active,
#directLoginOverlay.active {
  display: flex;
}

.auth-card {
  background: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--color-border);
  position: relative;
}

.auth-card h2 {
  font-family: var(--font-heading);
  margin-bottom: var(--space-lg);
}

.auth-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.auth-close:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
}

.auth-form-group {
  margin-bottom: var(--space-md);
}

.auth-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.auth-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  font-size: 15px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.auth-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
  outline: none;
}

.auth-error {
  color: var(--color-error);
  font-size: 13px;
  margin-bottom: var(--space-sm);
  min-height: 20px;
}

.auth-success {
  color: var(--color-success);
  font-size: 13px;
  margin-bottom: var(--space-sm);
}

.auth-btn-row {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.auth-btn-primary {
  flex: 1;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: var(--color-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.auth-btn-primary:hover {
  background: var(--color-accent-hover);
}

.auth-btn-secondary {
  flex: 1;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: var(--color-bg-elevated);
  color: var(--color-text-secondary);
  border: 1.5px solid var(--color-border);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.auth-btn-secondary:hover {
  border-color: var(--color-text-muted);
}

.auth-footer {
  margin-top: var(--space-md);
  font-size: 13px;
  color: var(--color-text-muted);
}

.auth-footer a {
  color: var(--color-accent);
  font-weight: 500;
}

.auth-forgot {
  text-align: right;
  margin-bottom: var(--space-md);
}

.auth-forgot a {
  font-size: 13px;
  color: var(--color-text-muted);
}
.auth-forgot a:hover {
  color: var(--color-accent);
}

/* Legacy modal support (loginModal) */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  backdrop-filter: blur(6px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--color-border);
}

.modal .close-button {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  font-size: 24px;
  color: var(--color-text-muted);
  cursor: pointer;
}

.tab-container {
  display: flex;
  gap: 2px;
  margin-bottom: var(--space-lg);
  border-bottom: 2px solid var(--color-border);
}

.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition-fast);
}

.tab.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  transition: border-color var(--transition-fast);
}

.form-group input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
  outline: none;
}

.error-message {
  color: var(--color-error);
  font-size: 12px;
  min-height: 18px;
  margin-top: 4px;
}

.success-message {
  color: var(--color-success);
  font-size: 12px;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  width: 100%;
}


/* ===== 11. FAQ ===== */

.faq-section {
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

.faq-section > h2 {
  margin-bottom: var(--space-lg);
}

.faq-item {
  border-bottom: 1px solid var(--color-border);
}

.faq-item:first-child {
  border-top: 1px solid var(--color-border);
}

.faq-question {
  width: 100%;
  background: none;
  border: none;
  padding: var(--space-md) 0;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text-primary);
  transition: color var(--transition-fast);
}

.faq-question:hover {
  color: var(--color-accent);
}

.faq-question i {
  font-size: 14px;
  color: var(--color-text-muted);
  transition: transform var(--transition-base), color var(--transition-fast);
  flex-shrink: 0;
}

.faq-question.expanded i,
.faq-question.active i {
  transform: rotate(45deg);
  color: var(--color-accent);
}

.faq-answer {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--transition-slow);
}

.faq-answer.expanded {
  grid-template-rows: 1fr;
}

.faq-answer-content,
.faq-answer > div {
  overflow: hidden;
}

.faq-answer-content p,
.faq-answer > div > p,
.faq-answer p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--color-text-secondary);
  padding-bottom: var(--space-md);
}


/* ===== 12. TRUST BAR ===== */

.trust-bar,
.security-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-lg);
  padding: var(--space-lg) 0;
  margin-top: var(--space-lg);
}

.trust-badge,
.badge-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.trust-badge i,
.badge-item i {
  color: var(--color-success);
  font-size: 14px;
}


/* ===== 13. FOOTER ===== */

.app-footer,
footer {
  text-align: center;
  padding: var(--space-lg) 0;
  border-top: 1px solid var(--color-border);
  margin-top: auto;
  font-size: 13px;
  color: var(--color-text-muted);
}

.app-footer a,
footer a {
  color: var(--color-accent);
}


/* ===== 14. TOAST / FEEDBACK ===== */

.toast {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px 20px;
  background: var(--color-bg-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  animation: toastSlideIn 0.3s ease-out;
}

.toast.hiding {
  animation: toastSlideOut 0.3s ease-in forwards;
}

.toast-icon {
  font-size: 16px;
}

.success-feedback {
  position: fixed;
  bottom: var(--space-lg);
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: var(--color-success);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  z-index: 2000;
  animation: toastSlideIn 0.3s ease-out;
}

/* Loading animation */
.loading-animation,
#loadingAnimation {
  display: none;
  text-align: center;
  font-size: 2rem;
  padding: var(--space-md);
}

/* Loading spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--color-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  z-index: 10;
}


/* ===== 15. ANIMATIONS ===== */

@keyframes resultReveal {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastSlideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}


/* ===== 16. RESPONSIVE: TABLET (768px) ===== */

@media (max-width: 768px) {
  .app-shell {
    padding: var(--space-md) var(--space-md) var(--space-xl);
  }

  .app-header {
    flex-direction: row;
    align-items: center;
    gap: var(--space-sm);
  }

  .header-brand {
    flex: 1;
    min-width: 0;
  }

  .header-actions {
    flex-shrink: 0;
    justify-content: flex-end;
  }

  .subscription-toggle {
    display: flex;
  }

  .subscription-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-slow);
  }

  .subscription-details.expanded {
    max-height: 300px;
    margin-top: var(--space-sm);
  }

  .plan-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .plan-action {
    width: 100%;
  }

  .plan-action p {
    flex-wrap: wrap;
  }

  #calculatorContainer {
    padding: var(--space-lg);
  }

  .input-fields,
  .input-grid {
    grid-template-columns: 1fr 1fr;
  }

  .results-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--space-sm);
  }

  .result-group input[readonly],
  .result-card input[readonly] {
    font-size: 1.75rem;
  }
}


/* ===== 17. RESPONSIVE: MOBILE (480px) ===== */

@media (max-width: 480px) {
  h1 { font-size: 1.25rem; }

  .app-shell {
    padding: var(--space-sm) var(--space-sm) var(--space-lg);
  }

  #calculatorContainer {
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }

  .input-fields,
  .input-grid {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
  }

  .input-group input[type="number"] {
    font-size: 16px;
    padding: 14px 16px;
    min-height: 48px;
  }

  .button-section {
    flex-direction: row;
    gap: var(--space-sm);
  }

  .calculate-button,
  .reset-button {
    font-size: 15px;
    padding: 12px var(--space-md);
    min-height: 48px;
  }

  .results-grid {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
  }

  .result-group,
  .result-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    text-align: left;
  }

  .result-group label,
  .result-card label {
    margin-bottom: 0;
    white-space: nowrap;
  }

  .result-group input[readonly],
  .result-card input[readonly] {
    font-size: 1.5rem;
    /* Constrain to the value width (results are <= 3 digits). A text input's
       default intrinsic width (~20ch) plus flex-shrink:0 was forcing the row
       451px wide in a 390px viewport, causing horizontal page scroll. */
    width: 4.5rem;
    text-align: right;
    flex-shrink: 0;
  }

  .result-group label,
  .result-card label {
    flex: 1;
    min-width: 0;
  }

  .results-section {
    padding: var(--space-md);
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .faq-question {
    font-size: 14px;
    padding: 14px 0;
  }

  .trust-bar,
  .security-badges {
    gap: var(--space-md);
  }

  .trust-badge,
  .badge-item {
    font-size: 11px;
  }

  .auth-card {
    padding: var(--space-lg);
    max-width: 100%;
    border-radius: var(--radius-md);
  }

  /* Toast on mobile */
  .toast {
    left: var(--space-md);
    right: var(--space-md);
    bottom: var(--space-md);
  }
}


/* ===== 18. RESPONSIVE: SMALL MOBILE (360px) ===== */

@media (max-width: 360px) {
  h1 { font-size: 1.1rem; }

  .header-tagline { font-size: 11px; }

  .account-chip .user-email { max-width: 120px; }

  .calculate-button,
  .reset-button {
    font-size: 14px;
    padding: 10px var(--space-sm);
  }
}


/* ===== 19. PRINT ===== */

@media print {
  .app-header,
  .subscription-strip,
  #subscriptionBanner,
  .subscription-toggle,
  .faq-section,
  .trust-bar,
  .security-badges,
  .app-footer,
  footer,
  .button-section,
  .expand-button,
  .results-actions,
  .toast,
  #directLoginOverlay,
  .auth-overlay,
  .modal {
    display: none;
  }

  body {
    background: #fff;
    color: #000;
  }

  #calculatorContainer {
    box-shadow: none;
    border: none;
    padding: 0;
  }

  .result-group input[readonly],
  .result-card input[readonly] {
    color: #000;
  }
}


/* ===== 20. UTILITY CLASSES ===== */

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

/* Ensure initial result visibility before animation triggers */
.results-section .result-group,
.results-section .result-card {
  opacity: 1;
  transform: none;
}


/* ===== 21. ACCESSIBILITY ===== */

/* Visible keyboard focus for interactive controls that previously had none
   (buttons, links, toggles). :focus-visible keeps the ring keyboard-only so it
   doesn't appear on mouse clicks. Inputs keep their existing accent focus ring. */
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
.subscribe-button:focus-visible,
.faq-question:focus-visible,
.theme-toggle:focus-visible,
.copy-button:focus-visible,
.print-button:focus-visible,
.expand-button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Respect users who prefer reduced motion. The UI has ~39 transitions and
   several keyframe animations; neutralize them for motion-sensitive users
   (vestibular disorders) while keeping the interface fully functional. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* ===== 22. EDITORIAL DETAILS ===== */

/* Masthead: a mono kicker over the wordmark and a heavier ink rule under the
   header, the way a journal nameplate sits over a rule. */
.header-kicker {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin-bottom: 5px;
}
.app-header {
  border-bottom-width: 1.5px;
  border-bottom-color: var(--color-text-primary);
}

/* FAQ as a numbered editorial index — 01, 02, 03 … in mono before each entry. */
.faq-section { counter-reset: faq; }
.faq-question { counter-increment: faq; }
.faq-question span::before {
  content: counter(faq, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--color-accent);
  margin-right: 14px;
}

/* The "Calculated on …" line reads as an editorial caption. */
.calculation-timestamp {
  font-style: italic;
}


/* ===== 23. ICON SET (self-hosted, replaces Font Awesome ~240KB) =====
   Reuses the existing .fas/.far/.fa-* class names so no HTML/JS changes are
   needed. Each icon is an inline-SVG CSS mask filled with currentColor, so it
   inherits text color and size like a font icon. Refined line style to suit
   the editorial aesthetic. */
.fas, .far, .fa-solid, .fa-regular {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  background-color: currentColor;
  -webkit-mask: var(--fa) center / contain no-repeat;
  mask: var(--fa) center / contain no-repeat;
}
.fa-plus        { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
.fa-minus       { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E"); }
.fa-chevron-down{ --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); }
.fa-chevron-up  { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 15l6-6 6 6'/%3E%3C/svg%3E"); }
.fa-check-circle{ --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M8.5 12.5l2.5 2.5 4.5-5'/%3E%3C/svg%3E"); }
.fa-calculator  { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='3' width='14' height='18' rx='2'/%3E%3Cline x1='8' y1='7' x2='16' y2='7'/%3E%3Cline x1='8' y1='12' x2='16' y2='12'/%3E%3Cline x1='8' y1='16' x2='12' y2='16'/%3E%3C/svg%3E"); }
.fa-sign-out-alt{ --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpath d='M16 17l5-5-5-5'/%3E%3Cpath d='M21 12H9'/%3E%3C/svg%3E"); }
.fa-undo        { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12a8 8 0 1 1 2.5 5.8'/%3E%3Cpolyline points='4 7 4 12 9 12'/%3E%3C/svg%3E"); }
.fa-spinner     { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M12 3a9 9 0 1 0 9 9'/%3E%3C/svg%3E"); }
.fa-shield-alt  { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3l7 3v5c0 4.5-3 7.6-7 9-4-1.4-7-4.5-7-9V6z'/%3E%3Cpath d='M9.3 12l1.9 1.9 3.6-3.9'/%3E%3C/svg%3E"); }
.fa-print       { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9V3h12v6'/%3E%3Cpath d='M6 18H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-2'/%3E%3Crect x='6' y='14' width='12' height='7'/%3E%3C/svg%3E"); }
.fa-copy        { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='11' height='11' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E"); }
.fa-clock       { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E"); }
.fa-moon        { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z'/%3E%3C/svg%3E"); }
.fa-sun         { --fa: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v2M12 20v2M2 12h2M20 12h2M5 5l1.5 1.5M17.5 17.5L19 19M19 5l-1.5 1.5M6.5 17.5L5 19'/%3E%3C/svg%3E"); }

@keyframes fa-spin { to { transform: rotate(360deg); } }
.fa-spin { animation: fa-spin 1s linear infinite; }
