:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #17212f;
  --muted: #66758a;
  --accent: #0e9f7a;
  --accent-strong: #0b8566;
  --accent-soft: #e3f6f0;
  --danger: #d6455d;
  --danger-soft: #fdecef;
  --warn: #b7791f;
  --warn-soft: #fdf3dc;
  --info: #2f6fde;
  --info-soft: #e8f0fe;
  --side: #0f1b2d;
  --side-text: #a9b6c9;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0c131f;
  --surface: #141d2b;
  --surface-2: #19243a;
  --border: #26334a;
  --text: #e6ecf5;
  --muted: #8d9bb1;
  --accent: #2cc79c;
  --accent-strong: #4bd8b0;
  --accent-soft: #123a31;
  --danger: #f0708a;
  --danger-soft: #3b1a24;
  --warn: #e6b450;
  --warn-soft: #3a2e12;
  --info: #7aa7ff;
  --info-soft: #16264a;
  --side: #0a111c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.note { display: block; min-width: 260px; white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; }

/* ---------- Giriş ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 500px at 15% 10%, rgba(14, 159, 122, 0.28), transparent 60%),
    radial-gradient(800px 500px at 90% 90%, rgba(47, 111, 222, 0.25), transparent 60%), var(--side);
}
.login-card {
  width: min(400px, 100%); background: var(--surface); border-radius: 18px; padding: 34px 32px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35); display: grid; gap: 16px;
}
.login-card h1 { font-size: 22px; letter-spacing: -0.02em; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.logo { height: 46px; width: auto; display: block; }
/* Harf aralığı son harften sonra da boşluk bırakır; soldaki ek dolgu yazıyı yatayda ortalar. */
.brand-tag { display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; line-height: 1; letter-spacing: 0.1em; text-transform: uppercase; white-space: nowrap; color: var(--accent); border: 1px solid currentColor; border-radius: 6px; padding: 5px 7px 5px calc(7px + 0.1em); }
.modal:focus { outline: none; }
.login-card .logo.white, [data-theme="dark"] .login-card .logo.color { display: none; }
[data-theme="dark"] .login-card .logo.white { display: block; }

/* ---------- İskelet ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 8px 14px; }
.side .brand-tag { color: #5fe3bd; }
/* "Fatura Takip" logonun yanına sığmaz; geniş ekranda logonun altında durur. */
.side .brand { flex-direction: column; align-items: flex-start; gap: 8px; }
.side .menu-btn { display: none; background: rgba(255, 255, 255, 0.08); border-color: transparent; color: #fff; font-size: 18px; padding: 6px 12px; }
.nav-title { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: #5f6f88; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: inherit; text-decoration: none;
  font-weight: 500; transition: background 0.15s, color 0.15s;
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active { background: rgba(44, 199, 156, 0.16); color: #5fe3bd; }
.nav svg, .icon { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; padding: 12px 8px 2px; border-top: 1px solid rgba(255, 255, 255, 0.08); display: grid; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; color: #fff; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #22344f; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.user-chip small { display: block; color: var(--side-text); }
.side-foot .row { display: flex; gap: 6px; }
.side-foot .btn { flex: 1; background: rgba(255, 255, 255, 0.06); border-color: transparent; color: var(--side-text); padding: 6px 8px; font-size: 12px; }
.side-foot .btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.main { padding: 26px 30px 60px; min-width: 0; }
.page { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; animation: rise 0.25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; letter-spacing: -0.02em; }
.page-head p { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Bileşenler ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
:root[data-theme="dark"] .btn.primary { color: #06261d; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; width: 30px; height: 30px; border-radius: 8px; font-size: 18px; line-height: 1; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.input, select.input, textarea.input {
  width: 100%; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s; min-height: 36px;
}
textarea.input { min-height: 70px; resize: vertical; }
.input:hover { border-color: var(--muted); }
.input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.field { display: grid; gap: 5px; align-content: start; min-width: 0; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field-label em { color: var(--danger); font-style: normal; }
.field small { color: var(--muted); font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: 1 / -1; }

.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 240px; overflow-y: auto; min-width: 200px;
}
.combo-list li { padding: 7px 9px; border-radius: 7px; cursor: pointer; }
.combo-list li.active { background: var(--surface-2); }
.combo-list li.selected { color: var(--accent); font-weight: 600; }
.combo-list li.none { color: var(--muted); cursor: default; }
.multi { border: 1px solid var(--border); border-radius: 10px; padding: 8px; display: grid; gap: 8px; }
.multi-list { max-height: 170px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 2px 10px; }
.multi-list .check { min-height: 28px; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; padding: 14px; }
.table-wrap { overflow-x: auto; transition: opacity 0.15s; }
.table-wrap.loading { opacity: 0.5; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
th.num { text-align: right; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty.error { color: var(--danger); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.rows-table td { padding: 5px 6px 5px 0; border: 0; }
.rows-table th { background: transparent; border: 0; padding: 0 6px 4px 0; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.off { background: var(--surface-2); color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--tone, var(--accent)); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 23px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.stat-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: 5px 12px; font-size: 13px; }
.chip b { font-variant-numeric: tabular-nums; }

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(8, 14, 24, 0.55); backdrop-filter: blur(3px); display: grid; place-items: start center; padding: 5vh 16px; overflow-y: auto; animation: fade 0.15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 16px; width: min(560px, 100%); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35); animation: rise 0.2s ease; }
.modal.wide { width: min(1080px, 100%); }
.modal.mid { width: min(760px, 100%); }
.modal > header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal h2 { font-size: 17px; letter-spacing: -0.01em; }
.modal-body { padding: 20px; display: grid; gap: 18px; }
.modal > footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; flex-wrap: wrap; }
.modal > footer .left { margin-right: auto; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 18px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
/* Fatura editörü: bölümler ayrı kutularda, her kalem numaralı ve başlıklı bir kart. */
.editor { display: grid; gap: 22px; }
.ed-section { display: grid; gap: 16px; padding: 18px 20px 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); }
.ed-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.ed-title .actions { text-transform: none; letter-spacing: 0; font-weight: 400; }
.ed-section .form-grid { gap: 16px 18px; }
.item-list { display: grid; gap: 16px; }
.item-list:empty { display: none; }
.item-card { border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 12px; background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06); overflow: hidden; }
.item-card:nth-child(even) { border-left-color: var(--info); }
.item-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.item-card:nth-child(even) .item-head { background: color-mix(in srgb, var(--info) 7%, var(--surface)); }
.item-num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; }
.item-card:nth-child(even) .item-num { background: var(--info); }
.item-title { flex: 1; min-width: 0; font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
.item-amount { font-weight: 700; font-size: 15px; }
.item-row { display: grid; gap: 14px 16px; align-items: end; padding: 14px; }
.item-row.a { grid-template-columns: minmax(0, 3fr) 110px 140px 100px; }
.item-row.b { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 0; }
.item-row.c { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.static { padding: 9px 0; }
/* Tahsilat dağıtım kartı: tutar girilene kadar nötr, girilince renkli. */
.item-card.alloc, .item-card.alloc:nth-child(even) { border-left-color: var(--border); }
.item-card.alloc .item-head, .item-card.alloc:nth-child(even) .item-head { background: var(--surface); }
.item-card.alloc.on, .item-card.alloc.on:nth-child(even) { border-left-color: var(--accent); }
.item-card.alloc.on .item-head, .item-card.alloc.on:nth-child(even) .item-head { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.item-list > .empty { padding: 24px 12px; }
.item-list.loading { opacity: 0.5; }
.item-verifier { display: grid; gap: 10px; margin: 0 14px 14px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 10px; background: var(--surface-2); }
.item-verifier[hidden] { display: none; }
.item-sub { font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.totals { margin-left: auto; width: min(360px, 100%); display: grid; gap: 8px; padding: 16px 18px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); }
.totals div { display: flex; justify-content: space-between; gap: 12px; }
.totals .grand { border-top: 1px solid var(--border); padding-top: 8px; font-size: 17px; font-weight: 700; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.notice.info { background: var(--info-soft); color: var(--info); }
.warn-list { margin: 0; padding-left: 18px; display: grid; gap: 8px; }

#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: grid; gap: 8px; }
.toast { background: var(--side); color: #fff; padding: 11px 15px; border-radius: 11px; box-shadow: var(--shadow); max-width: 420px; animation: rise 0.2s; border-left: 4px solid var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: #e6b450; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.7s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  /* Dar ekran: yan menü üstte sabit bir çubuğa dönüşür, ☰ ile açılır. */
  .side { height: auto; max-height: 100dvh; z-index: 40; padding: 8px 10px; }
  .side-head { padding: 0 4px; }
  .side .logo { height: 36px; }
  .side .brand { flex-direction: row; align-items: center; gap: 10px; }
  .side .menu-btn { display: block; }
  .side:not(.open) > :not(.side-head) { display: none; }
  .side.open .side-foot { margin-top: 12px; }
  .main { padding: 18px 14px 50px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span-3 { grid-column: 1 / -1; }
  .item-row.a, .item-row.b { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .main { padding: 14px 12px 40px; }
  .page-head h1 { font-size: 20px; }
  .form-grid, .item-row.a, .item-row.b, .item-row.c { grid-template-columns: 1fr; }
  .ed-section { padding: 14px 12px 16px; }
  .item-head { flex-wrap: wrap; }
  .form-grid > * { grid-column: 1 / -1; }
  .filters, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pager { flex-wrap: wrap; }
  .stat-value { font-size: 18px; }
  /* Liste tabloları telefonda satır başına bir karta dönüşür; başlık td'nin data-label'ından gelir. */
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr { display: block; }
  table.data tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  table.data tr:last-child { border-bottom: 0; }
  table.data td { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 4px 14px; border: 0; text-align: right; white-space: normal; overflow-wrap: anywhere; }
  table.data td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 12px; text-align: left; }
  table.data td:empty { display: none; }
  /* Not uzun olabilir: etiketin altında, tam genişlikte ve tamamı görünür. */
  table.data td:has(.note) { display: block; text-align: left; }
  table.data td:has(.note)::before { display: block; margin-bottom: 2px; }
  .note { min-width: 0; }
  .overlay { padding: 0; }
  .modal, .modal.wide, .modal.mid { width: 100%; min-height: 100dvh; border-radius: 0; }
  .modal > footer { border-radius: 0; }
  .login-card { padding: 26px 20px; }
  /* iOS, 16px'ten küçük yazılı alana odaklanınca sayfayı yakınlaştırır. */
  input, select, textarea { font-size: 16px !important; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
