:root {
  --bg: #0b0e0f;
  --panel: #12181a;
  --panel-border: #223028;
  --field: #0d1412;
  --text: #d7ded9;
  --dim: #6c7a74;
  --accent: #39ff88;
  --accent-dim: #1f8a52;
  --accent-tint: rgba(57, 255, 136, 0.09);
  --neg: #ff6b5e;
  --neg-dim: #8a3a33;
  --neg-tint: rgba(255, 107, 94, 0.09);
  --pos: #39ff88;
  --mono: "JetBrains Mono", "Fira Code", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.accent { color: var(--accent); }
.dim { color: var(--dim); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

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

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--field);
  border: 1px solid var(--panel-border);
  padding: 1px 4px;
  border-radius: 3px;
  word-break: break-all;
}

/* ------------------------------------------------------------------ каркас */

.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: calc(24px + var(--safe-top)) 16px 60px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 16px;
  margin-bottom: 24px;
}

.prompt {
  font-weight: 600;
  color: var(--text);
  font-size: 16px;
}
.prompt:hover { text-decoration: none; }
.prompt .dim { color: var(--accent); }

.tabs { display: flex; gap: 18px; }
.tabs a { color: var(--dim); }
.tabs a.active, .tabs a:hover { color: var(--accent); text-decoration: none; }

footer {
  margin-top: 32px;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
footer .logout { margin: 0; }

/* ------------------------------------------------------------------ карточки */

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 20px;
}
.card.narrow { max-width: 480px; }

.card h2 {
  margin: 0 0 16px;
  font-size: 14px;
  font-weight: 600;
  text-transform: lowercase;
  color: var(--dim);
  letter-spacing: 0.02em;
}

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

.stat-label {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
  white-space: nowrap;
}
.stat-value.big { font-size: 34px; line-height: 1.2; }

.balance-card .wallets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--panel-border);
}
.wallet { display: flex; flex-direction: column; justify-content: space-between; }
.wallet-value { font-size: 16px; font-weight: 600; white-space: nowrap; }

.balance-hint {
  display: block;
  margin-top: 16px;
  font-size: 12px;
}
.balance-hint:hover { text-decoration: none; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.grid-2 .card { margin-bottom: 0; }

/* ------------------------------------------------------------------ категории */

.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "label value"
    "track track";
  row-gap: 5px;
  column-gap: 10px;
  font-size: 13px;
}
.bar-label { grid-area: label; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-value { grid-area: value; text-align: right; color: var(--dim); white-space: nowrap; }
.bar-track {
  grid-area: track;
  background: var(--field);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  height: 10px;
  overflow: hidden;
}
.bar-fill { background: var(--accent-dim); height: 100%; }

/* ------------------------------------------------------------------ операции */

.tx-list { display: flex; flex-direction: column; }

.tx {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
  padding: 8px 6px;
  margin: 0 -6px;
  border-bottom: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 3px;
}
.tx:last-child { border-bottom: none; }
.tx:hover { text-decoration: none; background: var(--accent-tint); }
.tx:active { background: var(--accent-tint); }

.tx-main { display: flex; flex-direction: column; min-width: 0; }
.tx-cat { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-size: 14px; font-weight: 600; white-space: nowrap; }

.summary { font-size: 13px; margin: -4px 0 12px; }

.day { margin-top: 18px; }
.day:first-of-type { margin-top: 0; }
.day-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--accent-dim);
}
.day-head .dim span { margin-left: 8px; }

/* ------------------------------------------------------------------ кнопки */

.btn, .btn-link {
  font-family: var(--mono);
  background: transparent;
  cursor: pointer;
}
.btn {
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  padding: 10px 14px;
  border-radius: 3px;
  font-size: 15px;
  min-height: 46px;
}
.btn:hover, .btn:active { background: var(--accent-tint); }
.btn-wide { width: 100%; }
.btn-danger { border-color: var(--neg-dim); color: var(--neg); }
.btn-danger:hover, .btn-danger:active { background: var(--neg-tint); }

.btn-link {
  border: none;
  padding: 0;
  color: var(--dim);
  font-size: 13px;
  text-decoration: none;
}
.btn-link:hover { color: var(--accent); text-decoration: none; }

.delete-form { margin-top: 28px; padding-top: 20px; border-top: 1px dashed var(--panel-border); }

/* ------------------------------------------------------------------ формы */

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-size: 12px; color: var(--dim); }
.field .hint { font-size: 12px; }

.field input, .field select, .field textarea, .inline-filter select,
.quick-add input, .notes-search input, .note-title-input, .note-body {
  font-family: var(--mono);
  background: var(--field);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 3px;
  font-size: 16px;            /* меньше 16px — iOS зумит страницу при фокусе */
  min-height: 46px;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus, .inline-filter select:focus,
.quick-add input:focus, .notes-search input:focus, .note-title-input:focus, .note-body:focus {
  outline: none;
  border-color: var(--accent-dim);
}
.field input::placeholder { color: #3f4a45; }

.field select, .inline-filter select {
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236c7a74'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.field select[hidden] { display: none; }

.field input[type="date"] {
  display: block;
  text-align: left;
  color-scheme: dark;
}
.field input[type="date"]::-webkit-date-and-time-value { text-align: left; }

.amount-input { font-size: 22px !important; font-weight: 600; }

/* сегментные переключатели вместо мелких радиокнопок */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  overflow: hidden;
}
.seg-3 { grid-template-columns: repeat(3, 1fr); }
.seg label { position: relative; cursor: pointer; }
.seg label + label { border-left: 1px solid var(--panel-border); }
.seg input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  pointer-events: none;
}
.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  font-size: 14px;
  color: var(--dim);
  background: var(--field);
}
.seg input:checked + span { color: var(--accent); background: var(--accent-tint); }
.seg-type label:first-child input:checked + span { color: var(--neg); background: var(--neg-tint); }
.seg input:focus-visible + span { outline: 1px solid var(--accent); outline-offset: -3px; }

.errors, .errors-text {
  color: var(--neg);
  font-size: 13px;
  margin: 0 0 16px;
}
.errors { padding-left: 18px; }

.inline-filter { margin: 0; }
.inline-filter select { font-size: 14px; min-height: 36px; padding-top: 6px; padding-bottom: 6px; width: auto; }

.balance-help {
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 16px;
}

.login-card { margin: 8vh auto 0; }

/* ------------------------------------------------------------------ подменю бюджета */

.subnav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: -8px 0 18px;
  scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
  flex: 0 0 auto;
  padding: 7px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  color: var(--dim);
  font-size: 13px;
  white-space: nowrap;
}
.subnav a:hover { text-decoration: none; color: var(--text); }
.subnav a.active { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-tint); }

/* ------------------------------------------------------------------ главная */

.hero { margin: 4px 0 26px; }
.hero-hello { margin: 0 0 2px; color: var(--accent); font-size: 14px; }
.hero-weekday {
  margin: 0;
  font-size: clamp(40px, 11vw, 68px);
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  overflow-wrap: anywhere;
}
.cursor {
  display: inline-block;
  width: 0.5em;
  height: 0.12em;
  margin-left: 0.08em;
  background: var(--accent);
  vertical-align: baseline;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.hero-date { margin: 6px 0 0; font-size: 14px; }

.menu {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.menu .card { margin: 0; }
.menu-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 112px;
  color: var(--text);
  transition: border-color 0.15s;
}
.menu-item:hover { text-decoration: none; border-color: var(--accent-dim); }
.menu-item:active { background: var(--accent-tint); }
.menu-name { color: var(--dim); font-size: 13px; }
.menu-name::before { content: "./"; color: var(--accent-dim); }
.menu-stat { font-size: 19px; font-weight: 700; margin-top: auto; white-space: nowrap; }
.menu-sub { font-size: 12px; line-height: 1.35; }

.small { font-size: 12px; }
.empty { margin: 4px 0 8px; font-size: 13px; line-height: 1.6; }

/* ------------------------------------------------------------------ задачи */

.todo-list { display: flex; flex-direction: column; }
.todo {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  border-bottom: 1px solid var(--panel-border);
}
.todo:last-child { border-bottom: none; }
.todo-check { margin: 0; flex: 0 0 auto; }
.check {
  font-family: var(--mono);
  font-size: 15px;
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  padding: 0 6px 0 0;
  text-align: left;
  white-space: pre;
}
.todo-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  color: var(--text);
}
.todo-body:hover { text-decoration: none; }
.todo-title { font-size: 14px; overflow-wrap: anywhere; }
.todo-meta { font-size: 12px; }
.todo.is-done .todo-title { color: var(--dim); text-decoration: line-through; text-decoration-color: var(--accent-dim); }
.todo.is-done .check { color: var(--accent-dim); }
.todo-actions { flex: 0 0 auto; display: flex; gap: 10px; }
.todo-actions form { margin: 0; }
.todo-actions .btn-link { color: var(--accent); min-height: 44px; }

.quick-add {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.quick-add input[type="text"] { flex: 1 1 auto; min-width: 0; }
.quick-add:first-child { margin-top: 0; }
.quick-add .btn { flex: 0 0 46px; padding: 0; font-size: 20px; }
.quick-add-dated { flex-wrap: wrap; margin-bottom: 6px; }
.quick-add-dated > input[type="text"] { flex-basis: 100%; }
.qa-row { display: flex; gap: 8px; flex: 1 1 100%; }
.qa-due {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding-left: 12px;
  background: var(--field);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  font-size: 13px;
}
.qa-due input[type="date"] {
  flex: 1 1 auto;
  min-width: 0;
  border: none !important;
  background: transparent !important;
  padding-left: 0 !important;
  color-scheme: dark;
}

.card-warn { border-color: var(--neg-dim); }

.day-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.day-big { font-size: 22px; font-weight: 700; line-height: 1.2; }

.week {
  display: grid;
  grid-template-columns: 26px repeat(7, 1fr) 26px;
  gap: 4px;
  align-items: stretch;
}
.week-arrow {
  display: flex; align-items: center; justify-content: center;
  color: var(--dim);
}
.week-arrow:hover { color: var(--accent); text-decoration: none; }
.week-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text);
  line-height: 1.25;
}
.week-day:hover { text-decoration: none; border-color: var(--panel-border); }
.week-day .wd { font-size: 11px; color: var(--dim); }
.week-day .wn { font-size: 16px; font-weight: 600; }
.week-day .wc { font-size: 11px; color: var(--accent); min-height: 1.25em; }
.week-day.is-today .wn { color: var(--accent); }
.week-day.active { border-color: var(--accent-dim); background: var(--accent-tint); }

.seg-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}
.seg-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  font-size: 14px;
  color: var(--dim);
  background: var(--field);
}
.seg-links a + a { border-left: 1px solid var(--panel-border); }
.seg-links a:hover { text-decoration: none; color: var(--text); }
.seg-links a.active { color: var(--accent); background: var(--accent-tint); }

.done-block summary { cursor: pointer; font-size: 13px; list-style: none; }
.done-block summary::-webkit-details-marker { display: none; }
.done-block summary::before { content: "+ "; color: var(--accent-dim); }
.done-block[open] summary::before { content: "- "; }
.done-block[open] summary { margin-bottom: 8px; }
.done-block form { margin-top: 12px; }
.btn-link.neg { color: var(--neg); }

/* ------------------------------------------------------------------ записи */

.notes-bar { display: flex; gap: 8px; margin-bottom: 8px; }
.notes-search { flex: 1 1 auto; margin: 0; }
.notes-bar .btn { display: flex; align-items: center; white-space: nowrap; }
.notes-bar .btn:hover { text-decoration: none; }

.note-list { display: flex; flex-direction: column; }
.note {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 6px;
  margin: 0 -6px;
  border-bottom: 1px solid var(--panel-border);
  border-radius: 3px;
  color: var(--text);
}
.note:last-child { border-bottom: none; }
.note:hover, .note:active { text-decoration: none; background: var(--accent-tint); }
.note-head { display: flex; justify-content: space-between; gap: 12px; }
.note-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-date { font-size: 12px; white-space: nowrap; }
.note-preview {
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-editor .note-title-input { font-weight: 600; }
.note-body, .field textarea { resize: vertical; line-height: 1.6; min-height: 90px; }
.note-body { min-height: 240px; }
.note-stamps { margin: 16px 0 0; }

/* ------------------------------------------------------------------ телефон */

@media (max-width: 640px) {
  body { font-size: 14px; }

  .wrap {
    padding: calc(14px + var(--safe-top)) 12px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  }

  .topbar { margin-bottom: 14px; padding-bottom: 12px; }

  /* навигация уезжает вниз и становится панелью вкладок */
  .tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(18, 24, 26, 0.94);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--panel-border);
  }
  .tabs a {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    border-top: 2px solid transparent;
    margin-top: -1px;
  }
  .tabs a.active { border-top-color: var(--accent); }
  .tabs a { font-size: 12px; }

  .card { padding: 14px; margin-bottom: 12px; }
  .card.narrow { max-width: none; }
  .grid-2 { gap: 12px; margin-bottom: 12px; }
  .stat-value { font-size: 19px; }
  .stat-value.big { font-size: 30px; }
  .balance-card .wallets { gap: 8px; }
  .balance-card .wallets .stat-label { font-size: 11px; line-height: 1.3; }
  .wallet-value { font-size: 14px; }

  .login-card { margin-top: 4vh; }

  .menu { grid-template-columns: 1fr 1fr; gap: 10px; }
  .menu-item { min-height: 104px; padding: 14px; }
  .menu-stat { font-size: 17px; }
  .hero { margin-bottom: 20px; }
  .subnav { margin: -4px 0 12px; }
  .week { grid-template-columns: 20px repeat(7, 1fr) 20px; gap: 2px; }

  footer { margin-top: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .cursor { animation: none; }
}
