:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #171a21;
  --muted: #6b7280;
  --border: #e6e8ee;
  --accent: #2563eb;
  --accent-soft: #eef3ff;
  --ok: #059669;
  --ok-soft: #e8f7f0;
  --warn: #b45309;
  --warn-soft: #fdf1e3;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.04);
  --radius: 16px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }

p { margin: 0; }

code {
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #f1f3f7;
  padding: 2px 5px;
  border-radius: 6px;
  word-break: break-all;
}

.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 20px; }

/* ------------------------------------------------------------- верхняя панель */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 28px;
  height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  font-size: 16px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 7px 12px;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 500;
}
.nav a:hover { background: #f2f4f8; color: var(--text); text-decoration: none; }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); }

.logout { color: var(--muted); font-size: 14px; }

.main { padding: 28px 20px 48px; min-height: calc(100vh - 130px); }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 28px;
  color: var(--muted);
  font-size: 13px;
}

/* ------------------------------------------------------------------ заголовки */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head .muted { margin-top: 4px; }

.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.due-text { color: var(--danger); font-weight: 600; }

.flash {
  margin-bottom: 18px;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid #d7e3ff;
  color: #1e40af;
  font-size: 14px;
}

.error {
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 7px 10px;
  margin-top: 6px;
}

/* ------------------------------------------------------------------- кнопки */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  padding: 9px 15px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: #f7f8fb; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { background: #047857; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fef2f2; border-color: #fecaca; }

form { margin: 0; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; }

select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 11px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
select { width: auto; min-width: 190px; cursor: pointer; }
textarea { resize: vertical; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 550; color: #374151; }
.field.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field.checkbox input { width: 16px; height: 16px; }
.field.checkbox span { font-weight: 400; }

/* --------------------------------------------------------------- период */

.period-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.period-form { display: inline-flex; }
.period-bar .btn.ghost { padding: 7px 12px; font-size: 17px; line-height: 1; }
.sync-pulse { color: var(--accent); font-size: 13px; margin-left: 6px; }

/* --------------------------------------------------------------- сводка */

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.stat.due { border-color: #fbd5d5; background: #fffafa; }
.stat.due .stat-value { color: var(--danger); }

/* ----------------------------------------------------------------- карточки */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.card-head .muted { margin-top: 3px; }

.card-total { text-align: right; display: flex; flex-direction: column; gap: 3px; }
.card-total strong { font-size: 20px; letter-spacing: -0.01em; }
.card-total span { white-space: nowrap; }

.empty { text-align: center; padding: 42px 20px; }
.empty h2 { margin-bottom: 6px; }
.empty .muted { margin-bottom: 16px; }

/* ------------------------------------------------------------ начисления */

.charges { display: flex; flex-direction: column; }

.charge {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 18px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.charge:first-child { border-top: none; padding-top: 2px; }

.charge.is-paid .charge-provider,
.charge.is-paid .charge-amount strong { color: var(--muted); }

.charge-provider { font-weight: 600; }
.charge-sub { font-size: 13px; color: var(--muted); margin-top: 1px; }

.charge-amount { text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.charge-amount strong { font-size: 18px; letter-spacing: -0.01em; }

.charge-actions { display: flex; gap: 8px; align-items: flex-start; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.muted { background: #f1f3f7; color: var(--muted); }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }

.breakdown { margin-top: 6px; }
.breakdown > summary { color: var(--muted); font-size: 13px; }
.breakdown > summary::before { content: "▸ "; }
.breakdown[open] > summary::before { content: "▾ "; }
.breakdown ul { margin: 8px 0 0; padding: 0 0 0 14px; list-style: none; font-size: 13px; }
.breakdown li { display: flex; justify-content: space-between; gap: 20px; padding: 2px 0; color: #4b5563; }

/* ------------------------------------------------------------------- QR */

.qr-pop { position: relative; }
.qr-box {
  margin-top: 8px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: 250px;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  text-align: center;
}
.qr-box img { width: 200px; height: 200px; image-rendering: pixelated; }
.qr-close {
  position: absolute;
  top: 4px;
  right: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 8px;
}
.qr-close:hover { background: #f1f3f7; color: var(--text); }
.payload { width: 100%; }
.payload summary { text-align: left; }
.payload code { display: block; margin-top: 6px; max-height: 90px; overflow: auto; text-align: left; }
.qr-alt { width: 180px; height: 180px; margin-top: 8px; image-rendering: pixelated; }

@media (min-width: 761px) {
  .qr-pop[open] .qr-box {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    width: 340px;
    margin: 0;
    z-index: 100;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 0 0 100vmax rgba(15, 23, 42, 0.38), 0 24px 60px rgba(15, 23, 42, 0.25);
  }
  .qr-pop[open] .qr-box img { width: 260px; height: 260px; }
}

/* ---------------------------------------------------------------- журнал */

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--border);
}
.table th.num, .table td.num { text-align: right; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table.compact td, .table.compact th { padding: 8px 8px; }
.table td:first-child, .table th:first-child { padding-left: 0; }
.table td:last-child, .table th:last-child { padding-right: 0; }

.details-list { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.details-list li { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }

/* -------------------------------------------------------------- объекты */

.prop-list, .account-list { display: flex; flex-direction: column; }
.prop-item, .account-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.prop-item:first-child, .account-item:first-child { border-top: none; padding-top: 0; }

.prop-info, .account-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.prop-actions { display: flex; gap: 6px; align-items: flex-start; position: relative; }
.prop-actions form { display: inline-flex; }
.prop-edit-form, .account-edit-form {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: min(520px, 86vw);
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.account-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.account-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.account-actions form { display: inline-flex; }

.inline-details { position: relative; }
.password-form {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfc;
}

.add-form { margin-top: 16px; border-top: 1px dashed var(--border); padding-top: 14px; }
.add-form > summary { display: inline-flex; }
.add-form > form { margin-top: 14px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .span-2 { grid-column: 1 / -1; }

.row-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }

.prop-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  background: #f5f7fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  color: #374151;
}

/* ------------------------------------------------------------ страница входа */

.login-wrap {
  min-height: 70vh;
  display: grid;
  place-items: center;
  padding: 30px 0;
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}
.login-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 4px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
}
.login-card h1 { font-size: 22px; }
.login-card .field { text-align: left; margin-top: 8px; }
.login-card .btn { margin-top: 6px; }

/* ------------------------------------------------------------- адаптивность */

@media (max-width: 760px) {
  .topbar-inner { gap: 6px; height: 54px; }
  .brand-text { display: none; }
  .nav { gap: 0; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 6px 8px; font-size: 13.5px; white-space: nowrap; }
  .logout { font-size: 12.5px; white-space: nowrap; }

  .main { padding: 20px 14px 40px; }
  .summary { grid-template-columns: 1fr; gap: 8px; }
  .stat { flex-direction: row; justify-content: space-between; align-items: baseline; padding: 12px 15px; }
  .stat-value { font-size: 20px; }

  h1 { font-size: 22px; }
  .card { padding: 16px; border-radius: 14px; }

  .charge {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "main amount"
      "actions actions";
    gap: 10px 12px;
  }
  .charge-main { grid-area: main; }
  .charge-amount { grid-area: amount; }
  .charge-actions { grid-area: actions; justify-content: stretch; }
  .charge-actions form { flex: 1; }
  .charge-actions .btn { width: 100%; }

  .qr-box { position: static; width: 100%; margin-top: 10px; box-shadow: none; }
  .charge:nth-last-child(-n + 2) .qr-box { position: static; margin: 10px 0 0; }

  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .account-item { flex-direction: column; }
  .account-actions { justify-content: flex-start; width: 100%; }
  .prop-actions { flex-wrap: wrap; justify-content: flex-end; }
  .prop-edit-form, .account-edit-form { position: static; width: 100%; margin-top: 8px; }

  .table.responsive, .table.responsive thead, .table.responsive tbody,
  .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive thead { display: none; }
  .table.responsive tr { padding: 10px 0; border-bottom: 1px solid var(--border); }

  .table.stack thead { display: none; }
  .table.stack tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .table.stack tr:last-child { border-bottom: none; }
  .table.stack td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    border: none;
    padding: 3px 0;
    text-align: left;
  }
  .table.stack td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }
  .table.stack td > details { width: 100%; }
  .table.stack td:last-child { display: block; }
  .table.stack td:last-child::before { display: block; margin-bottom: 4px; }

  .history-table th:nth-child(5), .history-table td:nth-child(5) { display: none; }
}

@media print {
  .topbar, .footer, .charge-actions, .period-bar, .page-head form, .logout { display: none !important; }
  body { background: #fff; }
  .card, .stat { box-shadow: none; border-color: #ddd; }
}
