/* ============================================================================
 * Solar ROI Calculator — styles (responsive, light + dark)
 * ==========================================================================*/

:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --brand: #f59e0b;
  --brand-2: #22c55e;
  --accent: #2563eb;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #111a2e;
    --panel-2: #0e1626;
    --text: #e6edf7;
    --muted: #94a3b8;
    --border: #1e293b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── header / footer ─────────────────────────────────────────────────────── */
.site-header {
  padding: 20px 24px;
  background: linear-gradient(120deg, #f59e0b12, #22c55e12);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; max-width: 1200px; margin: 0 auto; }
.logo { font-size: 34px; line-height: 1; }
.site-header h1 { margin: 0; font-size: 1.35rem; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

.site-footer {
  max-width: 1200px;
  margin: 8px auto 32px;
  padding: 0 24px;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ── layout ──────────────────────────────────────────────────────────────── */
.layout {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.panel h2 { margin: 0 0 14px; font-size: 1.05rem; }
.planner-panel { position: sticky; top: 20px; }
@media (max-width: 900px) { .planner-panel { position: static; } }

/* ── map ─────────────────────────────────────────────────────────────────── */
.map-wrap { margin: 12px 0; }
#map {
  width: 100%;
  height: 360px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  overflow: hidden; /* clip Leaflet tiles to the rounded corners */
}
#map.map-disabled {
  display: flex;
  align-items: center;
  justify-content: center;
}
.planner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* crosshair while tracing the roof (override Leaflet's grab cursor) */
#map.drawing,
#map.drawing .leaflet-grab,
#map.drawing .leaflet-interactive { cursor: crosshair !important; }

/* on-map instruction banner shown while drawing */
.draw-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  background: rgba(17, 24, 39, 0.88);
  color: #fff;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 500;
  pointer-events: none;
  max-width: 92%;
  text-align: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.status {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.2em;
}
.status code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--border);
}

/* ── forms ───────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; }
.field > span { color: var(--muted); font-weight: 500; }
input, select {
  font: inherit;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 480px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}

/* financing (cash vs loan) */
.finance-box {
  margin: 14px 0 6px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
}
.finance-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.finance-head > span { font-weight: 600; font-size: 0.9rem; }
.finance-head select { width: auto; min-width: 160px; }
#loanInputs { margin-bottom: 10px; }
.finance-result { margin-top: 4px; }
.fin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.fin-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.fin-l { font-size: 0.68rem; color: var(--muted); }
.fin-v { font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }
.fin-note { margin: 10px 0 0; font-size: 0.82rem; }
.fin-ok { color: var(--brand-2); }
.fin-warn { color: #b45309; }
@media (prefers-color-scheme: dark) { .fin-warn { color: #fbbf24; } }

.bill-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin: 14px 0 6px;
  padding: 12px;
  background: var(--panel-2);
  border-radius: 10px;
  border: 1px dashed var(--border);
}
.bill-row .field { flex: 1; }

/* ── buttons ─────────────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  cursor: pointer;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--brand);
  color: #1a1206;
  font-weight: 600;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: var(--panel-2); color: var(--text); }
.btn-small { background: var(--accent); color: #fff; padding: 9px 12px; white-space: nowrap; }
.btn-finish { background: var(--brand-2); color: #06210f; } /* green while drawing */
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 12px 0 4px;
  font: inherit;
  font-weight: 600;
}
.geo-btn { margin-top: 8px; }

/* implausible-result warning banner */
.warn {
  margin: 6px 0 14px;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 0.85rem;
  color: #7c2d12;
  background: #fef3c7;
  border: 1px solid #f59e0b;
}
@media (prefers-color-scheme: dark) {
  .warn { color: #fde68a; background: #422006; border-color: #a16207; }
}

/* ── advanced (collapsible) ──────────────────────────────────────────────── */
.advanced {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
.advanced.open { max-height: 500px; padding-top: 8px; }

/* ── top-level tabs ──────────────────────────────────────────────────────── */
.tabs {
  max-width: 1200px;
  margin: 20px auto 0;
  padding: 0 24px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  background: none;
  color: var(--muted);
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.is-active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
}
.tab-panel[hidden] { display: none; }

/* ── appliance load builder (its own tab) ────────────────────────────────── */
.sizing-wrap {
  max-width: 760px;
  margin: 24px auto;
  padding: 0 24px;
}
.appliance-intro { margin: 0 0 14px; font-size: 0.88rem; color: var(--muted); }
.appliance-note { margin: 10px 0 16px; font-size: 0.76rem; color: var(--muted); }

/* backup power (inverter + battery) sub-card in the sizing tab */
.backup-box {
  margin-top: 18px;
  padding: 14px;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
}
.backup-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.backup-head > span { font-weight: 600; font-size: 0.9rem; }
.backup-hours { display: flex; flex-direction: column; gap: 5px; font-size: 0.78rem; }
.backup-hours > span { color: var(--muted); font-weight: 500; }
.backup-hours input { width: 130px; }

/* 4-col grid shared by the header + each row: name | watts | qty | hrs */
.appliance-head,
.appliance-row {
  display: grid;
  grid-template-columns: 1fr 72px 60px 72px;
  gap: 8px;
  align-items: center;
}
.appliance-head {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0 2px 6px;
}
.appliance-head span:not(:first-child) { text-align: center; }
.appliance-row { padding: 4px 2px; }
.appliance-row + .appliance-row { border-top: 1px solid var(--border); }
.appliance-name { font-size: 0.82rem; overflow-wrap: anywhere; }
.appliance-in {
  padding: 6px 7px;
  font-size: 0.82rem;
  text-align: center;
  border-radius: 7px;
}

.appliance-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0 10px;
}
.appliance-metric {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.appliance-metric-hero {
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 16%, transparent), color-mix(in srgb, var(--brand-2) 14%, transparent));
  border-color: color-mix(in srgb, var(--brand) 40%, var(--border));
}
.appliance-metric-l { font-size: 0.66rem; color: var(--muted); }
.appliance-metric-v { font-size: 1.02rem; font-weight: 700; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .appliance-summary { grid-template-columns: 1fr; }
}

/* ── results ─────────────────────────────────────────────────────────────── */
.results { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge {
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
}
.headline {
  margin: 6px 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--brand-2);
}
.results-empty {
  margin-top: 16px;
  padding: 22px 18px;
  text-align: center;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.results-empty-title { margin: 0 0 6px; font-weight: 600; color: var(--text); }
.results-empty-sub { margin: 0; font-size: 0.88rem; color: var(--muted); line-height: 1.5; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.metric {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0; /* let the card shrink so long values can't overflow */
}
.metric-hero {
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 16%, transparent), color-mix(in srgb, var(--brand-2) 14%, transparent));
  border-color: color-mix(in srgb, var(--brand) 40%, var(--border));
}
.metric-label { font-size: 0.75rem; color: var(--muted); }
.metric-value {
  font-size: clamp(1.05rem, 3.4vw, 1.35rem);
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere; /* never spill past the card edge */
}
.metric-hero .metric-value { font-size: clamp(1.2rem, 4.2vw, 1.6rem); }
.metric-sub { font-size: 0.72rem; color: var(--muted); }

/* ── chart ───────────────────────────────────────────────────────────────── */
.chart-card {
  margin-top: 18px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 14px;
}
.chart-card h3 { margin: 0 0 8px; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.chart-svg { width: 100%; height: auto; display: block; }

.chart-svg .grid { stroke: var(--border); stroke-width: 1; }
.chart-svg .area { fill: color-mix(in srgb, var(--brand-2) 18%, transparent); stroke: none; }
.chart-svg .line { fill: none; stroke: var(--brand-2); stroke-width: 2.5; }
.chart-svg .breakeven { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-svg .payback { stroke: var(--brand); stroke-width: 1.5; stroke-dasharray: 3 3; }
.chart-svg .payback-dot { fill: var(--brand); stroke: #fff; stroke-width: 1.5; }
.chart-svg .payback-text { fill: var(--brand); font-weight: 600; }
.chart-svg .axis-label { fill: var(--muted); font-size: 11px; }
.chart-svg .bar { fill: var(--brand); }
.chart-svg .bar:hover { fill: var(--brand-2); }

/* sun-hours auto-fill hint */
.hint { font-size: 0.72rem; color: var(--brand-2); min-height: 1em; }

/* ── Photon address autocomplete (free provider) ─────────────────────────── */
.ac-host { position: relative; }
.ac-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow-y: auto;
}
.ac-item {
  padding: 9px 11px;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--panel-2); }

/* draggable roof-corner handle (free provider) */
.roof-vertex {
  background: #4ade80;
  border: 2px solid #16a34a;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
  cursor: grab;
}

.report-actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 10px; }

/* ── printable report ────────────────────────────────────────────────────── */
/* Hidden on screen; revealed only when printing / saving to PDF. */
.report { display: none; }

@media print {
  :root { --text: #0f172a; --muted: #475569; --border: #d7dee8; }
  body { background: #fff; color: #000; }
  .site-header, .site-footer, .layout { display: none !important; }

  .report {
    display: block;
    color: #0f172a;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  @page { margin: 14mm; }

  .report-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 3px solid #f59e0b;
    padding-bottom: 10px;
  }
  .report-title { display: flex; align-items: center; gap: 10px; }
  .report-title h1 { margin: 0; font-size: 1.5rem; }
  .report-title span { font-size: 1.8rem; }
  .report-date { color: #64748b; font-size: 0.9rem; }

  .report-addr { margin: 12px 0 4px; font-size: 1rem; font-weight: 600; }
  .report-summary { margin: 8px 0 18px; font-size: 1.05rem; }

  .report-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
  }
  .rm {
    border: 1px solid #d7dee8;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }
  .rm-l { font-size: 0.68rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.02em; }
  .rm-v { font-size: 1.15rem; font-weight: 700; }

  .report-chart { margin: 8px 0 20px; page-break-inside: avoid; }
  .report-chart h3, .report-h3 { font-size: 0.95rem; margin: 0 0 8px; color: #334155; }
  .report-chart .chart-svg { width: 100%; height: auto; }

  .report-assumptions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 24px;
  }
  .ra {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dotted #cbd5e1;
    padding: 4px 0;
    font-size: 0.85rem;
  }
  .ra-l { color: #475569; }
  .ra-v { font-weight: 600; }

  .report-appliances {
    margin: 4px 0 6px;
    page-break-inside: avoid;
  }
  .rap {
    display: grid;
    grid-template-columns: 2fr 0.7fr 0.6fr 0.7fr 1fr;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px dotted #cbd5e1;
    font-size: 0.82rem;
  }
  .rap span:not(:first-child) { text-align: right; }
  .rap-head { color: #475569; font-weight: 600; }
  .rap-total { font-weight: 700; border-bottom: none; border-top: 1px solid #94a3b8; }

  .report-foot {
    margin-top: 22px;
    padding-top: 10px;
    border-top: 1px solid #d7dee8;
    font-size: 0.72rem;
    color: #64748b;
  }
}

/* ── SEO content / FAQ section ─────────────────────────────────────────── */
.seo-content {
  max-width: 1200px;
  margin: 40px auto 8px;
  padding: 36px 24px 0;
  border-top: 1px solid var(--border);
}
.seo-inner {
  max-width: 880px;
}
.seo-content h2 {
  font-size: 1.4rem;
  line-height: 1.25;
  margin: 0 0 14px;
  color: var(--text);
}
.seo-lead {
  color: var(--muted);
  line-height: 1.65;
  font-size: 0.98rem;
  margin: 0 0 8px;
}
.seo-lead strong { color: var(--text); font-weight: 600; }
.seo-subhead {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 30px 0 14px;
}
.faq {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.faq-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.faq-item h4 {
  margin: 0 0 6px;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text);
}
.faq-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.88rem;
}
.faq-item strong { color: var(--text); font-weight: 600; }
@media (max-width: 720px) {
  .faq { grid-template-columns: 1fr; }
  .seo-content { padding: 28px 16px 0; }
}
