:root {
  color-scheme: dark;
  --background: #151622;
  --panel: #202132;
  --raised: #292a40;
  --field: #191a28;
  --line: #3b3c55;
  --text: #f3f2fb;
  --muted: #b6b6cd;
  --accent: #df3049;
  --accent-hover: #cd2b43;
  --error: #ff9aad;
  --notice: #f2ce9c;
  --ok: #a9e4c4;
  --focus: #faa6b7;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.workspace {
  width: min(1280px, calc(100% - 64px));
  margin: 56px auto;
}

.page-header { margin-bottom: 24px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 38px); line-height: 1.15; font-weight: 650; }
h2 { font-size: 19px; line-height: 1.3; font-weight: 630; }
.muted { color: var(--muted); font-size: 13px; }

.panel {
  padding: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.input-group { min-width: 0; }
.field-label { display: block; font-weight: 600; margin-bottom: 8px; }
.file-control {
  position: relative;
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 6px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.file-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

button, .file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.file-button { background: var(--raised); font-size: 13px; }
.file-button:hover, .secondary:hover { border-color: #737594; }
.file-name { flex: 1 1 120px; overflow-wrap: anywhere; }
.file-name.selected { color: var(--text); }
.error-text { color: var(--error); font-size: 13px; margin-top: 8px; }
.file-overview { margin-top: 8px; }
.file-control:has(input[aria-invalid="true"]) { border-color: var(--error); }

.file-input:focus-visible + label,
button:focus-visible, input:focus-visible, summary:focus-visible,
.table-region:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

summary { color: var(--text); cursor: pointer; overflow-wrap: anywhere; }
.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 22px; }
.primary {
  min-height: 42px;
  min-width: 108px;
  color: #fff;
  background: var(--accent);
}
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.primary:disabled { color: #c2bcc9; background: #403344; cursor: default; }
.secondary { background: var(--raised); border-color: var(--line); color: var(--text); }
.secondary:disabled { opacity: .55; cursor: default; }

.result-panel { margin-top: 20px; }
.result-heading { margin-bottom: 12px; align-items: flex-start; }
#result-period { margin-top: 4px; }
.result-summary { color: var(--muted); }
.result-panel[data-outcome="equal"] h2 { color: var(--ok); }
.result-panel[data-outcome="review"] h2 { color: var(--notice); }
.result-controls { margin-top: 18px; }
.categories { display: flex; flex-wrap: wrap; gap: 8px; }
.category {
  gap: 8px;
  color: var(--text);
  background: var(--field);
  border-color: var(--line);
  font-size: 13px;
}
.category:hover { border-color: var(--muted); }
.category[aria-pressed="true"] {
  border-color: var(--focus);
  background: #352536;
}
.category-count {
  min-width: 24px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--raised);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.category-help { margin-top: 9px; }
.result-search {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px 12px;
  margin-top: 14px;
  font-size: 13px;
}
.result-search input {
  width: min(100%, 360px);
  min-height: 37px;
  padding: 7px 10px;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
}
.result-search input::placeholder { color: var(--muted); }
.filter-status:not(:empty) { margin-top: 7px; }
.table-region {
  max-height: 80vh;
  max-height: 80dvh;
  margin-top: 15px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; text-align: left; }
#findings { min-width: 840px; font-size: 13px; }
#findings[data-layout="clients"] { min-width: 1030px; }
#findings[data-layout="all"] { min-width: 980px; }
#findings[data-layout="review"] { min-width: 650px; }
#findings[data-layout="only_one_c"], #findings[data-layout="only_crm"] { min-width: 560px; }
th {
  background: var(--raised);
  color: var(--muted);
  font-weight: 600;
}
#findings thead { position: sticky; top: 0; z-index: 1; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
#findings tr:last-child td { border-bottom: 0; }
#findings tbody tr:hover { background: #26273a; }
.finding-key { min-width: 164px; font-weight: 600; overflow-wrap: anywhere; }
.finding-key .row-note { font-weight: 400; }
.finding-note { min-width: 155px; }
.source-cell { min-width: 100px; }
.comparison-text { overflow-wrap: anywhere; }
.client-source { white-space: nowrap; }
.numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th.numeric { white-space: normal; }
.difference-value { color: var(--notice); font-weight: 600; }
.row-note { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.source-list { margin: 7px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.source-item {
  min-width: 178px;
  padding: 7px;
  background: var(--field);
  border-radius: 6px;
  overflow-wrap: anywhere;
}
.source-item p { color: var(--muted); }
.source-cells { margin: 5px 0 0; }
.source-cells dt { color: var(--muted); }
.source-cells dd { margin: 0 0 4px; }
.copy-address { min-height: 24px; padding: 1px 6px; font-size: 12px; }
.copy-feedback:not(:empty) { display: block; margin: 3px 0; color: var(--muted); }
.copy-feedback code { color: var(--text); }

@media (max-width: 720px) {
  .workspace { width: calc(100% - 28px); margin: 26px auto; }
  .panel { padding: 17px; }
  .file-grid { grid-template-columns: 1fr; gap: 14px; }
  .result-heading { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
