:root {
  --bg: #f3f6fb;
  --bg-elev: #ffffff;
  --bg-soft: #eef3f9;
  --line: #d7e0ec;
  --text: #1b2433;
  --muted: #66758b;
  --accent: #0f9d8a;
  --accent-2: #2563eb;
  --income: #0f9d8a;
  --loss: #dc3d62;
  --shadow: 0 10px 30px rgba(27, 36, 51, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: "IBM Plex Sans", sans-serif;
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(15, 157, 138, 0.08), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(37, 99, 235, 0.08), transparent 50%),
    var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.03em; }

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  border-radius: 10px;
  box-shadow: 0 0 0 4px rgba(15, 157, 138, 0.08);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.lede {
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 28px;
}

.nav-btn, .btn, .icon-btn, select, input, button { font: inherit; }

.nav-btn {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
}

.nav-btn.is-active,
.nav-btn:hover {
  color: var(--text);
  background: var(--bg-soft);
  border-color: var(--line);
}

.main { padding: 32px 36px 64px; }

.panel { display: none; }
.panel.is-visible { display: block; }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 22px;
}

.year-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

.pill strong {
  color: var(--text);
  margin-left: 8px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-card {
  padding: 20px;
  margin-bottom: 20px;
}

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

.field { display: grid; gap: 6px; }
.field-wide { grid-column: 1 / -1; }

.field span {
  font-size: 12px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-color: #fff;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%2366758b' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 17px center;
  background-size: 12px 8px;
  padding-right: 36px;
}

input:focus, select:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

input[readonly] {
  color: var(--accent);
  font-family: "IBM Plex Mono", monospace;
}

.calc-line {
  margin: 0;
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--accent);
  font-family: "IBM Plex Mono", monospace;
  font-size: 16px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  font-family: "IBM Plex Mono", monospace;
}

.btn {
  margin-top: 8px;
  border: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.btn:hover { filter: brightness(1.08); }

.block-title {
  margin: 8px 0 12px;
  font-size: 15px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

.chart-card {
  padding: 18px 18px 10px;
  margin-bottom: 20px;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.chart-head h3 {
  font-size: 16px;
}

.chart-legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

.legend::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
}

.legend.income::before { background: var(--income); }
.legend.ozon::before { background: #1d4ed8; }
.legend.wb::before { background: #b57edc; }
.legend.yandex::before { background: #f5c400; }
.legend.spend::before { background: var(--loss); }
.legend.tax::before { background: #f59e0b; }
.legend.power::before { background: var(--accent-2); }

.chart-legend {
  flex-wrap: wrap;
}

.chart-wrap {
  position: relative;
}

#yearChart {
  display: block;
  width: 100%;
  height: 280px;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 180px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  font-family: "IBM Plex Sans", sans-serif;
  pointer-events: none;
  transform: translate(-50%, -110%);
}

.chart-tooltip b {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
}

.chart-tooltip .tip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0;
  color: var(--muted);
}

.chart-tooltip .tip-title {
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--text);
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.month-card {
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.month-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.month-card h3 {
  margin-bottom: 12px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 14px;
  color: var(--accent-2);
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  margin: 6px 0;
  color: var(--muted);
}

.stat b {
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 500;
}

.profit {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-weight: 600;
  font-family: "IBM Plex Mono", monospace;
}

.profit.positive { color: var(--income); }
.profit.negative { color: var(--loss); }

.table-wrap { overflow: auto; }

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

th, td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 500;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

td.mono { font-family: "IBM Plex Mono", monospace; }

.empty {
  padding: 28px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-family: "IBM Plex Mono", monospace;
  border: 1px solid var(--line);
}

.badge.income { color: var(--income); border-color: rgba(62, 224, 197, 0.35); }
.badge.spend { color: var(--loss); border-color: rgba(255, 107, 138, 0.35); }
.badge.util { color: var(--accent-2); border-color: rgba(79, 140, 255, 0.35); }

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.ghost:hover {
  color: var(--text);
  border-color: var(--text);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.check span {
  color: var(--text);
  font-family: "IBM Plex Sans", sans-serif;
}

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

.ghost.receipt:hover,
a.ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.ghost.danger:hover {
  color: var(--loss);
  border-color: var(--loss);
}

.dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: var(--bg-elev);
  color: var(--text);
}

.dialog::backdrop { background: rgba(27, 36, 51, 0.35); }

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 0;
}

#dialogBody { padding: 8px 20px 24px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 22px;
}

.breakdown {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin: 12px 0 18px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  padding: 28px;
  display: grid;
  gap: 14px;
}

.login-card .btn { margin-top: 4px; width: 100%; }

.login-error { color: var(--loss); }

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding: 22px 16px 48px; }
  .form-grid, .breakdown { grid-template-columns: 1fr; }
  .panel-head,
  .chart-head { flex-direction: column; align-items: flex-start; }
}
