/* ЭнергоУчёт — стили веб-кабинета */
:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #fcfcfb;
  --surface-2: #f1f1ee;
  --surface-3: #e8e8e3;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: rgba(42, 120, 214, 0.10);
  --sidebar: #12161d;
  --sidebar-ink: #c9ccd2;
  --sidebar-active: rgba(255, 255, 255, 0.08);

  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;

  --good: #0ca30c; --good-ink: #006300;
  --warning: #fab219; --warning-ink: #8a5a00;
  --serious: #ec835a;
  --critical: #d03b3b; --critical-ink: #b42323;
  --good-bg: rgba(12, 163, 12, 0.10);
  --warning-bg: rgba(250, 178, 25, 0.16);
  --critical-bg: rgba(208, 59, 59, 0.10);

  --res-electric: #eda100;
  --res-cold_water: #2a78d6;
  --res-gas: #eb6834;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.18);
    --text: #ffffff; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: rgba(57, 135, 229, 0.16);
    --sidebar: #111110; --sidebar-active: rgba(255, 255, 255, 0.07);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-ink: #0ca30c; --warning-ink: #fab219; --critical-ink: #e66767;
    --good-bg: rgba(12, 163, 12, 0.16); --warning-bg: rgba(250, 178, 25, 0.14); --critical-bg: rgba(208, 59, 59, 0.18);
    --res-electric: #c98500; --res-cold_water: #3987e5; --res-gas: #d95926;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.18);
  --text: #ffffff; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: rgba(57, 135, 229, 0.16);
  --sidebar: #111110; --sidebar-active: rgba(255, 255, 255, 0.07);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-ink: #0ca30c; --warning-ink: #fab219; --critical-ink: #e66767;
  --good-bg: rgba(12, 163, 12, 0.16); --warning-bg: rgba(250, 178, 25, 0.14); --critical-bg: rgba(208, 59, 59, 0.18);
  --res-electric: #c98500; --res-cold_water: #3987e5; --res-gas: #d95926;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }
.mono { font-family: Consolas, "SF Mono", monospace; }

/* ---------- вход ---------- */
.login-screen { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent), var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.login-logo { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; }
.login-title { font-size: 20px; font-weight: 700; }
.login-sub { color: var(--muted); font-size: 13px; }
.login-card label { font-size: 12px; color: var(--text-2); margin: 10px 0 4px; }
.login-error { color: var(--critical-ink); min-height: 20px; margin: 8px 0; font-size: 13px; }

/* ---------- каркас ---------- */
.app { display: flex; min-height: 100%; }
.sidebar { width: 232px; flex: 0 0 232px; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; }
.brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: #8b9099; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7079; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-ink);
  text-decoration: none; font-size: 13.5px; margin-bottom: 1px; }
.nav a svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: 0.75; }
.nav a:hover { background: var(--sidebar-active); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav a.active svg { opacity: 1; }
.nav .badge { margin-left: auto; }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, 0.07); padding: 12px; }
.user-box { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #2b313b; color: #fff; display: grid; place-items: center;
  font-weight: 600; font-size: 13px; }
.user-meta { font-size: 12.5px; color: #e4e6ea; min-width: 0; }
.user-meta > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-actions { display: flex; gap: 4px; }
.sidebar .icon-btn { color: var(--sidebar-ink); }
.sidebar .icon-btn:hover { background: var(--sidebar-active); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  min-height: 60px; flex-wrap: wrap; }
.topbar h1 { font-size: 18px; margin-right: auto; }
.topbar-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.menu-btn { display: none; }
.content { padding: 20px 24px 48px; max-width: 1480px; width: 100%; }

/* ---------- элементы ---------- */
.icon-btn { background: none; border: 0; width: 32px; height: 32px; border-radius: 8px; display: inline-grid; place-items: center;
  cursor: pointer; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 14px; font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap; text-decoration: none; line-height: 1.3; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-danger { color: var(--critical-ink); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; padding: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-ghost { border-color: transparent; background: none; }
.btn-ghost:hover { background: var(--surface-3); }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; font: inherit; font-weight: 550; color: var(--text-2);
  cursor: pointer; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.seg .dot { width: 8px; height: 8px; border-radius: 50%; }

.period-picker { display: inline-flex; align-items: center; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 9px; height: 34px; }
.period-picker button { border: 0; background: none; width: 30px; height: 100%; cursor: pointer; color: var(--text-2); font-size: 16px; }
.period-picker button:hover { color: var(--text); background: var(--surface-2); }
.period-picker input { border: 0; height: 100%; padding: 0 4px; width: 132px; text-align: center; font-weight: 600; background: none; }
.period-picker input:focus { outline: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; flex-wrap: wrap; }
.card-h h2 { margin-right: auto; }
.card-b { padding: 14px 16px 16px; }
.card-sub { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 6px; }

.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mb { margin-bottom: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* плитки */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { color: var(--text-2); font-size: 12.5px; display: flex; gap: 6px; align-items: center; }
.tile-value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -0.02em; white-space: nowrap; }
.tile-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.tile-foot { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta { font-weight: 600; }
.delta.up { color: var(--critical-ink); }
.delta.down { color: var(--good-ink); }
.delta.flat { color: var(--muted); }
.progress { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 3px; }

/* статусы */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good-ink); }
.badge.warn { background: var(--warning-bg); color: var(--warning-ink); }
.badge.bad { background: var(--critical-bg); color: var(--critical-ink); }
.badge.info { background: var(--accent-soft); color: var(--accent-ink); }
.badge svg { width: 12px; height: 12px; }
.res-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border-strong);
  background: var(--surface); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tr.group td { background: var(--surface-2); font-weight: 650; font-size: 12.5px; color: var(--text-2); padding-top: 10px; }
.tbl tr.total td { font-weight: 650; border-top: 1px solid var(--border-strong); background: var(--surface-2); }
.tbl tr.clickable { cursor: pointer; }
.tbl .sub { color: var(--muted); font-size: 12px; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl-scroll { max-height: calc(100vh - 230px); overflow: auto; }

/* ввод показаний */
.entry-input { width: 120px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; padding: 5px 8px; }
.entry-input.saved { border-color: color-mix(in srgb, var(--good) 60%, transparent); }
.entry-input.warn { border-color: var(--warning); background: var(--warning-bg); }
.entry-input.bad { border-color: var(--critical); background: var(--critical-bg); }
.entry-input.saving { opacity: 0.6; }
tr.row-warn td { background: color-mix(in srgb, var(--warning) 6%, transparent); }
.warn-text { color: var(--warning-ink); font-size: 12px; margin-top: 3px; }
.bad-text { color: var(--critical-ink); font-size: 12px; margin-top: 3px; }

/* графики */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 200px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 2px; border-radius: 1px; width: 14px; }

/* тепловая карта */
.heat { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
.heat th { font-weight: 500; color: var(--muted); padding: 4px; white-space: nowrap; font-size: 11px; }
.heat th.rowh { text-align: left; color: var(--text); font-weight: 500; font-size: 12.5px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.heat td { min-width: 52px; height: 28px; text-align: center; border-radius: 4px; font-variant-numeric: tabular-nums; cursor: default; font-size: 11px; }
.heat td:hover { outline: 2px solid var(--text); outline-offset: -1px; }
.heat td.empty { background: var(--surface-2); color: var(--muted); }
.scale { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
.scale .bar { width: 160px; height: 8px; border-radius: 4px; }

/* списки уведомлений */
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.alert-list li:last-child { border-bottom: 0; }
.alert-list .ic { flex: 0 0 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; }
.alert-list .ic svg { width: 14px; height: 14px; }
.alert-list .ic.warn { background: var(--warning-bg); color: var(--warning-ink); }
.alert-list .ic.bad { background: var(--critical-bg); color: var(--critical-ink); }
.alert-list .ic.info { background: var(--accent-soft); color: var(--accent-ink); }
.empty-state { text-align: center; color: var(--muted); padding: 32px 16px; }
.empty-state svg { width: 36px; height: 36px; opacity: 0.5; margin-bottom: 8px; }

/* балансы зданий */
.bal-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.bal-row:last-child { border-bottom: 0; }
.bal-bar { grid-column: 1 / -1; display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface-3); }
.bal-bar div { height: 100%; }
.bal-bar div:first-child { border-radius: 5px 0 0 5px; }
.bal-bar div:last-child { border-radius: 0 5px 5px 0; }

/* модальные окна */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; z-index: 100; padding: 16px;
  animation: fade 0.12s ease-out; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex;
  flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); border: 1px solid var(--border); }
.modal.wide { max-width: 860px; }
.modal-h { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-h h2 { font-size: 16px; margin-right: auto; }
.modal-b { padding: 16px 20px; overflow-y: auto; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .field > .label { font-size: 12px; color: var(--text-2); font-weight: 550; }
.field .hint { font-size: 11.5px; color: var(--muted); }
.form-section { grid-column: 1 / -1; font-weight: 650; font-size: 13px; padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px; }
.check-row { display: flex; gap: 8px; align-items: center; }

/* уведомления */
.toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 13px; max-width: 380px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); animation: fade 0.15s; }
.toast.error { background: var(--critical); color: #fff; }

/* вкладки */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.photo-thumb { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; cursor: zoom-in; vertical-align: middle; border: 1px solid var(--border); }
.photo-full { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 8px; }

.loading { padding: 48px; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2px solid var(--surface-3); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.chart-tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15); z-index: 50; min-width: 140px;
  transition: opacity 0.08s; }
.chart-tooltip .tt-title { font-weight: 650; margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chart-tooltip .tt-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.chart-tooltip .tt-row b { font-variant-numeric: tabular-nums; font-weight: 600; }
.chart-tooltip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* адаптив */
@media (max-width: 1100px) {
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-21 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.open { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 25; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .g-2, .g-3 { grid-template-columns: minmax(0, 1fr); }
  .form { grid-template-columns: minmax(0, 1fr); }
  .tile-value { font-size: 20px; }
  .hide-sm { display: none !important; }
}
@media print {
  .sidebar, .topbar-tools, .menu-btn { display: none !important; }
  .topbar { position: static; }
  body { background: #fff; }
}
