:root {
  --nh-green: #00a200;
  --nh-teal: #0a5c6a;
  --nh-teal-light: #e8f4f6;
  --pass: #198754;
  --pass-bg: #d1e7dd;
  --fail: #c0392b;
  --fail-bg: #f8d7da;
  --amber: #856404;
  --amber-bg: #fff3cd;
  --na: #6c757d;
  --na-bg: #e9ecef;
  --bg: #f8f9fa;
  --border: #dee2e6;
  --text: #212529;
  --muted: #6c757d;
  --radius: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

a { color: var(--nh-teal); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1600px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { background: var(--nh-teal); color: #fff; padding: 20px 0 16px; }
.site-header h1 { font-size: 1.6rem; font-weight: 700; }
.site-header .subtitle { opacity: .8; font-size: .9rem; margin-top: 2px; }

.meta-bar { display: flex; gap: 20px; margin-top: 10px; font-size: .82rem; opacity: .9; flex-wrap: wrap; }
.meta-bar span { white-space: nowrap; }
.meta-bar strong { color: #fff; }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0 8px; }
.filter-bar input, .filter-bar select { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; font-size: 13px; min-width: 160px; }
.filter-bar input { flex: 1; min-width: 200px; }
.filter-bar select { flex: 0 1 180px; }

.btn-secondary { padding: 6px 14px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius); cursor: pointer; font-size: 13px; color: var(--muted); white-space: nowrap; }
.btn-secondary:hover { background: var(--bg); }

/* Tabs */
.tab-nav { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-top: 8px; }
.tab-btn { padding: 8px 18px; border: none; background: none; cursor: pointer; font-size: .9rem; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; transition: color .15s; }
.tab-btn:hover { color: var(--nh-teal); }
.tab-btn.active { color: var(--nh-teal); border-bottom-color: var(--nh-teal); font-weight: 600; }

.tab-filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0; }
.tab-filters select { padding: 5px 9px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; font-size: 13px; min-width: 160px; }

/* Stat boxes — sticky inside .table-wrap (the scroll container) */
.stat-boxes { display: flex; flex-wrap: wrap; gap: 10px; padding: 10px 0 8px; position: sticky; top: 0; z-index: 3; background: var(--bg); width: 100%; }
.stat-box { background: var(--nh-green); color: #fff; border-radius: var(--radius); padding: 12px 18px; min-width: 140px; flex: 1 1 140px; max-width: 200px; box-shadow: var(--shadow); }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .78rem; opacity: .88; margin-top: 2px; line-height: 1.3; }
.stat-sub { font-size: .72rem; opacity: .72; margin-top: 3px; }

.results-count { font-size: .82rem; color: var(--muted); padding: 4px 0 6px; }

/* Table — fixed height so it scrolls internally; sticky elements work within this container */
.table-wrap { height: calc(100vh - 250px); min-height: 350px; border-radius: var(--radius); box-shadow: var(--shadow); background: #fff; margin-bottom: 0; overflow-x: auto; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
thead th { background: var(--nh-teal); color: #fff; padding: 6px 5px; text-align: left; white-space: normal; line-height: 1.3; vertical-align: bottom; font-weight: 600; position: sticky; z-index: 2; min-width: 0; }
tbody tr:nth-child(even) { background: var(--nh-teal-light); }
tbody tr:hover { background: #dbeef2; }
td { padding: 5px 5px; border-bottom: 1px solid var(--border); vertical-align: top; }
td:first-child { min-width: 110px; max-width: 150px; }
td:nth-child(2) { max-width: 100px; }

/* Badges */
.badge { display: inline-block; padding: 1px 5px; border-radius: 10px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-pass { background: var(--pass-bg); color: var(--pass); }
.badge-fail { background: var(--fail-bg); color: var(--fail); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-na { background: var(--na-bg); color: var(--na); }

/* Score bar */
.score-bar { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: .75rem; font-weight: 700; }
.bar-high { background: var(--pass-bg); color: var(--pass); }
.bar-mid { background: var(--amber-bg); color: var(--amber); }
.bar-low { background: var(--fail-bg); color: var(--fail); }

/* Region pills */
.region { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: .76rem; font-weight: 500; }
.region-north { background: #cff4fc; color: #0a4c5e; }
.region-central { background: #e2d9f3; color: #4a2d82; }
.region-south { background: #fde8d8; color: #8a3800; }

/* GMC span */
.gmc { display: block; font-size: .72rem; color: var(--muted); margin-top: 2px; }

/* Fix tags */
.fixes { max-width: 180px; }
.fix-tag { display: inline-block; margin: 1px 2px 0 0; padding: 1px 5px; background: var(--fail-bg); color: var(--fail); border-radius: 3px; font-size: .72rem; white-space: nowrap; }

/* Muted */
.muted { color: var(--muted); }

/* No results */
.no-results { text-align: center; padding: 40px; color: var(--muted); font-size: 1rem; }

/* Guide tab */
.guide-tab { padding: 8px 0 40px; }
.guide-section { max-width: 960px; margin: 32px 0; }
.guide-section h2 { font-size: 1.25rem; color: var(--nh-teal); border-bottom: 2px solid var(--nh-teal); padding-bottom: 6px; margin-bottom: 12px; }
.guide-section h3 { font-size: .95rem; font-weight: 600; color: var(--text); margin: 24px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.guide-url { font-size: .8rem; font-weight: 400; color: var(--muted); margin-left: 8px; }
.guide-intro { color: var(--muted); font-size: .9rem; margin-bottom: 10px; line-height: 1.5; }
.guide-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.guide-table thead th { background: var(--nh-teal); color: #fff; text-align: left; padding: 8px 12px; font-weight: 600; position: static; white-space: normal; }
.guide-table tbody tr:nth-child(even) { background: var(--nh-teal-light); }
.guide-table tbody tr:hover { background: #d0e8ec; }
.guide-table td { padding: 10px 12px; vertical-align: top; border-bottom: 1px solid var(--border); line-height: 1.5; max-width: none; min-width: 0; }
.guide-table td:first-child { white-space: nowrap; width: 160px; max-width: none; min-width: 0; }
.guide-table td:nth-child(2) { max-width: none; }
.guide-table em { color: var(--muted); }

/* Waits-by-hospital tab */
.waits-tab { padding: 8px 0 40px; }
.waits-stats { display: flex; flex-wrap: wrap; gap: 10px; padding: 10px 0 4px; }
.waits-stat { background: var(--nh-teal); color: #fff; border-radius: var(--radius); padding: 10px 16px; min-width: 140px; flex: 1 1 140px; max-width: 220px; box-shadow: var(--shadow); }
.waits-stat-label { font-size: .72rem; opacity: .88; margin-bottom: 2px; }
.waits-stat-value { font-size: 1.25rem; font-weight: 700; }
.waits-stat-sub { font-size: .68rem; opacity: .8; margin-top: 2px; line-height: 1.3; }
.waits-panel table.matrix { font-size: .8rem; }
.waits-panel table.matrix th, .waits-panel table.matrix td { padding: 6px 8px; white-space: nowrap; }
.waits-panel table.matrix th:first-child, .waits-panel table.matrix td:first-child { position: sticky; left: 0; background: inherit; z-index: 1; }
.waits-panel table.matrix thead th:first-child { background: var(--nh-teal); }
.waits-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 0 4px; }
.waits-subtabs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.waits-subtab { padding: 5px 12px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: .82rem; color: var(--muted); border-radius: var(--radius); }
.waits-subtab:hover { color: var(--nh-teal); border-color: var(--nh-teal); }
.waits-subtab.active { background: var(--nh-teal); color: #fff; border-color: var(--nh-teal); font-weight: 600; }
.waits-more { padding: 5px 9px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; font-size: .82rem; min-width: 180px; }
.waits-region-bar { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.waits-region-bar select { padding: 5px 9px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; font-size: .82rem; min-width: 140px; }
.waits-panel { margin-top: 8px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.waits-panel table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.waits-panel thead th { background: var(--nh-teal); color: #fff; padding: 8px 10px; text-align: left; font-weight: 600; white-space: normal; line-height: 1.3; position: sticky; top: 0; z-index: 2; }
.waits-panel tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.waits-panel tbody td:first-child { min-width: 0; max-width: none; }
.waits-panel tbody td:nth-child(2) { max-width: none; }
.waits-panel tr.hospital-row:hover { background: var(--nh-teal-light); }
.waits-panel tr.hospital-row.region-hidden { display: none; }
.waits-panel .hospital-btn { all: unset; cursor: pointer; color: var(--nh-teal); font-weight: 700; text-decoration: underline; }
.waits-panel .sort-btn { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; width: 100%; font-weight: 600; color: inherit; }
.waits-panel .sort-indicator { font-size: .75rem; opacity: .85; min-width: 12px; }
.waits-panel .detail-row td { background: #fbfefd; padding: 8px 18px 14px; }
.waits-panel .detail-table { width: 100%; border-collapse: collapse; }
.waits-panel .detail-table th { background: var(--nh-teal-light); color: var(--nh-teal); padding: 6px 10px; text-align: left; font-weight: 600; position: static; font-size: .82rem; }
.waits-panel .detail-table td { padding: 6px 10px; font-size: .82rem; border-bottom: 1px solid var(--border); }
.waits-panel .wait-consultant { display: block; font-size: .76rem; color: var(--muted); margin-top: 2px; }
.waits-note { padding: 10px 0; font-size: .82rem; color: var(--muted); }

/* Footer */
.site-footer { background: var(--nh-teal); color: rgba(255,255,255,.7); padding: 12px 0; font-size: .8rem; margin-top: 16px; }

/* Responsive */
@media (max-width: 768px) {
  .filter-bar input, .filter-bar select { min-width: 140px; }
  table { font-size: 10px; }
  thead th, td { padding: 4px 4px; }
}
