:root {
  --brand-teal: #0a5a64;
  --brand-yellow: #ffcd1c;
  --ink: #17383d;
  --muted: #61777a;
  --surface: #ffffff;
  --canvas: #f1f5f4;
  --line: #d9e4e4;
  --red: #d84a3a;
  --blue: #2767c7;
  --green: #0a5a64;
  --amber: #ffcd1c;
  --load-actual: #205f9f;
  --load-forecast: #86bfe9;
  --pv-actual: #d84a3a;
  --pv-forecast: #d84a3a;
  --grid-actual: #0a5a64;
  --grid-forecast: #73adb3;
  --battery-actual: #2767c7;
  --battery-forecast: #8cb8ee;
  --soc-actual: #d84a3a;
  --soc-forecast: #ec9a91;
  --buy-actual: #b67800;
  --buy-forecast: #e5b842;
  --sell-actual: #7553a6;
  --sell-forecast: #bca6db;
  --shadow: 0 14px 38px rgba(10, 90, 100, .09);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 205, 28, .11), transparent 24rem),
    radial-gradient(circle at 92% 8%, rgba(10, 90, 100, .10), transparent 30rem),
    var(--canvas);
  font: 15px/1.45 "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
button, input { font: inherit; }
button { touch-action: manipulation; }

.hero {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 164px;
  padding: 24px max(24px, calc((100vw - 1320px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 34px;
  color: var(--ink);
  background: rgba(255, 255, 255, .98);
  border-bottom: 5px solid var(--brand-yellow);
  box-shadow: 0 10px 30px rgba(10, 90, 100, .08);
  isolation: isolate;
}
.hero-brand { display: flex; align-items: center; gap: 34px; min-width: 0; }
.brand-logo { display: block; width: clamp(210px, 22vw, 285px); height: auto; flex: 0 0 auto; }
.hero-title { min-width: 0; padding-left: 34px; border-left: 1px solid #d8e4e4; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; color: var(--brand-teal); font-size: clamp(30px, 4vw, 44px); line-height: 1.06; letter-spacing: -.03em; }
h2 { margin-bottom: 4px; font-size: clamp(21px, 3vw, 27px); letter-spacing: -.025em; }
h3 { margin-bottom: 12px; font-size: 18px; }
.subtitle { margin: 0; color: var(--muted); }
.eyebrow { margin-bottom: 8px; color: var(--brand-teal); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.eyebrow.dark { color: var(--brand-teal); }
.hero-state { display: flex; align-items: center; gap: 10px; white-space: nowrap; padding: 10px 14px; border: 1px solid rgba(10,90,100,.16); border-radius: 999px; color: var(--brand-teal); background: #f1f7f7; }
.state-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand-yellow); box-shadow: 0 0 0 5px rgba(255,205,28,.18); }
.state-dot.ok { background: #35a36f; box-shadow: 0 0 0 5px rgba(53,163,111,.14); }
.state-dot.error { background: #ff796a; box-shadow: 0 0 0 5px rgba(255,121,106,.14); }

main { width: min(1320px, calc(100% - 32px)); margin: 24px auto 44px; display: grid; gap: 18px; }
.panel { border: 1px solid rgba(10,90,100,.11); border-radius: 17px; background: rgba(255,255,255,.98); box-shadow: var(--shadow); overflow: hidden; }
.controls-panel, .chart-panel { border-top: 3px solid var(--brand-yellow); }
.controls-panel, .configuration-panel { padding: 22px 24px; }
.live-panel { padding: 22px 24px 24px; border-top: 3px solid var(--brand-yellow); }
.dashboard-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.live-badge { display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px; border-radius: 999px; color: var(--brand-teal); background: #edf5f5; font-size: 12px; font-weight: 800; white-space: nowrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #35a36f; box-shadow: 0 0 0 4px rgba(53,163,111,.13); }
.kpi-grid { margin-top: 18px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpi-card { --kpi-accent: var(--brand-teal); position: relative; min-width: 0; min-height: 104px; padding: 17px 15px 13px; display: flex; flex-direction: column; justify-content: center; gap: 5px; border: 1px solid #dce7e7; border-radius: 13px; background: linear-gradient(145deg, #fff, #f5f9f9); overflow: hidden; }
.kpi-card::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--kpi-accent); }
.kpi-label { color: #506b70; font-size: 11px; font-weight: 800; letter-spacing: .035em; text-transform: uppercase; }
.kpi-value { color: var(--ink); font-size: clamp(18px, 2vw, 25px); line-height: 1.08; letter-spacing: -.025em; white-space: nowrap; }
.kpi-card small { min-height: 17px; color: var(--muted); font-size: 11px; font-weight: 700; }
.kpi-load { --kpi-accent: var(--load-actual); }
.kpi-pv { --kpi-accent: var(--pv-actual); }
.kpi-battery { --kpi-accent: var(--battery-actual); }
.kpi-soc { --kpi-accent: var(--soc-actual); }
.kpi-grid-active { --kpi-accent: var(--grid-actual); }
.kpi-grid-reactive { --kpi-accent: #7661a8; }
.kpi-reactive-compensation { --kpi-accent: var(--brand-yellow); }
.kpi-epex { --kpi-accent: var(--brand-teal); }
.kpi-buy { --kpi-accent: var(--buy-actual); }
.kpi-sell { --kpi-accent: var(--sell-actual); }
.kpi-energy-load { --kpi-accent: var(--load-actual); }
.kpi-energy-grid { --kpi-accent: var(--grid-actual); }
.kpi-autonomy { --kpi-accent: #35a36f; }
.kpi-savings { --kpi-accent: var(--brand-yellow); }
.kpi-savings-year { --kpi-accent: #2b8a5f; }
.kpi-battery-savings { --kpi-accent: var(--battery-actual); }
.kpi-battery-savings-year { --kpi-accent: #4b70b5; }
.bottom-controls { margin-top: 2px; }
.section-heading, .chart-heading, .subheading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.window-grid { margin-top: 18px; display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
label { display: grid; gap: 7px; color: #3c5b60; font-size: 13px; font-weight: 700; }
input { min-width: 0; width: 100%; height: 44px; padding: 9px 11px; border: 1px solid #c8d9da; border-radius: 10px; color: var(--ink); background: #fbfdfd; outline: none; }
input:focus { border-color: var(--brand-teal); box-shadow: 0 0 0 3px rgba(255,205,28,.28); }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.button { min-height: 42px; padding: 9px 14px; border: 0; border-radius: 10px; cursor: pointer; font-weight: 800; transition: transform .15s, background .15s; }
.button:active { transform: translateY(1px); }
.button.primary { color: white; background: var(--brand-teal); box-shadow: 0 7px 16px rgba(10,90,100,.18); }
.button.primary:hover { background: #074a52; }
.button.secondary { color: var(--brand-teal); background: #e4f0f1; }
.button.ghost { color: var(--brand-teal); background: #edf4f4; }
.button.danger { color: #9c3227; background: #fae8e5; }
.button.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }

.chart-panel { padding-top: 22px; }
.chart-heading { padding: 0 24px; }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 16px; color: var(--muted); font-size: 12px; }
.legend span { display: flex; align-items: center; gap: 7px; }
.legend-line { display: inline-block; width: 25px; height: 0; border-top: 3px solid; }
.legend-line.red { border-color: var(--red); }
.legend-line.blue { border-color: var(--blue); }
.legend-line.green { border-color: var(--green); }
.legend-line.load-actual { border-color: var(--load-actual); }
.legend-line.load-forecast { border-color: var(--load-forecast); }
.legend-line.pv-actual { border-color: var(--pv-actual); }
.legend-line.pv-forecast { border-color: var(--pv-forecast); }
.legend-line.grid-actual { border-color: var(--grid-actual); }
.legend-line.grid-forecast { border-color: var(--grid-forecast); }
.legend-line.battery-actual { border-color: var(--battery-actual); }
.legend-line.battery-forecast { border-color: var(--battery-forecast); }
.legend-line.soc-actual { border-color: var(--soc-actual); }
.legend-line.soc-forecast { border-color: var(--soc-forecast); }
.legend-line.epex-actual { border-color: var(--green); }
.legend-line.epex-forecast { border-color: #73adb3; }
.legend-line.buy-actual { border-color: var(--buy-actual); }
.legend-line.buy-forecast { border-color: var(--buy-forecast); }
.legend-line.sell-actual { border-color: var(--sell-actual); }
.legend-line.sell-forecast { border-color: var(--sell-forecast); }
.legend-line.dashed { border-top-style: dashed; }
.chart-status { min-height: 25px; padding: 3px 24px 0; color: var(--muted); font-size: 12px; }
.status-pill { display: inline-flex; margin: 3px 6px 0 0; padding: 4px 8px; border-radius: 999px; background: #edf3f0; color: #40564f; }
.status-pill.warning { background: #fff1d6; color: #825d16; }
.chart { position: relative; min-height: 335px; width: 100%; overflow: hidden; }
.chart svg { display: block; width: 100%; height: 335px; }
.chart .grid { stroke: #e3ecec; stroke-width: 1; }
.chart .axis-text { fill: #76857f; font-size: 11px; }
.chart .axis-title { font-size: 10px; font-weight: 700; }
.chart .power-axis { fill: var(--blue); }
.chart .soc-axis { fill: var(--red); }
.chart .zero { stroke: #aab7b2; stroke-width: 1.2; }
.chart .now { stroke: #c09100; stroke-width: 1; stroke-dasharray: 4 5; }
.chart .series { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .empty { fill: #718079; font-size: 14px; text-anchor: middle; }
.tooltip { position: fixed; z-index: 20; max-width: 250px; pointer-events: none; padding: 10px 12px; border-radius: 10px; color: white; background: rgba(7,69,77,.96); box-shadow: 0 8px 26px rgba(0,0,0,.22); font-size: 12px; }
.tooltip strong { display: block; margin-bottom: 4px; }

#config-form { margin-top: 20px; }
.config-block { padding: 18px 0; border-top: 1px solid var(--line); }
.site-grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 12px; }
.model-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tariff-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.inverter-card { margin-top: 14px; padding: 16px; border: 1px solid #dbe5e0; border-radius: 14px; background: #f8faf9; }
.inverter-head, .string-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.inverter-title { margin: 0; font-size: 16px; }
.inverter-fields { margin: 12px 0; display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.string-card { margin-top: 10px; padding: 13px; border-left: 3px solid #8bb9a8; border-radius: 8px; background: white; }
.string-grid { margin-top: 10px; display: grid; grid-template-columns: 1.5fr repeat(4, 1fr); gap: 10px; }
.battery-slot { margin-top: 14px; padding-top: 14px; border-top: 1px dashed #cbd9d3; }
.battery-card { margin-top: 12px; padding: 14px; border: 1px solid #cbded6; border-radius: 12px; background: #f3f8f6; }
.battery-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.battery-grid { margin-top: 12px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.optimizer-grid { margin-top: 16px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.check-field { min-height: 44px; display: flex; grid-auto-flow: column; grid-template-columns: auto 1fr; align-items: center; justify-content: start; gap: 9px; padding: 9px 11px; border: 1px solid #cfd9d4; border-radius: 10px; background: #fbfcfb; }
.check-field input[type="checkbox"] { width: 18px; min-width: 18px; height: 18px; margin: 0; accent-color: var(--brand-teal); box-shadow: none; }
.card-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 14px; }
#save-message { color: var(--muted); }
#save-message.error { color: #a23228; }
#save-message.ok { color: var(--brand-teal); }
.financial-panel { padding: 22px 24px 24px; border-top: 3px solid var(--brand-yellow); }
.financial-badge { display: inline-flex; align-items: center; padding: 7px 11px; border-radius: 999px; color: var(--brand-teal); background: #edf5f5; font-size: 12px; font-weight: 800; white-space: nowrap; }
.financial-window { margin: 12px 0 14px; color: var(--muted); font-size: 13px; }
.financial-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
.financial-table { width: 100%; border-collapse: collapse; background: #fff; }
.financial-table th, .financial-table td { padding: 14px 16px; border-bottom: 1px solid #e3ebeb; text-align: right; }
.financial-table thead th { color: #456267; background: #f2f7f7; font-size: 12px; letter-spacing: .025em; text-transform: uppercase; }
.financial-table thead th:first-child, .financial-table tbody th { text-align: left; }
.financial-table tbody th { color: var(--ink); font-size: 14px; }
.financial-table tbody td { color: var(--ink); font-size: 16px; font-weight: 800; white-space: nowrap; }
.financial-table tbody tr:last-child th, .financial-table tbody tr:last-child td { border-bottom: 0; }
.financial-table .financial-saving th, .financial-table .financial-saving td { color: var(--brand-teal); background: rgba(255,205,28,.08); }
footer { width: min(1320px, calc(100% - 32px)); margin: 0 auto 30px; padding-top: 14px; display: flex; justify-content: space-between; border-top: 1px solid rgba(10,90,100,.14); color: #63777a; font-size: 12px; }

@media (max-width: 1050px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 850px) {
  .hero { min-height: auto; padding: 22px 20px; align-items: flex-start; flex-direction: column; gap: 16px; }
  .hero-brand { width: 100%; }
  .brand-logo { width: 220px; }
  .hero-title { padding-left: 24px; }
  main { width: min(100% - 18px, 1320px); margin-top: 14px; }
  .window-grid, .site-grid, .model-grid, .tariff-grid, .inverter-fields, .string-grid, .battery-grid, .optimizer-grid { grid-template-columns: 1fr 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .window-grid .button { grid-column: 1 / -1; }
  .chart-heading { flex-direction: column; }
  .legend { justify-content: flex-start; }
  .chart, .chart svg { min-height: 300px; height: 300px; }
}

@media (max-width: 560px) {
  .hero { padding: 13px 16px 14px; gap: 9px; }
  .hero-state { padding: 7px 10px; white-space: normal; font-size: 13px; }
  .hero-brand { flex-direction: column; align-items: flex-start; gap: 8px; }
  .brand-logo { width: 165px; }
  .hero-title { width: 100%; padding: 8px 0 0; border-left: 0; border-top: 1px solid #d8e4e4; }
  h1 { font-size: 26px; }
  .controls-panel, .configuration-panel, .financial-panel { padding: 18px 15px; }
  .live-panel { padding: 18px 15px; }
  .dashboard-heading { align-items: flex-start; }
  .kpi-grid { gap: 9px; }
  .kpi-card { min-height: 96px; padding: 14px 11px 11px 14px; }
  .kpi-label { font-size: 10px; }
  .kpi-value { font-size: clamp(17px, 5vw, 21px); }
  .chart-heading { padding: 0 15px; }
  .chart-status { padding-left: 15px; padding-right: 15px; }
  .section-heading, .subheading { flex-direction: column; }
  .window-grid, .site-grid, .model-grid, .tariff-grid, .inverter-fields, .string-grid, .battery-grid, .optimizer-grid { grid-template-columns: 1fr; }
  .button { width: 100%; }
  .card-actions .button { width: auto; flex: 1; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .financial-badge { white-space: normal; }
  .financial-table th, .financial-table td { padding: 12px 10px; }
  .financial-table tbody th { min-width: 190px; }
  footer { flex-direction: column; gap: 5px; }
}
