/* Watt Costs — handcrafted styles */
:root {
  --paper: #f6f3ec;
  --paper-raised: #fffdf7;
  --ink: #20242b;
  --ink-soft: #5a616e;
  --ink-faint: #8b919d;
  --line: #e2ddd0;
  --accent: #e8960c;
  --accent-deep: #b96f00;
  --accent-soft: #fdf0d7;
  --good: #2e7d4f;
  --good-soft: #e3f2e8;
  --danger: #b3413a;
  --bar-track: #eee9dc;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(32, 36, 43, .05), 0 6px 24px -12px rgba(32, 36, 43, .18);
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}
.wrap { max-width: 1160px; margin: 0 auto; padding: 0 20px; }
.hidden { display: none !important; }

/* ---------- header ---------- */
.site-header {
  background: var(--ink);
  color: #f3f0e7;
  padding: 22px 0;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 30px; line-height: 1;
  background: var(--accent); color: var(--ink);
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center;
  box-shadow: 0 0 0 4px rgba(232, 150, 12, .25);
}
.site-header h1 {
  font-family: var(--font-display);
  font-size: 26px; margin: 0; letter-spacing: .2px;
}
.tagline { margin: 2px 0 0; color: #b9b29f; font-size: 13.5px; }
.tagline em { color: #e8d9b8; }
.header-total {
  text-align: right;
  display: flex; flex-direction: column; gap: 0;
  padding: 8px 16px; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .12);
  min-width: 170px;
}
.header-total-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: #b9b29f; }
.header-total-value { font-family: var(--font-display); font-size: 28px; color: var(--accent); font-variant-numeric: tabular-nums; }
.header-total-sub { font-size: 11.5px; color: #b9b29f; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: 22px;
  padding-top: 26px;
  padding-bottom: 40px;
  align-items: start;
}
.col-results { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 18px; }
.col-inputs { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.card h2 {
  font-family: var(--font-display);
  font-size: 19px; margin: 0 0 4px;
}
.card-sub { margin: 0 0 14px; color: var(--ink-soft); font-size: 13px; }
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head-row h2 { margin: 0; }
.card-actions { display: flex; gap: 6px; }

/* ---------- fields & buttons ---------- */
.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; border: 0; padding: 0; margin: 0; }
.field-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-soft); }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
input[type="number"], input[type="text"], input[type="search"], select {
  font: inherit; color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 150, 12, .22);
}
input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(179, 65, 58, .18); }
.field-hint { font-size: 12.5px; color: var(--ink-faint); margin: 8px 0 0; }

.btn {
  font: inherit; font-weight: 600; font-size: 13.5px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 8px 14px; cursor: pointer;
  transition: transform .08s ease, background .12s ease, box-shadow .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: #f6f3ec; }
.btn-primary:hover { background: #000; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--ink); border-color: #ecd9ae; }
.btn-ghost.danger:hover { background: #fbe9e7; color: var(--danger); border-color: #ecc2bf; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------- segmented control ---------- */
.segmented {
  display: inline-flex; background: var(--bar-track); border-radius: var(--radius-sm); padding: 3px; gap: 2px;
}
.seg-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.seg-btn[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(32,36,43,.18); }

.rate-panel { border-top: 1px dashed var(--line); padding-top: 14px; margin-top: 4px; }
#panel-flat .field { max-width: 180px; }

/* tiers */
.tier-row { display: grid; grid-template-columns: auto minmax(60px, 130px) auto minmax(60px, 110px) auto; align-items: center; gap: 8px; margin-bottom: 8px; }
.tier-row .tier-upto { max-width: 130px; }
.tier-row .tier-rate { max-width: 110px; }
.tier-label { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; }
.tier-remove {
  border: 0; background: transparent; color: var(--ink-faint); cursor: pointer;
  font-size: 15px; padding: 2px 6px; border-radius: 6px;
}
.tier-remove:hover { color: var(--danger); background: #fbe9e7; }
.tier-result, .tou-result {
  margin-top: 12px; font-size: 13px; color: var(--ink-soft);
  background: var(--accent-soft); border: 1px solid #f0dfb6;
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.tier-result:empty, .tou-result:empty { display: none; }
.tier-result table, .tou-result table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tier-result td, .tier-result th, .tou-result td, .tou-result th { padding: 3px 0; text-align: right; font-size: 12.5px; }
.tier-result td:first-child, .tier-result th:first-child, .tou-result td:first-child, .tou-result th:first-child { text-align: left; }
.tier-result tfoot td, .tou-result tfoot td { border-top: 1px solid #e3cf9f; font-weight: 700; color: var(--ink); }

/* ---------- add box ---------- */
.add-box { position: relative; margin-bottom: 14px; }
.add-search-row { display: flex; gap: 8px; }
.add-search-row input { flex: 1; }
.library-results {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px -8px rgba(32, 36, 43, .25);
  max-height: 300px; overflow: auto;
}
.library-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f2eee3;
}
.library-item:last-child { border-bottom: 0; }
.library-item:hover, .library-item.active { background: var(--accent-soft); }
.library-item .li-name { font-weight: 600; font-size: 13.5px; }
.library-item .li-meta { font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
.library-item .li-cat { display: block; font-size: 11px; color: var(--accent-deep); text-transform: uppercase; letter-spacing: .06em; }
.quick-add { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font: inherit; font-size: 12.5px; font-weight: 600;
  background: #fff; border: 1px solid var(--line); color: var(--ink-soft);
  border-radius: 999px; padding: 4px 11px; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { background: var(--accent-soft); color: var(--ink); border-color: #ecd9ae; }
.chip.added { opacity: .45; text-decoration: line-through; pointer-events: none; }

/* ---------- appliance list ---------- */
.appliance-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.appliance {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; padding: 12px 14px 10px;
  transition: border-color .15s ease;
}
.appliance:hover { border-color: #d4ccb6; }
.appliance-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.appliance-name { font-weight: 700; font-size: 14px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  border-radius: 999px; padding: 1px 8px; white-space: nowrap;
}
.badge-custom { background: #e7e3f7; color: #5b4b9e; }
.badge-edited { background: var(--accent-soft); color: var(--accent-deep); border: 1px solid #f0dfb6; cursor: pointer; }
.appliance-cost { font-family: var(--font-display); font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.appliance-cost small { font-family: var(--font-ui); font-size: 11px; color: var(--ink-faint); font-weight: 400; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--ink-faint);
  font-size: 14px; padding: 3px 7px; border-radius: 6px; line-height: 1;
}
.icon-btn:hover { background: #f1ede1; color: var(--ink); }
.icon-btn.delete:hover { background: #fbe9e7; color: var(--danger); }

.appliance-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  align-items: end;
}
.mini-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mini-field label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.mini-field input, .mini-field select { padding: 6px 8px; font-size: 13.5px; }
.hours-combo { display: flex; gap: 4px; }
.hours-combo input { flex: 1; min-width: 0; }
.hours-combo select { width: 64px; flex: none; padding: 6px 4px; font-size: 12.5px; }

.peak-share-row { margin-top: 8px; display: flex; align-items: center; gap: 10px; }
.peak-share-row label { font-size: 11px; color: var(--ink-soft); white-space: nowrap; }
.peak-share-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.peak-share-value { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink); width: 38px; text-align: right; }

.share-bar { height: 5px; background: var(--bar-track); border-radius: 99px; margin-top: 10px; overflow: hidden; }
.share-bar > div {
  height: 100%; background: linear-gradient(90deg, #f2b13d, var(--accent));
  border-radius: 99px; width: 0;
  transition: width .35s cubic-bezier(.22, .8, .3, 1);
}
.appliance-meta {
  display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px;
  font-size: 12px; color: var(--ink-soft);
}
.appliance-meta .meta-item { font-variant-numeric: tabular-nums; }
.hint {
  margin-top: 8px; font-size: 12px; color: var(--accent-deep);
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0; padding: 6px 10px;
}
.math-line {
  margin-top: 8px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-faint);
  overflow-wrap: anywhere;
}

/* ---------- empty state ---------- */
.empty-state { text-align: center; padding: 34px 20px 28px; }
.empty-icon { font-size: 40px; margin-bottom: 6px; }
.empty-state h3 { font-family: var(--font-display); margin: 0 0 6px; font-size: 19px; }
.empty-state p { color: var(--ink-soft); margin: 0 0 16px; font-size: 13.5px; }

/* ---------- totals ---------- */
.totals-card { background: var(--ink); color: #f3f0e7; border-color: var(--ink); }
.totals-card h2 { color: #f3f0e7; }
.totals-grid { display: grid; grid-template-columns: 1fr 1.25fr 1fr; gap: 10px; margin-top: 10px; }
.total-cell {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 1px;
}
.total-cell.hero { background: rgba(232, 150, 12, .14); border-color: rgba(232, 150, 12, .4); }
.total-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: #b9b29f; }
.total-value { font-family: var(--font-display); font-size: 24px; font-variant-numeric: tabular-nums; color: #fff; }
.total-cell.hero .total-value { font-size: 30px; color: var(--accent); }
.total-kwh { font-size: 11.5px; color: #b9b29f; font-variant-numeric: tabular-nums; }
.totals-note { margin: 12px 0 0; font-size: 12px; color: #b9b29f; }
.totals-note:empty { display: none; }

/* ---------- breakdown ---------- */
.breakdown { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }
.bd-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 2fr) auto; gap: 10px; align-items: center; }
.bd-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd-bar { height: 18px; background: var(--bar-track); border-radius: 5px; overflow: hidden; }
.bd-bar > div {
  height: 100%; border-radius: 5px;
  background: linear-gradient(90deg, #f2b13d, var(--accent));
  width: 0; transition: width .35s cubic-bezier(.22, .8, .3, 1);
}
.bd-row.top .bd-bar > div { background: linear-gradient(90deg, #d97b10, #b3413a); }
.bd-val { font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.bd-val small { color: var(--ink-faint); }
.breakdown-empty { color: var(--ink-faint); font-size: 13px; }

/* ---------- insights ---------- */
.insight {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-top: 10px; background: #fff;
}
.insight.good { background: var(--good-soft); border-color: #c4e2cf; }
.insight h3 { margin: 0 0 4px; font-size: 13.5px; }
.insight p { margin: 0; font-size: 12.5px; color: var(--ink-soft); }
.insight .savings { font-weight: 700; color: var(--good); font-variant-numeric: tabular-nums; }
.whatif { margin-top: 10px; }
.whatif label { font-size: 12.5px; font-weight: 600; display: block; margin-bottom: 6px; }
.whatif-slider-row { display: flex; align-items: center; gap: 10px; }
.whatif-slider-row input[type="range"] { flex: 1; accent-color: var(--good); }
.whatif-value { font-size: 13px; font-weight: 700; width: 40px; text-align: right; font-variant-numeric: tabular-nums; }
.whatif-result { margin-top: 6px; font-size: 13px; color: var(--good); font-weight: 600; }

/* ---------- math card ---------- */
.math-card summary {
  font-family: var(--font-display); font-size: 16px; font-weight: 700; cursor: pointer;
}
.math-body { margin-top: 10px; font-size: 13px; color: var(--ink-soft); }
.math-body ol { padding-left: 20px; margin: 0 0 10px; }
.math-body li { margin-bottom: 6px; }
.math-body p { margin: 0; font-size: 12.5px; color: var(--ink-faint); }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 18px 0 30px; }
.site-footer p { margin: 0; font-size: 12px; color: var(--ink-faint); }

/* ---------- motion ---------- */
@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px) scale(.99); }
  to { opacity: 1; transform: none; }
}
.appliance { animation: pop-in .22s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .appliance { animation: none; }
  .share-bar > div, .bd-bar > div { transition: none; }
}

/* number flash on change */
@keyframes value-flash { 0% { color: var(--accent); } 100% { } }
.flash { animation: value-flash .5s ease-out; }

/* ---------- responsive ---------- */
@media (max-width: 940px) {
  .layout { grid-template-columns: 1fr; }
  .col-results { position: static; }
}
@media (max-width: 560px) {
  .wrap { padding: 0 14px; }
  .card { padding: 16px; }
  .site-header h1 { font-size: 22px; }
  .header-total { min-width: 0; flex: 1; text-align: left; }
  .rate-mode-field { flex-basis: 100%; }
  .segmented { display: flex; width: 100%; }
  .seg-btn { flex: 1; padding: 6px 4px; font-size: 12.5px; white-space: nowrap; }
  .totals-grid { grid-template-columns: 1fr; }
  .total-cell.hero .total-value { font-size: 26px; }
  .appliance-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bd-row { grid-template-columns: minmax(0, 1fr) auto; }
  .bd-bar { grid-column: 1 / -1; order: 3; }
  .add-search-row { flex-direction: column; }
}
