:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f7f4;
  color: #142019;
  font-synthesis: none;
  --ink: #142019;
  --muted: #68756d;
  --line: #dce5de;
  --surface: #fff;
  --green: #0a8f5b;
  --green-dark: #067047;
  --green-soft: #e7f6ee;
  --amber: #c77b13;
  --red: #b94343;
  --shadow: 0 18px 55px rgb(26 51 36 / 8%);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; overflow-x: hidden; background: radial-gradient(circle at 50% -20%, #fff 0, #f4f7f4 42rem); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
h1, h2, p { margin: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 72px; padding: 12px max(24px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid rgb(220 229 222 / 80%); background: rgb(255 255 255 / 86%);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand > span:last-child { display: grid; gap: 1px; }
.brand strong { font-size: 16px; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: 12px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--ink); }
.brand-mark svg { width: 22px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.dashboard { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 40px 0 72px; }
.control-card {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 40px; align-items: center;
  min-height: 248px; padding: clamp(28px, 5vw, 56px); overflow: hidden;
  border: 1px solid #d5e2d9; border-radius: 28px;
  background: linear-gradient(125deg, #fff 25%, #edf8f1 100%); box-shadow: var(--shadow);
  position: relative;
}
.control-card::after { content: ""; position: absolute; width: 260px; height: 260px; right: -90px; top: -120px; border-radius: 50%; background: rgb(10 143 91 / 8%); }
.control-card.is-active { border-color: #9dd5b8; background: linear-gradient(125deg, #fff 20%, #e2f7eb 100%); }
.control-card.has-error { border-color: #e7c1c1; background: linear-gradient(125deg, #fff 20%, #fff3f3 100%); }
.control-copy, .control-actions { position: relative; z-index: 1; }
.status-line { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #a8b0aa; box-shadow: 0 0 0 5px rgb(168 176 170 / 14%); }
.is-active .status-dot { background: var(--green); box-shadow: 0 0 0 5px rgb(10 143 91 / 13%); animation: breathe 2.6s ease-in-out infinite; }
.has-error .status-dot { background: var(--red); box-shadow: 0 0 0 5px rgb(185 67 67 / 13%); }
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.control-card h1 { max-width: 680px; font-size: clamp(30px, 4vw, 48px); line-height: 1.06; letter-spacing: -.045em; }
.decision { max-width: 720px; margin-top: 16px; color: #526057; font-size: 16px; line-height: 1.55; }
.control-actions { display: grid; gap: 12px; width: min(100%, 310px); }
.control-actions p { max-width: 300px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }
.inline-alert { margin-top: 20px; padding: 12px 14px; border: 1px solid #eac4c4; border-radius: 12px; background: #fff7f7; color: #9f3636; font-size: 13px; line-height: 1.45; }

.section { margin-top: 46px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.section-heading > div { display: grid; gap: 5px; }
.section h2 { font-size: 23px; letter-spacing: -.025em; }
.freshness { color: var(--muted); font-size: 12px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.metric {
  min-width: 0; min-height: 188px; padding: 24px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface); box-shadow: 0 8px 30px rgb(26 51 36 / 5%);
}
.metric-icon { display: grid; place-items: center; width: 36px; height: 36px; margin-bottom: 22px; border-radius: 11px; background: #f0f4f1; color: #536159; font-size: 18px; }
.metric > span { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.metric strong { display: block; margin-top: 7px; color: var(--ink); font-size: clamp(25px, 3vw, 34px); letter-spacing: -.045em; white-space: nowrap; }
.metric small { display: block; margin-top: 9px; color: #929d96; font-size: 11px; }
.metric-solar .metric-icon { background: #fff4d9; color: #b77005; }
.metric-surplus { border-color: #b9dec9; background: linear-gradient(145deg, #fff, #effaf4); }
.metric-surplus .metric-icon { background: var(--green-soft); color: var(--green); }
.metric-surplus strong { color: var(--green-dark); }

.vehicle-card { display: grid; grid-template-columns: 260px 1fr; gap: 28px; padding: 28px; border: 1px solid var(--line); border-radius: 22px; background: #fff; box-shadow: 0 8px 30px rgb(26 51 36 / 5%); }
.vehicle-visual { min-height: 152px; overflow: hidden; border-radius: 18px; background: #f0f3f3; }
.vehicle-visual img { display: block; width: 100%; height: 100%; min-height: 152px; object-fit: cover; object-position: center; }
.vehicle-facts { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: center; }
.vehicle-facts > div { min-width: 0; padding: 8px 18px; border-left: 1px solid #edf1ee; }
.vehicle-facts > div:first-child { border-left: 0; }
.vehicle-facts span { display: block; color: var(--muted); font-size: 11px; }
.vehicle-facts strong { display: block; margin-top: 6px; overflow: hidden; color: var(--ink); font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.vehicle-foot { grid-column: 2; display: flex; justify-content: space-between; gap: 16px; padding: 13px 18px 0; border-top: 1px solid #edf1ee; color: var(--muted); font-size: 11px; }

.panel { margin-top: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: #fff; }
.panel:first-of-type { margin-top: 46px; }
.panel summary { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 24px; cursor: pointer; list-style: none; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary > span:first-child { display: grid; gap: 4px; }
.panel summary strong { color: var(--ink); font-size: 16px; }
.panel summary small { color: var(--muted); font-size: 12px; font-weight: 400; }
.chevron { color: var(--muted); font-size: 24px; transition: transform 180ms ease; }
.panel[open] .chevron { transform: rotate(180deg); }
.panel-body { padding: 4px 24px 24px; border-top: 1px solid #edf1ee; }
.panel-intro { margin-top: 20px; color: var(--muted); line-height: 1.5; }
.info-note { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: #f2f6f3; color: #526057; font-size: 13px; }

form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; margin-top: 24px; }
label { display: grid; gap: 8px; color: #2b3930; font-size: 13px; font-weight: 750; }
label small { color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.4; }
input, select { width: 100%; min-height: 48px; border: 1px solid #cfdbd2; border-radius: 12px; padding: 0 14px; outline: none; background: #fff; color: var(--ink); transition: border-color 150ms, box-shadow 150ms; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgb(10 143 91 / 10%); }
.input-unit { position: relative; }
.input-unit input { padding-right: 46px; }
.input-unit span { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }
.form-action { display: flex; align-items: end; justify-content: end; }
.setup-actions { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 20px; }
.error-count { display: grid; place-items: center; min-width: 28px; height: 28px; padding: 0 8px; border-radius: 999px; background: #f1f4f2; color: var(--muted); font-size: 12px; font-weight: 800; }
.error-panel.has-errors .error-count { background: #fff0f0; color: var(--red); }
.log-list { margin: 18px 0 0; padding: 0; list-style: none; }
.log-list li { padding: 12px 14px; border-radius: 10px; background: #fff7f7; color: #8e3b3b; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.log-list li + li { margin-top: 8px; }

.button { position: relative; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid transparent; border-radius: 12px; padding: 0 18px; color: var(--ink); background: #fff; font-weight: 750; text-decoration: none; cursor: pointer; transition: transform 140ms, box-shadow 140ms, background 140ms; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:focus-visible, summary:focus-visible { outline: 3px solid rgb(10 143 91 / 24%); outline-offset: 2px; }
.button-primary { min-height: 52px; background: var(--green); color: #fff; box-shadow: 0 10px 26px rgb(10 143 91 / 20%); }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.button-secondary { border-color: #d3ddd6; background: #fff; box-shadow: 0 3px 10px rgb(26 51 36 / 5%); }
.button-danger { min-height: 52px; border-color: #e7c5c5; background: #fff; color: #a43a3a; }
.button-quiet { min-height: 36px; padding: 0 12px; border-color: #dce5de; color: #556259; background: transparent; font-size: 12px; }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none; box-shadow: none; }
.button.is-loading { cursor: wait; padding-right: 42px; }
.button.is-loading::after { content: ""; position: absolute; right: 15px; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 700ms linear infinite; }
.badge { display: inline-flex; align-items: center; min-height: 30px; padding: 0 10px; border-radius: 999px; background: #eef3ef; color: #536159; font-size: 11px; font-weight: 800; }
.badge.is-ready { background: var(--green-soft); color: var(--green-dark); }
.toast { position: fixed; z-index: 50; right: 24px; bottom: 24px; width: min(420px, calc(100vw - 48px)); padding: 15px 18px; border: 1px solid #a9d9bf; border-radius: 14px; background: #f1fbf5; color: var(--green-dark); font-size: 13px; font-weight: 700; box-shadow: 0 18px 50px rgb(26 51 36 / 18%); }
.toast.is-error { border-color: #e1b8b8; background: #fff5f5; color: #9e3737; }
.toast.pending { display: flex; align-items: center; gap: 10px; border-color: #d5ded7; background: #fff; color: #536159; }
.toast.pending::before { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 700ms linear infinite; }
.hidden { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 420px); display: grid; gap: 16px; padding: 38px; border: 1px solid var(--line); border-radius: 22px; background: #fff; box-shadow: var(--shadow); }
.login-card .brand-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: var(--ink); color: #fff; font-size: 24px; }
.login-form { grid-template-columns: 1fr; margin-top: 6px; }
.login-form button { width: 100%; }
.login-form .error { position: static; padding: 11px 13px; border-radius: 10px; background: #fff4f4; color: var(--red); font-size: 12px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { box-shadow: 0 0 0 9px rgb(10 143 91 / 7%); } }

@media (max-width: 980px) {
  .control-card { grid-template-columns: 1fr; gap: 28px; }
  .control-actions { width: 100%; }
  .control-actions p { max-width: none; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .vehicle-card { grid-template-columns: 210px 1fr; }
  .vehicle-facts { grid-template-columns: repeat(3, 1fr); }
  .vehicle-facts > div:nth-child(4) { border-left: 0; }
  .vehicle-foot { flex-direction: column; gap: 5px; }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  .brand small, #teslaBadge { display: none; }
  .dashboard { width: min(100% - 28px, 1180px); padding-top: 20px; }
  .control-card { padding: 28px 22px; border-radius: 22px; }
  .section { margin-top: 34px; }
  .section-heading { align-items: flex-start; }
  .freshness { max-width: 48%; text-align: right; }
  .metric-grid { gap: 10px; }
  .metric { min-height: 160px; padding: 18px; }
  .metric-icon { margin-bottom: 16px; }
  .metric strong { font-size: 25px; }
  .vehicle-card { grid-template-columns: 1fr; padding: 18px; }
  .vehicle-visual, .vehicle-visual img { min-height: 170px; max-height: 170px; }
  .vehicle-visual img { object-position: center 58%; }
  .vehicle-facts { grid-template-columns: repeat(2, 1fr); }
  .vehicle-facts > div, .vehicle-facts > div:nth-child(4) { padding: 11px 12px; border-left: 1px solid #edf1ee; border-bottom: 1px solid #edf1ee; }
  .vehicle-facts > div:nth-child(odd) { border-left: 0; }
  .vehicle-facts > div:nth-last-child(-n+2) { border-bottom: 0; }
  .vehicle-foot { grid-column: 1; padding: 13px 2px 0; }
  form { grid-template-columns: 1fr; }
  .form-action .button { width: 100%; }
  .panel summary, .panel-body { padding-left: 18px; padding-right: 18px; }
}
@media (max-width: 420px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric { min-height: 138px; }
  .metric-icon { float: right; margin: 0; }
  .section-heading { flex-wrap: wrap; }
  .section-heading .button { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; } }
