:root {
  --primary: #4f46e5;
  --primary-deep: #4338ca;
  --primary-soft: #eef2ff;
  --ring: rgba(79, 70, 229, .14);
  --bg: #f6f7fb;
  --card: #ffffff;
  --line: #edeff6;
  --field: #f3f4f9;
  --text: #111827;
  --muted: #6b7280;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --grad: linear-gradient(135deg, #6366f1 0%, #4f46e5 55%, #4338ca 100%);
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 11px;
  --shadow-card: 0 1px 2px rgba(67, 56, 202, .05), 0 4px 14px rgba(67, 56, 202, .05);
  --shadow-pop: 0 10px 32px rgba(67, 56, 202, .16);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea, a { touch-action: manipulation; font-family: inherit; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* ---------- Header: iOS-style large title ---------- */
.topbar {
  background: var(--card);
  padding: calc(14px + env(safe-area-inset-top)) 20px 10px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -.03em;
}
.topbar-sub { font-size: 13px; color: var(--muted); margin-top: 1px; }

main { max-width: 680px; margin: 0 auto; padding: 16px 16px 28px; }
.view.hidden, .hidden { display: none !important; }

/* Section titles become quiet "eyebrows" so values dominate */
h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 22px 4px 10px;
}
.mt { margin-top: 8px; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  box-shadow: var(--shadow-card);
  margin-bottom: 12px;
}

.row { display: flex; gap: 8px; margin-top: 8px; align-items: stretch; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; margin-bottom: 4px; align-items: center; }
.row > select, .row > input:not([type="checkbox"]), .date-field { height: 48px; }
.date-display { padding: 0 12px; line-height: 1; }
.row.end, .form-actions { align-items: center; }
.row > * { flex: 1; min-width: 0; }

.form-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.tx-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.tx-grid > input, .tx-grid > select { height: 48px; }
#tx-desc { margin-top: 12px; }

/* ---------- Inputs: filled style ---------- */
input, select, textarea {
  width: 100%;
  border: 1.5px solid transparent;
  border-radius: var(--r-sm);
  padding: 11px 12px;
  font-size: 16px;
  background: var(--field);
  color: var(--text);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  background: var(--card);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}
input.money { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
textarea { resize: vertical; margin-top: 8px; }

.month-stepper {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--card); border-radius: 999px; padding: 3px;
  border: 1px solid var(--line); flex-shrink: 0;
}
.month-stepper button {
  border: none; background: var(--primary-soft); color: var(--primary);
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 19px; cursor: pointer; line-height: 1; padding: 0;
}
.month-stepper button:active { transform: scale(.92); }
.month-stepper span {
  font-size: 13px; font-weight: 700; padding: 0 4px; min-width: 108px; text-align: center;
  font-variant-numeric: tabular-nums;
}

.date-field { position: relative; flex: 1; min-width: 0; }
.date-display {
  position: absolute; inset: 0; display: flex; align-items: center;
  padding: 11px 12px; border: 1.5px solid transparent; border-radius: var(--r-sm);
  background: var(--field); font-size: 16px; color: var(--text);
  pointer-events: none; overflow: hidden; white-space: nowrap; z-index: 1;
}
.date-display.empty { color: var(--muted); }
.date-field input[type="date"] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; padding: 0; border: none; cursor: pointer;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--r-sm);
  padding: 12px 18px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  background: var(--primary-soft);
  color: var(--primary);
  transition: transform .12s ease, filter .15s;
}
.btn:active { transform: scale(.97); filter: brightness(.96); }
.btn.primary {
  background: var(--primary); color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 4px 12px rgba(79, 70, 229, .28);
}
.btn.primary:active { filter: brightness(.92); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 14px; min-height: 38px; font-size: 13px; margin-top: 8px; }
.btn.danger-ghost { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: .55; pointer-events: none; }

/* ---------- Unified segmented control ---------- */
.seg, .filters, .subtabs {
  display: flex; gap: 4px;
  background: #ebeef5; border-radius: var(--r-sm); padding: 4px;
}
.filters { margin: 4px 0 12px; }
.subtabs { margin-bottom: 16px; box-shadow: none; border: none; }
.filters button, .subtabs button, .seg button {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 10px 2px; min-height: 42px; border-radius: 9px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: color .15s;
}
.seg button { font-size: 14px; }
.filters button.active, .subtabs button.active, .seg button.active {
  background: var(--card); color: var(--primary);
  box-shadow: 0 1px 4px rgba(17, 24, 39, .1);
}
.seg button[data-t="income"].active { color: var(--ok); }

/* ---------- Lists ---------- */
.list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.list.plain { gap: 4px; }
.list li {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 1px 2px rgba(67, 56, 202, .04);
  animation: rise .22s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.list .grow { flex: 1; min-width: 0; }
.list .title { word-break: break-all; font-weight: 500; }
.list .sub { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.done-item .title { text-decoration: line-through; color: var(--muted); font-weight: 400; }

.badge {
  font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; flex-shrink: 0;
}
.badge.High { background: var(--danger-soft); color: #b91c1c; }
.badge.Medium { background: var(--warn-soft); color: var(--warn); }
.badge.Low { background: var(--ok-soft); color: #047857; }
.overdue { color: var(--danger); font-weight: 600; }

.icon-btn {
  border: none; background: none; font-size: 18px; color: var(--muted);
  cursor: pointer; padding: 11px; min-width: 44px; min-height: 44px;
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
}
.icon-btn:active { background: var(--field); transform: scale(.94); }
.icon-btn.del:active { color: var(--danger); background: var(--danger-soft); }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); flex-shrink: 0; }

/* ---------- Empty states ---------- */
.list li.empty-wrap {
  display: block; background: none !important; border: none !important;
  box-shadow: none !important; animation: none; padding: 12px 0;
}
li.goal-li { flex-direction: column; align-items: stretch; gap: 6px; padding: 14px 16px; }
.goal-top { display: flex; align-items: center; gap: 6px; }
.empty { text-align: center; padding: 28px 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty-ic { font-size: 34px; line-height: 1; }
.empty b { font-size: 14px; font-weight: 700; color: var(--text); }
.empty span { font-size: 13px; color: var(--muted); max-width: 260px; }

/* ---------- Recipes ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 14px; }
.day {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 2px; text-align: center; cursor: pointer;
  min-height: 68px; transition: transform .12s;
}
.day:active { transform: scale(.95); }
.day.today { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.35); }
.day.today .d-label, .day.today .d-meal { color: rgba(255,255,255,.85); }
.day .d-num { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.day .d-label { font-size: 11px; color: var(--muted); font-weight: 600; }
.day .d-meal {
  font-size: 10px; color: var(--primary); margin-top: 4px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px;
}

.recipe-card .ings { margin: 10px 0 4px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--primary-soft); color: var(--primary-deep); border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 600; }
.recipe-card .steps { font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.card-actions { display: flex; gap: 6px; margin-top: 12px; }
.card-actions .btn { padding: 8px 12px; min-height: 38px; font-size: 13px; flex: 1; }

#ingredient-rows .ing-row { display: flex; gap: 6px; margin-top: 8px; }
#ingredient-rows input[name="iname"] { flex: 1.4; }
#ingredient-rows input[name="iqty"] { flex: 1; }

/* ---------- Money & stats ---------- */
.hero-card {
  background: var(--grad); color: #fff; border: none;
  border-radius: var(--r-lg); position: relative; overflow: hidden;
  padding: 20px;
}
.hero-card::before {
  content: ""; position: absolute; top: -60px; right: -50px;
  width: 190px; height: 190px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.22), transparent 65%);
  pointer-events: none;
}
.hero-card label { font-size: 13px; font-weight: 600; opacity: .85; }
.total-num {
  font-size: 40px; font-weight: 800; margin: 4px 0;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.total-num small { font-size: 15px; font-weight: 500; opacity: .85; }
.hero-card .muted { color: rgba(255,255,255,.78); }
.fc-line { margin-top: 8px; font-size: 13px; opacity: .95; font-weight: 500; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.stat label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.stat b {
  font-size: 19px; display: block; margin-top: 3px; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.stat small { font-size: 11px; }
@media (min-width: 560px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }

.warn-banner {
  background: var(--danger-soft); color: #b91c1c; border: 1px solid #fecaca;
  border-radius: var(--r-sm); padding: 12px 14px; margin-bottom: 12px;
  font-size: 13px; font-weight: 600;
}

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 11px 14px; box-shadow: 0 1px 2px rgba(67, 56, 202, .04);
}
.bar-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.bar-track { height: 8px; background: #eceef5; border-radius: 999px; overflow: hidden; }
.bar-fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  transition: width .45s cubic-bezier(.22,1,.36,1);
}
.bar-limit { display: flex; align-items: center; gap: 6px; margin-top: 7px; font-size: 12px; color: var(--muted); }
.bar-limit input { width: 90px; padding: 6px 8px; font-size: 16px; }

.expense-amt { font-weight: 700; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.tx-in .expense-amt { color: var(--ok); }
.fx-hint {
  font-size: 13px; color: var(--warn); background: var(--warn-soft);
  border-radius: var(--r-sm); padding: 8px 12px; margin-top: 8px; font-weight: 500;
}
.eur-chip { font-weight: 700; color: var(--muted); }
.inline-label { flex: 0 0 auto; font-size: 13px; color: var(--muted); }

.mini-progress { height: 7px; background: #eceef5; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.mini-progress div {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  transition: width .45s cubic-bezier(.22,1,.36,1);
}

/* ---------- Trend chart ---------- */
.trend {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 16px; box-shadow: 0 1px 2px rgba(67, 56, 202, .04);
}
.trend-row {
  display: flex; align-items: flex-end; justify-content: space-between; height: 116px;
  padding: 0 6px; border-bottom: 1.5px solid var(--line);
}
.trend-col { display: flex; flex-direction: column; align-items: center; width: 13%; }
.trend-bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.trend-bar { width: 11px; border-radius: 5px 5px 2px 2px; min-height: 2px; }
.trend-bar.inc { background: linear-gradient(180deg, #34d399, var(--ok)); }
.trend-bar.exp { background: linear-gradient(180deg, #f87171, #ef4444); }
.trend-label { font-size: 11px; color: var(--muted); margin-top: 7px; font-variant-numeric: tabular-nums; }
.trend-legend { display: flex; gap: 16px; justify-content: center; margin-top: 12px; font-size: 12px; color: var(--muted); }
.trend-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.trend-legend i.inc { background: var(--ok); }
.trend-legend i.exp { background: #ef4444; }

/* ---------- Total card (legacy-safe) ---------- */
.total-card { background: var(--grad); color: #fff; border: none; }
.total-card label { font-size: 13px; opacity: .85; }
.total-card .muted { color: rgba(255,255,255,.75); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: none; background: none; padding: 8px 0 10px;
  font-size: 11px; font-weight: 600; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: color .15s;
}
.tabbar button span {
  font-size: 19px; line-height: 1; padding: 3px 16px; border-radius: 999px;
  transition: background .2s;
}
.tabbar button.active { color: var(--primary); }
.tabbar button.active span { background: var(--primary-soft); }

/* ---------- Modal: bottom sheet on mobile ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask { position: absolute; inset: 0; background: rgba(17, 24, 39, .5); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.modal-body {
  position: relative; width: 100%; max-width: 420px; margin: 0;
  max-height: 82vh; overflow-y: auto;
  animation: pop .24s cubic-bezier(.22,1,.36,1);
}
@keyframes pop { from { opacity: 0; transform: translateY(24px) scale(.98); } }
@media (max-width: 560px) {
  .modal { align-items: flex-end; padding: 0; }
  .modal-body {
    max-width: none; border-radius: var(--r-lg) var(--r-lg) 0 0;
    margin-bottom: env(safe-area-inset-bottom);
    animation: sheet .28s cubic-bezier(.22,1,.36,1);
  }
  @keyframes sheet { from { transform: translateY(100%); } }
}
.modal h3 { font-size: 17px; font-weight: 700; margin-bottom: 2px; }
.modal-day-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.modal-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.modal-list .btn { text-align: left; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: calc(74px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  background: #111827; color: #fff;
  padding: 10px 20px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 99;
  box-shadow: var(--shadow-pop);
  animation: toastIn .25s cubic-bezier(.22,1,.36,1);
  max-width: 86vw; text-align: center;
}
.toast.err { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-12px); } }

.tap-card { cursor: pointer; transition: background .15s, transform .12s; }
.tap-card:active { background: var(--primary-soft); transform: scale(.99); }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid var(--ring); outline-offset: 1px;
}

@media (min-width: 700px) {
  .topbar { padding-left: calc((100% - 680px)/2 + 20px); padding-right: calc((100% - 680px)/2 + 20px); }
  .tabbar { left: 50%; transform: translateX(-50%); width: 680px; border-radius: 18px 18px 0 0; }
}
