:root {
  --ink: #17201b;
  --muted: #66736b;
  --line: #dbe3dc;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --green: #1d6f55;
  --green-dark: #13513e;
  --blue: #3267a8;
  --gold: #b7791f;
  --red: #b5413e;
  --shadow: 0 16px 38px rgba(23, 32, 27, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
}

body:not(.is-authenticated) .app-shell {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(135deg, #f7f8f4 0%, #eef4ef 100%);
}

.auth-screen[hidden] {
  display: none;
}

.auth-card {
  display: grid;
  gap: 18px;
  width: min(430px, 100%);
  padding: 22px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: grid;
  gap: 2px;
}

.project-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.project-choice {
  display: grid;
  gap: 3px;
  min-height: 70px;
  padding: 12px;
  color: var(--ink);
  text-decoration: none;
  background: #f6f8f5;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.project-choice:hover,
.project-choice:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 111, 85, 0.12);
  outline: none;
}

.project-choice.active {
  background: #eef4ef;
  border-color: rgba(29, 111, 85, 0.48);
}

.project-choice strong {
  font-size: 0.95rem;
}

.project-choice span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form[hidden] {
  display: none;
}

.auth-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(1120px, 100%);
  min-width: 0;
  min-height: calc(100vh - 36px);
  margin: 0 auto;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  z-index: 4;
}

.brand-panel,
.panel-title,
.drawer-header,
.commune-row,
.toolbar,
.drawer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.35rem;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

h3 {
  margin: 0;
  font-size: 0.92rem;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  color: var(--ink);
  background: #eef4ef;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.menu-toggle {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 16px;
  color: white;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 8px;
  font-weight: 800;
}

.menu-toggle[aria-expanded="true"] {
  color: var(--ink);
  background: #eef4ef;
  border-color: var(--line);
}

.main-menu-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
  background: #f5f8f3;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.main-menu-panel[hidden],
.admin-menu-section[hidden] {
  display: none;
}

.menu-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-menu-section {
  padding: 0;
  background: transparent;
  border: 0;
}

.toolbar {
  flex-wrap: wrap;
}

.excel-paste-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #f5f8f3;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.excel-paste-panel[hidden] {
  display: none;
}

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

.primary-button,
.ghost-button,
.danger-button,
.file-button,
.commune-row button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  color: white;
  background: var(--green);
}

.primary-button:hover {
  background: var(--green-dark);
}

.ghost-button,
.file-button,
.commune-row button {
  color: var(--ink);
  background: #eef4ef;
  border-color: var(--line);
}

.danger-button {
  color: white;
  background: var(--red);
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  overflow: hidden;
}

.session-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: #f5f8f3;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.session-panel span,
.access-card span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.session-panel strong {
  display: block;
  margin-top: 2px;
}

.access-panel,
.updates-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.access-panel[hidden],
.updates-panel[hidden] {
  display: none;
}

.access-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(120px, 160px) auto;
  gap: 10px;
  align-items: end;
}

.access-list {
  display: grid;
  gap: 8px;
}

.access-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.access-card strong {
  display: block;
  line-height: 1.25;
}

.access-card button {
  flex: 0 0 auto;
}

.update-list,
.history-list {
  display: grid;
  gap: 8px;
}

.update-card,
.history-entry {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 10px;
  color: var(--ink);
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.update-card {
  cursor: pointer;
}

.update-card:hover {
  border-color: var(--green);
}

.update-card strong,
.history-entry strong {
  line-height: 1.25;
}

.update-card span,
.history-entry span,
.change-list {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.change-list {
  margin: 0;
  padding-left: 18px;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.search-panel,
.metrics,
.constituency-panel,
.map-panel,
.address-list-panel {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 10px 11px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 111, 85, 0.12);
}

.commune-row {
  align-items: stretch;
}

.commune-row button {
  flex: 0 0 52px;
}

.ban-panel {
  display: grid;
  gap: 8px;
}

.constituency-panel {
  gap: 12px;
}

.constituency-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.constituency-controls button {
  min-height: 42px;
  padding: 0 16px;
  color: white;
  background: var(--green);
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
}

.constituency-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.constituency-map-shell {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.constituency-map {
  display: block;
  width: 100%;
  height: clamp(360px, 55vw, 620px);
  background: #ffffff;
}

.constituency-commune {
  stroke: #6d7a72;
  stroke-width: 1.25;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: filter 120ms ease, stroke-width 120ms ease;
}

.constituency-outline {
  fill: rgba(29, 111, 85, 0.04);
  stroke: var(--green);
  stroke-width: 2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.constituency-commune:hover,
.constituency-commune:focus {
  filter: brightness(0.96) saturate(1.15);
  stroke: var(--ink);
  stroke-width: 2.2;
  outline: none;
}

.constituency-commune.active {
  stroke: var(--green);
  stroke-width: 2.6;
}

.constituency-hover-label {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.constituency-hover-label.visible {
  opacity: 1;
}

.constituency-hover-label rect {
  fill: rgba(255, 255, 255, 0.94);
  stroke: rgba(109, 122, 114, 0.42);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.constituency-hover-label text {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-anchor: middle;
}

.constituency-label {
  fill: #445149;
  font-size: 12px;
  font-weight: 800;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.82);
  stroke-width: 4px;
  pointer-events: none;
}

.constituency-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.constituency-gradient {
  width: min(240px, 50vw);
  height: 10px;
  background: linear-gradient(90deg, #ffffff 0%, #1d6f55 100%);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.ban-actions {
  display: grid;
  grid-template-columns: 1fr minmax(112px, 136px);
  gap: 8px;
  align-items: end;
}

.compact-field {
  font-size: 0.75rem;
}

.ban-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.view-grid {
  display: grid;
  gap: 8px;
}

.view-grid {
  grid-template-columns: repeat(2, 1fr);
}

.view-chip {
  min-height: 34px;
  color: var(--muted);
  background: #f2f5f1;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 800;
}

.view-chip.active {
  color: white;
  background: var(--ink);
  border-color: var(--ink);
}

.filter-select select {
  font-weight: 800;
}

.metrics {
  grid-template-columns: repeat(3, 1fr);
}

.metrics article {
  padding: 12px;
  background: #f5f8f3;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics strong,
.metrics span {
  display: block;
}

.metrics strong {
  font-size: 1.45rem;
}

.metrics span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.panel-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.map-panel {
  gap: 8px;
}

.map-shell {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  touch-action: none;
}

.address-map {
  display: block;
  position: relative;
  width: 100%;
  height: clamp(380px, 62vw, 680px);
  overflow: hidden;
  background: #ffffff;
}

.map-canvas,
.map-layer {
  position: absolute;
  inset: 0;
}

.map-layer {
  transform-origin: 0 0;
}

.map-boundary-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.map-boundary-fill {
  fill: rgba(29, 111, 85, 0.06);
  stroke: none;
}

.map-boundary-line {
  fill: none;
  stroke: #1d6f55;
  stroke-width: 2.8;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.map-boundary-fill.fallback {
  fill: rgba(104, 115, 122, 0.04);
}

.map-boundary-line.fallback {
  stroke: #9aa8a0;
  stroke-dasharray: 8 7;
}

.map-road-edge,
.map-road-core {
  position: absolute;
  border-radius: 2px;
  transform-origin: left center;
  pointer-events: none;
  z-index: 1;
}

.map-road-edge {
  height: 6px;
  background: rgba(197, 208, 202, 0.6);
}

.map-road-core {
  height: 3px;
  background: rgba(248, 250, 249, 0.96);
}

.map-road-edge.road-major {
  height: 8px;
  background: rgba(191, 208, 198, 0.8);
}

.map-road-core.road-major {
  height: 5px;
  background: #ffffff;
}

.map-road-edge.road-path {
  height: 4px;
  background: rgba(218, 229, 222, 0.62);
}

.map-road-core.road-path {
  height: 2px;
  background: rgba(255, 255, 255, 0.82);
}

.map-marker {
  position: absolute;
  z-index: 4;
  display: block;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 999px;
  transform: translate(-50%, -50%) scale(var(--marker-scale, 1));
  cursor: pointer;
  outline: none;
  transform-origin: center center;
}

.marker-halo {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(23, 32, 27, 0.12);
  border-radius: inherit;
}

.marker-core {
  position: absolute;
  inset: 25%;
  background: var(--blue);
  border: 1.5px solid #ffffff;
  border-radius: inherit;
}

.map-marker.marker-ban .marker-core {
  background: var(--green);
}

.map-marker.marker-manual .marker-core {
  background: var(--blue);
}

.map-marker.marker-todo .marker-core {
  background: #68737a;
}

.map-marker.marker-visited .marker-core {
  background: var(--blue);
}

.map-marker.marker-supporter .marker-core {
  background: var(--green);
}

.map-marker.marker-undecided .marker-core {
  background: var(--gold);
}

.map-marker.marker-opposed .marker-core {
  background: var(--red);
}

.map-marker.marker-absent .marker-core {
  background: #7a5c9b;
}

.map-marker.marker-ban .marker-core {
  background: var(--green);
}

.map-marker.marker-manual .marker-core {
  background: var(--blue);
}

.map-marker.active .marker-halo,
.map-marker:focus-visible .marker-halo {
  background: rgba(29, 111, 85, 0.12);
  border-color: var(--ink);
  border-width: 2px;
  box-shadow: 0 0 0 6px rgba(23, 32, 27, 0.12);
}

.map-marker.active .marker-core {
  background: var(--ink);
}

.map-label {
  position: absolute;
  color: #66736b;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0;
  z-index: 2;
  padding: 2px 5px;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 6px;
  transform: translate(-50%, -50%) scale(var(--street-label-scale, 1));
  transform-origin: center center;
  pointer-events: none;
}

.map-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(320px, calc(100% - 48px));
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
  transform: translate(-50%, -50%);
}

.map-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  gap: 6px;
}

.map-control {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(23, 32, 27, 0.08);
  font-weight: 900;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 2px solid white;
  box-shadow: 0 0 0 1px rgba(23, 32, 27, 0.2);
}

.legend-ban {
  background: var(--green);
}

.legend-manual {
  background: var(--blue);
}

.legend-active {
  background: var(--ink);
}

.address-list {
  display: grid;
  gap: 8px;
}

.address-list-title {
  align-items: end;
}

.address-list-title > div:first-child {
  display: grid;
  gap: 3px;
}

.pagination-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
}

.page-size-field {
  display: grid;
  gap: 4px;
  min-width: 98px;
  font-size: 0.74rem;
}

.page-size-field select {
  height: 34px;
  font-weight: 800;
}

.page-button {
  min-height: 34px;
  padding: 0 10px;
}

.page-info {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.street-group {
  display: grid;
  gap: 8px;
}

.street-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #eef4ef;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}

.street-heading span {
  color: var(--muted);
  font-size: 0.78rem;
}

.address-card {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 12px;
  text-align: left;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
}

.address-card:hover,
.address-card.active {
  border-color: var(--green);
  border-left-color: var(--green);
}

.address-card.ban-card {
  border-left-color: var(--green);
}

.address-card strong {
  line-height: 1.25;
}

.address-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

.resident-preview {
  color: var(--ink);
  font-weight: 700;
}

.participation-preview {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.voice-count {
  width: max-content;
  padding: 3px 8px;
  color: var(--green);
  background: #eef4ef;
  border: 1px solid #cfe0d3;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  width: max-content;
  padding: 3px 8px;
  color: white;
  background: var(--blue);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.status-todo {
  background: #68737a;
}

.status-visited {
  background: var(--blue);
}

.status-supporter {
  background: var(--green);
}

.status-undecided {
  background: var(--gold);
}

.status-opposed {
  background: var(--red);
}

.status-absent {
  background: #7a5c9b;
}

.drawer {
  position: fixed;
  top: 24px;
  left: 50%;
  z-index: 5;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 18px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  transform: translate(-50%, 0);
  overflow: auto;
}

.drawer.open {
  display: block;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.full-span {
  grid-column: 1 / -1;
}

.participation-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #f5f8f3;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.participation-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.participation-title span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.participation-list {
  display: grid;
  gap: 8px;
}

.participation-person {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.participation-person strong {
  line-height: 1.25;
}

.participation-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.participation-check {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 8px;
  color: var(--ink);
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.76rem;
  font-weight: 800;
}

.participation-check input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.drawer-actions {
  margin-top: 18px;
}

.popup-title {
  display: block;
  margin-bottom: 4px;
  font-weight: 800;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  background: #f5f8f3;
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-weight: 700;
  text-align: center;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 0;
  }

  .sidebar {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }
}

@media (max-width: 560px) {
  .sidebar {
    padding: 14px;
  }

  .brand-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics,
  .form-grid,
  .participation-options,
  .constituency-controls {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar > *,
  .session-panel > *,
  .access-form > * {
    flex: 1 1 100%;
    justify-content: center;
  }

  .session-panel,
  .access-card {
    align-items: stretch;
    flex-direction: column;
  }

  .access-form {
    grid-template-columns: 1fr;
  }

  .main-menu-panel,
  .menu-section {
    padding: 10px;
  }
}
