* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1c1c1c;
  background: #f4f5f7;
}
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: #23272e;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}
header b { font-size: 15px; letter-spacing: .3px; }
header nav { display: flex; gap: 4px; }
header nav a, .subtabs a {
  color: #cfd3da;
  text-decoration: none;
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 13px;
}
header nav a:hover, .subtabs a:hover { background: #333842; color: #fff; }
header nav a.on { background: #3b82f6; color: #fff; }
.grow { flex: 1; }
.reload { color: #cfd3da; font-size: 18px; text-decoration: none; }

main { max-width: 1180px; margin: 0 auto; padding: 22px 18px 60px; }
h1 { font-size: 20px; margin: 0 0 14px; }
h1 small, h2 small, h3 small { font-weight: 400; color: #8a909a; font-size: 13px; }
h2 { font-size: 16px; margin: 26px 0 10px; }
h3 { font-size: 14px; margin: 18px 0 6px; }
.muted, .legend { color: #6b7280; font-size: 13px; }
.path code { background: #e9ebef; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.err { color: #b42318; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 16px;
  align-items: center;
}
.filters select, .filters input, .filters button {
  font: inherit;
  padding: 6px 9px;
  border: 1px solid #cbd0d8;
  border-radius: 6px;
  background: #fff;
}
.filters input[type="search"] { min-width: 240px; flex: 1; }
.filters button { background: #3b82f6; color: #fff; border-color: #3b82f6; cursor: pointer; }
.filters .clear, .filters a.clear { align-self: center; color: #6b7280; font-size: 13px; }

.subtabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.subtabs a { background: #e9ebef; color: #333; }
.subtabs a.on { background: #3b82f6; color: #fff; }

table.grid {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #e2e4e9;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 18px;
}
table.grid th, table.grid td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid #eef0f3;
  vertical-align: top;
}
table.grid th { background: #f0f1f4; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: #5b616e; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr:hover td { background: #fafbfc; }

td.ts { white-space: nowrap; color: #6b7280; font-variant-numeric: tabular-nums; }
td.oid { white-space: nowrap; font-weight: 600; }
td.cat { color: #6b7280; }
td.sku { font-family: ui-monospace, Menlo, Consolas, monospace; white-space: nowrap; }
td.url a { color: #2563eb; word-break: break-all; }
td.msg span { white-space: pre-wrap; }
td.msg details { margin-top: 4px; }
td.msg summary { cursor: pointer; color: #6b7280; font-size: 12px; }
td.msg pre { white-space: pre-wrap; background: #f4f5f7; padding: 8px; border-radius: 6px; margin: 6px 0 0; font-size: 12px; }
td.empty, .empty { color: #8a909a; text-align: center; padding: 20px; }

tr.ev.error td.ts { box-shadow: inset 3px 0 0 #e5484d; }
tr.ev.ok td.ts { box-shadow: inset 3px 0 0 #30a46c; }
tr.ev.start td.ts { box-shadow: inset 3px 0 0 #3b82f6; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: #e7f6ee; color: #18794e; }
.badge.error { background: #fdeceb; color: #b42318; }
.badge.start { background: #e8f0fe; color: #1d4ed8; }
.badge.info { background: #eceef1; color: #55606e; }

section.rule { background: #fff; border: 1px solid #e2e4e9; border-radius: 10px; padding: 16px 18px; margin-bottom: 18px; }
section.rule h2 { margin-top: 0; }

/* --- редагування правил --- */
table.grid.editable td { padding: 4px 6px; }
table.grid.editable input {
  width: 100%;
  font: inherit;
  padding: 5px 7px;
  border: 1px solid #cbd0d8;
  border-radius: 5px;
  background: #fff;
}
table.grid.editable input:focus { outline: 2px solid #93c5fd; border-color: #3b82f6; }
button.del {
  border: 0; background: #f3f4f6; color: #b42318;
  width: 26px; height: 26px; border-radius: 5px; cursor: pointer; font-size: 13px;
}
button.del:hover { background: #fdeceb; }

.toolbar { display: flex; align-items: center; gap: 10px; margin: 14px 0 4px; }
.toolbar button {
  font: inherit; padding: 7px 14px; border-radius: 6px; cursor: pointer; border: 1px solid #cbd0d8; background: #fff;
}
.toolbar button.add { color: #1d4ed8; }
.toolbar button.save { background: #3b82f6; color: #fff; border-color: #3b82f6; font-weight: 600; }
.toolbar button:disabled { opacity: .55; cursor: default; }
.result { font-size: 13px; }
.result.ok { color: #18794e; }
.result.err { color: #b42318; }

.fields { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 8px; }
.fields label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fields label > span { min-width: 210px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.fields label small { color: #8a909a; }
.fields input[type="text"], .fields input:not([type]) {
  font: inherit; padding: 5px 8px; border: 1px solid #cbd0d8; border-radius: 5px; min-width: 220px;
}

pre.raw {
  background: #1c1f24;
  color: #d7dbe0;
  padding: 14px;
  border-radius: 8px;
  overflow-x: auto;
  font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
  max-height: 72vh;
}

/* --- вкладка «Звітність» --- */
.report-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.report-upload { display: flex; align-items: center; gap: 10px; }
.btn-file {
  display: inline-block;
  background: #3b82f6;
  color: #fff;
  padding: 8px 15px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.btn-file:hover { background: #2f6fd6; }
.report-frame {
  width: 100%;
  height: calc(100vh - 175px);
  min-height: 480px;
  border: 1px solid #e2e4e9;
  border-radius: 8px;
  background: #fff;
}

/* --- вкладка «Відмови» --- */
table.grid.editable td.num, table.grid.editable th { white-space: nowrap; }
td.num, tfoot td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.ctr { text-align: center; }
table.grid.editable td.num input { text-align: right; }
table.grid.editable td.ctr input { width: auto; }
td.eff { font-weight: 600; color: #b42318; }
tr.excluded td { opacity: .5; }
tr.excluded td.oid, tr.excluded td.ttn { text-decoration: line-through; }
tr.overridden td.oid { box-shadow: inset 3px 0 0 #3b82f6; }
table.grid tfoot td { border-top: 2px solid #e2e4e9; font-weight: 600; background: #f7f8fa; }
