:root {
  --bg: #f3f4f7; --card: #ffffff; --text: #14171c; --muted: #6b7280; --line: #e4e7ec;
  --seg: #e6e8ed; --primary: #4f46e5;
  --expense: #dc2626; --income: #16a34a; --transfer: #2563eb; --adjust: #b45309;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --tabh: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --card: #181b21; --text: #eceff4; --muted: #98a2b3; --line: #2a2f38;
    --seg: #262a33; --primary: #818cf8;
    --expense: #f87171; --income: #4ade80; --transfer: #60a5fa; --adjust: #fbbf24;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --card: #181b21; --text: #eceff4; --muted: #98a2b3; --line: #2a2f38;
  --seg: #262a33; --primary: #818cf8;
  --expense: #f87171; --income: #4ade80; --transfer: #60a5fa; --adjust: #fbbf24;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; min-height: 100dvh;
  padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
#app { max-width: 560px; margin: 0 auto; }
button { font: inherit; color: inherit; cursor: pointer; }

/* Üst çubuk */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
}
.top h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); display: grid; place-items: center; }
.icon-btn:active { background: var(--seg); }

.screen { padding: 4px 16px 24px; }

/* Form */
.field { display: block; margin: 0 0 14px; }
.field.gap { margin-top: 16px; }
.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.opt { font-weight: 400; opacity: .8; }
input, select {
  width: 100%; min-height: 48px; padding: 12px 14px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  outline: none; appearance: none; -webkit-appearance: none;
}
input[type="date"] { appearance: auto; -webkit-appearance: auto; text-align: left; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus { border-color: var(--accent, var(--primary)); }
input.invalid { border-color: var(--expense); }
::placeholder { color: var(--muted); opacity: .6; }

#add-form { --accent: var(--expense); }
#add-form[data-type="income"] { --accent: var(--income); }
#add-form[data-type="transfer"] { --accent: var(--transfer); }

.amount-row {
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
}
.amount-row:focus-within { border-color: var(--accent, var(--primary)); }
.amount-row.invalid { border-color: var(--expense); }
.amount-row input { border: 0; background: transparent; padding: 8px 0; min-height: 64px; font-size: 34px; font-weight: 700; letter-spacing: -.01em; }
.amount-row.small input { min-height: 52px; font-size: 24px; }
.amount-row .cur { font-weight: 700; color: var(--muted); font-size: 16px; }
.hint { min-height: 20px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.hint.ok { color: var(--accent, var(--muted)); }
.hint.err { color: var(--expense); }

.seg { display: flex; gap: 3px; padding: 3px; background: var(--seg); border-radius: 12px; }
.seg button { flex: 1; min-height: 44px; padding: 8px 6px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg.types button.on[data-v="expense"] { color: var(--expense); }
.seg.types button.on[data-v="income"] { color: var(--income); }
.seg.types button.on[data-v="transfer"] { color: var(--transfer); }

.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; padding: 10px 12px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.chip b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.on { border-color: var(--accent, var(--primary)); box-shadow: 0 0 0 1px var(--accent, var(--primary)) inset; }
.ccy { flex: none; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--seg); padding: 2px 8px; border-radius: 999px; }

.primary {
  width: 100%; min-height: 54px; border: 0; border-radius: 14px; font-size: 17px; font-weight: 700;
  color: #fff; background: var(--accent, var(--primary));
}
.primary:disabled { opacity: .45; }
.primary:active:not(:disabled) { filter: brightness(.92); }
.ghost { min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-weight: 600; }
.ghost.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.ghost.block { width: 100%; text-align: left; margin-bottom: 8px; }
.danger { min-height: 44px; padding: 0 16px; border: 1px solid var(--expense); border-radius: 12px; background: transparent; color: var(--expense); font-weight: 600; }
.danger.confirm { background: var(--expense); color: #fff; }

.savebar {
  position: sticky; bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding: 12px 0 10px; margin-top: 4px;
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}

/* Kartlar */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow); }
.card-h { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.tot { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 0; }
.tot b { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--expense); }
.pos { color: var(--income); }

.acc { display: flex; align-items: center; gap: 12px; }
.acc .info { flex: 1; min-width: 0; }
.acc .name { font-weight: 700; }
.acc .tags { margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }
.acc .bal { text-align: right; font-size: 20px; font-weight: 700; white-space: nowrap; }
.acc .bal small { display: block; margin-bottom: 6px; font-size: 12px; color: var(--muted); font-weight: 700; }
.tag { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--seg); padding: 2px 8px; border-radius: 999px; }

.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin: 0 0 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--adjust); font-size: 14px; }
.banner span { flex: 1; }

/* Hareketler */
.filters { display: grid; gap: 8px; margin: 10px 0 12px; }
.sum { display: grid; grid-template-columns: auto 1fr 1fr 1fr; gap: 6px 10px; align-items: baseline; text-align: right; font-size: 15px; }
.sum .h { font-size: 12px; font-weight: 600; color: var(--muted); }
.sum .c { text-align: left; font-weight: 700; color: var(--muted); font-size: 13px; }
.sum .n { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.day-h { font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 4px 6px; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 0 12px; box-shadow: var(--shadow); }
.tx { border-bottom: 1px solid var(--line); }
.tx:last-child { border-bottom: 0; }
.tx-main { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 0; border: 0; background: none; text-align: left; }
.ico { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--seg); font-weight: 700; font-size: 18px; }
.expense .ico { color: var(--expense); } .income .ico { color: var(--income); }
.transfer .ico { color: var(--transfer); } .adjust .ico { color: var(--adjust); }
.tx-t { flex: 1; min-width: 0; }
.t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t2 { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-a { text-align: right; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-a small { font-size: 12px; font-weight: 600; color: var(--muted); }
.tx-a .sub { font-size: 13px; font-weight: 600; }
.expense .tx-a .main { color: var(--expense); } .income .tx-a .main { color: var(--income); }
.transfer .tx-a .main { color: var(--transfer); } .adjust .tx-a .main { color: var(--adjust); }
.detail { padding: 0 0 14px 48px; font-size: 14px; }
.detail dl { margin: 0 0 12px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; overflow-wrap: anywhere; }

/* Alt menü */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs-in { display: flex; max-width: 560px; margin: 0 auto; }
.tabs button { flex: 1; height: var(--tabh); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabs button.on { color: var(--primary); }

/* Bildirim */
#toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 84px); transform: translate(-50%, 12px); z-index: 30; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 14px; background: #20232a; color: #fff; font-size: 15px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; display: flex; gap: 12px; align-items: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast.err { background: #b91c1c; }
#toast button { border: 0; background: rgba(255, 255, 255, .18); color: #fff; padding: 6px 10px; border-radius: 8px; font-weight: 700; }

/* Alt sayfa */
dialog#sheet { border: 0; padding: 0; margin: auto 0 0 0; width: 100%; max-width: none; max-height: 92vh; max-height: 92dvh; overflow: auto; border-radius: 20px 20px 0 0; background: var(--card); color: var(--text); }
dialog#sheet::backdrop { background: rgba(0, 0, 0, .5); }
.sheet-body { max-width: 560px; margin: 0 auto; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-body h2 { margin: 0 0 4px; font-size: 20px; }
.sheet-body p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.sheet-body .field { margin-bottom: 12px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.row > .ghost.sm { flex: none; }
.sec-h { margin: 18px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
