:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #9ca3af;
  --line: #e5e7eb;
  --brand: #1f2933;
  --accent: #c8102e;
  --accent-soft: #fdecee;
  --green: #0f7b4f;
  --green-soft: #e6f4ee;
  --amber: #a15c00;
  --amber-soft: #fff4e0;
  --blue: #1d4ed8;
  --blue-soft: #e8efff;
  --ust: #6d28d9;
  --ust-soft: #f1eafe;
  --alt: #0e7490;
  --alt-soft: #e3f5f9;
  --line-2: #d1d5db;
  --brand-ink: #ffffff;
  --big: #1f2933;
  --overlay: rgba(17,24,39,.5);
  --radius: 12px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }
.boot { padding: 40vh 0; text-align: center; color: var(--ink-3); }
.hidden { display: none !important; }

/* ---------- yerleşim ---------- */
.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { background: none; border: 0; color: #fff; font-size: 22px; padding: 2px 8px 2px 0; cursor: pointer; }
.topbar .who { font-size: 12px; opacity: .75; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; display: inline-block; margin-right: 6px; }
.live-dot.on { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.25); }
main { padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 90px); max-width: 1100px; margin: 0 auto; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line);
  display: flex; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
}
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--ink-2); }
.bottomnav a svg { width: 22px; height: 22px; }
.bottomnav a.active { color: var(--accent); font-weight: 600; }
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 31;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: 0 6px 18px rgba(200,16,46,.35); cursor: pointer;
}
.sidenav { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 220px 1fr; }
  .sidenav { display: flex; flex-direction: column; gap: 2px; background: var(--brand); color: #d1d5db; padding: 18px 10px; position: sticky; top: 0; height: 100vh; }
  .sidenav .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
  .sidenav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
  .sidenav a svg { width: 18px; height: 18px; }
  .sidenav a:hover { background: rgba(255,255,255,.07); }
  .sidenav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
  .sidenav .spacer { flex: 1; }
  .sidenav .quick { display: grid; gap: 6px; margin: 14px 4px; }
  .sidenav .quick button { border: 0; border-radius: 8px; padding: 9px; cursor: pointer; font-weight: 600; font-size: 13px; }
  .bottomnav, .fab { display: none; }
  .topbar { position: sticky; }
  main { padding: 22px 24px 60px; }
}

/* ---------- kartlar ---------- */
.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 14px; margin: 0 0 10px; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; display: flex; align-items: center; gap: 8px; }
.card h2 .count { background: var(--bg); color: var(--ink-2); border-radius: 10px; padding: 0 7px; font-size: 12px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--ink-2); }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.stat.big { grid-column: 1 / -1; background: var(--big); color: #fff; border: 0; }
.stat.big .label, .stat.big .sub { color: rgba(255,255,255,.7); }
.stat.big .value { font-size: 28px; }
.stat.big .split { display: flex; gap: 16px; margin-top: 8px; font-size: 13px; flex-wrap: wrap; }
.stat.big .split span b { font-weight: 650; }
@media (min-width: 900px) { .stat.big { grid-column: span 2; } }
.stat.warn .value { color: var(--accent); }
.stat.good .value { color: var(--green); }

/* ---------- listeler ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 12.5px; color: var(--ink-2); margin-top: 1px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row .right { text-align: right; }
.row .amount { font-weight: 700; }
.empty { text-align: center; color: var(--ink-3); padding: 22px 8px; font-size: 14px; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.badge.ust { background: var(--ust-soft); color: var(--ust); }
.badge.alt { background: var(--alt-soft); color: var(--alt); }
.badge.red { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gray { background: var(--bg); color: var(--ink-2); }
.pos { color: var(--accent); }
.neg { color: var(--green); }

/* ---------- araç çubuğu ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 1px solid var(--line); background: var(--card); padding: 7px 13px; border-radius: 20px; font-size: 13.5px; cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--ink); color: var(--card); border-color: var(--ink); }
.tab .n { opacity: .7; margin-left: 4px; font-size: 12px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 180px; }
input.search, .field input, .field select, .field textarea, select.sel {
  width: 100%; border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; background: var(--card); font-size: 16px;
}
select.sel { width: auto; font-size: 14px; padding: 9px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(200,16,46,.25); border-color: var(--accent); }

/* ---------- butonlar ---------- */
.btn { border: 1px solid var(--line-2); background: var(--card); border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--card); }
.btn.wa { background: #1fa855; border-color: #1fa855; color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--accent); border-color: #f3c3ca; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 700px) { .actions { grid-template-columns: repeat(4, auto); justify-content: start; } }

/* ---------- cari detay ---------- */
.cust-head { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.cust-head .name { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.cust-head .info { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13.5px; color: var(--ink-2); }
.balance-box { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.balance-box > div { flex: 1; min-width: 120px; background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.balance-box .label { font-size: 12px; color: var(--ink-2); }
.balance-box .value { font-size: 19px; font-weight: 700; }
.balance-box .main-bal { background: var(--accent-soft); }
.balance-box .main-bal.zero { background: var(--green-soft); }
.promise { display: flex; align-items: center; gap: 10px; background: var(--amber-soft); color: var(--amber); border-radius: 10px; padding: 9px 12px; margin-bottom: 12px; font-size: 14px; }
.promise.late { background: var(--accent-soft); color: var(--accent); }
.promise .grow { flex: 1; }

.entry { display: flex; gap: 10px; padding: 11px 2px; cursor: pointer; }
.entry .ico { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; font-size: 14px; }
.entry .ico.is { background: var(--accent-soft); color: var(--accent); }
.entry .ico.tahsilat { background: var(--green-soft); color: var(--green); }
.entry .ico.bounced { background: var(--bg); color: var(--ink-3); }
.entry .main { flex: 1; min-width: 0; }
.entry .title { font-weight: 600; }
.entry .meta { font-size: 12.5px; color: var(--ink-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 1px; }
.entry .right { text-align: right; }
.entry .run { font-size: 12px; color: var(--ink-3); }
.entry.struck .amount { text-decoration: line-through; color: var(--ink-3); }
.month-sep { font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; padding: 12px 2px 4px; border-top: 0 !important; }

/* ---------- tablo ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--ink-2); font-weight: 600; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 8px; border-bottom: 1px solid var(--line); }
table.t td.r, table.t th.r { text-align: right; }
table.t tfoot td { font-weight: 700; border-bottom: 0; }

.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 3px; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 100; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); animation: up .18s ease-out; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 16px; max-height: 88vh; } }
.sheet h3 { margin: 0 0 14px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sheet h3 .x { margin-left: auto; background: var(--bg); border: 0; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 18px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 3px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.methods { flex-wrap: wrap; }
.seg.methods button { flex: 1 0 30%; }
.amount-input { font-size: 26px !important; font-weight: 700; text-align: right; }
.sheet .foot { display: flex; gap: 8px; margin-top: 16px; }
.sheet .foot .btn { flex: 1; padding: 13px; }
.err { background: var(--accent-soft); color: var(--accent); padding: 9px 12px; border-radius: 9px; font-size: 14px; margin-bottom: 10px; }
.menu-list button { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px 6px; border: 0; background: none; border-bottom: 1px solid var(--line); font-size: 16px; cursor: pointer; text-align: left; }
.menu-list button:last-child { border-bottom: 0; }
.menu-list .mi { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; }

.picker { position: relative; }
.picker .opts { position: absolute; left: 0; right: 0; top: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto; z-index: 5; margin-top: 4px; }
.picker .opt { padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); }
.picker .opt:last-child { border-bottom: 0; }
.picker .opt:hover, .picker .opt.hl { background: var(--bg); }
.picked { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 12px; }
.picked .grow { flex: 1; font-weight: 600; }

/* ---------- toast ---------- */
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 10px); z-index: 200; display: grid; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--brand); color: #fff; padding: 11px 14px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: down .2s; }
.toast.err { background: var(--accent); color: #fff; margin: 0; }
.toast.ok { background: var(--green); }

/* ---------- giriş ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--brand); }
.login .box { background: var(--card); border-radius: 16px; padding: 26px 22px; width: 100%; max-width: 360px; }
.login .logo { width: 56px; height: 56px; margin: 0 auto 10px; display: block; }
.login h1 { text-align: center; font-size: 20px; margin: 0 0 4px; }
.login p { text-align: center; color: var(--ink-2); margin: 0 0 20px; font-size: 14px; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes down { from { transform: translateY(-10px); opacity: 0; } }

/* ---------- yazdırma ---------- */
.print-only { display: none; }
@media print {
  body { background: var(--card); font-size: 12px; }
  .topbar, .bottomnav, .fab, .sidenav, .no-print, .btn, .tabs, .toolbar { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .card, .cust-head, .stat { border: 0; padding: 0; margin-bottom: 10px; }
  .print-only { display: block; }
  .entry { padding: 5px 0; }
  .entry .ico { display: none; }
}

/* ---------- gece modu ---------- */
html { color-scheme: light; }
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141a;
  --card: #1a2129;
  --ink: #e6e9ee;
  --ink-2: #a5aebb;
  --ink-3: #6f7986;
  --line: #29323c;
  --line-2: #3a4450;
  --brand: #0b0f14;
  --big: #25303d;
  --accent: #f0566a;
  --accent-soft: rgba(240,86,106,.16);
  --green: #3cc794;
  --green-soft: rgba(60,199,148,.15);
  --amber: #f2b85e;
  --amber-soft: rgba(242,184,94,.15);
  --blue: #86a8ff;
  --blue-soft: rgba(134,168,255,.16);
  --ust: #bc9cf7;
  --ust-soft: rgba(188,156,247,.16);
  --alt: #62cbe0;
  --alt-soft: rgba(98,203,224,.15);
  --overlay: rgba(0,0,0,.6);
}
html[data-theme="dark"] .btn.primary, html[data-theme="dark"] .fab { background: #d42a42; border-color: #d42a42; }
html[data-theme="dark"] .btn.green { background: #13865a; border-color: #13865a; }
html[data-theme="dark"] .toast { background: #2c3744; }
html[data-theme="dark"] .toast.ok { background: #13865a; }
html[data-theme="dark"] .login { background: #0b0f14; }
html[data-theme="dark"] .bottomnav { border-top-color: var(--line); }
html[data-theme="dark"] .picker .opts { box-shadow: 0 8px 24px rgba(0,0,0,.5); }
html[data-theme="dark"] .sidenav .quick button[data-quick="cari"] { background: rgba(255,255,255,.08) !important; }
.theme-seg { max-width: 360px; }
@media print {
  html[data-theme="dark"] { --bg: #fff; --card: #fff; --ink: #111827; --ink-2: #4b5563; --ink-3: #6b7280; --line: #e5e7eb; --accent: #c8102e; --green: #0f7b4f; }
}

/* ---------- internet yok / bekleyen kayıt şeridi ---------- */
.net-bar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 32; padding: 8px 14px; font-size: 13px; font-weight: 600; text-align: center; cursor: pointer; color: #fff; }
.net-bar.off { background: #4b5563; }
.net-bar.wait { background: #a15c00; }
.net-bar.err { background: #c8102e; }
@media (min-width: 900px) { .net-bar { left: 220px; bottom: 0; } }
details > summary { list-style: none; }
details > summary::before { content: '▸ '; }
details[open] > summary::before { content: '▾ '; }
