:root{
  --bg:#141a26; --bg2:#202d42; --panel:#202d42; --panel2:#3b4556;
  --accent:#f2cc83; --accent2:#f7d89a; --text:#f9fafb; --muted:#9ca3af;
  --border:rgba(148,163,184,.5); --danger:#e34242; --ok:#22c55e;
  --warn:#f59e0b;
  --shadow:0 18px 45px rgba(0,0,0,.22); --t:150ms ease-out;

  --btn-bg:var(--accent); --btn-text:#111827;
  --btn-shadow:0 12px 26px rgba(0,0,0,.28);
  --btn-hover-bg:var(--accent2); --btn-hover-shadow:0 16px 34px rgba(0,0,0,.34);
  --btn-active-shadow:0 10px 22px rgba(0,0,0,.28);

  --shell-max:1900px;
  --line-power:rgba(59,130,246,.95);
  --fill-power:rgba(59,130,246,.14);
  --line-gas:rgba(34,197,94,.95);
  --fill-gas:rgba(34,197,94,.14);

  --col-date:140px;
  --col-gas:170px;
  --col-power:180px;
  --col-note:auto;
  --col-actions:150px;
}

body.theme-light{
  --bg:#f7ecd4; --bg2:#faefdc; --panel:#fff7e7; --panel2:#f2cc83;
  --accent:#296117; --accent2:#3b7f22; --text:#111827; --muted:#4b5563;
  --border:rgba(148,119,81,.6); --danger:#b91c1c; --ok:#296117;
  --warn:#b45309;

  --btn-bg:var(--accent); --btn-text:#fff;
  --btn-shadow:0 12px 26px rgba(0,0,0,.18);
  --btn-hover-bg:var(--accent2); --btn-hover-shadow:0 16px 34px rgba(0,0,0,.22);
  --btn-active-shadow:0 10px 22px rgba(0,0,0,.18);

  --line-power:rgba(37,99,235,.95);
  --fill-power:rgba(37,99,235,.14);
  --line-gas:rgba(22,163,74,.95);
  --fill-gas:rgba(22,163,74,.14);
}

*{ box-sizing:border-box; min-width:0; }

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

body{
  padding:18px;
  padding-left:max(18px, env(safe-area-inset-left));
  padding-right:max(18px, env(safe-area-inset-right));
  padding-top:max(18px, env(safe-area-inset-top));
  padding-bottom:max(18px, env(safe-area-inset-bottom));
}

.wrap{ width:100%; display:flex; justify-content:center; }

.shell{
  width:100%;
  max-width:var(--shell-max);
  background:var(--bg2);
  border-radius:1.8rem;
  border:1px solid var(--border);
  box-shadow:var(--shadow);
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:16px;
}

.topbar,.calcHeader,.panelHead{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  flex-wrap:wrap;
  margin-bottom:14px;
}

.panelHeadTight{ align-items:flex-start; }

.brand{
  display:inline-flex; align-items:center; gap:10px;
  text-decoration:none; color:inherit;
}

.brand img{
  width:26px; height:26px; border-radius:8px; border:1px solid var(--border);
}

.bt{ display:inline-flex; flex-direction:column; line-height:1.1; }
.bt strong{ font-weight:900; font-size:.92rem; }
.bt span{ color:var(--muted); font-size:.76rem; }

.actions,.headActions,.btnRow,.btnCluster{
  display:flex; gap:8px; flex-wrap:wrap; align-items:center;
}

.title{ display:flex; flex-direction:column; gap:6px; }

h1{ margin:0; font-size:1.65rem; font-weight:950; letter-spacing:.02em; }
h1 .em{ color:var(--accent); }

.subtitle{ margin:0; color:var(--muted); font-size:.92rem; line-height:1.35; }

.right{ display:flex; flex-direction:column; gap:10px; align-items:flex-end; }

.pill{
  display:inline-flex; align-items:center; gap:6px;
  padding:6px 10px; border-radius:999px;
  border:1px solid var(--border); background:var(--panel2); color:var(--muted);
}
.pill strong{ color:var(--text); }

.layout{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:16px;
}

.panel{
  background:var(--panel);
  border-radius:1.4rem;
  border:1px solid var(--border);
  padding:14px 16px 16px;
  box-shadow:0 12px 30px rgba(0,0,0,.25);
}

.panel.full{ grid-column:1 / -1; }
.panel.half{ grid-column:span 1; }
.panelInner{ padding:12px; }

.panelHead h2{
  margin:0;
  font-size:.95rem;
  letter-spacing:.08em;
  text-transform:uppercase;
}

.titleRow{
  display:flex;
  align-items:center;
  gap:12px;
  flex-wrap:wrap;
}

.providerTitleRow{ flex:1 1 auto; }

.tariffsHead{
  align-items:flex-start;
  flex-wrap:nowrap;
}

.tariffsTitleRow{
  flex:1 1 auto;
  display:flex;
  align-items:flex-start;
  gap:16px;
  flex-wrap:nowrap;
}

.tariffsHeadActions{
  margin-left:auto;
  flex:0 0 auto;
  justify-content:flex-end;
}

.inlineSelect{
  min-width:250px;
  max-width:420px;
}

.subPanel,.chartCard,.resultCard,.kpiCard,.shareCard,.statItem{
  border:1px solid var(--border);
  border-radius:1rem;
  background:rgba(0,0,0,.06);
}

body.theme-light .subPanel,
body.theme-light .chartCard,
body.theme-light .resultCard,
body.theme-light .kpiCard,
body.theme-light .shareCard,
body.theme-light .statItem{ background:rgba(0,0,0,.03); }

.subPanel{ padding:12px; }

.subHead{
  font-size:.75rem;
  text-transform:uppercase;
  letter-spacing:.08em;
  color:var(--accent);
  margin-bottom:10px;
  font-weight:900;
}

.providerGrid{
  display:grid;
  grid-template-columns:1.25fr .95fr;
  gap:14px;
}

.providerForm .fullSpan{ grid-column:1 / -1; }

.grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px 12px;
}

label{
  display:flex;
  flex-direction:column;
  gap:4px;
  font-size:.82rem;
}

.labRow{
  display:flex;
  justify-content:space-between;
  gap:8px;
  align-items:baseline;
}

.labRow strong{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.hint{
  font-size:.72rem;
  color:var(--muted);
  white-space:nowrap;
}

input[type=text], input[type=date], input[type=number], select, textarea{
  width:100%;
  min-width:0;
  padding:9px 10px;
  border-radius:.8rem;
  border:1px solid var(--border);
  background:var(--panel2);
  color:var(--text);
  font-size:.86rem;
  outline:none;
  transition:border-color var(--t), box-shadow var(--t), transform var(--t);
}

textarea{ resize:vertical; min-height:98px; }

input:focus, select:focus, textarea:focus{
  border-color:var(--accent);
  box-shadow:0 0 0 1px var(--accent2), 0 0 0 5px rgba(0,0,0,.22);
  transform:translateY(-1px);
}

input[type=date]{ color-scheme:dark; }
body.theme-light input[type=date]{ color-scheme:light; }

.btn{
  border:none; cursor:pointer;
  padding:10px 14px; border-radius:1rem;
  background:var(--btn-bg); color:var(--btn-text);
  font-weight:900; letter-spacing:.02em;
  box-shadow:var(--btn-shadow);
  transition:transform var(--t), box-shadow var(--t), filter var(--t), background var(--t);
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
}

.btn:hover{
  transform:translateY(-1px);
  background:var(--btn-hover-bg);
  box-shadow:var(--btn-hover-shadow);
  filter:saturate(1.05);
}

.btn:active{
  transform:translateY(0);
  box-shadow:var(--btn-active-shadow);
}

.btn.ghost{
  background:transparent;
  border:1px solid var(--border);
  box-shadow:none;
  color:var(--text);
}

.btn.ghost:hover{
  background:var(--panel2);
  box-shadow:0 10px 22px rgba(0,0,0,.18);
}

.btn.danger{ background:var(--danger); color:#fff; }

.btn.small{
  padding:7px 10px;
  border-radius:.9rem;
  font-size:.82rem;
  min-height:36px;
}

.mini{
  padding:7px 10px; border-radius:.85rem;
  border:1px solid var(--border); background:transparent; color:var(--text);
  cursor:pointer; font-size:.78rem; font-weight:800;
}

.mini:hover{ background:var(--panel2); }

.helpBox,.status,.errorBox,.filterInfo{
  margin-top:10px;
  padding:10px 12px;
  border-radius:1rem;
  border:1px solid var(--border);
  font-size:.82rem;
  line-height:1.35;
}

.helpBox{ background:rgba(255,255,255,.03); color:var(--muted); }
body.theme-light .helpBox{ background:rgba(0,0,0,.03); }

.status{ color:var(--muted); min-height:1.2em; }

.status.bad,.errorBox{
  color:var(--danger);
  background:rgba(227,66,66,.10);
  border-color:rgba(227,66,66,.5);
}

.errorBox{ display:none; }

.filterInfo{
  background:rgba(255,255,255,.03);
  color:var(--muted);
}

body.theme-light .filterInfo{
  background:rgba(0,0,0,.03);
}

.infoGrid{
  display:grid;
  grid-template-columns:170px 1fr;
  gap:8px 10px;
}

.infoLbl{ color:var(--muted); font-size:.78rem; }

.infoVal{
  font-weight:900;
  border:1px solid var(--border);
  border-radius:.8rem;
  padding:8px 10px;
  background:var(--panel2);
  min-height:40px;
}

.multiline{ white-space:pre-wrap; }

.sectionBtnRow{
  margin-top:18px;
  padding-top:4px;
}

.stackPanels{
  display:flex;
  flex-direction:column;
  gap:16px;
}

.subSection{
  border:1px solid var(--border);
  border-radius:1rem;
  padding:12px;
  background:rgba(255,255,255,.03);
}

body.theme-light .subSection{ background:rgba(0,0,0,.03); }

.subSectionHead{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
  flex-wrap:wrap;
  margin-bottom:10px;
}

.subSectionHead h3{
  margin:0;
  font-size:.88rem;
  letter-spacing:.04em;
  text-transform:uppercase;
}

.tariffRangeRow{
  display:flex;
  gap:12px;
  flex-wrap:nowrap;
  align-items:flex-end;
}

.tariffRangeRow label{ min-width:180px; }

.periodControlGrid{
  display:grid;
  grid-template-columns:repeat(4, minmax(0, 1fr));
  gap:10px 12px;
}

.periodMatrixWrap{ margin-top:12px; }
.periodHintBox{ margin-top:12px; }

.periodMatrix{
  width:100%;
  border-collapse:collapse;
  table-layout:fixed;
}

.periodMatrix th,
.periodMatrix td{
  padding:11px 10px;
  border-bottom:1px solid rgba(148,163,184,.22);
  font-size:.84rem;
  vertical-align:bottom;
}

body.theme-light .periodMatrix th,
body.theme-light .periodMatrix td{
  border-bottom:1px solid rgba(148,119,81,.22);
}

.periodMatrix th{
  text-align:left;
  font-size:.72rem;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:var(--muted);
  background:rgba(255,255,255,.03);
}

body.theme-light .periodMatrix th{ background:rgba(0,0,0,.03); }

.periodMatrix .num{ text-align:right; font-variant-numeric:tabular-nums; }

.periodMatrix .valueBottom{ vertical-align:bottom; font-weight:900; }
.periodMatrix .strongCell{ font-weight:950; }

.periodMatrix .summaryRow td{ background:rgba(255,255,255,.02); }
body.theme-light .periodMatrix .summaryRow td{ background:rgba(0,0,0,.02); }

.periodMatrix .summaryLabel{
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.05em;
  font-size:.76rem;
  font-weight:900;
}

.balance-positive{ color:var(--ok); }
.balance-negative{ color:var(--danger); }

.toolbar{
  display:grid;
  gap:10px 12px;
  margin-bottom:12px;
}

.toolbarReadings{
  grid-template-columns:1.2fr .9fr .9fr .9fr .9fr;
}

.advanceFilterGrid{
  display:grid;
  grid-template-columns:repeat(4, minmax(0, 1fr));
  gap:10px 12px;
  margin-bottom:12px;
}

.advanceConditional.isHidden{
  display:none;
}

.readingsBtnRow{
  justify-content:flex-start;
}

.tableWrap{
  border:1px solid var(--border);
  border-radius:1rem;
  overflow:auto;
  background:var(--panel);
}

table{
  width:100%;
  border-collapse:collapse;
  table-layout:fixed;
}

.col-date{ width:var(--col-date); }
.col-gas{ width:var(--col-gas); }
.col-power{ width:var(--col-power); }
.col-note{ width:var(--col-note); }
.col-actions{ width:var(--col-actions); }

.tariffTable{ table-layout:auto; min-width:820px; }

th,td{
  padding:10px 10px;
  border-bottom:1px solid rgba(148,163,184,.22);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-size:.82rem;
}

body.theme-light th, body.theme-light td{
  border-bottom:1px solid rgba(148,119,81,.22);
}

th{
  text-align:left;
  font-size:.72rem;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:var(--muted);
  background:rgba(255,255,255,.03);
}

body.theme-light th{ background:rgba(0,0,0,.03); }

td.num, th.num{ text-align:right; font-variant-numeric:tabular-nums; }

.rowActions{
  display:flex;
  gap:6px;
  justify-content:flex-end;
  flex-wrap:nowrap;
}

.rowBtn{
  padding:6px 8px;
  border-radius:.75rem;
  border:1px solid var(--border);
  background:transparent;
  color:var(--text);
  cursor:pointer;
  font-size:.74rem;
  font-weight:900;
}

.rowBtn:hover{ background:var(--panel2); }

.rowBtn.danger:hover{
  background:rgba(227,66,66,.18);
  border-color:rgba(227,66,66,.6);
}

.readonlyDays{
  display:inline-block;
  min-width:28px;
  font-weight:900;
}

.kpiGrid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
}

.kpiCard{ padding:12px; }

.kpiCard .k{
  display:block;
  font-size:.74rem;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.06em;
}

.kpiCard .v{
  display:block;
  margin-top:6px;
  font-weight:950;
  font-size:1rem;
  font-variant-numeric:tabular-nums;
}

.analyticsBlock{
  display:flex;
  flex-direction:column;
  gap:16px;
  margin-top:12px;
}

.analyticsFilterPanel{
  border:1px solid var(--border);
  border-radius:1rem;
  padding:12px;
  background:rgba(255,255,255,.03);
}

body.theme-light .analyticsFilterPanel{
  background:rgba(0,0,0,.03);
}

.analyticsFilterGrid{
  display:grid;
  grid-template-columns:minmax(220px, 320px);
  gap:10px 12px;
}

.checksHead{
  display:flex;
  justify-content:space-between;
  gap:8px;
  align-items:baseline;
  margin:2px 0 8px;
}

.yearChecksWrap{ margin-top:10px; }

.yearChecks{
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(110px, 1fr));
  gap:8px;
}

.yearCheck{
  display:flex;
  align-items:center;
  gap:8px;
  padding:8px 10px;
  border:1px solid var(--border);
  border-radius:.85rem;
  background:rgba(0,0,0,.08);
}

body.theme-light .yearCheck{ background:rgba(0,0,0,.03); }

.yearCheck input[type="checkbox"]{
  width:16px;
  height:16px;
  min-width:16px;
  margin:0;
  padding:0;
  box-shadow:none;
  transform:none;
}

.analyticsGrid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:16px;
}

.analyticsYearCompareGrid{
  display:grid;
  grid-template-columns:1fr;
  gap:16px;
}

.chartCard{
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.chartTitle{
  font-size:.76rem;
  text-transform:uppercase;
  letter-spacing:.08em;
  color:var(--muted);
  font-weight:900;
}

.barChart,.compareChart{
  display:flex;
  gap:10px;
  align-items:flex-end;
  min-height:210px;
  padding:10px 4px 2px;
  overflow-x:auto;
}

.compareChartTall{
  min-height:260px;
}

.barItem{
  min-width:58px;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
}

.barCols{
  width:100%;
  height:170px;
  display:flex;
  align-items:flex-end;
  justify-content:center;
  gap:6px;
}

.barSingle,.barDualA,.barDualB{
  border-radius:10px 10px 4px 4px;
  min-width:18px;
}

.barSingle{
  width:28px;
  background:var(--line-power);
}

.barGas{ background:var(--line-gas); }
.barPower{ background:var(--line-power); }

.barDualA,.barDualB{ width:16px; }
.barDualA{ background:var(--line-power); }
.barDualB{ background:var(--line-gas); }

.barLabel{
  font-size:.74rem;
  color:var(--muted);
  text-align:center;
}

.barValue{
  font-size:.74rem;
  font-weight:900;
  text-align:center;
}

.lineChart{
  width:100%;
  height:180px;
  display:block;
  border:1px solid var(--border);
  border-radius:1rem;
  background:rgba(0,0,0,.04);
}

body.theme-light .lineChart{ background:rgba(0,0,0,.02); }

.shareBox{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
}

.shareCard{ padding:12px; }

.shareBar{
  margin-top:8px;
  height:12px;
  border-radius:999px;
  overflow:hidden;
  background:rgba(255,255,255,.08);
}

body.theme-light .shareBar{ background:rgba(0,0,0,.08); }

.shareFillA,.shareFillB{
  height:100%;
  float:left;
}

.shareFillA{ background:var(--line-power); }
.shareFillB{ background:var(--accent); }

.statsList{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.statItem{ padding:12px; }

.statItem .sTitle{
  font-size:.75rem;
  text-transform:uppercase;
  letter-spacing:.08em;
  color:var(--muted);
}

.statItem .sVal{
  margin-top:6px;
  font-weight:950;
  font-size:1rem;
}

.diffPositive{
  color:var(--ok);
  font-weight:900;
}

.diffNegative{
  color:var(--danger);
  font-weight:900;
}

dialog{
  border:none;
  border-radius:1.2rem;
  padding:0;
  width:min(760px, calc(100vw - 20px));
  max-width:calc(100vw - 20px);
  background:var(--panel);
  color:var(--text);
  box-shadow:0 24px 70px rgba(0,0,0,.55);
}

dialog::backdrop{ background:rgba(0,0,0,.55); }

.dlgHead,.dlgFoot{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:10px;
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  flex-wrap:wrap;
}

.dlgHead{ justify-content:space-between; }
.dlgHead h3{ margin:0; font-size:1rem; font-weight:950; }

.dlgBody{
  padding:12px 14px;
  max-height:70vh;
  overflow-y:auto;
}

.dlgFoot{
  border-top:1px solid var(--border);
  border-bottom:none;
}

.isCollapsedSection{ display:none !important; }

@media (max-width:1400px){
  .layout{ grid-template-columns:1fr; }
  .panel.half{ grid-column:1; }
  .analyticsGrid{ grid-template-columns:1fr; }
  .providerGrid{ grid-template-columns:1fr; }
  .periodControlGrid{ grid-template-columns:repeat(2, minmax(0, 1fr)); }
  .toolbarReadings{ grid-template-columns:repeat(2, minmax(0, 1fr)); }
  .advanceFilterGrid{ grid-template-columns:repeat(2, minmax(0, 1fr)); }
}

@media (max-width:1100px){
  .tariffsHead{
    flex-wrap:wrap;
    align-items:flex-start;
  }

  .tariffsTitleRow{
    width:100%;
    flex-wrap:wrap;
    align-items:flex-start;
  }

  .tariffRangeRow{ flex-wrap:wrap; }

  .tariffsHeadActions{
    width:100%;
    margin-left:0;
    justify-content:flex-start;
  }
}

@media (max-width:980px){
  .grid{ grid-template-columns:1fr; }
  .kpiGrid,.shareBox{ grid-template-columns:1fr; }
  .right{ width:100%; align-items:flex-start; }
  .actions,.headActions,.btnRow,.btnCluster{ width:100%; }
  .actions .btn,.actions label.btn,.btnRow .btn,.btnCluster .btn,.headActions .btn{ flex:1 1 calc(50% - 8px); }
  .infoGrid{ grid-template-columns:1fr; }
  .periodControlGrid{ grid-template-columns:1fr; }
  .toolbarReadings{ grid-template-columns:1fr; }
  .advanceFilterGrid{ grid-template-columns:1fr; }
}

@media (max-width:760px){
  .periodMatrix{ min-width:980px; }
  .yearChecks{ grid-template-columns:repeat(2, minmax(0, 1fr)); }
}

@media (max-width:620px){
  body{ padding:10px; }
  .shell{ padding:10px; border-radius:1rem; }
  h1{ font-size:1.3rem; }
  .subtitle{ font-size:.84rem; }
  .panel{ padding:12px 12px 14px; border-radius:1.05rem; }
  .actions .btn,.actions label.btn,.btnRow .btn,.btnCluster .btn,.headActions .btn{ flex:1 1 100%; }
  .dlgFoot{ flex-direction:column-reverse; align-items:stretch; }
  .dlgFoot .btn{ width:100%; }
}