/* =========================================================
   THEME VARIABLES
   Change these colors in one place to restyle the whole site.
   ========================================================= */
:root {
  --bg: #f6f7f9;             /* Soft light-neutral page background */
  --surface: #ffffff;        /* Crisp solid white cards */
  --surface-subtle: #f9fafb; /* Subtle inner box (results & mini cards) */
  --border: #e2e5ea;         /* Light hairline borders */
  --border-strong: #cbd2dc;  /* Hover / input border */
  --text: #111827;           /* High-contrast primary text */
  --text-muted: #4b5563;     /* Readable secondary labels & hints */
  --accent: #1d4ed8;         /* Clean primary blue */
  --accent-hover: #1e40af;
  --accent-soft: #eff6ff;    /* Soft tint for active tab/button */
  --success: #0f766e;        /* Teal accent for interest earned */
  --error: #b91c1c;          /* High-contrast error red */
  --error-bg: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
}

/* =========================================================
   BASE RESET & TYPOGRAPHY
   ========================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Ensures HTML "hidden" attribute always hides elements, even flex/grid ones */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
}

/* Clear keyboard focus ring for accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* =========================================================
   TOP NAVIGATION BAR
   ========================================================= */
.top-nav {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
}

.top-nav-inner {
  max-width: 1024px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-secondary {
  appearance: none;
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover {
  background-color: var(--surface-subtle);
  border-color: var(--text-muted);
}

/* =========================================================
   PAGE LAYOUT: SIDEBAR + MAIN CALCULATOR AREA
   ========================================================= */
.app-layout {
  width: 100%;
  max-width: 1024px;
  margin: 24px auto;
  padding: 0 20px;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr; /* Mobile-first: stacked */
  gap: 20px;
  align-items: start;
}

/* Desktop layout: 240px sidebar on the left, main card on the right */
@media (min-width: 768px) {
  .app-layout {
    grid-template-columns: 240px 1fr;
    gap: 24px;
    margin-top: 32px;
  }
}

/* =========================================================
   SIDEBAR / TAB SWITCHER
   ========================================================= */
.sidebar {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.sidebar-label {
  margin: 0 0 8px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  display: none;
}

/* Horizontal scrollable tabs on mobile */
.tab-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.tab-btn {
  appearance: none;
  background-color: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab-btn:hover {
  background-color: var(--surface-subtle);
  color: var(--text);
}

.tab-btn.is-active {
  background-color: var(--accent-soft);
  color: var(--accent);
  border-color: #bfdbfe;
}

/* Vertical sidebar tabs on desktop */
@media (min-width: 768px) {
  .sidebar {
    padding: 14px;
  }

  .sidebar-label {
    display: block;
  }

  .tab-list {
    flex-direction: column;
    overflow-x: visible;
    gap: 4px;
  }

  .tab-btn {
    width: 100%;
  }
}

/* =========================================================
   CALCULATOR CARDS & HEADERS
   ========================================================= */
.calc-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

@media (max-width: 520px) {
  .calc-card {
    padding: 18px;
  }
}

.card-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.25;
}

.card-header p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* =========================================================
   FORMS, INPUTS & BUTTONS
   ========================================================= */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 540px) {
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label,
.field-label-text {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.field input,
.field select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:hover,
.field select:hover {
  border-color: var(--text-muted);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.14);
}

/* Unit Converter From / Swap / To row */
.unit-pair {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: end;
}

@media (min-width: 560px) {
  .unit-pair {
    grid-template-columns: 1fr auto 1fr;
  }
}

.btn-swap {
  height: 44px;
  padding: 0 14px;
  appearance: none;
  background-color: var(--surface-subtle);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-swap:hover {
  background-color: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Area & Volume shape selector + unit dropdown */
.geometry-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
}

.geometry-controls > .field:first-child {
  flex: 1 1 280px;
}

.field-unit-select {
  width: 96px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

@media (max-width: 480px) {
  .segmented-control {
    grid-template-columns: 1fr;
  }
}

.shape-btn {
  appearance: none;
  background-color: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.shape-btn:hover {
  color: var(--text);
}

.shape-btn.is-active {
  background-color: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08);
}

/* =========================================================
   VALIDATION MESSAGE
   ========================================================= */
.error-msg {
  margin: 16px 0 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background-color: var(--error-bg);
  color: var(--error);
  border: 1px solid #fecaca;
  font-size: 0.9rem;
  font-weight: 500;
}

/* =========================================================
   RESULTS DISPLAY
   ========================================================= */
.result-box {
  margin-top: 20px;
  padding: 18px 20px;
  background-color: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.result-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.result-value {
  display: block;
  margin-top: 4px;
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.result-value-accent {
  color: var(--success);
}

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

/* Two-column metrics for Compound Interest */
.result-metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 520px) {
  .result-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.metric {
  min-width: 0;
}

/* Compound Interest visual breakdown bar */
.breakdown {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.breakdown-bar {
  display: flex;
  height: 10px;
  width: 100%;
  border-radius: 999px;
  overflow: hidden;
  background-color: var(--border);
}

.bar-principal {
  background-color: var(--accent);
  transition: width 0.2s ease;
}

.bar-interest {
  background-color: var(--success);
  transition: width 0.2s ease;
}

/* All-Units mini reference grid inside Unit Converter */
.sub-results {
  margin-top: 20px;
}

.sub-results-title {
  margin: 0 0 10px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.mini-card {
  padding: 10px 12px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.mini-card-unit {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.mini-card-value {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

/* =========================================================
   FOOTER
   ========================================================= */
.site-footer {
  max-width: 1024px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 20px 28px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.site-footer p {
  margin: 0;
}
