:root {
  --accent: #305496;
  --accent-dark: #264073;
  --accent-tint: #eef3fb;
  --navy: #1f2c45;
  --brand-cyan: #1ab1e3;
  --text: #222;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #c7ccd1;
  --bg: #ffffff;
  --bg-subtle: #fafbfc;
  --danger: #c0392b;
  --danger-bg: #fdecec;
  --warning: #8a6d00;
  --warning-bg: #fdf6dd;
  --ok: #2e7d32;
  --ok-bg: #e9f5ea;
  --mono-bg: #f3f4f6;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
          monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 900px;
  margin: 48px auto;
  padding: 0 24px;
}

.container--wide {
  max-width: 1100px;
}

.page-header {
  margin-bottom: 48px;
}

.page-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-muted);
  margin: 0;
  font-size: 1rem;
}

.page-footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.page-footer a {
  color: var(--accent);
  text-decoration: none;
}

.page-footer a:hover {
  text-decoration: underline;
}

/* ---------- Top bar: back to the MWDSL Tools landing page ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
}

.topbar__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.topbar__back:hover {
  color: var(--text);
}

/* ---------- Cards ---------- */

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card + .card,
section + section {
  margin-top: 48px;
}

.card--flush {
  padding: 0;
  overflow-x: auto;
}

/* ---------- Alerts ---------- */

.alert {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(192, 57, 43, 0.25);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 24px;
  font-weight: 500;
}

/* ---------- Form ---------- */

.field {
  margin-bottom: 20px;
}

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.field .required {
  color: var(--danger);
}

.field input[type="text"],
.field input[type="file"],
.field textarea,
.field select,
select#config-picker {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font: inherit;
  color: inherit;
  background: var(--bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input[type="text"]:focus,
.field textarea:focus,
.field select:focus,
select#config-picker:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(48, 84, 150, 0.15);
}

.field textarea {
  min-height: 96px;
  resize: vertical;
  font-family: inherit;
}

.field-row {
  display: flex;
  gap: 16px;
}

.field-row .field {
  flex: 1;
}

.field--checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field--checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.field--checkbox label {
  margin-bottom: 0;
  font-weight: 500;
}

.field-hint {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-muted, #6b7280);
  font-style: italic;
}

.form-actions {
  margin-top: 32px;
}

/* ---------- Dropzone ---------- */

.dropzone {
  display: block;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  background: var(--bg-subtle);
}

.dropzone:hover {
  border-color: var(--accent);
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-tint);
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.dropzone__text {
  display: block;
}

.dropzone__text strong {
  display: block;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 4px;
}

.dropzone__hint {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.dropzone__filename {
  display: block;
  margin-top: 12px;
  color: var(--accent);
  font-weight: 500;
  font-size: 0.95rem;
}

/* ---------- Buttons ---------- */

.button {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.button.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.button.secondary {
  background: var(--bg);
  color: var(--accent);
  border-color: var(--accent);
}

.button.secondary:hover {
  background: var(--accent-tint);
}

/* ---------- Error page ---------- */

.error-section-heading {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.error-output {
  background: var(--mono-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow: auto;
  margin: 0 0 24px;
}

.error-output:last-child {
  margin-bottom: 0;
}

/* ---------- Select picker ---------- */

select#config-picker {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%236b7280' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ====================================================================
   Setup page (upload form) — Direction C, two-column. Scoped under
   .setup so the results / error pages are unaffected.
   ==================================================================== */

.container.setup {
  max-width: 880px;
  margin-top: 36px;
}

/* ---------- Brand lockup ---------- */
.brand-lock {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.brand-lock__logo {
  width: 34px;
  height: 34px;
  display: block;
  border-radius: 6px;
}
.brand-lock__txt { line-height: 1.18; }
.brand-lock__txt b {
  display: block;
  color: var(--navy);
  font-weight: 800;
  font-size: 1.06rem;
  letter-spacing: -0.01em;
}
.brand-lock__txt span {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.brand-lock__badge {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-tint);
  border: 1px solid #d8e4f0;
  padding: 5px 12px;
  border-radius: 999px;
}

/* ---------- Setup card ---------- */
.setup-card {
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.05);
  overflow: hidden;
}
.setup-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--border);
}
.setup-card__intro h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
}
.setup-card__intro p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* saved-job picker tucked into the header */
.saved-config {
  flex-shrink: 0;
  text-align: right;
}
.saved-config label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.saved-config select {
  min-width: 190px;
  padding: 8px 32px 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  color: inherit;
  background: var(--bg);
}

/* ---------- Two-column grid ---------- */
.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.setup-col { padding: 24px 26px; }
.setup-col + .setup-col { border-left: 1px solid var(--border); }
.setup-grid .field:last-child { margin-bottom: 0; }

/* custom dropdown arrow for all setup selects (parity with the mock) */
.setup select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%236b7280' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* month + year side by side */
.twin { display: flex; gap: 10px; }
.twin #balance_month { flex: 1.4; }
.twin #balance_year { flex: 1; }

/* read-only derived prior date */
.derived {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 0.92rem;
}
.derived b { color: var(--text); font-weight: 600; }
.derived__icon { color: var(--accent); }

/* compact dropzone with icon for the two-column layout */
.setup .dropzone { padding: 30px 20px; }
.dropzone__icon {
  width: 32px;
  height: 32px;
  margin: 0 auto 10px;
  color: var(--accent);
  display: block;
}

/* ---------- Footer action bar ---------- */
.setup-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 26px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
}
.setup-card__foot .field--checkbox { margin: 0; }

/* ---------- Responsive: stack to one column ---------- */
@media (max-width: 720px) {
  .setup-grid { grid-template-columns: 1fr; }
  .setup-col + .setup-col { border-left: 0; border-top: 1px solid var(--border); }
  .setup-card__head { flex-direction: column; }
  .saved-config { text-align: left; }
  .saved-config select { width: 100%; }
}

/* ====================================================================
   Scan overlay — full-page "scanning" animation shown on submit.
   ==================================================================== */

.scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: rgba(246, 247, 249, 0.72);
  backdrop-filter: saturate(160%) blur(7px);
  -webkit-backdrop-filter: saturate(160%) blur(7px);
}
.scan-overlay[hidden] { display: none; }  /* beats the display:flex above when hidden */

.scan-overlay__logo {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  animation: scan-pulse 1.8s ease-in-out infinite;
}
@keyframes scan-pulse {
  0%, 100% { transform: scale(1); opacity: 0.92; }
  50% { transform: scale(1.06); opacity: 1; }
}

/* the stylised sheet being scanned */
.scan-sheet {
  position: relative;
  width: 240px;
  height: 150px;
  background: #fff;
  border: 1px solid #dfe4ec;
  border-radius: 10px;
  box-shadow: 0 8px 26px rgba(20, 30, 50, 0.13);
  overflow: hidden;
  padding: 16px 16px 0;
}
.scan-sheet__row {
  display: block;
  height: 8px;
  border-radius: 3px;
  background: #eef1f5;
  margin-bottom: 9px;
}
.scan-sheet__row:nth-child(1) { width: 60%; }
.scan-sheet__row:nth-child(2) { width: 88%; }
.scan-sheet__row:nth-child(3) { width: 74%; }
.scan-sheet__row:nth-child(4) { width: 92%; }
.scan-sheet__row:nth-child(5) { width: 50%; }
.scan-sheet__row:nth-child(6) { width: 80%; }
.scan-sheet__beam {
  position: absolute;
  left: 0;
  right: 0;
  top: -34px;
  height: 34px;
  background: linear-gradient(180deg, rgba(26, 177, 227, 0) 0%, rgba(26, 177, 227, 0.18) 60%, rgba(26, 177, 227, 0.42) 100%);
  border-bottom: 2px solid var(--brand-cyan);
  box-shadow: 0 0 16px rgba(26, 177, 227, 0.55);
  animation: scan-sweep 1.9s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}
@keyframes scan-sweep {
  0% { top: -34px; }
  100% { top: 150px; }
}

.scan-overlay__title {
  font-weight: 700;
  color: var(--navy);
  font-size: 1.12rem;
  letter-spacing: -0.01em;
}
.scan-overlay__entity { color: var(--accent); }
.scan-overlay__status {
  color: var(--text-muted);
  font-size: 0.95rem;
  min-height: 20px;
  font-variant-numeric: tabular-nums;
}
.scan-overlay__dots { display: flex; gap: 6px; margin-top: -6px; }
.scan-overlay__dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #c3ccd8;
  animation: scan-blink 1.4s infinite;
}
.scan-overlay__dots i:nth-child(2) { animation-delay: 0.2s; }
.scan-overlay__dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes scan-blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; background: var(--accent); }
}

/* Respect reduced-motion: keep the overlay + cycling text, drop the motion. */
@media (prefers-reduced-motion: reduce) {
  .scan-overlay__logo,
  .scan-sheet__beam,
  .scan-overlay__dots i { animation: none; }
  .scan-sheet__beam { top: 58px; opacity: 0.5; }
}

/* validation cue for the dropzone (form is novalidate; JS guards required fields) */
.dropzone--error {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.dropzone--error .dropzone__filename { color: var(--danger); }

/* ====================================================================
   Results page — card layout (per finding), grouped by severity.
   Scoped under .results / .page-results so other pages are unaffected.
   ==================================================================== */

.page-results { background: #f6f7f9; }
.container.results { max-width: 880px; margin-top: 34px; }

/* header: logo lockup + download button */
.rhead { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.rhead__logo { width: 34px; height: 34px; border-radius: 6px; }
.rhead__txt b { display: block; color: var(--navy); font-weight: 800; font-size: 1.06rem; letter-spacing: -0.01em; }
.rhead__txt span { font-size: 0.8rem; color: var(--text-muted); word-break: break-all; }
.rhead__dl { margin-left: auto; flex-shrink: 0; white-space: nowrap; }

/* verdict / summary band */
.verdict {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 24px; margin-bottom: 26px; display: flex; align-items: center; gap: 18px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.05);
}
.verdict__title { font-size: 1.15rem; font-weight: 700; color: var(--navy); }
.verdict__sub { color: var(--text-muted); font-size: 0.9rem; }
.verdict--clean { border-color: rgba(46, 125, 50, 0.3); background: var(--ok-bg); }
.verdict--clean .verdict__title { color: var(--ok); }
.verdict--clean .verdict__sub { color: #3a6b3d; }
.verdict__glyph {
  width: 40px; height: 40px; border-radius: 50%; background: var(--ok); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0;
}

.chips { margin-left: auto; display: flex; gap: 10px; flex-shrink: 0; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 999px; font-weight: 600; font-size: 0.86rem; }
.chip--critical { background: var(--danger-bg); color: var(--danger); }
.chip--warning { background: var(--warning-bg); color: var(--warning); }
.chip__dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* severity groups */
.group + .group { margin-top: 26px; }
.group__head { margin: 0 2px 12px; }
.group__head h2 { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; margin: 0; }
.group--critical h2 { color: var(--danger); }
.group--warning h2 { color: var(--warning); }

/* finding card */
.rcard {
  background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: 11px; padding: 18px 20px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.rcard--critical { border-left-color: var(--danger); }
.rcard--warning { border-left-color: #caa53a; }
.rcard__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.rcard__head h3 { margin: 0; font-size: 1rem; font-weight: 700; color: var(--navy); letter-spacing: -0.01em; }

.pill { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 3px 10px; border-radius: 999px; flex-shrink: 0; }
.pill--critical { background: var(--danger-bg); color: var(--danger); }
.pill--warning { background: var(--warning-bg); color: var(--warning); }

/* comparison block */
.cmp { background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.cmp__row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 14px; }
.cmp__row + .cmp__row { border-top: 1px solid var(--border); }
.cmp__lbl { color: #3a4250; font-size: 0.92rem; }
.cmp__amt { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.98rem; color: var(--text); white-space: nowrap; }
.cmp__diff { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 1px solid var(--border); }
.cmp__diff span { font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.cmp__diff b { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.05rem; }
.cmp__diff--critical { background: var(--danger-bg); border-top-color: #f3d6d2; }
.cmp__diff--critical span, .cmp__diff--critical b { color: var(--danger); }
.cmp__diff--warning { background: var(--warning-bg); border-top-color: #ece2b0; }
.cmp__diff--warning span, .cmp__diff--warning b { color: var(--warning); }

.results code { font-family: var(--mono); font-size: 0.82em; background: #eef1f5; color: #465061; padding: 1px 6px; border-radius: 4px; }

.rcard__desc { margin: 0; color: #3a4250; font-size: 0.95rem; }
.rcard__fix { margin: 13px 0 0; color: #3a4250; font-size: 0.92rem; display: flex; gap: 8px; align-items: flex-start; }
.rcard__fix-dot { color: var(--accent); }
.rcard__desc + .rcard__fix { margin-top: 10px; }

.results__footer { margin-top: 34px; }
.results__footer a { color: var(--accent); text-decoration: none; font-weight: 500; }
.results__footer a:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .rhead { flex-wrap: wrap; }
  .rhead__dl { margin-left: 0; width: 100%; text-align: center; }
  .verdict, .rcard__head, .cmp__row { flex-wrap: wrap; }
  .chips { margin-left: 0; }
}
