:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1b1f27;
  --muted: #667085;
  --primary: #2f5bd3;
  --primary-soft: #e7edfc;
  --in: #0f8a6a;
  --in-soft: #dcf3ec;
  --out: #c8463d;
  --out-soft: #fbe5e3;
  --warn: #b7791f;
  --warn-soft: #fdf1dc;
  --vacant: #0b8f9c;
  --vacant-soft: #d8f3f5;   /* boş daireler: turkuaz */
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --c1: #2f5bd3; --c2: #0f8a6a; --c3: #d08a1c; --c4: #9b4dca; --c5: #c8463d;
  --c6: #1f9bb5; --c7: #6b7a2a; --c8: #b84f87; --c9: #5a6474;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #181b21; --surface-2: #20242c; --border: #2b3039;
    --text: #e8eaee; --muted: #98a1b0; --primary: #7b9cf5; --primary-soft: #1e2a4a;
    --in: #3cc49c; --in-soft: #12352c; --out: #f07a70; --out-soft: #3d1c1a;
    --warn: #e6b04f; --warn-soft: #3a2c12; --vacant: #3fd3da; --vacant-soft: #0e3a3f;
    --shadow: none;
    --c1: #7b9cf5; --c2: #3cc49c; --c3: #e6b04f; --c4: #c08ae6; --c5: #f07a70;
    --c6: #5cc7de; --c7: #b3c25a; --c8: #e486b7; --c9: #98a1b0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #181b21; --surface-2: #20242c; --border: #2b3039;
  --text: #e8eaee; --muted: #98a1b0; --primary: #7b9cf5; --primary-soft: #1e2a4a;
  --in: #3cc49c; --in-soft: #12352c; --out: #f07a70; --out-soft: #3d1c1a;
  --warn: #e6b04f; --warn-soft: #3a2c12; --vacant: #3fd3da; --vacant-soft: #0e3a3f;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.in { color: var(--in); } .out { color: var(--out); }
.hidden { display: none !important; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi .label { color: var(--muted); font-size: .8rem; }
.kpi .value { font-size: 1.35rem; font-weight: 650; margin-top: 2px; }

button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 7px 13px; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--out); }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: default; }
button.sm { padding: 4px 9px; font-size: .85rem; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
label.field input, label.field select { color: var(--text); }

.badge {
  display: inline-block; font-size: .74rem; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.in { background: var(--in-soft); color: var(--in); }
.badge.out { background: var(--out-soft); color: var(--out); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
td.r, th.r { text-align: right; }
.table-wrap { overflow: auto; max-width: 100%; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--in); }
.switch input:checked + span::before { transform: translateX(18px); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 99;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: 90vw;
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.err { background: var(--out); color: #fff; }

/* ---------- grafikler ---------- */
.chart-months { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 8px; }
.chart-months .m { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.chart-months .bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.chart-months .bar { width: 42%; max-width: 16px; border-radius: 4px 4px 0 0; min-height: 0; }
.chart-months .bar.in { background: var(--in); }
.chart-months .bar.out { background: var(--out); }
.chart-months .lbl { font-size: .7rem; color: var(--muted); margin-top: 4px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.hbars { display: grid; gap: 10px; }
.hbar .top { display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; }
.hbar .track { height: 8px; background: var(--surface-2); border-radius: 99px; margin-top: 4px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 99px; }

.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; border-radius: 50%; position: relative; flex: none; }
.donut::after { content: ""; position: absolute; inset: 26px; background: var(--surface); border-radius: 50%; }
.donut .center { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; text-align: center; font-size: .78rem; color: var(--muted); }
.donut .center b { display: block; color: var(--text); font-size: .95rem; }
.donut-legend { display: grid; gap: 6px; font-size: .84rem; flex: 1; min-width: 160px; }
.donut-legend div { display: flex; gap: 8px; align-items: center; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.donut-legend span:nth-child(2) { flex: 1; }

.mycells { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.mycells div { border-radius: 8px; padding: 6px 4px; text-align: center; font-size: .74rem; background: var(--surface-2); color: var(--muted); }
.mycells div.paid { background: var(--in-soft); color: var(--in); font-weight: 600; }
.mycells div.part { background: var(--warn-soft); color: var(--warn); font-weight: 600; }

/* ---------- bina görünüşü ---------- */
.bld {
  --glow: #0a9dff;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 6px; overflow-x: auto;
  background-color: var(--surface);
  background-image: linear-gradient(var(--surface-2) 1px, transparent 1px), linear-gradient(90deg, var(--surface-2) 1px, transparent 1px);
  background-size: 16px 16px;
}
.bld + .legend { --glow: #0a9dff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bld, :root:not([data-theme="light"]) .bld + .legend { --glow: #6fd6ff; } }
:root[data-theme="dark"] .bld, :root[data-theme="dark"] .bld + .legend { --glow: #6fd6ff; }
.bld svg { display: block; width: 100%; max-width: 640px; height: auto; margin: 0 auto; }
.bld .ln { fill: var(--surface); stroke: var(--primary); stroke-width: 1; }
.bld .thin { fill: none; stroke: var(--primary); stroke-width: .6; opacity: .7; }
.bld text { font: 600 10px ui-monospace, Consolas, monospace; text-anchor: middle; fill: var(--text); pointer-events: none; }
.bld text.lvl { text-anchor: end; fill: var(--muted); font-weight: 400; font-size: 8.5px; }
.bld text.ttl { font-size: 11px; letter-spacing: .18em; fill: var(--primary); }
.bld .flat { cursor: pointer; outline: none; }
.bld .flat .box { fill: var(--surface); stroke: var(--primary); stroke-width: 1; }
.bld .flat.ok .box { fill: var(--in-soft); }
.bld .flat.debt .box { fill: var(--out-soft); }
.bld .flat.static { cursor: default; }
.bld .flat:not(.static):hover .box, .bld .flat:focus-visible .box { stroke-width: 2; }
.bld .flat.sel .box { stroke: var(--text); stroke-width: 2.2; }
.bld .flat.me .box {
  stroke: var(--glow); stroke-width: 2.6;
  filter: drop-shadow(0 0 2px var(--glow)) drop-shadow(0 0 6px var(--glow));
  animation: bld-glow 1.6s ease-in-out infinite alternate;
}
.bld .flat.me text { fill: var(--text); font-size: 11px; }
@keyframes bld-glow { from { filter: drop-shadow(0 0 1px var(--glow)); } to { filter: drop-shadow(0 0 3px var(--glow)) drop-shadow(0 0 9px var(--glow)); } }
@media (prefers-reduced-motion: reduce) { .bld .flat.me .box { animation: none; } }

.paygrid { border-collapse: separate; border-spacing: 3px; width: auto; }
.paygrid td, .paygrid th { border: 0; padding: 0; text-align: center; font-size: .72rem; }
.paygrid th { position: static; padding: 0 2px; }
.paygrid td.code { text-align: left; padding-right: 8px; white-space: nowrap; font-weight: 600; font-size: .8rem; }
.paygrid .cell { width: 28px; height: 22px; border-radius: 5px; background: var(--surface-2); }
.paygrid .cell.paid { background: var(--in); }
.paygrid .cell.part { background: var(--warn); }
.paygrid .cell.debt { background: var(--out); }

/* bina çizimindeki daire kutusunun içindeki 12 aylık küçük kutucuklar */
.bld .flat .mc { fill: transparent; stroke: var(--border); stroke-width: .4; }
.bld .flat .mc.paid { fill: var(--in); fill-opacity: .45; stroke: none; }
.bld .flat .mc.debt { fill: var(--out); fill-opacity: .45; stroke: none; }
.bld .flat .mc.part { fill: var(--warn); fill-opacity: .45; stroke: none; }
.bld .flat.cells text { paint-order: stroke; stroke: var(--surface); stroke-width: 2.4px; stroke-linejoin: round; }

/* 12 aylık yatay aidat şeridi */
.strip12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 3px; }
.strip12 button { padding: 7px 0; border: 0; border-radius: 5px; font-size: .6rem; letter-spacing: -.02em; line-height: 1.1; background: var(--surface-2); color: var(--muted); overflow: hidden; }
.strip12 button.paid { background: var(--in); color: var(--surface); font-weight: 600; }
.strip12 button.debt { background: var(--out); color: var(--surface); font-weight: 600; }
.strip12 button.part { background: var(--warn); color: var(--surface); font-weight: 600; }
.strip12 button.sel { outline: 2px solid var(--text); outline-offset: 1px; }
.strip12 button:hover { filter: brightness(1.08); }

a.btn { display: inline-block; text-decoration: none; text-align: center; }
a.btn.wa { background: #1faa59; border-color: #1faa59; color: #fff; font-weight: 600; padding: 10px 14px; }
a.btn.wa:hover { filter: brightness(1.07); }

/* boş daireler */
.badge.vacant { background: var(--vacant-soft); color: var(--vacant); border: 1px dashed var(--vacant); font-weight: 600; }
tr.vacant > td { background: var(--vacant-soft); }
tr.vacant input[data-f="resident_name"] { border: 1px dashed var(--vacant); color: var(--vacant); font-weight: 700; }
.bld .flat.vacant .box { fill: var(--vacant-soft); stroke: var(--vacant); stroke-dasharray: 3 2; }
.bld .flat.vacant .thin { stroke: var(--vacant); }

.poll { display: grid; gap: 8px; }
.poll-opts { display: grid; gap: 6px; }
.poll-opts button { text-align: left; white-space: normal; padding: 9px 12px; }
.chat { display: grid; gap: 6px; }
.chat .msg { max-width: 86%; padding: 7px 11px; border-radius: 12px; background: var(--surface-2); font-size: .9rem; overflow-wrap: anywhere; }
.chat .msg.own { justify-self: end; background: var(--primary-soft); }
.chat .msg .when { display: block; font-size: .7rem; color: var(--muted); margin-top: 2px; }
dialog.notice { width: min(560px, 94vw); max-height: 88vh; overflow: auto; color: var(--text); }
dialog.notice::backdrop { background: rgba(0, 0, 0, .6); }

.clock { display: flex; flex-direction: column; line-height: 1.25; font-size: .78rem; color: var(--muted); }
.clock b { font-size: 1.05rem; color: var(--text); }
.dues-table td, .dues-table th { white-space: nowrap; }
.dues-table td.m, .dues-table th.m { text-align: center; padding: 6px 4px; }
.dues-table tr.debtor td.code { box-shadow: inset 3px 0 0 var(--out); }
.dues-table tr.clear td.code { box-shadow: inset 3px 0 0 var(--in); }
