:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7785;
  --line: #e3e8ee;
  --accent: #2563eb;
  --paid: #1f9d57;
  --paid-fill: rgba(31, 157, 87, 0.45);
  --paid-stroke: #1f9d57;
  --unpaid-fill: rgba(120, 130, 145, 0.10);
  --unpaid-stroke: #8a94a3;
  --danger: #d23b3b;
  --shadow: 0 1px 3px rgba(20,30,45,.08), 0 1px 2px rgba(20,30,45,.06);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.container { max-width: 1100px; margin: 0 auto; padding: 20px; }
.muted { color: var(--muted); }
code { background: #eef1f5; padding: 1px 6px; border-radius: 6px; font-size: .9em; }

.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
}
.site-header > .brand { justify-self: start; }
.site-header > .topnav { justify-self: end; }
@media (max-width: 900px) {
  .site-header { grid-template-columns: 1fr auto; }
  .site-header > .clock { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 30px; }
.brand h1 { font-size: 20px; margin: 0; }
.brand .subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.topnav { display: flex; gap: 8px; }
.topnav a {
  text-decoration: none; color: var(--ink); padding: 8px 14px; border-radius: 8px; font-weight: 500;
}
.topnav a:hover { background: var(--bg); }
.topnav a.active { background: var(--accent); color: #fff; }
.topnav a.site-link { background: #16a34a; color: #fff; }
.topnav a.site-link:hover { background: #15803d; }
.topnav { align-items: center; flex-wrap: wrap; }
.site-header > .clock {
  justify-self: center; font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 600;
  color: var(--ink); white-space: nowrap; padding: 8px 16px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
}

/* Админка: часы сразу после логотипа, все кнопки — в одну строку справа. */
.site-header.admin-header {
  display: flex; flex-wrap: nowrap; justify-content: flex-start; gap: 12px;
  padding: 10px 16px;
}
.site-header.admin-header > .brand { flex: 0 0 auto; }
.site-header.admin-header > .clock {
  justify-self: auto; margin-left: auto; margin-right: auto;
  font-size: 16px; font-weight: 500; padding: 6px 10px;
}
.site-header.admin-header > .topnav {
  flex: 0 0 auto; flex-wrap: nowrap; gap: 6px;
}
.site-header.admin-header .topnav a,
.site-header.admin-header .topnav button {
  padding: 6px 9px; font-size: 13px; white-space: nowrap;
}
.site-header.admin-header .role-pill {
  max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px;
}
.settings-inline { display: flex; align-items: center; gap: 6px; }
.settings-inline .settings-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.settings-inline .dropdown {
  position: static; display: flex; flex-direction: row; align-items: center; gap: 6px;
  padding: 0; border: 0; box-shadow: none; background: transparent; min-width: 0;
}
.settings-inline .dropdown button {
  padding: 6px 9px; font-size: 13px; white-space: nowrap;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.settings-inline .dropdown button:hover { background: var(--bg); }
@media (max-width: 1100px) {
  .site-header.admin-header .brand .subtitle { display: none; }
  .site-header.admin-header .role-pill { display: none; }
}
@media (max-width: 760px) {
  .site-header.admin-header { flex-wrap: wrap; }
  .site-header.admin-header > .clock { margin-left: 0; margin-right: 0; }
  .site-header.admin-header > .topnav { flex-wrap: wrap; }
}

.menu-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 190px;
  background: var(--card); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column;
}
.dropdown button {
  text-align: left; background: transparent; border: 0; padding: 9px 10px; border-radius: 6px;
  color: var(--ink); font-size: 14px; cursor: pointer;
}
.dropdown button:hover { background: var(--bg); }

.site-footer {
  max-width: 1100px; margin: 8px auto 32px; padding: 0 20px; color: var(--muted); font-size: 13px;
  display: flex; flex-direction: column; gap: 4px;
}

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card h2 { margin-top: 0; font-size: 18px; }

/* Спойлеры на публичной странице */
details.spoiler { padding: 0; }
details.spoiler > summary {
  cursor: pointer; list-style: none; padding: 16px 18px; font-weight: 600; font-size: 16px;
  border-radius: var(--radius); display: flex; align-items: center; gap: 10px;
}
details.spoiler > summary::-webkit-details-marker { display: none; }
details.spoiler > summary::before { content: '▸'; color: var(--accent); font-size: 14px; }
details.spoiler[open] > summary::before { content: '▾'; }
details.spoiler[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
details.spoiler > :not(summary) { margin-left: 18px; margin-right: 18px; }
details.spoiler > :last-child { margin-bottom: 18px; }

/* summary cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .num { font-size: 24px; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat.paid .num { color: var(--paid); }
.stat.bank { border-color: #b9d9ff; background: linear-gradient(180deg, #f2f8ff, #fff); }
.stat.bank .num { color: #1657a8; }
.stat.expense .num { color: #c0552c; }
.stat.overpay .num { color: #7a4fb5; }
.bank-bar .stat { padding: 12px 14px; }
.bank-bar .stat .num { font-size: 20px; }
@media (max-width: 900px) { .bank-bar { grid-template-columns: repeat(2, minmax(120px, 1fr)); } }

/* map */
.map-card { padding: 16px; }
.map-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.map-toolbar input { flex: 1 1 240px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid; }
.swatch.paid { background: var(--paid-fill); border-color: var(--paid-stroke); }
.swatch.unpaid { background: var(--unpaid-fill); border-color: var(--unpaid-stroke); }

.map-wrap { position: relative; width: 100%; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #e9edf1; line-height: 0; touch-action: none; }
.map-scene { position: relative; width: 100%; transform-origin: center center; will-change: transform; }
.map-wrap img { width: 100%; height: auto; display: block; user-select: none; }
.map-wrap.dragging { cursor: grabbing; }
.map-wrap.dragging .plot { pointer-events: none; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.overlay .plot { cursor: pointer; transition: fill .12s, stroke .12s; stroke-width: 1; vector-effect: non-scaling-stroke; }
.overlay .plot.unpaid { fill: var(--unpaid-fill); stroke: var(--unpaid-stroke); }
.overlay .plot.paid { fill: var(--paid-fill); stroke: var(--paid-stroke); stroke-width: 1.4; }
.overlay .plot:hover, .overlay .plot.hover, .overlay .plot.selected { stroke-width: 2.6; filter: brightness(1.05); }
.overlay .plot.paid:hover { fill: rgba(31,157,87,.6); }
.overlay .plot.dim { opacity: .25; }
.overlay .plot-target-outline { fill: none; stroke: #ffb300; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; stroke-dasharray: 5 3; }
.plot-labels { position: absolute; inset: 0; pointer-events: none; line-height: 1; }
.plot-labels .plot-label {
  position: absolute; transform: translate(-50%, -50%) scale(var(--inv, 1));
  padding: 1px 4px; border-radius: 4px; font-size: 9px; font-weight: 700; color: #10261a;
  background: rgba(255,255,255,.78); box-shadow: 0 1px 3px rgba(0,0,0,.2); white-space: nowrap;
}
.plot-labels .plot-label.dim { opacity: .3; }
.plot-labels .plot-label.selected { background: #ffb300; color: #241700; }
.map-zoom { position: absolute; z-index: 6; top: 10px; right: 10px; display: flex; gap: 5px; line-height: 1.2; }
.map-zoom button { min-width: 34px; height: 32px; padding: 0 9px; font-size: 17px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.map-zoom button.small { font-size: 12px; }

.tooltip {
  position: absolute; z-index: 10; pointer-events: none;
  background: rgba(20,28,40,.96); color: #fff; padding: 9px 11px; border-radius: 8px;
  font-size: 13px; line-height: 1.45; max-width: 320px; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.tooltip .t-num { font-weight: 700; }
.tooltip .t-name { color: #aeb8c6; font-size: 12px; }
.tooltip .t-status { margin-top: 4px; font-weight: 600; }
.tooltip .t-status.paid { color: #6ee7a8; }
.tooltip .t-status.unpaid { color: #ffd28a; }
.tooltip .t-rows {
  display: grid; grid-template-columns: auto 1fr; column-gap: 14px; row-gap: 3px;
  margin: 7px 0 0; padding-top: 6px; border-top: 1px solid rgba(255,255,255,.14);
}
.tooltip .t-rows dt { color: #aeb8c6; }
.tooltip .t-rows dd { margin: 0; text-align: right; font-weight: 600; white-space: nowrap; }
.tooltip .t-overpay { color: #d6b6ff; }
.tooltip .t-note { margin-top: 6px; font-size: 12px; color: #aeb8c6; }

/* lists */
.public-payment-card { padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; margin-top: 10px; }
.public-payment-card .p-num { font-size: 14px; }
.plot-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow: auto; }
.plot-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; }
.plot-row .p-num { font-weight: 600; }
.plot-row .p-meta { color: var(--muted); font-size: 13px; line-height: 1.45; }
.plot-row .p-meta div + div { margin-top: 2px; }
.plot-row .p-meta .t-overpay { color: #7a4fb5; font-weight: 600; }
.badge { font-size: 12px; padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.badge.paid { background: #e3f6ec; color: var(--paid); }
.badge.unpaid { background: #f1f3f6; color: var(--muted); }
.badge.overpay { background: #efe8fa; color: #6d3fb0; }

/* forms */
input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,.3); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; align-items: end; }
@media (max-width: 900px){ .grid4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px){ .grid2, .grid4 { grid-template-columns: 1fr; } }
.payment-cards { display: flex; flex-direction: column; gap: 16px; }
.payment-card { border-left: 3px solid #2563eb; }
.cards.mini { margin-bottom: 0; }
.cards.mini .stat { padding: 9px 12px; }
.cards.mini .stat .num { font-size: 18px; }
.month-pick { position: relative; margin-top: 6px; }
.stat .period-pick {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 8px;
  min-width: 190px; padding: 4px 8px; font-size: 13px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.stat .period-pick .caret { color: var(--accent); }
.month-pop {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 50; width: 280px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 10px;
}
.mp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mp-head button { padding: 2px 8px; font-size: 18px; line-height: 1; }
.mp-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.mp-grid button {
  padding: 7px 2px; font-size: 12px; background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
}
.mp-grid button.in-range { background: #eef2ff; border-color: #a5b4fc; }
.mp-grid button.sel { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.mp-hint { margin-top: 8px; font-size: 11px; color: var(--muted); }
.mp-actions { display: flex; justify-content: space-between; gap: 6px; margin-top: 8px; }
.payment-form { padding: 12px; border: 1px dashed var(--line); border-radius: 9px; background: #fbfcfe; }
.payment-form .row-actions { grid-column: 1 / -1; }
.err-text { color: #b42318; min-height: 1em; }
.plot-picker { display: flex; flex-wrap: wrap; gap: 8px; max-height: 210px; overflow: auto; padding: 4px 0; }
.plot-pick { font-size: 13px; padding: 7px 11px; background: #fff; color: var(--ink); border-color: var(--line); }
.plot-pick.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.plot-pick .small { opacity: .75; }
.month-tree { display: flex; flex-direction: column; gap: 8px; }
.month-group { border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.month-group > summary {
  cursor: pointer; list-style: none; padding: 10px 12px; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; border-radius: 9px;
}
.month-group > summary::-webkit-details-marker { display: none; }
.month-group > summary::before { content: '▸'; color: var(--accent); margin-right: 2px; }
.month-group[open] > summary::before { content: '▾'; }
.month-group > summary .m-label { font-weight: 600; margin-right: auto; }
.month-group[open] > summary { border-bottom: 1px solid var(--line); border-radius: 9px 9px 0 0; }
.month-group > div { padding: 0 10px 10px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  cursor: pointer; font-weight: 500; text-decoration: none;
}
button:hover, .btn:hover { filter: brightness(1.05); }
button.secondary, .btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
button.danger, .btn.danger { background: var(--danger); border-color: var(--danger); }
button.small, .btn.small { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.p-phone { white-space: nowrap; }
.p-phone .max-link {
  position: relative; display: inline-flex; align-items: center; gap: 5px;
  margin-left: 6px; padding: 6px 10px; font-size: 13px; line-height: 1;
  text-decoration: none; font-weight: 700; letter-spacing: .02em;
  border-radius: 12px 12px 12px 4px;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9); color: #fff;
  border: 1px solid #6d28d9; box-shadow: 0 2px 5px rgba(109, 40, 217, .25);
}
/* Хвостик речевого облака. */
.p-phone .max-link::after {
  content: ''; position: absolute; left: 3px; bottom: -6px; width: 0; height: 0;
  border-style: solid; border-width: 7px 7px 0 0;
  border-color: #6d28d9 transparent transparent transparent;
}
.p-phone .max-link svg { width: 14px; height: 14px; fill: #fff; }
.p-phone .max-link:hover { background: linear-gradient(135deg, #7c3aed, #5b21b6); color: #fff; }

/* checkbox */
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; cursor: pointer; }
.check input { width: auto; }

/* table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
tr[hidden] { display: none !important; }
.plot-search { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.plot-search input { flex: 1 1 320px; max-width: 560px; }
.plot-search input[type="month"] { flex: 0 1 190px; max-width: 200px; }
.plot-search #plotCount, .plot-search #historyCount { white-space: nowrap; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr:hover td { background: #fafbfc; }

/* tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.tab { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* admin */
.admin-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.role-pill { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: #eef2ff; color: #3730a3; }
.notice { padding: 10px 12px; border-radius: 8px; margin: 10px 0; font-size: 14px; }
.notice.ok { background: #e3f6ec; color: #156b3c; }
.notice.err { background: #fdeaea; color: #a11; }
.notice.info { background: #eef4ff; color: #2a4a9b; }

.auth-wrap { max-width: 420px; margin: 40px auto; }
.auth-wrap .card { padding: 24px; }

/* charts */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px,1fr)); gap: 16px; }
.chart-box { border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.chart-box h3 { margin: 0 0 10px; font-size: 15px; }
.chart-svg { width: 100%; height: auto; }
.bar-label { font-size: 11px; fill: var(--muted); }
.bar-value { font-size: 11px; fill: var(--ink); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,20,30,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 18px; width: min(560px, 96vw); max-height: 92vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.3); }

/* editor */
.editor-map { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background:#e9edf1; line-height:0; margin-top: 8px; }
.editor-map img { width: 100%; height: auto; display:block; }
.editor-map svg { position:absolute; inset:0; width:100%; height:100%; cursor: crosshair; }
.editor-map .vhandle { fill: #2563eb; stroke:#fff; stroke-width:.4; cursor: move; }

.hidden { display: none !important; }
.space-between { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
.small { font-size: 13px; }
.mt { margin-top: 14px; }
