/* Reset and base styles */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  color: #0B1A2B;
  background: #F7FBFF;
  font-size: 16px;
}

/* Colors */
:root {
  --bg-primary: #F7FBFF;
  --bg-secondary: #ffffff;
  --bg-accent: #E6F0FF;
  --text-primary: #0B1A2B;
  --text-secondary: #4A5568;
  --text-muted: #718096;
  --primary: #2F80ED;
  --primary-hover: #2563EB;
  --primary-light: #EBF4FF;
  --border: #E2E8F0;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-lg: rgba(0, 0, 0, 0.15);
  --success: #48BB78;
  --error: #F56565;
  --warning: #ED8936;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1A202C;
    --bg-secondary: #2D3748;
    --bg-accent: #2A4A6B;
    --text-primary: #F7FAFC;
    --text-secondary: #E2E8F0;
    --text-muted: #A0AEC0;
    --primary: #63B3ED;
    --primary-hover: #4299E1;
    --primary-light: #2A4A6B;
    --border: #4A5568;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.4);
  }
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 1rem 0;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.25rem;
}

p {
  margin: 0 0 1rem 0;
  color: var(--text-secondary);
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Layout */
.site-header {
  padding: 1rem;
  text-align: center;
  background: var(--bg-secondary);
  box-shadow: 0 1px 3px var(--shadow);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text-primary);
}

.brand:hover {
  text-decoration: none;
}

.brand img {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.main-content {
  display: grid;
  gap: 2rem;
  margin: 2rem 0;
}

@media (min-width: 768px) {
  .main-content {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* Cards */
.calculator,
.results,
.how,
.faq,
.about,
.intro {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 4px var(--shadow);
  border: 1px solid var(--border);
}

.steps {
  margin-top: 1.5rem;
}

.steps ol {
  padding-left: 1.2rem;
}

.steps li {
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

/* Forms */
.form-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
}

label {
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-size: 0.9rem;
}

input,
select {
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input:invalid {
  border-color: var(--error);
}

.error-message {
  color: var(--error);
  font-size: 0.8rem;
  margin-top: 0.25rem;
  min-height: 1rem;
}

/* Fieldsets and radio groups */
fieldset {
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  margin: 0;
}

legend {
  font-weight: 500;
  color: var(--text-primary);
  padding: 0 0.5rem;
  font-size: 0.9rem;
}

.radio-group {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0;
  cursor: pointer;
}

.radio-group input[type="radio"] {
  margin: 0;
  width: auto;
}

/* Checkboxes */
.options {
  margin-bottom: 1.5rem;
}

.checkbox-group {
  margin-bottom: 0.75rem;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  margin: 0;
  width: auto;
}

/* Buttons */
.btn-primary,
.btn-secondary {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow);
}

.btn-secondary {
  background: var(--bg-accent);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow);
}

.btn-primary:active,
.btn-secondary:active {
  transform: translateY(0);
}

.result-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

/* Results */
.results-grid {
  display: grid;
  gap: 1rem;
  margin: 1rem 0;
}

.result-item {
  padding: 1rem;
  background: var(--bg-accent);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.result-label {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.result-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.result-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.result-raw {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}

.placeholder {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  margin: 2rem 0;
}

/* How We Calculate */
.how details {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.how summary {
  padding: 1rem;
  background: var(--bg-accent);
  cursor: pointer;
  font-weight: 500;
  color: var(--text-primary);
}

.how summary:hover {
  background: var(--border);
}

.how details[open] summary {
  border-bottom: 1px solid var(--border);
}

.how details div {
  padding: 1rem;
}

.how details p {
  margin-bottom: 0.5rem;
}

.how details p:last-child {
  margin-bottom: 0;
}

/* FAQ */
.faq-item {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.faq-question {
  width: 100%;
  padding: 1rem;
  background: var(--bg-accent);
  border: none;
  text-align: left;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-primary);
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-question:hover {
  background: var(--border);
}

.faq-question::after {
  content: "+";
  font-size: 1.2rem;
  font-weight: bold;
  transition: transform 0.2s;
}

.faq-question[aria-expanded="true"]::after {
  content: "−";
}

.faq-answer {
  display: none;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.faq-answer.show {
  display: block;
}

.faq-answer p {
  margin: 0;
}

/* Footer */
.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 2rem 1rem;
  text-align: center;
  margin-top: 3rem;
}

.site-footer nav {
  margin-bottom: 1rem;
}

.site-footer nav a {
  margin: 0 0.25rem;
}

.site-footer small {
  color: var(--text-muted);
  font-size: 0.8rem;
}

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

/* Skip to main content */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--primary);
  color: white;
  padding: 8px;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 500;
  z-index: 1000;
}

.skip-link:focus {
  top: 6px;
}

/* Focus styles */
button:focus,
input:focus,
select:focus,
.faq-question:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Print styles */
@media print {
  .site-header,
  .site-footer,
  .result-actions,
  .calculator {
    display: none;
  }
  
  .results {
    box-shadow: none;
    border: 1px solid #000;
  }
  
  body {
    background: white;
    color: black;
  }
}

/* Mobile optimizations */
@media (max-width: 640px) {
  main {
    padding: 0.5rem;
  }
  
  .calculator,
  .results,
  .how,
  .faq,
  .about,
  .intro {
    padding: 1rem;
    margin-bottom: 1rem;
  }
  
  h1 {
    font-size: 1.5rem;
  }
  
  .radio-group {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .result-actions {
    flex-direction: column;
  }
  
  .btn-primary,
  .btn-secondary {
    width: 100%;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --border: #000000;
    --shadow: rgba(0, 0, 0, 0.5);
  }
  
  button,
  input,
  select {
    border-width: 3px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}