:root {
  --bg: #EDF1F0;
  --surface: #FFFFFF;
  --surface-2: #F5F8F7;
  --ink: #15232B;
  --muted: #5B6C74;
  --line: #D7DEDC;
  --accent: #0B5C63;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEEEF;
  --income: #1B7F55;
  --expense: #BE3F2C;
  --warn: #8F5A06;
  --warn-soft: #FBF0D9;
  --danger-soft: #FBE6E2;
  --focus: #1D6FD1;
  --shadow: 0 1px 2px rgba(21, 35, 43, .06), 0 8px 24px -12px rgba(21, 35, 43, .18);
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1619;
    --surface: #162228;
    --surface-2: #1B2A31;
    --ink: #E7EFF1;
    --muted: #95A8AF;
    --line: #27373E;
    --accent: #5CC0C9;
    --accent-ink: #05282C;
    --accent-soft: #17383C;
    --income: #4CC38A;
    --expense: #F0806C;
    --warn: #E6B04A;
    --warn-soft: #33290F;
    --danger-soft: #3A1E19;
    --focus: #6CB0FF;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- uygulama kabuğu ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 96px);
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabbar-h); color: var(--muted); text-decoration: none; font-size: .68rem; min-width: 0; text-align: center;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); font-weight: 600; }
.brand { display: none; }

.fab {
  position: fixed; right: 18px; z-index: 21;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  width: 58px; height: 58px; border-radius: 20px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 10px 24px -8px rgba(11, 92, 99, .7);
  display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 232px 1fr; }
  .main { max-width: 860px; width: 100%; padding: 32px 32px 120px; margin: 0; }
  .tabbar {
    position: sticky; top: 0; height: 100vh; height: 100dvh; bottom: auto;
    display: flex; flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); padding: 24px 12px;
  }
  .brand { display: block; font-size: 1.35rem; font-weight: 700; letter-spacing: -0.03em; padding: 4px 12px 20px; color: var(--accent); }
  .tab { flex-direction: row; justify-content: flex-start; gap: 12px; height: 44px; padding: 0 12px; border-radius: 10px; font-size: .95rem; }
  .tab[aria-current="page"] { background: var(--accent-soft); }
  .fab { right: 40px; bottom: 36px; }
}

/* ---------- yüzeyler ---------- */
.surface { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.section { margin-top: 24px; }
.section > h2 { font-size: 1.05rem; margin: 0 0 8px; padding: 0 4px; display: flex; align-items: baseline; justify-content: space-between; }
.section > h2 a, .linklike { font-size: .88rem; font-weight: 500; color: var(--accent); background: none; border: 0; padding: 0; text-decoration: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; background: none; border: 0; text-align: left;
}
button.row:hover, a.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { display: block; font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amount { font-weight: 600; white-space: nowrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }

/* ---------- özet ---------- */
.hero { padding: 20px 20px 8px; overflow: hidden; }
.hero .label { color: var(--muted); font-size: .9rem; }
.hero .big { font-size: 2.5rem; font-weight: 700; line-height: 1.1; margin: 2px 0 6px; }
.hero .big.negative { color: var(--expense); }
.hero .outlook { font-size: .92rem; color: var(--muted); }
.hero .outlook b { color: var(--ink); font-weight: 600; }
.hero svg { display: block; width: calc(100% + 40px); margin: 12px -20px 0; height: 72px; }

.triple { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 16px; }
.triple > div { padding: 14px 12px 14px 14px; min-width: 0; }
.triple > div + div { border-left: 1px solid var(--line); }
.triple .label { font-size: .82rem; color: var(--muted); }
.triple .value { font-size: clamp(.9rem, 3.9vw, 1.1rem); font-weight: 650; margin-top: 2px; white-space: nowrap; }
.triple .delta { font-size: .76rem; color: var(--muted); }

.bars { padding: 6px 0; }
.bar-row { display: block; width: 100%; background: none; border: 0; padding: 9px 16px; text-align: left; }
button.bar-row:hover { background: var(--surface-2); }
.bar-top { display: flex; justify-content: space-between; gap: 12px; font-size: .95rem; }
.bar-top .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-track { height: 8px; border-radius: 4px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.pill.late { background: var(--danger-soft); color: var(--expense); }
.pill.soon { background: var(--warn-soft); color: var(--warn); }
.pill.off { background: var(--surface-2); color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--expense); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }

.notice { padding: 12px 16px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-weight: 500; margin-bottom: 16px; }
.notice.bad { background: var(--danger-soft); color: var(--expense); }

/* ---------- ay seçici, filtre ---------- */
.monthnav { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.monthnav button { width: 40px; height: 40px; border: 0; background: none; border-radius: 12px; display: grid; place-items: center; }
.monthnav button:hover { background: var(--surface-2); }
.monthnav svg { width: 20px; height: 20px; }
.monthnav .current { min-width: 120px; text-align: center; font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; align-items: center; }
.chip-btn { min-height: 36px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-size: .9rem; }
.chip-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.search { flex: 1; min-width: 140px; min-height: 36px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; }

.daygroup { margin-top: 16px; }
.daygroup > header { display: flex; justify-content: space-between; padding: 0 4px 6px; font-size: .86rem; color: var(--muted); font-weight: 600; }

/* ---------- grafikler ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--expense); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .area { fill: var(--accent); opacity: .12; }
.chart .ev-in { fill: var(--income); }
.chart .ev-out { fill: var(--expense); }
.chart .bar-in { fill: var(--income); }
.chart .bar-out { fill: var(--expense); opacity: .85; }
.chart .low { fill: var(--surface); stroke: var(--expense); stroke-width: 2; }
.chart .low-label { fill: var(--expense); font-weight: 600; }
.legend { display: flex; gap: 16px; padding: 0 16px 14px; font-size: .84rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.pad { padding: 16px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .82rem; }
table.tbl th { text-align: left; font-weight: 600; color: var(--muted); padding: 10px 6px; font-size: .8rem; white-space: nowrap; }
table.tbl td { padding: 10px 6px; border-top: 1px solid var(--line); vertical-align: top; }
table.tbl td.num { white-space: nowrap; }
table.tbl th:first-child, table.tbl td:first-child { padding-left: 14px; }
table.tbl th:last-child, table.tbl td:last-child { padding-right: 14px; }
table.tbl td.r, table.tbl th.r { text-align: right; }
.scroll-x { overflow-x: auto; }

/* ---------- diyalog / alt sayfa ---------- */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--ink);
  width: min(520px, 100%); max-width: min(520px, 100%); max-height: 92dvh; border-radius: 22px 22px 0 0;
  margin: auto auto 0; box-shadow: 0 -12px 48px rgba(0, 0, 0, .3);
}
dialog.sheet::backdrop { background: rgba(8, 18, 22, .55); }
@media (min-width: 640px) { dialog.sheet { margin: auto; border-radius: 22px; } }
.sheet-body { padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; overflow-x: hidden; max-height: 92dvh; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
dialog.sheet { overscroll-behavior: contain; touch-action: pan-y; }
body.modal-open { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
.sheet h2 { margin: 0 0 14px; font-size: 1.2rem; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .86rem; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.input, .select {
  width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); padding: 0 14px; color: var(--ink);
}
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-height: 28px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.form-error { color: var(--expense); font-weight: 500; margin: 0 0 12px; min-height: 0; }
.actions { display: flex; gap: 10px; margin-top: 8px; }
.actions .btn { flex: 1; }
.actions .btn.primary { flex: 2; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.seg label { text-align: center; padding: 9px 4px; border-radius: 9px; font-weight: 600; font-size: .92rem; cursor: pointer; color: var(--muted); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--ink); }
.seg label:has(input:checked) { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); color: var(--ink); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--focus); }

.amount-input {
  width: 100%; border: 0; background: none; text-align: center; font-size: 2.4rem; font-weight: 700;
  padding: 4px 0 8px; border-bottom: 2px solid var(--line); border-radius: 0; margin-bottom: 16px; color: var(--ink);
}
.amount-input:focus { outline: none; border-bottom-color: var(--accent); }
.amount-input.expense-tone { color: var(--expense); }
.amount-input.income-tone { color: var(--income); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chips label { cursor: pointer; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface-2); font-size: .9rem; }
.chips input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chips input:focus-visible + span { outline: 3px solid var(--focus); }

/* ---------- giriş ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); padding: 28px 24px; }
.login-card h1 { margin: 0 0 4px; font-size: 1.8rem; letter-spacing: -0.03em; color: var(--accent); }
.login-card p { margin: 0 0 20px; color: var(--muted); }

#toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 90px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 500; z-index: 60;
  transition: opacity .2s, transform .2s; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { #toast { bottom: 40px; } }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* yaklaşan ödeme satırı: üstte ad ve tutar, altta vade ve eylem */
.row.up { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 6px; align-items: center; }
.row.up .dot { grid-column: 1; grid-row: 1; }
.row.up .title { grid-column: 2; grid-row: 1; }
.row.up .amount { grid-column: 3; grid-row: 1; }
.row.up .sub { grid-column: 2; grid-row: 2; white-space: normal; overflow: visible; }
.row.up .pill { white-space: nowrap; }
.row.up .btn { grid-column: 3; grid-row: 2; justify-self: end; }
.row.up.noact .sub { grid-column: 2 / 4; }

a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--ink); text-align: center; }

/* yatırım satırı: sağda değer ve altında kâr/zarar */
.row .amt-col { text-align: right; white-space: nowrap; flex: none; }
.row .amt-col .amount { display: block; }
.row .amt-col .pl { display: block; font-size: .82rem; font-weight: 500; }
.row .amt-col .pl.muted { color: var(--muted); }

/* yönetici: başka kullanıcıyı salt okunur görüntüleme */
.viewbar {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: .9rem;
}
.viewbar .btn { flex: none; }
.viewing .fab, .viewing .page-head .btn, .viewing .row .btn.small, .viewing button.linklike { display: none; }

.receipt-thumb { display: block; max-width: 100%; max-height: 180px; border-radius: 12px; border: 1px solid var(--line); }

.head-right { display: flex; align-items: center; gap: 8px; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 12px;
  color: var(--accent); background: var(--surface); border: 1px solid var(--line); text-decoration: none; flex: none; }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn:hover { background: var(--accent-soft); }
@media (max-width: 480px) {
  .page-head { gap: 8px; }
  .page-head h1 { font-size: 1.35rem; }
  .head-right { gap: 6px; }
  .monthnav button { width: 34px; }
  .monthnav .current { min-width: 88px; font-size: .95rem; }
  .iconbtn { width: 38px; height: 38px; }
}
@media (max-width: 340px) {
  .page-head h1 { font-size: 1.2rem; }
  .monthnav button { width: 30px; }
  .monthnav .current { min-width: 70px; font-size: .85rem; }
}
