:root {
  --bg: #0b0d12;
  --bg-2: #10131a;
  --surface: #151924;
  --surface-2: #1c2130;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #eef1f7;
  --muted: #8a92a6;
  --faint: #5c6478;

  --home: #8b9cff;
  --gas: #ff8a3d;
  --water: #3ec5ff;
  --power: #ffd23f;
  --ok: #3ddc97;
  --warn: #ffb547;
  --bad: #ff6b6b;

  --accent: var(--home);
  --radius: 22px;
  --radius-sm: 14px;
  --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  color-scheme: dark;
}

body[data-theme="gas"] { --accent: var(--gas); }
body[data-theme="water"] { --accent: var(--water); }
body[data-theme="power"] { --accent: var(--power); }
body[data-theme="ok"] { --accent: var(--ok); }

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
}

/* Мягкое свечение сверху в цвет текущего раздела */
body::before {
  content: '';
  position: fixed;
  inset: -30vh -20vw auto;
  height: 70vh;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 22%, transparent), transparent);
  opacity: 0.55;
  pointer-events: none;
  transition: background 0.5s ease;
  z-index: 0;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.ico {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 20px) 18px calc(var(--safe-b) + 28px);
  min-height: 100dvh;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 48px);
  animation: enter 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
}

/* ---------- typography ---------- */

.h1 { margin: 0; font-size: 34px; line-height: 1.1; font-weight: 800; letter-spacing: -0.02em; }
.h2 { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 800; letter-spacing: -0.01em; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  width: 100%;
  padding: 14px 20px;
  border: 1px solid transparent;
  border-radius: 18px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  text-wrap: balance;
  transition: transform 0.12s ease, background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.7; cursor: default; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #0b0d12;
  box-shadow: 0 10px 30px -12px color-mix(in srgb, var(--accent) 70%, transparent);
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--line-strong);
}

.btn-ghost:hover { background: var(--surface-2); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}

.icon-btn.small { width: 38px; height: 38px; border-radius: 12px; }
.icon-btn:disabled { opacity: 0.3; cursor: default; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- chips & badges ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.chip .ico { width: 16px; height: 16px; }
.chip.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }

.badge-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 22px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

.badge-icon .ico { width: 30px; height: 30px; }
.badge-icon.ok { --accent: var(--ok); }
.badge-icon.bad { --accent: var(--bad); }
.badge-icon.big { width: 88px; height: 88px; border-radius: 30px; }
.badge-icon.big .ico { width: 42px; height: 42px; stroke-width: 2.4; }

.center-stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.center-stack .actions, .center-stack .total-card { width: 100%; }

/* ---------- loader ---------- */

.loader { display: flex; gap: 8px; }
.loader span {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1s infinite ease-in-out;
}
.loader span:nth-child(2) { animation-delay: 0.15s; }
.loader span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.spinner {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- home ---------- */

.home-head { padding: 22px 4px 6px; }

.total-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 22px;
  border-radius: var(--radius);
  background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 16%, var(--surface)), var(--surface) 70%);
  border: 1px solid var(--line);
  text-align: left;
}

.total-sum { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.total-sum.muted { font-size: 17px; font-weight: 600; }

.mini-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.mini {
  --c: var(--home);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.mini[data-kind="gas"] { --c: var(--gas); }
.mini[data-kind="water"] { --c: var(--water); }
.mini[data-kind="power"] { --c: var(--power); }

.mini-icon {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 12px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
}

.mini-label { font-size: 13px; font-weight: 700; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini.is-done .mini-label { color: var(--text); }

.mini-state {
  position: absolute;
  top: 12px; right: 12px;
  color: var(--ok);
}

.mini-state .ico { width: 18px; height: 18px; stroke-width: 2.6; }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding-top: 8px; }

.last-month {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-radius: 18px;
  border: 1px dashed var(--line-strong);
  background: transparent;
  text-align: left;
  color: var(--muted);
}

.last-month > span { display: flex; flex-direction: column; }
.last-sum { color: var(--text); font-weight: 700; font-size: 17px; }

/* ---------- step ---------- */

.step-form { display: flex; flex-direction: column; gap: 16px; flex: 1; }

.topbar { display: flex; align-items: center; gap: 14px; }
.topbar-spacer { width: 44px; flex: none; }

.progress { flex: 1; display: flex; gap: 6px; }
.progress span { flex: 1; height: 5px; border-radius: 3px; background: var(--surface-2); transition: background 0.3s; }
.progress .past { background: color-mix(in srgb, var(--accent) 45%, var(--surface-2)); }
.progress .now { background: var(--accent); }

.step-count { color: var(--muted); font-weight: 700; font-size: 14px; min-width: 28px; text-align: right; }

.step-hero { display: flex; align-items: center; gap: 16px; padding: 12px 2px 4px; }

.hero-icon {
  display: grid;
  place-items: center;
  width: 64px; height: 64px;
  border-radius: 22px;
  flex: none;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

.hero-icon .ico { width: 32px; height: 32px; }

.meter-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

.meter-title { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 18px; font-weight: 800; }
.meter-title .ico { color: var(--accent); }

.prev-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
}

.prev-val { font-size: 20px; font-weight: 700; }
.prev-val small, .unit { color: var(--muted); font-weight: 600; font-size: 14px; margin-left: 5px; }

.input-wrap { position: relative; display: block; }

.reading {
  width: 100%;
  height: 76px;
  padding: 0 70px 0 20px;
  border-radius: 18px;
  border: 2px solid var(--line-strong);
  background: var(--bg-2);
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.02em;
  caret-color: var(--accent);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.reading::placeholder { color: var(--faint); font-size: 18px; font-weight: 600; letter-spacing: 0; }

.reading:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 16%, transparent);
}

.reading.invalid { border-color: var(--bad); }

.unit {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  margin: 0;
}

.delta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: -2px 4px 0;
  min-height: 22px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.delta.good b { color: var(--accent); }
.delta.warn { color: var(--warn); }
.delta.bad { color: var(--bad); }

.form-msg { margin: 0; min-height: 0; font-size: 15px; font-weight: 600; }
.form-msg:empty { display: none; }
.form-msg.bad { color: var(--bad); }
.form-msg.warn {
  color: var(--warn);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
}

.bottom-bar {
  position: sticky;
  bottom: 0;
  margin: auto -18px calc(-28px - var(--safe-b));
  padding: 16px 18px calc(var(--safe-b) + 18px);
  display: flex;
  justify-content: center;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}

.btn-next { max-width: 320px; }

/* ---------- PIN ---------- */

.pin-form { max-width: 320px; margin: 0 auto; width: 100%; }

.pin-input {
  width: 100%;
  height: 68px;
  border-radius: 18px;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  text-align: center;
  font-size: 30px;
  letter-spacing: 0.4em;
  padding: 0 0 0 0.4em;
}

.pin-input:focus { outline: none; border-color: var(--accent); }
.field-msg { margin: 0; font-weight: 600; }
.field-msg.bad { color: var(--bad); }

/* ---------- info ---------- */

.month-switch { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; }
.month-name { font-weight: 800; font-size: 17px; min-width: 140px; text-align: center; }

.note {
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.group {
  --c: var(--home);
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

.group[data-kind="gas"] { --c: var(--gas); }
.group[data-kind="water"] { --c: var(--water); }
.group[data-kind="power"] { --c: var(--power); }
.group[data-kind="extra"] { --c: var(--muted); }

.group-head { display: flex; align-items: center; gap: 12px; }

.group-icon {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 12px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
}

.group-title { flex: 1; margin: 0; font-size: 17px; font-weight: 800; }
.group-sum { font-weight: 800; font-size: 17px; }

.usage-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.usage-label { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.usage-label .ico { width: 18px; height: 18px; color: var(--c); }
.usage-reading { text-align: right; color: var(--muted); font-size: 14px; }
.usage-amount { color: var(--c); font-weight: 700; }
.usage-cost { text-align: right; font-weight: 700; }
.usage-tariff { grid-column: 2; text-align: right; color: var(--faint); font-size: 12px; }
.usage-row.is-empty .usage-reading { font-style: italic; }

.extra-row {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.extra-row span:last-child { color: var(--text); font-weight: 700; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 100px);
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100% - 36px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  font-weight: 600;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.7);
  animation: enter 0.25s ease;
}

.toast.bad { border-color: color-mix(in srgb, var(--bad) 50%, transparent); color: var(--bad); }

@media (min-width: 600px) {
  .app { padding-top: calc(var(--safe-t) + 48px); }
}
