:root {
  --bg: #f4f2ee; --card: #fff; --ink: #1f2a2a; --muted: #6b7575; --line: #e3dfd7;
  --brand: #2f7d6d; --brand-ink: #fff; --busy: #2f7d6d; --busy-bg: #e3f1ec;
  --idle: #8a6d1d; --idle-bg: #fbf3dc; --late: #b23b2e; --late-bg: #fbe7e4;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151a1a; --card: #1e2525; --ink: #e8ecea; --muted: #97a3a1; --line: #2f3838;
    --brand: #46a58f; --busy: #6fc7b1; --busy-bg: #1f3631; --idle: #e0c060; --idle-bg: #3a331c;
    --late: #f08a7c; --late-bg: #402220; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 6px; color: var(--muted); font-weight: 600; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.pre { white-space: pre-wrap; }

/* шапка */
.top { background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center;
  gap: 16px; padding: 0 16px; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 17px; color: var(--ink); padding: 14px 0; }
.top nav { display: flex; gap: 2px; flex: 1; }
.top nav a { padding: 16px 10px; color: var(--ink); border-bottom: 2px solid transparent; }
.top nav a.on { border-color: var(--brand); color: var(--brand); }
.top nav a.muted { margin-left: auto; color: var(--muted); }
.burger { display: none; margin-left: auto; background: none; border: 0; font-size: 22px; color: var(--ink); }
@media (max-width: 800px) {
  .burger { display: block; }
  .top { flex-wrap: wrap; }
  .top nav { display: none; flex-basis: 100%; flex-direction: column; }
  .menu-open .top nav { display: flex; }
  .top nav a { padding: 10px 0; border: 0; } .top nav a.muted { margin: 0; }
}

/* общие блоки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.inner { background: var(--bg); }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.bar h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { margin: 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .card { margin-bottom: 0; } .cols { margin-bottom: 16px; }
@media (max-width: 800px) { .cols { grid-template-columns: 1fr; } }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.grid .card { margin: 0; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.flash { background: var(--busy-bg); color: var(--busy); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }
.flash.err { background: var(--late-bg); color: var(--late); }

/* кнопки и формы */
.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--late); }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font: inherit; }
form.inline { display: inline; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
label input, label select, label textarea { margin-top: 4px; font-size: 15px; }
.form { max-width: 720px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.search { margin-bottom: 14px; } .search input { max-width: 420px; }
.form-err { color: var(--late); min-height: 1em; }
fieldset.picker { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0 0 14px; }
fieldset.picker legend { padding: 0 6px; font-weight: 600; }
.picker-row { display: flex; gap: 8px; flex-wrap: wrap; }
.picker-row select { flex: 1; min-width: 200px; width: auto; }
.chips-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tchip { display: inline-flex; align-items: center; gap: 4px; background: var(--busy-bg); color: var(--busy);
  border-radius: 20px; padding: 4px 6px 4px 12px; }
.tchip button { background: none; border: 0; color: inherit; cursor: pointer; font-size: 15px; padding: 0 4px; }
.upload { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.upload input, .upload select { width: auto; flex: 1; min-width: 160px; }

/* чипы и бейджи */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px; font-size: 13px; }
.chip.ok { background: var(--busy-bg); color: var(--busy); border-color: transparent; }
.chip.free { background: var(--idle-bg); color: var(--idle); border-color: transparent; }
.chip.late { background: var(--late-bg); color: var(--late); border-color: transparent; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px; white-space: nowrap; }
.badge.busy { background: var(--busy-bg); color: var(--busy); }
.badge.idle { background: var(--idle-bg); color: var(--idle); }
.badge.late { background: var(--late-bg); color: var(--late); }
.late-t { color: var(--late); }

/* карточки квартир */
.apt { color: var(--ink); display: block; border-left: 4px solid var(--line); }
.apt:hover { text-decoration: none; border-color: var(--brand); }
.apt.busy { border-left-color: var(--busy); } .apt.idle { border-left-color: var(--idle); }
.apt-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; margin-bottom: 4px; }
.apt-term { margin-top: 10px; }
.apt-term .left { display: inline-block; background: var(--busy-bg); color: var(--busy); border-radius: 6px; padding: 0 6px; font-size: 13px; margin-left: 4px; }

/* таблицы */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.tbl tfoot th { color: var(--ink); font-size: 14px; text-transform: none; }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl tr.dim td { opacity: .55; }
table.card { padding: 0; overflow: hidden; }
@media (max-width: 700px) {
  .tbl thead { display: none; }
  .tbl tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .tbl td, .tbl tfoot th { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 3px 10px; text-align: right; }
  .tbl td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: 13px; text-align: left; }
  .tbl td:empty { display: none; }
  .row3 { grid-template-columns: 1fr 1fr; }
}

dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; }
ul.plain { list-style: none; padding: 0; margin: 0; } ul.plain li { padding: 3px 0; }
details summary { cursor: pointer; margin-top: 10px; }
.inline-edit summary { margin: 0; } .inline-edit .form { margin-top: 10px; min-width: 240px; }

/* документы */
.docs { list-style: none; padding: 0; margin: 0; }
.docs li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.doc-name { flex: 1; min-width: 160px; word-break: break-word; }
.doc-actions { display: flex; gap: 6px; align-items: center; }
.doc-actions form { margin: 0; }
.doc-actions button, .doc-actions a { background: none; border: 0; cursor: pointer; font-size: 15px; padding: 2px 4px; color: var(--ink); }

/* показания */
.period-nav { display: flex; align-items: center; gap: 10px; }
.reading { border-left: 4px solid var(--line); }
.reading.done { border-left-color: var(--busy); } .reading.late { border-left-color: var(--late); } .reading.wait { border-left-color: var(--idle); }
.meters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.meters div { background: var(--bg); border-radius: 8px; padding: 6px; text-align: center; }
.meters span { display: block; font-size: 11px; color: var(--muted); }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.steps { font-size: 14px; margin-bottom: 10px; }

/* статистика */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile span { display: block; color: var(--muted); font-size: 13px; }
.tile b { font-size: 22px; }
.tile.accent { border-color: var(--brand); }
.small-tiles .tile b { font-size: 18px; }
.up { color: var(--busy); } .down { color: var(--late); }
.period-form { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.pf { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pf-l { font-size: 13px; color: var(--muted); width: 100px; }
.pf input { width: auto; }
.tx-form { display: flex; gap: 8px; flex-wrap: wrap; }
.tx-form > * { width: auto; flex: 1; min-width: 130px; }
.tx-form input[name=description] { flex: 3; min-width: 220px; }

/* вход */
.auth { max-width: 380px; margin: 60px auto; }

/* модальное окно */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--card); border-radius: var(--radius); width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; padding: 16px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 17px; }
.x { background: none; border: 0; font-size: 26px; cursor: pointer; color: var(--muted); line-height: 1; }

/* переключатель объектов */
.switcher { position: relative; }
.switcher summary { list-style: none; cursor: pointer; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher summary::-webkit-details-marker { display: none; }
.switcher-menu { position: absolute; top: 110%; left: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-width: 240px; padding: 6px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.switcher-menu a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--ink); }
.switcher-menu a.on { background: var(--busy-bg); color: var(--busy); }
.switcher-menu a.muted { color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; }
.top nav a.push { margin-left: auto; }
.top nav a.muted { margin-left: 0; }
.new-estate { border-style: dashed; display: flex; flex-direction: column; gap: 8px; }
.new-estate p { margin: 0; }
.danger-zone { border-color: var(--late); }
.resend { margin-top: 10px; text-align: center; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--ink); background: var(--card); border: 1px solid var(--line); }
.tabs a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
@media (max-width: 800px) { .top nav a.push { margin-left: 0; } .switcher summary { max-width: 160px; } }
