:root {
  --bg: #f5f6f4;
  --card: #ffffff;
  --text: #1d2321;
  --muted: #6b7470;
  --line: #e3e6e3;
  --brand: #1f6f5c;
  --brand-2: #e8f2ef;
  --red: #c9372c;
  --red-bg: #fdecea;
  --orange: #c26a00;
  --orange-bg: #fff3e0;
  --yellow: #8a6d00;
  --green: #2e7d4f;
  --green-bg: #e9f5ee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; }
h2 { font-size: 22px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 10px; }
a { color: var(--brand); }
code { background: #eef0ee; padding: 1px 5px; border-radius: 4px; font-size: 13px; }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 20px 60px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.warn { color: var(--orange); }
.grow { flex: 1; }

/* ---- шапка ---- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 0 20px; height: 58px; position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand img { width: 26px; height: 26px; }
.brand.big { font-size: 20px; justify-content: center; margin-bottom: 8px; }
.brand.big img { width: 34px; height: 34px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab {
  border: 0; background: none; font: inherit; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tab:hover { background: var(--bg); color: var(--text); }
.tab.active { background: var(--brand-2); color: var(--brand); font-weight: 600; }
.me { white-space: nowrap; color: var(--muted); }

/* ---- кнопки ---- */
.btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #c7ccc8; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #185a4a; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.link { border: 0; background: none; font: inherit; color: var(--brand); cursor: pointer; padding: 0; text-align: left; }
.link.strong { color: var(--text); }
.link.strong:hover { color: var(--brand); text-decoration: underline; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px 20px; }

.pill { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; font-size: 12px; line-height: 20px; text-align: center; }
.pill-red { background: var(--red); color: #fff; }
.tag { font-size: 12px; background: var(--bg); color: var(--muted); padding: 2px 8px; border-radius: 10px; }

.banner { padding: 12px 16px; border-radius: 10px; background: var(--brand-2); margin-bottom: 16px; }
.banner-red { background: var(--red-bg); color: var(--red); }

/* ---- місяць ---- */
.month-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.month-head h2 { min-width: 190px; text-align: center; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.stat { padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.stat.ok .stat-value { color: var(--green); }
.stat.bad { background: var(--red-bg); border-color: #f5c6c1; }
.stat.bad .stat-value { color: var(--red); }

.group { margin-bottom: 26px; }
.group h3 { font-size: 16px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.empty { padding: 18px; color: var(--muted); text-align: center; }

.row {
  display: grid; grid-template-columns: 6px 1fr 150px 130px 230px; gap: 16px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 12px 0;
  box-shadow: var(--shadow); overflow: hidden;
}
.row-dot { align-self: stretch; margin: -12px 0; background: var(--line); }
.row.st-overdue .row-dot { background: var(--red); }
.row.st-today .row-dot { background: var(--orange); }
.row.st-soon .row-dot { background: #e0b000; }
.row.st-paid .row-dot { background: var(--green); }
.row.st-paid { background: #fbfcfb; }
.row-main { min-width: 0; }
.row-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row-files { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.row-files:empty { display: none; }
.row-amount { text-align: right; font-size: 16px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.hint { padding: 0 6px; }

.status { font-size: 13px; }
.status.st-overdue { color: var(--red); font-weight: 600; }
.status.st-today { color: var(--orange); font-weight: 600; }
.status.st-soon { color: var(--yellow); }
.status.st-paid { color: var(--green); }
.status.st-wait { color: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 2px; max-width: 240px;
  background: var(--brand-2); border-radius: 6px; font-size: 12px; padding: 2px 4px 2px 8px;
}
.chip a { text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; }
.chip-x:hover { color: var(--red); }

/* ---- таблиці ---- */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { margin-right: auto; }
.monthly-note { margin: -4px 0 12px; }
.search, select, input, textarea {
  font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--text);
}
.search { width: 240px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); border-color: var(--brand); }
.check { display: flex; flex-direction: row; gap: 6px; align-items: center; color: var(--muted); cursor: pointer; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { border-top: 1px solid var(--line); border-bottom: 0; background: var(--bg); }
.clickable { cursor: pointer; }
.clickable:hover td { background: #f9faf9; }
.files-cell { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---- налаштування ---- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.form-col { display: flex; flex-direction: column; gap: 10px; }
.plain { margin: 0 0 10px; padding-left: 18px; }

.users-card { margin-top: 16px; padding: 18px 0 8px; }
.users-head { display: flex; justify-content: space-between; align-items: center; padding: 0 20px 6px; }
.users-head h3 { margin: 0; }
.users-note { padding: 4px 20px 6px; margin: 0; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.tag-admin { background: var(--brand-2); color: var(--brand); }
.creds { background: var(--bg); border-radius: 8px; padding: 12px 14px; line-height: 1.8; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; }

/* ---- форми / модалки ---- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label select, label textarea { color: var(--text); font-size: 15px; }
.overlay { position: fixed; inset: 0; background: rgba(20, 28, 25, .35); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 20; overflow-y: auto; }
.modal { width: 100%; max-width: 640px; padding: 20px 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-foot { display: flex; gap: 8px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: span 2; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { width: 100%; max-width: 360px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 30;
  background: #1d2321; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); max-width: 90vw;
}
.toast-error { background: var(--red); }

/* ---- мобільні ---- */
@media (max-width: 900px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .row { grid-template-columns: 6px 1fr auto; padding-right: 12px; }
  .row-due { grid-column: 2; }
  .row-amount { grid-column: 3; grid-row: 1; }
  .row-actions { grid-column: 2 / span 2; justify-content: flex-start; }
  .topbar { gap: 10px; padding: 0 12px; }
  .brand { font-size: 0; }
  .me { font-size: 13px; }
}
@media (max-width: 560px) {
  .grid2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .search { width: 100%; }
}
