:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #172b45;
  background: #f3f6fa;
  --blue: #175fc4;
  --border: #dce3ed;
  --muted: #617186;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
button, input, select, textarea, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); overflow-wrap: anywhere; }
a, button { touch-action: manipulation; }
button, .button {
  min-height: 42px; padding: 8px 13px; border: 1px solid #bfcde0;
  border-radius: 8px; background: #fff; color: #174e94; cursor: pointer;
}
.button { display: inline-flex; align-items: center; text-decoration: none; }
button:hover, .button:hover { background: #edf4ff; border-color: #8cabd5; }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.primary:hover { background: #104da2; }
button.danger { color: #b52434; border-color: #e6b6bc; }
button:disabled { opacity: .55; cursor: wait; }
:focus-visible { outline: 3px solid #75aaff; outline-offset: 2px; }
input, select, textarea {
  display: block; width: 100%; min-width: 0; min-height: 42px; margin-top: 5px;
  padding: 8px 10px; border: 1px solid #bfcbd9; border-radius: 7px;
  background: #fff; color: #172b45;
}
input:disabled, select:disabled { background: #edf0f4; color: var(--muted); }
input[type='checkbox'], input[type='radio'] {
  display: inline-block; width: 22px; height: 40px; min-height: 40px;
  margin: 0; padding: 0; accent-color: var(--blue); flex: 0 0 auto;
}
textarea { resize: vertical; min-height: 90px; }
label { display: block; min-width: 0; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 9px; min-height: 42px; font-weight: 400; }
fieldset { min-width: 0; border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
fieldset .check { display: inline-flex; margin-right: 14px; }
header { background: #fff; border-bottom: 1px solid var(--border); }
.header-top, nav { max-width: 1280px; margin: auto; padding: 12px 24px; }
.header-top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { color: #172b45; font-size: 23px; font-weight: 750; text-decoration: none; }
.user { display: flex; align-items: center; gap: 12px; min-width: 0; overflow-wrap: anywhere; }
nav { display: flex; gap: 6px; padding-top: 0; overflow-x: auto; white-space: nowrap; }
nav a { flex: 0 0 auto; min-height: 42px; padding: 9px 13px; border-radius: 8px; text-decoration: none; color: #435671; }
nav a:hover { background: #f0f5fc; }
nav a[aria-current='page'] { background: #e9f1ff; color: #1553aa; font-weight: 650; }
main { width: 100%; max-width: 1280px; min-width: 0; margin: auto; padding: 24px; }
h1 { margin: 0 0 20px; font-size: 27px; line-height: 1.3; overflow-wrap: anywhere; }
h2 { margin: 0 0 16px; font-size: 20px; line-height: 1.35; overflow-wrap: anywhere; }
h3 { font-size: 17px; overflow-wrap: anywhere; }
p { margin: 12px 0; overflow-wrap: anywhere; }
small, .muted, .hint, .loading { color: var(--muted); }
small { display: block; font-size: 13px; font-weight: 400; }
.card { min-width: 0; padding: 20px; margin-bottom: 20px; border: 1px solid var(--border); border-radius: 12px; background: #fff; box-shadow: 0 2px 5px #173b6210; }
.summary-grid, .settings-grid, .grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; min-width: 0; }
.summary-grid .card { margin-bottom: 0; }
.summary-grid { margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.wide { grid-column: 1 / -1; }
.actions, .toolbar, .totals { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 14px 0; min-width: 0; }
.toolbar { align-items: end; }
.toolbar > label { flex: 1 1 180px; }
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; align-items: end; }
.balance-row { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 10px; padding: 8px 0; }
.balance-row > :first-child { min-width: 0; overflow-wrap: anywhere; }
.total { font-weight: 700; background: #f2f6fb; }
.big-money { font-size: clamp(24px, 3vw, 36px); font-weight: 750; overflow-wrap: anywhere; }
.amount, .money, .num { font-variant-numeric: tabular-nums; }
.amount { white-space: nowrap; }
.neg, .negative, .form-error, .error { color: #b32030; }
.positive { color: #167440; }
.warning { padding: 12px; background: #fff0f1; color: #a92232; border: 1px solid #edb6bd; border-radius: 8px; overflow-wrap: anywhere; }
.notice, .preview { padding: 12px; background: #edf4ff; border: 1px solid #d8e6fb; border-radius: 8px; overflow-wrap: anywhere; }
.preview:empty, .form-error:empty { display: none; }
.table-wrap { width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; border: 1px solid var(--border); border-radius: 9px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 13px; border-bottom: 1px solid #e5ebf3; vertical-align: top; }
th { background: #f1f5fa; color: #4c5f77; font-weight: 650; text-align: left; white-space: nowrap; }
td { min-width: 90px; max-width: 460px; overflow-wrap: anywhere; }
th.money, td.money, th.num, td.num { text-align: right; white-space: nowrap; }
td small { margin-top: 4px; }
tbody tr:last-child td { border-bottom: 0; }
tr[data-id] { cursor: pointer; }
tr[data-id]:hover { background: #f0f6ff; }
tr[data-id]:focus-visible { outline-offset: -3px; }
tr.own, tr[data-own='true'] { background: #eaf3ff; }
tfoot { font-weight: 700; background: #f2f6fb; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.badge, .status { display: inline-block; padding: 4px 8px; border-radius: 6px; background: #edf0f4; color: #566171; font-size: 13px; white-space: nowrap; }
.badge.active, .badge.paid, .badge.running, .status.active, .status.paid, .status.running { color: #116039; background: #dff5e9; }
.badge.grace, .badge.done, .status.grace, .status.done { color: #1252ae; background: #e3efff; }
.badge.overdue, .status.overdue { color: #ac152b; background: #ffe7ec; }
.badge.in_progress, .badge.maintenance, .status.in_progress, .status.maintenance { color: #8d4a06; background: #fff0d4; }
.badge.disabled, .badge.archived, .badge.stopped, .badge.retired { color: #596273; background: #edf0f4; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips a { display: inline-flex; align-items: center; min-height: 42px; text-decoration: none; }
.comment, .audit-details, .form-error { white-space: pre-wrap; overflow-wrap: anywhere; }
.audit-details { min-width: 240px; }
.directory-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.directory-row > span { min-width: 0; overflow-wrap: anywhere; }
.login { display: flex; justify-content: center; align-items: center; min-height: 100dvh; }
.login .card { width: 100%; max-width: 400px; padding: 28px; }
.login label { margin-bottom: 18px; }
.login button[type='submit'] { width: 100%; }
dialog { width: min(660px, calc(100% - 32px)); max-width: 100%; max-height: calc(100dvh - 32px); padding: 24px; overflow-y: auto; color: #172b45; background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 20px 80px #14243e40; }
dialog.wide-dialog { width: min(1100px, calc(100% - 32px)); }
dialog::backdrop { background: #14243e75; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dialog-heading h2 { margin: 5px 0; }
.form-actions { padding-top: 16px; border-top: 1px solid var(--border); }
dialog section { margin-top: 20px; }
#toast { position: fixed; z-index: 10000; bottom: 22px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); padding: 13px 20px; border-radius: 9px; background: #184f39; color: #fff; box-shadow: 0 5px 25px #14243e30; overflow-wrap: anywhere; pointer-events: none; }
[aria-busy='true'] { opacity: .65; }
@media (max-width: 1000px) { .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 719px) {
  main { padding: 16px 12px; }
  .header-top { padding: 12px; }
  .brand { font-size: 21px; }
  .user { font-size: 13px; flex-wrap: wrap; }
  nav { padding: 0 12px 10px; }
  nav a { padding: 9px 12px; }
  h1 { font-size: 24px; }
  .card { padding: 16px 12px; }
  .summary-grid, .settings-grid, .grid, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-actions button { flex: 1 1 auto; }
  dialog, dialog.wide-dialog { width: 100%; max-width: 100%; max-height: 100dvh; margin: auto 0; padding: 16px 12px; border-radius: 0; }
  th, td { padding: 10px; }
  .big-money { font-size: 26px; }
}
@media (prefers-reduced-motion: no-preference) { button, nav a { transition: background-color .12s ease; } }
/* реквизиты и сводки: подпись слева, значение справа; на телефоне - друг под другом */
dl { display: grid; grid-template-columns: minmax(130px, 220px) 1fr; gap: 6px 16px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 720px) { dl { grid-template-columns: 1fr; gap: 0; } dd { margin-bottom: 8px; } }
