/* DadCalc — styles */
:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --ink: #1c2532;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #1976d2;
  --accent-dark: #0f5aa3;
  --good: #2e7d32;
  --bad: #c62828;
  --warn-bg: #fffae6;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0 0 .25em; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: .25em 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* Header */
.site-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand .tagline { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.header-controls { display: flex; gap: 12px; align-items: center; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: .9rem; cursor: pointer; }
button {
  background: var(--accent); color: #fff; border: 0; padding: 8px 14px;
  border-radius: 6px; font-size: .9rem; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--accent-dark); }

/* Shared inputs */
.shared-inputs {
  margin: 18px 24px; padding: 16px 20px; background: var(--card);
  border-radius: 10px; box-shadow: var(--shadow);
}
.shared-inputs .grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
label {
  display: flex; flex-direction: column; gap: 4px; font-size: .82rem;
  color: var(--muted); font-weight: 500;
}
input[type=number], input[type=text], select {
  font-size: .95rem; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Comparison columns */
.compare {
  display: grid; gap: 14px; margin: 0 24px 18px;
  grid-template-columns: repeat(3, 1fr);
}
.col {
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.col header { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.inputs { display: grid; gap: 10px; }
.dp { display: flex; gap: 6px; }
.dp input { flex: 1; }
.dp select { width: 56px; }
.va-only label { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }

.outputs { border-top: 1px solid var(--line); padding-top: 10px; }
.row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4px 0; font-size: .9rem;
}
.row + .row { border-top: 1px dashed var(--line); }
.row span:first-child { color: var(--muted); }
.row span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.row.total {
  background: var(--warn-bg); margin: 8px -8px 0; padding: 8px;
  border-radius: 6px; font-size: 1rem;
}
.row.total span:first-child, .row.total span:last-child { color: var(--ink); font-weight: 700; }
.mi-note { margin-top: 6px; }
.delta { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: .85rem; }
.delta .better { color: var(--good); font-weight: 600; }
.delta .worse  { color: var(--bad);  font-weight: 600; }
.delta .same   { color: var(--muted); }

/* Amortization */
details.amort-box { border-top: 1px solid var(--line); padding-top: 8px; }
details.amort-box summary { cursor: pointer; font-size: .85rem; color: var(--accent); font-weight: 600; }
.amort-chart { display: block; margin: 8px 0; width: 100%; height: auto; }
.amort-table { width: 100%; border-collapse: collapse; font-size: .78rem; margin-top: 6px; }
.amort-table th, .amort-table td { padding: 3px 5px; text-align: right; border-bottom: 1px solid var(--line); }
.amort-table th:first-child, .amort-table td:first-child { text-align: left; }

/* Tooltip terms */
.term {
  position: relative; border-bottom: 1px dotted var(--accent);
  cursor: help; color: var(--accent);
}
.term .tooltip {
  position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%);
  background: #1c2532; color: #fff; font-size: .78rem; font-weight: normal;
  padding: 8px 10px; border-radius: 6px; width: 220px; z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .15s;
  box-shadow: 0 4px 12px rgba(0,0,0,.2); line-height: 1.35;
}
.term:hover .tooltip, .term:focus .tooltip, .term:focus-within .tooltip {
  opacity: 1;
}

/* Rent vs Buy */
.rvb { margin: 0 24px 18px; padding: 16px 20px; background: var(--card); border-radius: 10px; box-shadow: var(--shadow); }
.rvb-inputs { margin-top: 10px; }
.rvb-answer {
  margin: 14px 0; padding: 12px 14px; background: var(--warn-bg);
  border-radius: 6px; font-size: 1rem;
}
#rvbChart svg { width: 100%; height: auto; max-width: 600px; }
.rvb-summary { margin-top: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.rvb-summary > div { display: flex; flex-direction: column; gap: 2px; padding: 8px; background: #f1f4f8; border-radius: 6px; }
.rvb-summary .lbl { font-size: .75rem; color: var(--muted); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* Simple rent vs. buy comparison */
.simp-compare { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.simp-compare h3 { font-size: 1rem; margin-bottom: 10px; }
.simp-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.simp-card { padding: 14px; border-radius: 8px; background: #f1f4f8; }
.simp-card .lbl { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.simp-card .val { font-size: 1.5rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.simp-card .sub { font-size: .78rem; color: var(--muted); margin-top: 6px; }
.simp-card.rent { background: #fdecea; }
.simp-card.rent .val { color: var(--bad); }
.simp-card.buy { background: #e8f5e9; }
.simp-card.buy .val { color: var(--good); }
.simp-card.adv { background: #1c2532; color: #fff; }
.simp-card.adv .lbl, .simp-card.adv .sub { color: #9aa4b2; }
.simp-card.adv .val { color: #81c784; }

/* Sticky mobile PITIA bar */
.sticky-bar {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--ink); color: #fff;
  padding: 8px 12px; font-size: .82rem;
  justify-content: space-around; gap: 8px;
  box-shadow: 0 -2px 8px rgba(0,0,0,.2); z-index: 100;
}
.sticky-bar .lbl { color: #9aa4b2; margin-right: 4px; }

/* Footer */
.site-footer { padding: 16px 24px 32px; color: var(--muted); font-size: .78rem; text-align: center; }

/* Responsive */
@media (max-width: 900px) {
  .compare { grid-template-columns: 1fr; }
  .sticky-bar { display: flex; }
  body { padding-bottom: 50px; }
  .site-header { flex-direction: column; gap: 10px; align-items: flex-start; }
}

/* Print-only title (hidden on screen) */
.print-title { display: none; }

/* Buyer name field in header */
.buyer-field, .lang-field { font-size: .82rem; color: var(--muted); }
.buyer-field input, .lang-field select { font-size: .9rem; }

/* Print */
@page { size: letter; margin: 0.5in; }
@media print {
  /* Force background colors to print */
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide chrome */
  .site-header,
  .sticky-bar,
  .shared-inputs,
  .site-footer,
  details.amort-box,
  #downloadPdfBtn,
  .header-controls,
  .term .tooltip { display: none !important; }

  /* Show print title */
  .print-title { display: block; text-align: center; margin: 0 0 14px; }
  .print-title h1 { font-size: 18pt; margin: 0; color: #1c2532; }
  .print-title p { font-size: 12pt; margin: 4px 0 0; color: var(--muted); }

  body { background: #fff; padding: 0; margin: 0; }

  /* Hide native selects (replaced with spans by JS) and show the spans */
  select { display: none !important; }
  .print-select {
    display: inline-block;
    font-weight: 600;
    color: var(--ink);
    padding: 2px 0;
  }

  /* Compress inputs so they read like values, not form fields */
  input[type=number], input[type=text] {
    border: none !important;
    padding: 2px 0 !important;
    font-weight: 600;
    background: transparent;
    color: var(--ink);
  }

  /* Comparison columns: keep three across, tighter */
  .compare {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px;
    margin: 0;
    page-break-inside: avoid;
  }
  .col {
    box-shadow: none !important;
    border: 1px solid #ccc;
    padding: 10px;
    page-break-inside: avoid;
  }
  .col header h3 { font-size: 11pt; }
  .row { font-size: 9pt; padding: 2px 0; }
  .row.total { font-size: 10pt; }

  /* Rent vs. buy section */
  .rvb { box-shadow: none !important; border: 1px solid #ccc; margin: 14px 0 0; padding: 12px; page-break-inside: avoid; }
  .rvb-inputs { display: none; }
  .simp-card { page-break-inside: avoid; }
  .simp-card .val { font-size: 14pt; }

  /* Force the colored backgrounds to render */
  .simp-card.rent { background: #fdecea !important; }
  .simp-card.rent .val { color: var(--bad) !important; }
  .simp-card.buy { background: #e8f5e9 !important; }
  .simp-card.buy .val { color: var(--good) !important; }
  .row.total { background: var(--warn-bg) !important; }
}
