:root {
  --purple-1: #6d5593;
  --purple-2: #877caf;
  --purple-3: #a59dc3;
  --green: #16a085;
  --green-2: #6abba7;
  --orange: #f39c12;
  --orange-2: #f1bb4f;
  --blue: #2980b9;
  --blue-2: #70a5d0;
  --gray-1: #6c7785;
  --gray-2: #7f8c8d;
  --gray-3: #bdc3c7;
  --ink: #2e3440;
  --surface: #ffffff;
  --background: #f5f4f8;
  --border: #e6e3ec;
  --shadow: 0 14px 36px rgba(61, 47, 88, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--background);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button, label { cursor: pointer; }

.app-header {
  color: white;
  background: linear-gradient(118deg, #5d477f 0%, var(--purple-1) 52%, #8174a9 100%);
  box-shadow: 0 5px 20px rgba(56, 40, 82, 0.2);
}

.header-inner, .page-shell, .app-footer {
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto;
}

.header-inner {
  display: flex;
  gap: 32px;
  align-items: center;
  padding: 26px 0 30px;
}

.brand {
  display: flex;
  flex: 0 0 210px;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border-radius: 10px;
  background: white;
}

.brand img { display: block; width: 100%; height: auto; }
.header-copy h1 { margin: 2px 0 4px; font-size: clamp(1.5rem, 3vw, 2.35rem); letter-spacing: -0.03em; }
.subtitle { margin: 0; color: rgba(255,255,255,.78); }
.eyebrow { margin: 0 0 6px; color: rgba(255,255,255,.7); font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.eyebrow.accent { color: var(--purple-1); }

.page-shell { padding: 34px 0 52px; }
.hero-panel, .card, .sites-section, .insight-panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-panel { position: relative; overflow: hidden; padding: 28px 32px 24px; }
.hero-panel::after {
  position: absolute; right: -70px; top: -110px; width: 300px; height: 300px; content: "";
  border: 40px solid rgba(135,124,175,.09); border-radius: 50%;
}
.hero-panel h2, .section-heading h2 { margin: 0; color: var(--purple-1); letter-spacing: -.025em; }
.hero-text { max-width: 730px; margin: 8px 0 0; color: var(--gray-1); }
.upload-actions { position: absolute; right: 32px; top: 30px; z-index: 1; display: flex; gap: 10px; align-items: center; }
#csv-input { display: none; }
.upload-button, .secondary-button, .text-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; border-radius: 8px; padding: 10px 15px; font-size: .86rem; font-weight: 700;
}
.upload-button { color: white; background: var(--purple-1); }
.upload-button:hover { background: #59447e; }
.secondary-button { color: var(--purple-1); border: 1px solid var(--purple-3); background: white; }
.secondary-button:hover { background: #f6f3fa; }
.text-button { border: 0; color: var(--gray-1); background: transparent; }
.text-button:hover { color: var(--purple-1); }
.drop-zone {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 24px; padding: 17px 18px; color: var(--gray-1); border: 1px dashed var(--purple-3); border-radius: 10px; background: #fbfaff; transition: .2s ease;
}
.drop-zone.dragover { border-color: var(--green); background: #f1fbf8; }
.drop-icon { display: inline-flex; align-items: center; justify-content: center; width: 31px; height: 31px; color: white; border-radius: 50%; background: var(--green); font-size: 1.2rem; }
.drop-zone small { flex-basis: 100%; margin-left: 42px; color: var(--gray-2); font-size: .77rem; }
.status-message { min-height: 1.2em; margin: 10px 0 0; color: var(--gray-1); font-size: .84rem; }
.status-message.error { color: #bd3d30; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 38px 0 17px; }
.section-heading.compact { margin-top: 0; padding: 28px 28px 0; }
.data-meta { color: var(--gray-2); font-size: .82rem; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
.kpi-card { position: relative; display: block; width: 100%; overflow: hidden; padding: 19px 20px; color: inherit; border: 1px solid var(--border); border-radius: 13px; background: white; box-shadow: var(--shadow); font: inherit; text-align: left; cursor: pointer; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.kpi-card:hover, .kpi-card.active { border-color: var(--kpi-color); box-shadow: 0 10px 26px rgba(61, 47, 88, 0.14); transform: translateY(-2px); }
.kpi-card.critical-kpi { border: 2px solid #c0392b; background: linear-gradient(135deg, #fff8f6, #fff); box-shadow: 0 8px 24px rgba(192, 57, 43, 0.13); }
.kpi-card.critical-kpi .kpi-label::before { display: inline-block; margin-right: 5px; content: "⚠"; }
.kpi-card.critical-kpi:hover, .kpi-card.critical-kpi.active { border-color: #a93226; box-shadow: 0 12px 30px rgba(192, 57, 43, 0.22); }
.kpi-card::after { position: absolute; right: -23px; bottom: -32px; width: 90px; height: 90px; content: ""; border: 18px solid var(--kpi-color); border-radius: 50%; opacity: .12; }
.kpi-label { margin: 0 0 7px; color: var(--gray-1); font-size: .77rem; font-weight: 700; }
.kpi-value { margin: 0; color: var(--kpi-color); font-size: 2rem; font-weight: 800; letter-spacing: -.05em; }
.kpi-note { margin: 4px 0 0; color: var(--gray-2); font-size: .75rem; }
.insight-panel { display: flex; gap: 14px; align-items: center; margin-top: 15px; padding: 15px 20px; border-left: 4px solid var(--orange); }
.insight-panel.public-risk { border-left-color: #c0392b; background: #fff8f6; }
.insight-icon { font-size: 1.5rem; }
.insight-panel p { margin: 0; color: var(--gray-1); font-size: .88rem; }
.insight-panel strong { color: var(--ink); }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 15px; }
.card { min-height: 280px; padding: 22px; }
.wide-card { min-height: 230px; }
.card-heading h3 { margin: 0; color: var(--purple-1); font-size: 1.03rem; }
.card-heading p { margin: 3px 0 0; color: var(--gray-2); font-size: .77rem; }
.chart-layout { display: flex; align-items: center; gap: 24px; margin-top: 20px; }
.donut-chart { flex: 0 0 160px; width: 160px; height: 160px; border-radius: 50%; background: conic-gradient(var(--purple-1) 0 40%, var(--green) 40% 70%, var(--orange) 70% 100%); position: relative; }
.donut-chart::after { position: absolute; inset: 28px; display: flex; align-items: center; justify-content: center; content: attr(data-total); color: var(--purple-1); border-radius: 50%; background: white; font-size: 1.35rem; font-weight: 800; }
.legend { display: grid; gap: 9px; width: 100%; }
.legend-item { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; color: var(--gray-1); font-size: .78rem; }
.legend-label { display: flex; gap: 7px; align-items: center; min-width: 0; }
.legend-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; }
.legend-item strong { color: var(--ink); }
.bar-chart { display: grid; gap: 18px; margin-top: 28px; }
.bar-row { display: grid; grid-template-columns: 116px 1fr 32px; gap: 9px; align-items: center; font-size: .76rem; }
.bar-label { overflow: hidden; color: var(--gray-1); text-overflow: ellipsis; white-space: nowrap; }
.bar-track, .hbar-track { overflow: hidden; height: 11px; border-radius: 10px; background: #efedf4; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--blue-2)); }
.bar-count { color: var(--ink); font-weight: 800; text-align: right; }
.horizontal-bars { display: grid; gap: 11px; margin-top: 18px; }
.wide-card .horizontal-bars { width: min(100%, 520px); }
.hbar-row { display: grid; grid-template-columns: 230px 1fr 38px; gap: 10px; align-items: center; font-size: .77rem; }
.hbar-label { overflow: hidden; color: var(--gray-1); text-overflow: ellipsis; white-space: nowrap; }
.hbar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--purple-2), var(--purple-3)); }

.sites-section { margin-top: 15px; overflow: hidden; }
.table-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.search-field input, .table-tools select { height: 37px; padding: 0 11px; color: var(--ink); border: 1px solid var(--border); border-radius: 7px; outline: none; background: white; font-size: .78rem; }
.search-field input { width: 210px; }
.search-field input:focus, .table-tools select:focus { border-color: var(--purple-2); box-shadow: 0 0 0 3px rgba(135,124,175,.15); }
.site-filter-status { display: flex; gap: 8px; align-items: center; margin: 0 28px 12px; padding: 8px 11px; color: var(--purple-1); border: 1px solid var(--purple-3); border-radius: 7px; background: #faf8fd; font-size: .78rem; font-weight: 700; }
.site-filter-status .text-button { margin-left: auto; padding: 0; color: var(--purple-1); }
.table-wrap { overflow-x: auto; margin-top: 18px; }
table { width: 100%; min-width: 830px; border-collapse: collapse; }
th { padding: 10px 28px; color: var(--gray-2); border-bottom: 1px solid var(--border); font-size: .69rem; letter-spacing: .08em; text-align: left; text-transform: uppercase; }
.sort-button { display: inline-flex; gap: 6px; align-items: center; padding: 0; color: inherit; border: 0; background: transparent; font: inherit; font-weight: 750; letter-spacing: inherit; text-align: left; text-transform: inherit; }
.sort-button:hover, .sort-button.active { color: var(--purple-1); }
.sort-indicator { display: inline-block; min-width: 9px; color: var(--purple-1); font-size: .7rem; }
td { padding: 13px 28px; border-bottom: 1px solid #f0eef3; color: var(--gray-1); font-size: .78rem; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfaff; }
.site-name { max-width: 220px; color: var(--ink); font-weight: 750; }
.site-name a { display: block; overflow: hidden; color: inherit; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.site-name a:hover { color: var(--purple-1); text-decoration: underline; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 999px; font-size: .7rem; font-weight: 750; white-space: nowrap; }
.pill::before { width: 6px; height: 6px; content: ""; border-radius: 50%; background: currentColor; }
.pill.good { color: #118066; background: #e6f6f1; }
.pill.warning { color: #b16e00; background: #fff4de; }
.pill.neutral { color: var(--gray-1); background: #f0f1f3; }
.risk { font-weight: 750; }
.risk.high { color: #c06b06; }
.risk.critical { color: #c0392b; }
.risk.medium { color: var(--blue); }
.risk.low { color: var(--green); }
.empty-table { padding: 28px; color: var(--gray-2); text-align: center; }
.table-footer { padding: 12px 28px 17px; color: var(--gray-2); font-size: .76rem; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 5px; }
.row-action { padding: 5px 8px; color: var(--purple-1); border: 1px solid var(--purple-3); border-radius: 6px; background: white; font-size: .7rem; font-weight: 750; white-space: nowrap; }
.row-action.empty { color: var(--gray-3); border-color: #e5e3e8; background: #fafafa; }
.row-action.empty:hover, .row-action.empty.active { color: var(--gray-1); background: #f0eef3; }
.row-action:hover, .row-action.active { color: white; background: var(--purple-1); }
.site-detail-row td { padding: 0 28px 17px; background: #fbfaff; }
.site-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: white; }
.detail-panel { min-width: 0; }
.detail-panel h4 { margin: 0 0 8px; color: var(--purple-1); font-size: .82rem; }
.detail-metadata p { margin: 0 0 5px; color: var(--gray-1); font-size: .74rem; }
.person-list { display: flex; flex-direction: column; gap: 6px; align-items: stretch; margin: 0; padding: 0; list-style: none; }
.person-chip { display: inline-flex; gap: 6px; align-items: center; max-width: 100%; padding: 5px 7px 5px 9px; color: var(--gray-1); border: 1px solid var(--border); border-radius: 999px; background: #faf9fc; font-size: .72rem; }
.person-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.remove-person { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; padding: 0; color: #b33b30; border: 0; border-radius: 50%; background: #fbe9e7; font-weight: 800; line-height: 1; }
.remove-person:hover { color: white; background: #c0392b; }
.empty-person-list { color: var(--gray-2); font-size: .75rem; }
.person-chip.added { color: #118066; border-color: #b9e4d6; background: #effaf6; }
.person-chip.added .remove-person { color: #118066; background: #d9f3e9; }
.add-person { display: flex; gap: 6px; margin-top: 9px; }
.add-person select { min-width: 0; flex: 1; height: 30px; padding: 0 7px; color: var(--gray-1); border: 1px solid var(--border); border-radius: 6px; background: white; font-size: .7rem; }
.add-person button { padding: 0 9px; color: white; border: 0; border-radius: 6px; background: var(--green); font-size: .7rem; font-weight: 750; }
.add-person button:hover { background: #117d68; }
.corrections-section { margin-top: 15px; overflow: hidden; border: 1px solid var(--border); border-radius: 16px; background: white; box-shadow: var(--shadow); }
.corrections-intro { margin: 0; padding: 0 28px 15px; color: var(--gray-1); font-size: .8rem; }
.corrections-table-wrap { overflow-x: auto; }
.corrections-section table { min-width: 650px; }
.correction-remove { color: #c0392b; font-weight: 700; }
.correction-add { color: #118066; font-weight: 700; }
.empty-state { padding: 80px 20px 35px; color: var(--gray-1); text-align: center; }
.empty-state-icon { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; color: white; border-radius: 20px; background: var(--purple-2); box-shadow: 0 10px 20px rgba(109,85,147,.2); font-size: 2rem; }
.empty-state h2 { margin: 17px 0 5px; color: var(--purple-1); }
.empty-state p { margin: 0; font-size: .9rem; }
.app-footer { display: flex; justify-content: space-between; padding: 0 0 25px; color: var(--gray-2); font-size: .74rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .upload-actions { position: static; flex-wrap: wrap; margin-top: 20px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .section-heading { align-items: start; flex-direction: column; }
  .section-heading.compact { align-items: start; }
}

@media (max-width: 640px) {
  .header-inner, .page-shell, .app-footer { width: min(100% - 28px, 1240px); }
  .header-inner { align-items: start; flex-direction: column; gap: 16px; }
  .brand { flex-basis: auto; width: 170px; }
  .hero-panel { padding: 22px 18px 18px; }
  .kpi-grid, .dashboard-grid { grid-template-columns: 1fr; }
  .wide-card { grid-column: auto; }
  .card { padding: 18px; }
  .chart-layout { gap: 14px; }
  .donut-chart { flex-basis: 125px; width: 125px; height: 125px; }
  .donut-chart::after { inset: 23px; font-size: 1.1rem; }
  .section-heading.compact { padding: 20px 18px 0; }
  .table-tools { width: 100%; }
  .search-field, .search-field input, .table-tools select { width: 100%; }
  .site-detail { grid-template-columns: 1fr; }
  .app-footer { align-items: start; flex-direction: column; gap: 4px; }
}
