:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16191d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1f6f4a;
  --accent-soft: #e8f2ec;
  --head: #dfe4ea;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* Повноекранний layout: скролиться лише таблиця, шапка й фільтри завжди на місці */
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }

/* --- шапка --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 650; }
.topbar p { margin: 0; font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 7px 14px;
  border-radius: 8px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; filter: none; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); filter: none; }

/* --- фільтри --- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.field > span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.field select, .field input {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  min-width: 150px;
}
.field select:focus, .field input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field-grow { flex: 1 1 220px; }
.field-grow input { width: 100%; min-width: 0; }
.field[data-multi] { justify-content: flex-start; }
.multi-btn {
  font: inherit;
  text-align: left;
  padding: 7px 26px 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 9px center;
  color: inherit;
  cursor: pointer;
  min-width: 150px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.multi-btn:hover { border-color: #c8cdd4; }
.multi-btn.active { border-color: var(--accent); background-color: var(--accent-soft); }

/* спільна випадайка мультивибору */
.popover {
  position: fixed;
  z-index: 20;
  width: 290px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(16, 24, 40, .16);
  overflow: hidden;
}
.popover[hidden] { display: none; }
.popover-head { display: flex; gap: 8px; align-items: center; padding: 8px; border-bottom: 1px solid var(--line); }
.popover-head input { flex: 1; min-width: 0; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; }
.popover-list { max-height: 280px; overflow-y: auto; padding: 4px; }
.popover-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.popover-row:hover { background: var(--accent-soft); }
.popover-row input { width: 15px; height: 15px; accent-color: var(--accent); flex: none; }
.popover-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-empty { margin: 0; padding: 14px; text-align: center; color: var(--muted); }
.link { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 4px; }
.link:hover { text-decoration: underline; }
.link.danger { color: #b3261e; }

.field-check { flex-direction: row; align-items: center; gap: 7px; align-self: end; padding-bottom: 8px; min-width: 0; }
.field-check > span { text-transform: none; font-size: 13px; letter-spacing: 0; color: var(--ink); }
.field-check input { min-width: 0; width: 16px; height: 16px; accent-color: var(--accent); }

/* --- підсумки --- */
.summary { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 20px 0; flex: none; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-width: 120px;
}
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-meta b { font-size: 13px; font-weight: 550; padding-top: 4px; }

.state { padding: 14px 20px 0; color: var(--muted); flex: none; }
.state:empty { display: none; }
.state.error { color: #b3261e; }

/* --- таблиця --- */
.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  margin: 14px 20px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--head);
  text-align: left;
  font-weight: 650;
  font-size: 12px;
  padding: 10px 12px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--line);
}
thead th:hover { background: #d5dae1; }
thead th.no-sort { cursor: default; }
thead th.no-sort:hover { background: var(--head); }
thead th.num, tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th[data-dir]::after { content: " ▲"; font-size: 9px; }
thead th[data-dir="desc"]::after { content: " ▼"; }
tbody td { padding: 8px 12px; border-bottom: 1px solid #f0f2f4; }
/* ПІБ і шоурум тримаємо в один рядок — інакше рядки стають утричі вищі.
   Довгі ПІБ ріжемо трикрапкою, повний текст лишається в title рядка. */
tbody td:first-child, tbody td:nth-child(2) { white-space: nowrap; }
tbody td:first-child { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
tbody td.category { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
tbody td.name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 250px; }
tbody tr:hover { background: #fafbfc; }
tbody td.name { min-width: 200px; }
tbody td.check { white-space: nowrap; }
.check-btn {
  display: inline-block;
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  font-weight: 550;
}
.check-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

tbody .empty { padding: 30px; text-align: center; color: var(--muted); }
.more { padding: 12px; text-align: center; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

@media (max-width: 720px) {
  body { height: auto; overflow: visible; }
  .topbar { flex-direction: column; align-items: stretch; }
  .table-wrap { max-height: none; }
}

/* [hidden] програє класу за специфічністю, коли клас задає display */
.summary[hidden], .more[hidden] { display: none; }

/* --- налаштування --- */
.dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 24px 60px rgba(16, 24, 40, .24);
}
.dialog::backdrop { background: rgba(16, 24, 40, .4); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body h2 { margin: 0; font-size: 16px; }
.dialog-body p { margin: 0; font-size: 13px; }
.dialog-body code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.wf-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.wf-row { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 8px; }
.wf-row:hover { background: #f6f7f9; }
.wf-row b { font-variant-numeric: tabular-nums; min-width: 34px; }
.wf-row span { flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-add { display: flex; gap: 8px; }
.wf-add input { flex: 1; font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; }
.dialog-error { color: #b3261e; font-size: 13px; }
.dialog-error[hidden] { display: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

/* --- сторінка входу --- */
.login-page {
  height: 100vh;
  display: grid;
  place-items: center;
  overflow: auto;
  background: var(--bg);
}
.login-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(340px, calc(100vw - 32px));
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .08);
  text-align: center;
}
.login-card .brand-mark { margin: 0 auto 4px; width: 40px; height: 40px; font-size: 18px; }
.login-card h1 { margin: 0; font-size: 17px; }
.login-card p { margin: 0; font-size: 13px; }
.login-card input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-top: 6px;
  text-align: center;
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-card .btn { padding: 10px; }
.login-error { color: #b3261e; }
.login-error[hidden] { display: none; }
