:root {
  --ink: #2e1a47;
  --grape: #5b2a86;
  --grape-deep: #3f1d5e;
  --pink: #d6429a;
  --pink-deep: #a8247a;
  --gold: #c9a227;
  --gold-soft: #fbf3d5;
  --white: #ffffff;
  --surface: #f7f2fb;
  --line: #ddd0ea;
  --text: #2b2233;
  --muted: #5d5069;
  --file1: #add8e6; /* same blue as the VBA highlight */
  --file2: #d8bfd8; /* same purple as the VBA highlight */
  --danger: #a1123f;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--white);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.2; color: var(--ink); }
p { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 0; background: var(--gold); color: var(--ink); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }

/* Header */
.top { background: var(--ink); color: var(--white); border-bottom: 4px solid var(--gold); }
.top-inner { max-width: 960px; margin: 0 auto; padding: 28px 16px 26px; }
.brand { color: var(--gold); font-weight: 600; font-size: 0.95rem; letter-spacing: 0.01em; }
.top h1 { color: var(--white); font: 700 clamp(2rem, 6vw, 2.9rem)/1.1 Georgia, "Times New Roman", serif; margin: 4px 0 10px; }
.lede { max-width: 62ch; color: #e8dcf3; }

.wrap { max-width: 960px; margin: 0 auto; padding: 8px 16px 40px; }
section { padding-top: 28px; }
h2 { font: 700 1.45rem/1.2 Georgia, "Times New Roman", serif; margin-bottom: 14px; }
h3 { font-size: 1.05rem; }

/* Files */
.files { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.slot { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; border-top-width: 6px; }
.slot-1 { border-top-color: var(--file1); }
.slot-2 { border-top-color: var(--file2); }
.slot h3 { margin-bottom: 10px; }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 4px; min-height: 120px; padding: 16px; cursor: pointer;
  background: var(--white); border: 2px dashed var(--grape); border-radius: var(--radius);
  transition: background-color 0.15s, border-color 0.15s;
}
.drop:hover { background: #fdf9ff; }
.drop:focus-within { outline: 3px solid var(--pink); outline-offset: 2px; }
.drop.over { background: var(--gold-soft); border-color: var(--gold); border-style: solid; }
.drop-main { font-weight: 600; color: var(--grape-deep); }
.drop-sub { font-size: 0.875rem; color: var(--muted); }
.slot.has-file .drop { display: none; }

.loaded { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.fname { font-weight: 600; word-break: break-word; }
.fmeta { font-size: 0.875rem; color: var(--muted); margin-top: 2px; }

.field { margin-top: 12px; }
.field label, legend { display: block; font-weight: 600; margin-bottom: 4px; color: var(--ink); }
select, input[type="text"], input[type="number"] {
  width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--white); border: 1px solid #b9a8cc; border-radius: 8px;
}
select:disabled { background: #efe9f5; color: var(--muted); }
input:focus-visible, select:focus-visible, button:focus-visible, .check input:focus-visible, .mode input:focus-visible {
  outline: 3px solid var(--pink); outline-offset: 2px;
}
.hint { font-size: 0.875rem; color: var(--muted); margin-top: 4px; max-width: 70ch; }
.msg { font-size: 0.9rem; margin-top: 10px; color: var(--ink); min-height: 0; }
.msg:empty { display: none; }
.msg.warn { background: var(--gold-soft); border-left: 4px solid var(--gold); padding: 8px 10px; border-radius: 4px; }
.msg.bad, .err { color: var(--danger); font-weight: 600; font-size: 0.9rem; }
.err:empty { display: none; }
.err { margin-top: 6px; }
.link { background: none; border: 0; padding: 6px 0; margin-top: 4px; color: var(--grape); font: inherit; text-decoration: underline; cursor: pointer; min-height: 32px; }

/* Settings */
.modes { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modes legend { grid-column: 1 / -1; padding: 0; }
.mode { display: flex; gap: 10px; align-items: flex-start; padding: 14px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.mode:has(input:checked) { border-color: var(--grape); box-shadow: inset 0 0 0 1px var(--grape); background: #fbf8fe; }
.mode input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--grape); flex: none; }
.mode-body { display: block; }
.mode-name { display: block; font-weight: 600; color: var(--ink); }
.mode-desc { display: block; font-size: 0.9rem; color: var(--muted); margin-top: 2px; }

.row-fields { display: flex; gap: 16px; margin-top: 18px; align-items: flex-start; }
.grow { flex: 1 1 auto; margin-top: 0; }
.short { flex: 0 0 150px; margin-top: 0; }

.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 20px; }
.btn {
  min-height: 44px; padding: 10px 22px; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--grape-deep); background: var(--white); border: 2px solid var(--grape); border-radius: 8px;
}
.btn:hover:not(:disabled) { background: var(--surface); }
.btn.primary { background: var(--grape); color: var(--white); }
.btn.primary:hover:not(:disabled) { background: var(--grape-deep); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.gold:hover:not(:disabled) { background: #b8921c; }
.btn.small { min-height: 40px; padding: 6px 16px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.proc { display: inline-flex; align-items: center; gap: 8px; color: var(--grape-deep); font-weight: 600; }
.spin { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--pink); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Results */
.notes { display: grid; gap: 8px; margin-bottom: 14px; }
.notes p { background: var(--gold-soft); border-left: 4px solid var(--gold); padding: 8px 12px; border-radius: 4px; font-size: 0.92rem; }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--ink); color: var(--white); font-weight: 600; white-space: nowrap; }
.summary thead th.c1 { background: var(--file1); color: var(--ink); }
.summary thead th.c2 { background: var(--file2); color: var(--ink); }
.summary td:not(:first-child), .summary th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.summary tbody th { font-weight: 600; color: var(--ink); background: var(--white); }
.summary tr.hot td { font-weight: 700; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
.def { font-size: 0.9rem; color: var(--muted); margin-top: 8px; max-width: 78ch; }

.download { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 22px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.92rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--grape); }
#h-preview { margin-top: 30px; margin-bottom: 10px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { min-height: 44px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; color: var(--ink); background: var(--white); border: 2px solid var(--line); border-radius: 999px; }
.chip .n { font-weight: 400; color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { border-color: var(--grape); background: var(--surface); box-shadow: inset 0 0 0 1px var(--grape); }
.chip.c1 { border-left: 10px solid var(--file1); }
.chip.c2 { border-left: 10px solid var(--file2); }

.preview { max-height: 520px; overflow: auto; }
.rows th { position: sticky; top: 0; z-index: 1; }
.rows td { word-break: break-word; min-width: 90px; }
.rows td.num { font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 0; }
.rows tr.r1 td { background: var(--file1); }
.rows tr.r2 td { background: var(--file2); }
.rows tr.skip td { color: var(--muted); font-style: italic; background: #f3f0f6; }
.rows td.empty { text-align: center; color: var(--muted); padding: 22px; background: var(--white); font-style: normal; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
#pager-info { color: var(--muted); font-size: 0.92rem; }

.foot { border-top: 1px solid var(--line); background: var(--surface); }
.foot p { max-width: 960px; margin: 0 auto; padding: 18px 16px; font-size: 0.875rem; color: var(--muted); }

.th-short { display: none; }

/* Tablet */
@media (max-width: 800px) {
  .modes { grid-template-columns: 1fr; }
}
/* Phone */
@media (max-width: 640px) {
  .files { grid-template-columns: 1fr; }
  .row-fields { flex-direction: column; gap: 14px; }
  .short { flex: none; width: 100%; }
  .btn { flex: 1 1 140px; }
  .download .btn { flex: 1 1 100%; }
  .pager .btn { flex: 1 1 120px; }
  #pager-info { order: -1; width: 100%; }
  .top-inner { padding-top: 22px; }
  th, td { padding: 8px 9px; }
  /* The summary must be readable without sideways scrolling: short headers, tighter cells. */
  .th-long { display: none; }
  .th-short { display: inline; }
  .summary th, .summary td { padding: 8px 8px; }
  .summary tbody th { width: 46%; }
}
@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 3s; }
  .drop { transition: none; }
}
