/* Palette: change these to rebrand (defaults = AmpMatter slate / sage / ink) */
:root {
  --ink: #16222b;
  --slate: #8fa7b4;
  --sage: #5f8a80;
  --sage-dark: #4a6f66;
  --bg: #f3f6f7;
  --card: #ffffff;
  --line: #dbe3e7;
  --muted: #5b6b75;
  --ok: #5f8a80;
  --short: #d08a3c;
  --off: #c9d4da;
  --warn-bg: #fdf1e3;
  --warn-ink: #8a4b0f;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e6edf0; --bg: #10181e; --card: #182329; --line: #2a3a43; --muted: #9aaab3;
    --off: #33444e; --warn-bg: #3a2a17; --warn-ink: #f0c48f; --sage-dark: #4a6f66;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #e6edf0; --bg: #10181e; --card: #182329; --line: #2a3a43; --muted: #9aaab3;
  --off: #33444e; --warn-bg: #3a2a17; --warn-ink: #f0c48f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Rubik, system-ui, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.45; font-size: 15px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.08rem; display: flex; align-items: center; gap: .5rem; }
h3 { font-size: .95rem; margin-top: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
code { font-size: .85em; background: var(--bg); padding: 1px 4px; border-radius: 4px; }

.top { background: var(--ink); color: #fff; padding: 18px 0; margin-bottom: 20px; }
:root[data-theme="dark"] .top { background: #0b1115; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .top { background: #0b1115; } }
.top .muted { color: var(--slate); margin: 0; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { border-radius: 10px; flex: none; }
.built { display: block; margin-top: 6px; }
.built a { color: var(--sage); }
.top-inner { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.mode { display: flex; background: rgba(255,255,255,.1); border-radius: 999px; padding: 4px; }
.mode button { border: 0; background: none; color: #fff; font: inherit; padding: 6px 16px; border-radius: 999px; cursor: pointer; }
.mode button[aria-selected="true"] { background: var(--sage); }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 920px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.results { position: sticky; top: 12px; }
@media (max-width: 920px) { .results { position: static; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--sage); color: #fff; font-size: .8rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; padding: 7px 14px; border-radius: 999px; cursor: pointer; }
.chip:hover { border-color: var(--sage); }
.chip.on { background: var(--sage); border-color: var(--sage); color: #fff; }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); }
.fields label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.fields label.wide { grid-column: 1 / -1; }
.hint { font-size: .78rem; }
.pair { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.pair input { flex: 1; width: 0; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sage); outline-offset: -1px; border-color: var(--sage); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--sage); }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; font-size: .8rem; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
td { padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.c { text-align: center; }
.loads input[type="number"] { width: 68px; }
.loads input.name { width: 100%; min-width: 150px; }
.x { border: 0; background: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1; }
.x:hover { color: var(--warn-ink); }
.add-row { display: flex; gap: 8px; margin-top: 12px; }
.add-row select { flex: 1; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--sage); }
.btn.primary { background: var(--sage); border-color: var(--sage); color: #fff; }
.btn.primary:hover { background: var(--sage-dark); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.kpi { display: flex; flex-direction: column; background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.kpi b { font-size: 1.25rem; font-weight: 600; }
.tag { font-size: .7rem; color: var(--sage); border: 1px solid var(--sage); border-radius: 4px; padding: 0 4px; margin-left: 4px; vertical-align: 1px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 12px; border-radius: 8px; margin: 10px 0 0; font-size: .9rem; }

.chart { width: 100%; height: auto; display: block; }
.chart .bar.ok { fill: var(--ok); }
.chart .bar.short { fill: var(--short); }
.chart .bar.off { fill: var(--off); }
.chart .need { stroke: var(--ink); stroke-dasharray: 4 3; stroke-width: 1.5; }
.chart .need-l, .chart .ax { fill: var(--muted); font-size: 10px; font-family: inherit; }
.legend { display: flex; gap: 14px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend i.ok { background: var(--ok); } .legend i.short { background: var(--short); } .legend i.off { background: var(--off); }

.kit { list-style: none; margin: 0; padding: 0; }
.kit li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.notes { margin: 0; padding-left: 18px; font-size: .9rem; }
.notes li { margin-bottom: 4px; }
tfoot td { font-weight: 500; }
tr.tot td { font-weight: 700; font-size: 1.05rem; }
.price .big { font-size: 1.7rem; font-weight: 600; margin: 0; }

/* Assistant */
.assist { border-color: var(--sage); }
.spark { background: var(--ink); }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; margin: 4px 0 10px; }
.chat:empty { display: none; }
.msg { padding: 8px 12px; border-radius: 12px; max-width: 92%; white-space: pre-wrap; font-size: .92rem; }
.msg.user { align-self: flex-end; background: var(--sage); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bg); border-bottom-left-radius: 4px; }
.msg.error { align-self: flex-start; background: var(--warn-bg); color: var(--warn-ink); }
.msg .who { display: block; font-size: .75rem; font-weight: 600; opacity: .75; margin-bottom: 2px; }
.chat-form textarea { width: 100%; resize: vertical; }
.chat-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.linkish { border: 0; background: none; color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer; text-decoration: underline; padding: 0; }
.busy { color: var(--sage); margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.busy[hidden] { display: none; }
.dots { width: 22px; height: 6px; background: radial-gradient(circle, currentColor 2.5px, transparent 3px) 0 0 / 8px 6px repeat-x; animation: dots 1s steps(3) infinite; }
@keyframes dots { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@media (prefers-reduced-motion: reduce) { .dots { animation: none; } }

/* Off-grid / grid-tied switch */
.calc-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px }
.calc-switch button { font: inherit; text-align: left; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; font-weight: 600 }
.calc-switch button span { display: block; font-weight: 400; font-size: .8rem; color: var(--muted) }
.calc-switch button[aria-selected="true"] { border-color: var(--sage); box-shadow: inset 0 0 0 1px var(--sage); background: color-mix(in srgb, var(--sage) 10%, var(--card)) }
body[data-calc="home"] .og, body[data-calc="offgrid"] .gt { display: none }

/* Grid-tied comparison */
.compare th, .compare td { vertical-align: top }
.compare thead th { font-size: .95rem; color: var(--ink); font-weight: 600 }
.compare td.lbl { color: var(--muted); font-size: .85rem; white-space: nowrap }
.compare tr.big td { font-weight: 700; font-size: 1.05rem }
.compare ul { margin: 0; padding-left: 16px; font-size: .85rem }
.compare ul.pros li::marker { color: var(--ok) }
.compare ul.cons li::marker { color: var(--short) }
.chart .usedot { fill: var(--ink) }
.chart .useline { stroke: var(--ink); stroke-width: 1.5; fill: none; stroke-dasharray: 4 3 }
details.bomopt { margin-top: 10px }
details.bomopt summary { cursor: pointer; font-weight: 600 }

body[data-mode="customer"] .installer-only { display: none; }
.foot { padding: 12px 16px 30px; }

/* Printed quote */
.quote { display: none; }
@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  body > *:not(.quote) { display: none !important; }
  .quote { display: block; padding: 0; }
  .q-head { display: flex; justify-content: space-between; border-bottom: 2px solid #5f8a80; padding-bottom: 10px; margin-bottom: 14px; }
  .q-head h1 { font-size: 18pt; margin: 0; }
  .q-meta { text-align: right; }
  .q-meta h2 { display: block; color: #5f8a80; font-size: 14pt; }
  .quote table { margin: 8px 0 14px; }
  .quote th, .quote td { border-bottom: 1px solid #ccc; padding: 5px 4px; }
  .quote td:last-child, .quote th:last-child { text-align: right; white-space: nowrap; }
  .quote td:nth-child(2), .quote th:nth-child(2) { text-align: center; }
  .q-small { font-size: 8.5pt; color: #555; }
  @page { margin: 16mm; }
}
