:root {
  color-scheme: light dark;
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #17201b;
  --muted: #5b6961;
  --border: #dde3df;
  --accent: #0e7a5a;
  --accent-ink: #ffffff;
  --accent-soft: #dcf1e8;
  --danger: #b8400b;
  --danger-soft: #fdeadf;
  --warn: #8a5a00;
  --warn-soft: #fdf3d7;
  --radius: 16px;
  --tabbar-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #171d1a;
    --surface-2: #212a25;
    --text: #e8eeea;
    --muted: #9aa8a0;
    --border: #2a3430;
    --accent: #3cc795;
    --accent-ink: #062619;
    --accent-soft: #173a2d;
    --danger: #ff9a62;
    --danger-soft: #3a2216;
    --warn: #f5cd4f;
    --warn-soft: #3a3214;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 17px; }
small, .muted { color: var(--muted); }
button { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 10px;
}
.topbar-row { max-width: 528px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h1 { font-size: 26px; letter-spacing: -0.01em; }
.sync {
  border: 0; background: var(--surface-2); color: var(--muted); cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 99px; white-space: nowrap;
}
.sync.warn { background: var(--warn-soft); color: var(--warn); }
.sync[hidden] { display: none; }

/* Giriş / kayıt ekranı */
body.auth-mode .tabbar, body.auth-mode .fab { display: none; }
body.auth-mode main { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
.auth { padding-top: 8px; }
.auth-brand { text-align: center; margin: 8px 0 20px; }
.auth-brand img { border-radius: 16px; display: block; margin: 0 auto 12px; }
.auth-brand h2 { font-size: 24px; }
.auth-brand p { margin: 6px auto 0; max-width: 34ch; }
.auth .seg { margin-bottom: 4px; }
.btn:disabled { opacity: .6; cursor: progress; }

main {
  max-width: 560px; margin: 0 auto;
  padding: 0 16px calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.card > h2 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

.hero .label { color: var(--muted); font-size: 14px; }
.hero .big { font-size: 38px; font-weight: 750; letter-spacing: -0.02em; margin: 2px 0 4px; }
.hero .big.neg { color: var(--danger); }

.rows { margin: 12px 0 0; padding: 0; }
.rows div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--border); }
.rows div:first-child { border-top: 0; }
.rows dt { color: var(--muted); }
.rows dd { margin: 0; font-weight: 600; text-align: right; white-space: nowrap; }
.rows .total dt, .rows .total dd { color: var(--text); font-weight: 750; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.stat small { display: block; }
.stat strong { font-size: 19px; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; margin-bottom: 5px; }
.bar-label small { margin-left: 4px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.bar.target { position: relative; overflow: visible; }
.bar.target > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); border-radius: 1px; }
.bar.over > i { background: var(--danger); }

.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--border); }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 0; background: none; border: 0; text-align: left; cursor: pointer;
}
.item .ico { width: 38px; height: 38px; flex: none; display: grid; place-items: center; background: var(--surface-2); border-radius: 12px; font-size: 19px; }
.item .grow { flex: 1; min-width: 0; }
.item .grow strong, .item .grow small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .grow strong { font-weight: 600; }
.item .amt { font-weight: 650; white-space: nowrap; }
.day-head { margin: 18px 0 2px; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 0; }
.month-nav strong { font-size: 17px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; font-size: 20px;
}
.icon-btn:disabled { opacity: .35; cursor: default; }

.debt .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.debt .top strong.balance { font-size: 22px; white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-top: 3px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 0 12px; font-size: 14px; color: var(--muted); }
.meta b { color: var(--text); font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }

.notice { border-radius: 12px; padding: 12px 14px; margin: 12px 0; background: var(--warn-soft); color: var(--text); font-size: 15px; }
.notice.danger { background: var(--danger-soft); }
.notice.ok { background: var(--accent-soft); }
.notice strong { display: block; margin-bottom: 2px; }
.hint { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.steps li { counter-increment: s; display: flex; gap: 10px; align-items: center; }
.steps li::before {
  content: counter(s); width: 26px; height: 26px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--surface-2); color: var(--muted);
}
.steps li.done::before { content: "✓"; background: var(--accent); color: var(--accent-ink); }
.steps li.done .link { color: var(--muted); font-weight: 500; }

.advice { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.advice li { display: grid; grid-template-columns: 26px 1fr; gap: 10px; }
.advice .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.advice li.done .dot { background: var(--accent); color: var(--accent-ink); }
.advice li.now .dot { background: var(--warn-soft); color: var(--warn); outline: 2px solid var(--warn); }
.advice p { margin: 2px 0 0; font-size: 15px; color: var(--muted); }

.big-result { font-size: 26px; font-weight: 750; letter-spacing: -0.01em; }
.chart { width: 100%; height: 110px; display: block; margin-top: 12px; }
.chart .area { fill: var(--accent-soft); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* Formlar */
.field { display: block; margin: 14px 0 0; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input, select {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; min-height: 46px;
}
input:focus-visible, select:focus-visible, button:focus-visible, .chip input:focus-visible + span, .seg input:focus-visible + span {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.amount-input { font-size: 32px; font-weight: 750; text-align: center; padding: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; border: 0; padding: 0; margin: 14px 0 0; }
.chips legend, .seg-wrap legend { font-size: 14px; font-weight: 600; margin-bottom: 6px; padding: 0; }
.chip, .seg label { position: relative; cursor: pointer; }
.chip input, .seg input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.chip span { display: inline-block; padding: 8px 12px; border-radius: 99px; border: 1px solid var(--border); font-size: 15px; }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }

.seg-wrap { border: 0; padding: 0; margin: 14px 0 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg span { display: block; text-align: center; padding: 9px 6px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

.extra-row { display: grid; grid-template-columns: 1fr 120px; gap: 10px; align-items: center; }
input[type="range"] { padding: 0; min-height: 30px; background: none; border: 0; accent-color: var(--accent); }

form[data-kind="card"] .loan-only, form[data-kind="loan"] .card-only { display: none; }
.form-error { color: var(--danger); font-weight: 600; min-height: 1px; margin: 12px 0 0; }
.form-error:empty { display: none; }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet-actions .spacer { flex: 1; }

/* Alt menü ve ekle butonu */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  height: var(--tabbar-h); border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--muted);
}
.tabbar svg, .fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); }

.fab {
  position: fixed; z-index: 11;
  right: max(16px, calc(50vw - 264px));
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 20px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: 0 6px 20px rgb(0 0 0 / .22);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.5; }
.fab[hidden] { display: none; }

dialog#sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; border: 0;
  border-radius: 22px 22px 0 0; padding: 20px 16px calc(18px + env(safe-area-inset-bottom));
  background: var(--surface); color: var(--text);
  max-height: 92dvh; overflow: auto;
}
dialog#sheet::backdrop { background: rgb(0 0 0 / .45); }
dialog#sheet h2 { font-size: 20px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--tabbar-h) + 90px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: 15px; opacity: 0; pointer-events: none; transition: .2s; z-index: 20;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
