:root {
  color-scheme: light;
  --paper: oklch(0.985 0.010 96);
  --surface: oklch(0.965 0.014 96);
  --panel: oklch(0.997 0.006 96);
  --ink: oklch(0.205 0.034 88);
  --muted: oklch(0.52 0.030 86);
  --line: oklch(0.885 0.018 92);
  --green: oklch(0.48 0.120 154);
  --red: oklch(0.54 0.150 32);
  --amber: oklch(0.63 0.130 72);
  --blue: oklch(0.47 0.085 238);
  --shadow: 0 18px 42px color-mix(in oklch, var(--ink) 10%, transparent);
  --r: 8px;
  --gap: clamp(14px, 1.8vw, 24px);
  font-family: ui-sans-serif, "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: linear-gradient(180deg, var(--paper), var(--surface));
  color: var(--ink);
  min-height: 100vh;
}

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

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card h1 { margin: 12px 0; }
.login-card p { color: var(--muted); }
.auth-status {
  padding: 10px 12px;
  border: 1px solid color-mix(in oklch, var(--green) 30%, var(--line));
  border-radius: var(--r);
  background: color-mix(in oklch, var(--green) 9%, var(--panel));
  color: var(--green) !important;
  font-weight: 700;
}
.auth-error {
  padding: 10px 12px;
  border: 1px solid color-mix(in oklch, var(--red) 34%, var(--line));
  border-radius: var(--r);
  background: color-mix(in oklch, var(--red) 9%, var(--panel));
  color: var(--red) !important;
  font-weight: 700;
}
.telegram-webapp .telegram-login-widget { display: none; }
.bot-login-button { width: 100%; margin: 8px 0 10px; }

a { color: inherit; text-decoration: none; }

button, input, select, textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: var(--r);
  padding: 0 16px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease;
}

button:hover { transform: translateY(-1px); background: color-mix(in oklch, var(--ink) 88%, var(--green)); }
button:disabled, input:disabled, select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in oklch, var(--blue) 55%, transparent);
  outline-offset: 2px;
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: color-mix(in oklch, var(--panel) 88%, var(--paper));
  color: var(--ink);
  padding: 10px 12px;
}

textarea { resize: vertical; min-height: 108px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: color-mix(in oklch, var(--panel) 78%, var(--paper));
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-weight: 800;
}

.brand strong { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }

.nav { display: grid; gap: 6px; }
.nav a {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: var(--r);
  color: var(--muted);
}
.nav a:hover, .nav a.active {
  background: color-mix(in oklch, var(--green) 11%, transparent);
  color: var(--ink);
}

.main {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 2.4vw, 34px);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr minmax(320px, 520px);
  gap: var(--gap);
  align-items: end;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2 { margin: 0; line-height: 1.08; letter-spacing: 0; }
h1 { font-size: clamp(32px, 4vw, 54px); }
h2 { font-size: 18px; }

.quick-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.metric-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.5fr) repeat(3, minmax(180px, 1fr));
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.metric, .panel, .account-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.metric {
  padding: 20px;
  min-height: 142px;
  display: grid;
  align-content: space-between;
}

.metric span, .account-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  font-size: clamp(26px, 3vw, 42px);
  line-height: 1;
  margin: 12px 0 10px;
}

.metric small { color: var(--muted); }
.metric.primary { border-color: color-mix(in oklch, var(--green) 34%, var(--line)); }
.metric.danger strong { color: var(--red); }
.metric.success strong { color: var(--green); }

.two-col, .work-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.work-grid { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.wide { grid-column: 1 / -1; }

.panel { padding: 18px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.panel-head a { color: var(--green); font-size: 14px; font-weight: 700; }

.list { display: grid; gap: 8px; }
.row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid color-mix(in oklch, var(--line) 72%, transparent);
}
.row:last-child { border-bottom: 0; }
.row small { display: block; color: var(--muted); margin-top: 2px; }
.row.warn strong { color: var(--amber); }

.muted { color: var(--muted); font-size: 13px; }

.chart-bars {
  height: 190px;
  display: flex;
  align-items: end;
  gap: 8px;
  padding-top: 16px;
}

.bar-day {
  flex: 1;
  min-width: 18px;
  height: 160px;
  display: grid;
  grid-template-rows: 1fr auto;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  align-items: end;
}

.bar-day span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.bar-day i {
  min-height: 2px;
  border-radius: 4px 4px 0 0;
}

.income-bar { background: var(--green); }
.expense-bar { background: var(--red); }

.chart-list {
  display: grid;
  gap: 12px;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  position: relative;
  padding-bottom: 10px;
}

.category-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-row strong { white-space: nowrap; }

.category-row i {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 99px;
  background: var(--red);
}

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}
th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}
.num { text-align: right; white-space: nowrap; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 99px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
  background: color-mix(in oklch, var(--muted) 12%, transparent);
}
.pill.income, .pill.incoming { color: var(--green); background: color-mix(in oklch, var(--green) 12%, transparent); }
.pill.expense, .pill.outgoing { color: var(--red); background: color-mix(in oklch, var(--red) 11%, transparent); }
.pill.transfer, .pill.split_bill { color: var(--blue); background: color-mix(in oklch, var(--blue) 10%, transparent); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}
.form-stack { display: grid; gap: 12px; }
.check {
  grid-template-columns: auto 1fr;
  align-items: center;
}
.check input { width: 18px; min-height: 18px; }

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--gap);
}
.account-card {
  min-height: 158px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}
.account-card h2 { margin-top: 8px; }
.account-card strong { font-size: 28px; }
.account-card.credit_card strong { color: var(--red); }

.chip-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip-cloud span {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 0 11px;
  background: color-mix(in oklch, var(--surface) 62%, var(--panel));
  color: var(--muted);
  font-size: 13px;
}

.settings {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px 14px;
  margin: 0 0 16px;
}
.settings dt { color: var(--muted); }
.settings dd { margin: 0; overflow-wrap: anywhere; }

.empty, .empty-cell { color: var(--muted); }
.empty-cell { text-align: center; padding: 32px; }
.flash {
  margin: -8px 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px 14px;
  background: color-mix(in oklch, var(--green) 10%, var(--panel));
}
.flash.error { background: color-mix(in oklch, var(--red) 10%, var(--panel)); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 920px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .topbar, .metric-grid, .two-col { grid-template-columns: 1fr; }
  .quick-add { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
