:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1e222b;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #4ade80;
  --danger: #f87171;
  --line: #262b36;
  --radius: 16px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --card: #ffffff;
    --card-2: #eef0f5;
    --text: #14171f;
    --muted: #6b7280;
    --line: #e2e5ec;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
button, a, input, .chip, .item { touch-action: manipulation; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
main, .topbar, .limit, .foot { max-width: 620px; margin: 0 auto; }
main { padding: 0 12px 40px; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 12px 6px;
}
.icon {
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 12px;
  background: var(--card); color: var(--text);
  font-size: 26px; line-height: 1; cursor: pointer;
}
.icon:active { background: var(--card-2); }
.month { flex: 1; text-align: center; min-width: 0; }
.month-label {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 14px; text-transform: capitalize; padding: 0;
}
.month-total { font-size: 34px; font-weight: 650; letter-spacing: -0.5px; }
.cur { color: var(--muted); font-weight: 400; }

.limit { padding: 0 12px 10px; }
.limit-bar { height: 6px; background: var(--card); border-radius: 99px; overflow: hidden; }
.limit-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.limit-fill.over { background: var(--danger); }
.limit-text {
  display: block; width: 100%; margin-top: 6px;
  background: none; border: 0; color: var(--muted);
  font: inherit; font-size: 13px; text-align: center; cursor: pointer;
}

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
@media (min-width: 620px) {
  .add { position: sticky; top: 0; z-index: 5; box-shadow: 0 8px 16px -12px rgba(0,0,0,.6); }
}

.amount-row { display: flex; align-items: center; gap: 8px; }
.amount {
  flex: 1; min-width: 0;
  background: none; border: 0; color: var(--text);
  font: inherit; font-size: 40px; font-weight: 650; letter-spacing: -1px;
  padding: 0; outline: none;
}
.amount::placeholder { color: var(--line); }
.cur.big { font-size: 28px; }
.add-btn {
  flex: none; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--accent); color: #08120b;
  font: inherit; font-weight: 650; padding: 12px 18px;
}
.add-btn:active { transform: scale(.97); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  border: 1px solid var(--line); border-radius: 99px; cursor: pointer;
  background: var(--card-2); color: var(--text);
  font: inherit; font-size: 15px; padding: 10px 15px; min-height: 40px;
  display: inline-flex; align-items: center; gap: 7px;
}
.chip .dot { width: 9px; height: 9px; border-radius: 99px; }
.chip.on { border-color: currentColor; background: color-mix(in srgb, currentColor 16%, var(--card-2)); }

.meta-row { display: flex; gap: 8px; margin-top: 12px; }
.note, .date {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font: inherit; font-size: 16px; padding: 11px 12px; outline: none;
}
.note { flex: 1; min-width: 0; }
.date { flex: none; color: var(--muted); }
.note:focus, .date:focus { border-color: var(--muted); }

.add.editing { outline: 2px solid var(--accent); }
.edit-bar { display: none; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
.add.editing .edit-bar { display: flex; }
.edit-bar .cancel {
  margin-left: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--card-2);
  color: var(--text); font: inherit; font-size: 14px; min-height: 36px; padding: 0 12px; cursor: pointer;
}
.item.editing { outline: 1px solid var(--accent); }
.item .who { cursor: pointer; }

@media (max-width: 619px) {
  .chips { gap: 6px; margin-top: 10px; }
  .chip { font-size: 14px; padding: 7px 11px; min-height: 34px; gap: 6px; }
  .chip .dot { width: 8px; height: 8px; }
  .meta-row { margin-top: 10px; }
  .note, .date { padding: 10px 11px; }
  main { padding: 0 10px 32px; }
  .card { padding: 12px; }
}

.breakdown { display: grid; gap: 10px; }
.bd-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 14px; align-items: center; }
.bd-name { color: var(--muted); }
.bd-sum { font-variant-numeric: tabular-nums; }
.bd-bar { grid-column: 1 / -1; height: 5px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.bd-bar > i { display: block; height: 100%; }

.day { margin: 18px 2px 8px; display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.item {
  display: flex; align-items: center; gap: 12px; min-height: 56px;
  background: var(--card); border-radius: 12px; padding: 10px 6px 10px 14px; margin-bottom: 6px;
}
.item .dot { width: 10px; height: 10px; border-radius: 99px; flex: none; }
.item .who { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 7px; overflow: hidden; }
.item .cat { font-size: 15px; }
.item .note-txt { font-size: 13px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sum { font-variant-numeric: tabular-nums; font-weight: 600; }
.item .del {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  width: 44px; height: 44px; flex: none; font-size: 22px; line-height: 1;
  display: grid; place-items: center; border-radius: 10px;
}
.item .del:hover { color: var(--danger); }
.item.confirming { background: color-mix(in srgb, var(--danger) 14%, var(--card)); }
.item.confirming .who { display: block; font-size: 15px; }
.item .yes, .item .no {
  border: 0; border-radius: 10px; cursor: pointer; font: inherit; font-size: 15px;
  min-height: 40px; padding: 0 14px; flex: none;
}
.item .yes { background: var(--danger); color: #2a0b0b; font-weight: 600; }
.item .no { background: none; color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 36px 0; font-size: 15px; }

.foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 4px 12px 28px; font-size: 13px; }
.foot a, .linkish {
  color: var(--muted); text-decoration: none; background: none; border: 0;
  font: inherit; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px;
}
.foot a:hover, .linkish:hover { color: var(--text); }

.dialog { border: 0; border-radius: var(--radius); background: var(--card); color: var(--text); width: min(440px, 92vw); padding: 0; }
.dialog::backdrop { background: rgba(0,0,0,.5); }
.dialog-inner { padding: 18px; }
.dialog h2 { margin: 0 0 14px; font-size: 18px; }
.cat-list { display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.cat-row { display: flex; gap: 8px; align-items: center; }
.cat-row input[type=text] {
  flex: 1; min-width: 0; background: var(--card-2); border: 1px solid var(--line);
  border-radius: 10px; color: var(--text); font: inherit; font-size: 16px; padding: 11px 12px;
}
.cat-row input[type=color] { width: 44px; height: 44px; flex: none; border: 0; background: none; padding: 0; cursor: pointer; }
.cat-row .del {
  border: 0; background: none; color: var(--muted); font-size: 22px; cursor: pointer;
  width: 44px; height: 44px; flex: none; border-radius: 10px;
}
.ghost, .primary {
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
  background: var(--card-2); color: var(--text); font: inherit; font-size: 15px;
  min-height: 44px; padding: 0 16px;
}
.primary { background: var(--accent); color: #08120b; border-color: transparent; font-weight: 600; }
#addCat { width: 100%; margin-top: 10px; }
.dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 16px 0 0; padding: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--card-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 16px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.hidden { display: none !important; }

.login-page { display: grid; place-items: center; min-height: 100vh; min-height: 100svh; padding: 20px; }
.login { width: min(360px, 100%); text-align: center; padding: 26px 22px; margin: 0; }
.login h1 { margin: 0 0 6px; font-size: 22px; }
.login .hint { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.key {
  width: 100%; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); font: inherit; font-size: 17px; padding: 13px 14px; outline: none; text-align: center;
}
.key:focus { border-color: var(--muted); }
.add-btn.wide { width: 100%; margin-top: 10px; padding: 13px; font-size: 16px; }
.login .err { min-height: 18px; margin: 10px 0 0; color: var(--danger); font-size: 13px; }
