/* IDACI postcode lookup
   Built on Fluent 2 design rules (type sizes, 4px spacing grid, corner radii,
   shadows, control styles) using the Bristol & Beyond Stronger Practice Hub palette.
   Light theme only: the SPH logo's black lettering needs a light background. */

:root {
  /* SPH palette: BBEYH Blue */
  --gold: #eaa53e;
  --navy-900: #133967;
  --navy: #224c7f;
  --blue-500: #5b7da6;
  --blue-50: #dbeff5;
  /* SPH palette: BBEYH Orange */
  --orange: #d35615;
  --amber: #d38715;
  --raspberry: #c2133c;
  --wine: #9d0629;

  /* Fluent-style neutrals */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #242424;
  --text-2: #616161;
  --stroke: #d1d1d1;
  --stroke-subtle: #e0e0e0;
  --stroke-accessible: #616161;

  /* Fluent status colours, tuned to the palette */
  --success: #107c10;  --success-bg: #f1faf1;
  --warning: #8a4b00;  --warning-bg: #fff9f0;
  --danger: var(--wine); --danger-bg: #fdf3f4;

  /* Fluent radii, shadows, motion */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --shadow-2: 0 0 2px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.14);
  --shadow-4: 0 0 2px rgba(0,0,0,.12), 0 2px 4px rgba(0,0,0,.14);
  --shadow-8: 0 0 2px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.14);
  --ease: cubic-bezier(0.33, 0, 0.67, 1);

  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;

  color-scheme: light;
  font-family: var(--font);
  font-size: 14px;
  line-height: 20px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; }
svg { fill: currentColor; flex: none; }
u { text-underline-offset: 2px; }

/* ---------- Type ramp (Fluent 2) ---------- */
h1 { font: 600 40px/52px var(--font-display); margin: 0; letter-spacing: -0.01em; }
h2 { font: 600 20px/28px var(--font-display); margin: 0 0 16px; display: flex; align-items: center; gap: 12px; }
h3 { font: 600 16px/22px var(--font); margin: 24px 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--text-2); font-weight: 400; }
.hint { color: var(--text-2); margin: 8px 0 16px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Header ---------- */
.hero {
  background:
    radial-gradient(1200px 300px at 50% -60px, #ffffff 0%, rgba(255,255,255,0) 70%),
    var(--blue-50);
  border-bottom: 4px solid var(--gold);
  padding: 32px 20px 40px;
  text-align: center;
}
.hero-inner { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; }
.brand-logo { display: block; width: 200px; height: auto; margin: 0 0 24px; }
.hero h1 { color: var(--navy-900); }
.lede { font-size: 16px; line-height: 22px; color: #3d3d3d; max-width: 560px; margin: 8px 0 20px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0; padding: 4px 12px 4px 8px;
  background: var(--surface); color: var(--navy);
  border: 1px solid rgba(34, 76, 127, .25); border-radius: 999px;
  font-size: 12px; line-height: 16px; font-weight: 600;
  box-shadow: var(--shadow-2);
}
.badge svg { width: 16px; height: 16px; color: var(--navy); }

/* ---------- Layout ---------- */
main { max-width: 880px; margin: -20px auto 0; padding: 0 20px 48px; position: relative; }

.card {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-4);
  padding: 24px;
  margin-bottom: 16px;
}

.divider {
  display: flex; align-items: center; gap: 16px;
  margin: 32px 0 16px; color: var(--text-2);
  font-size: 12px; line-height: 16px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--stroke); }

.num {
  display: inline-grid; place-items: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--navy); color: #fff;
  font: 600 14px/1 var(--font);
}

/* ---------- Controls (Fluent 2) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 5px 12px;
  font: 600 14px/20px var(--font);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--stroke); border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .1s var(--ease), border-color .1s var(--ease);
}
.btn svg { width: 20px; height: 20px; }
.btn:hover { background: #f5f5f5; border-color: #c7c7c7; }
.btn:active { background: #e0e0e0; }
.btn.primary { background: var(--navy); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--navy-900); }
.btn.primary:active { background: #0e2b4e; }
.btn:disabled { background: #f0f0f0; border-color: var(--stroke-subtle); color: #bdbdbd; cursor: default; }
.btn:focus-visible, .drop:focus-within, select:focus-visible {
  outline: 2px solid var(--text); outline-offset: 2px;
}

input[type="text"], select {
  font: 400 14px/20px var(--font); color: var(--text);
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-bottom-color: var(--stroke-accessible);
  border-radius: var(--r-sm);
  min-height: 32px; padding: 5px 10px;
}
select { min-width: 260px; padding-right: 28px; }

.input-wrap { position: relative; display: inline-flex; align-items: center; }
.input-wrap svg { position: absolute; left: 10px; width: 20px; height: 20px; color: var(--text-2); pointer-events: none; }
.input-wrap input { padding-left: 36px; }
/* Fluent's bottom-edge focus indicator */
.input-wrap::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: var(--navy); border-radius: 0 0 var(--r-sm) var(--r-sm);
  transform: scaleX(0); transition: transform .15s var(--ease);
}
.input-wrap:focus-within::after { transform: scaleX(1); }
input[type="text"]:focus, select:focus { outline: none; }

/* ---------- Quick lookup ---------- */
.quick { border-top: 4px solid var(--raspberry); }
.quick-form { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-form input {
  width: 220px; min-height: 40px;
  font-size: 16px; line-height: 22px; text-transform: uppercase; letter-spacing: .04em;
}
.quick-form .btn { min-height: 40px; padding: 8px 20px; font-size: 16px; }
.quick-result { margin-top: 20px; }
.quick-result .where { font-size: 16px; line-height: 22px; margin: 0 0 16px; }
.quick-result .where b { color: var(--navy); }
.quick-result .note { color: var(--text-2); margin: 16px 0 0; }
.quick-result .summary { grid-template-columns: repeat(3, 1fr); }
.quick-result .stat { padding: 12px; }
@media (max-width: 380px) { .quick-result .summary { grid-template-columns: 1fr; } }

/* Fluent MessageBar */
.msg {
  display: flex; align-items: center; gap: 8px;
  margin: 0; padding: 8px 12px;
  border: 1px solid var(--stroke-subtle); border-radius: var(--r-sm);
  background: #fafafa;
}
.msg::before {
  content: ""; width: 4px; align-self: stretch; border-radius: 2px; background: var(--blue-500);
}
.msg.bad { background: var(--danger-bg); border-color: #f3d6db; color: var(--danger); }
.msg.bad::before { background: var(--danger); }
.msg.warn { background: var(--warning-bg); border-color: #f6e0bf; color: var(--warning); }
.msg.warn::before { background: var(--amber); }

/* Decile scale: SPH palette from most deprived (wine) to least deprived (navy) */
.decile-bar {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px;
  margin: 20px 0 6px; max-width: 520px;
}
.decile-bar span {
  height: 32px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: #fff;
  opacity: .28; transition: opacity .15s var(--ease), transform .15s var(--ease);
}
.decile-bar span:nth-child(1)  { background: var(--wine); }
.decile-bar span:nth-child(2)  { background: var(--raspberry); }
.decile-bar span:nth-child(3)  { background: var(--orange); }
.decile-bar span:nth-child(4)  { background: var(--amber); }
.decile-bar span:nth-child(5)  { background: var(--gold); color: var(--text); }
.decile-bar span:nth-child(6)  { background: #a9c3d9; color: var(--text); }
.decile-bar span:nth-child(7)  { background: #85a0c0; }
.decile-bar span:nth-child(8)  { background: var(--blue-500); }
.decile-bar span:nth-child(9)  { background: var(--navy); }
.decile-bar span:nth-child(10) { background: var(--navy-900); }
.decile-bar span.on { opacity: 1; transform: scaleY(1.18); box-shadow: var(--shadow-4); }
.decile-ends { display: flex; justify-content: space-between; max-width: 520px; font-size: 12px; line-height: 16px; color: var(--text-2); }

/* ---------- Upload ---------- */
.drop {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 32px 16px;
  border: 1px dashed #9e9e9e; border-radius: var(--r-md);
  background: #fafafa;
  cursor: pointer; text-align: center;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.drop:hover, .drop.over { border-color: var(--navy); background: #f2f8fb; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-icon { width: 32px; height: 32px; color: var(--navy); margin-bottom: 4px; }
.drop-main { font-weight: 600; font-size: 16px; line-height: 22px; }
.drop-main u { color: var(--navy); }
.drop-sub { color: var(--text-2); }

.fields { display: flex; flex-wrap: wrap; gap: 16px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }

/* ---------- Results ---------- */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  border: 1px solid var(--stroke-subtle); border-radius: var(--r-md);
  padding: 12px 16px; background: var(--surface);
}
.stat b { display: block; font: 600 28px/36px var(--font-display); font-variant-numeric: tabular-nums; color: var(--navy-900); }
.stat span { color: var(--text-2); font-size: 12px; line-height: 16px; display: block; }
.stat.ok { border-left: 4px solid var(--success); }
.stat.ok b { color: var(--success); }
.stat.warn { border-left: 4px solid var(--amber); }
.stat.warn b { color: var(--warning); }
.stat.bad { border-left: 4px solid var(--raspberry); }
.stat.bad b { color: var(--danger); }
.summary .hint { margin: 0; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--stroke-subtle); border-radius: var(--r-md); }
table { border-collapse: collapse; font-size: 12px; line-height: 16px; width: 100%; }
th, td { padding: 8px 12px; border-bottom: 1px solid #f0f0f0; text-align: left; white-space: nowrap; }
th { background: #fafafa; position: sticky; top: 0; font-weight: 600; z-index: 1; }
th.added { color: var(--navy); background: #f2f8fb; }
tbody tr:hover { background: #f5f5f5; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.status { min-height: 20px; color: var(--text-2); margin: 8px 0; }
.status:empty { display: none; }
.status.error {
  color: var(--danger); background: var(--danger-bg);
  border: 1px solid #f3d6db; border-radius: var(--r-sm); padding: 8px 12px; font-weight: 600;
}

/* ---------- About + footer ---------- */
.about { margin-top: 32px; color: #3d3d3d; }
.about h2 { font-size: 16px; line-height: 22px; }
.about #sources { font-size: 12px; line-height: 16px; margin: 0; }

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--stroke-subtle);
  padding: 32px 20px 40px;
  text-align: center;
}
.credit-logos { display: flex; align-items: center; justify-content: center; gap: 24px; margin-bottom: 16px; }
.sph-icon { width: 64px; height: auto; }
.cc-logo { width: 140px; height: auto; }
.logo-sep { width: 1px; height: 48px; background: var(--stroke); }
.credit { color: #3d3d3d; margin: 0 0 4px; }
.copyright { color: var(--text-2); font-size: 12px; line-height: 16px; margin: 0; }

@media (max-width: 560px) {
  h1 { font-size: 28px; line-height: 36px; }
  .brand-logo { width: 160px; }
  .card { padding: 20px 16px; }
  .quick-form input { width: 100%; }
  .input-wrap { flex: 1 1 100%; }
  .quick-form .btn { flex: 1; }
  select { min-width: 0; width: 100%; }
  .fields label { flex: 1 1 100%; }
}

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