*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --ink: #1a1a18; --paper: #f5f2eb; --accent: #c0392b;
  --rule: #c8c0b0; --muted: #524a3f;
  /* --mono is the caption face used for labels/eyebrows; --sans is the body face */
  --mono: 'PT Sans Caption', -apple-system, system-ui, sans-serif; --sans: 'PT Sans', -apple-system, system-ui, sans-serif;
}
body { background: var(--paper); color: var(--ink); font-family: var(--sans); min-height: 100vh; line-height: 1.6; }

header { border-bottom: 3px double var(--ink); }
.header-inner { max-width: 1200px; margin: 0 auto; padding: 2rem 3rem 1.5rem; }
.masthead-label { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.4rem; }
h1 { font-size: clamp(1.6rem, 3vw, 2.4rem); font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
h1 span { color: var(--accent); }
.byline { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); letter-spacing: 0.05em; margin-top: 0.5rem; }

main { padding: 2.5rem 3rem; max-width: 1200px; margin: 0 auto; }

/* Upload row */
.upload-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 2rem; }

.drop-zone {
  border: 2px dashed var(--rule); padding: 2rem 1.5rem; text-align: center;
  cursor: pointer; transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--ink); background: rgba(0,0,0,0.02); }
.drop-zone.loaded { border-color: #8bc34a; border-style: solid; }
.drop-zone.disabled { opacity: 0.45; pointer-events: none; }

.drop-zone h2 { font-size: 1rem; font-weight: 600; margin-bottom: 0.3rem; }
.drop-zone p { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); line-height: 1.6; }
.guide-link { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent); }
.guide-link:hover { color: var(--ink); border-bottom-color: var(--ink); }

.dz-tag {
  display: inline-block; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 0.15rem 0.6rem; border: 1px solid var(--rule);
  color: var(--muted); margin-bottom: 0.6rem;
}
.drop-zone.loaded .dz-tag { border-color: #8bc34a; color: #155724; background: #d4edda; }

.file-btn {
  display: inline-block; margin-top: 1rem; padding: 0.55rem 1.3rem;
  background: var(--ink); color: var(--paper); font-family: var(--mono);
  font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase;
  cursor: pointer; border: none; transition: background 0.15s;
}
.file-btn:hover { background: var(--accent); }
.file-btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--rule); }
.file-btn.secondary:hover { background: var(--ink); color: var(--paper); }

#file-input-csv, #file-input-json { display: none; }
.loaded-name { font-family: var(--mono); font-size: 0.75rem; color: #155724; margin-top: 0.6rem; display: none; }
.drop-zone.loaded .loaded-name { display: block; }

/* Report ("What the cleaner did") */
#log-section { display: none; margin-bottom: 2rem; }
.log-label { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.log-label::after { content: ''; flex: 1; height: 1px; background: var(--rule); }
#log { background: #fff; border: 1px solid var(--rule); border-left: 3px solid var(--accent); font-family: var(--sans); font-size: 0.9rem; line-height: 1.5; padding: 0.6rem 1.25rem; overflow-y: auto; max-height: 300px; }
#log > div { padding: 0.35rem 0; border-bottom: 1px solid rgba(0,0,0,0.05); color: var(--ink); }
#log > div:last-child { border-bottom: none; }
#log .step { color: var(--muted); }
#log .ok   { color: var(--ink); }
#log .info { color: var(--muted); font-style: italic; }
#log .warn { color: var(--accent); font-weight: 700; }

/* Stats */
#stats-bar { display: none; grid-template-columns: repeat(4, 1fr); border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule); margin-bottom: 2rem; }
.stat { padding: 0.85rem 1.1rem; border-right: 1px solid var(--rule); }
.stat:last-child { border-right: none; }
.stat-num { font-family: var(--sans); font-size: 1.5rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.stat-label { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-top: 0.2rem; }

/* Table */
#table-section { display: none; }
.table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; }
.table-controls-left, .table-controls-right { display: flex; gap: 0.5rem; align-items: center; }

input[type="text"] { font-family: var(--mono); font-size: 0.85rem; padding: 0.5rem 0.85rem; border: 1px solid var(--rule); background: white; outline: none; width: 220px; transition: border-color 0.15s; }
input[type="text"]:focus { border-color: var(--ink); }
select { font-family: var(--mono); font-size: 0.85rem; padding: 0.5rem 0.85rem; border: 1px solid var(--rule); background: white; outline: none; cursor: pointer; }
.download-btn { padding: 0.5rem 1.1rem; background: var(--accent); color: white; font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer; border: none; transition: opacity 0.15s; }
.download-btn:hover { opacity: 0.85; }
.clipboard-btn { background: #6c757d; }
.clipboard-btn:hover { opacity: 0.85; }

.table-wrap { overflow-x: auto; border: 1px solid var(--rule); }
table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead { background: var(--ink); color: var(--paper); position: sticky; top: 0; }
th { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; padding: 0.75rem 0.95rem; text-align: left; white-space: nowrap; cursor: pointer; user-select: none; }
th:hover { background: #333; }
th.sorted-asc::after { content: ' ↑'; color: var(--accent); }
th.sorted-desc::after { content: ' ↓'; color: var(--accent); }
td { padding: 0.65rem 0.95rem; border-bottom: 1px solid var(--rule); vertical-align: top; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:nth-child(even) td { background: rgba(0,0,0,0.02); }
tr:hover td { background: rgba(192,57,43,0.05); }
tbody tr { cursor: pointer; }

.badge { display: inline-block; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.05em; padding: 0.2rem 0.55rem; white-space: nowrap; }
.badge-open     { background: #fef3cd; color: #7d5a00; border: 1px solid #f0c040; }
.badge-closed   { background: #d4edda; color: #155724; border: 1px solid #8bc34a; }
.badge-other    { background: #e8e8e8; color: #555;    border: 1px solid #ccc; }
.badge-urgent   { background: #fde8e8; color: #7b1a1a; border: 1px solid #e88; }
.badge-true     { background: #c8e6c9; color: #1b5e20; border: 1px solid #66bb6a; font-weight: 500; }
.badge-false    { background: #e0e0e0; color: #424242; border: 1px solid #9e9e9e; }

.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 1rem; font-family: var(--mono); font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; gap: 0.5rem; }
.page-btns { display: flex; gap: 0.25rem; }
.page-btns button { padding: 0.35rem 0.7rem; border: 1px solid var(--rule); background: var(--paper); font-family: var(--mono); font-size: 0.8rem; cursor: pointer; transition: background 0.1s; }
.page-btns button:hover, .page-btns button.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(26,26,24,0.65); z-index: 100; align-items: center; justify-content: center; padding: 2rem; backdrop-filter: blur(2px); }
.modal-overlay.open { display: flex; }
.modal { background: var(--paper); border: 2px solid var(--ink); max-width: 800px; width: 100%; max-height: 88vh; overflow-y: auto; animation: modalIn 0.18s ease; }
@keyframes modalIn { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }

.modal-header { border-bottom: 2px solid var(--ink); padding: 1.25rem 1.5rem; display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; position: sticky; top: 0; background: var(--paper); z-index: 1; }
.modal-srid { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.3rem; }
.modal-title { font-size: 1.3rem; font-weight: 600; line-height: 1.3; }
.modal-close { background: none; border: 1px solid var(--rule); font-family: var(--mono); font-size: 0.8rem; cursor: pointer; padding: 0.2rem 0.6rem; color: var(--muted); flex-shrink: 0; transition: border-color 0.15s, color 0.15s; }
.modal-close:hover { border-color: var(--ink); color: var(--ink); }

.modal-body { padding: 1.5rem; }
.modal-rec-text { font-size: 1rem; line-height: 1.7; font-style: italic; margin-bottom: 1.5rem; }

.modal-section-label { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.5rem; margin-top: 2.5rem; display: flex; align-items: center; gap: 0.5rem; }
.modal-section-label::after { content: ''; flex: 1; height: 1px; background: var(--rule); }
.modal-section-label:first-child { margin-top: 0; }

.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--rule); border: 1px solid var(--rule); margin-bottom: 1rem; }
.modal-field { background: var(--paper); padding: 0.7rem 1rem; }
.modal-field.full-width { grid-column: 1 / -1; }
.modal-field-label { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.25rem; }
.modal-field-value { font-size: 0.92rem; line-height: 1.5; word-break: break-word; }

.modal-enriched { display: none; }
.modal-enriched.visible { display: block; }

.modal-links { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1.25rem; }
.modal-link { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; padding: 0.4rem 0.9rem; border: 1px solid var(--ink); color: var(--ink); text-decoration: none; transition: background 0.15s, color 0.15s; }
.modal-link:hover { background: var(--ink); color: var(--paper); }

/* Guide modal */
.guide-list { margin: 0.4rem 0 0.5rem 1.2rem; }
.guide-list li { font-size: 0.92rem; line-height: 1.55; margin-bottom: 0.5rem; }
.guide-list li:last-child { margin-bottom: 0; }
.guide-list a { color: var(--accent); }
.guide-list code { font-family: var(--mono); font-size: 0.85em; background: rgba(0,0,0,0.05); padding: 0.05rem 0.3rem; }

/* Footer */
footer { border-top: 3px double var(--ink); margin-top: 3rem; }
.footer-inner { max-width: 1200px; margin: 0 auto; padding: 1.5rem 3rem; text-align: center; }
.footer-credit { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.footer-credit a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.15s; }
.footer-credit a:hover { border-bottom-color: var(--accent); }

@media (max-width: 700px) {
  .header-inner, main { padding: 1.25rem; }
  .footer-inner { padding: 1.25rem; }
  .upload-row { grid-template-columns: 1fr; }
  #stats-bar { grid-template-columns: repeat(2,1fr); }
  td { max-width: 140px; }
  .modal-grid { grid-template-columns: 1fr; }
}
