:root {
  --bg: #0e1420;
  --panel: #16202f;
  --panel-2: #1d2a3d;
  --border: #26364d;
  --text: #e8eef7;
  --muted: #9fb0c7;
  --accent: #2fd27a;
  --accent-dim: #1f8f54;
  --pin: #ff7a45;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---------------- Header ---------------- */
.app-header {
  padding: 16px 24px;
  background: linear-gradient(180deg, #16202f 0%, #111a27 100%);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-areas:
    "brand stats admin"
    "tag   stats admin";
  align-items: center;
  gap: 2px 24px;
}

.admin-area {
  grid-area: admin;
  display: flex;
  align-items: center;
}

.admin-signedin {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #06210f;
  background: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
}

.admin-btn {
  background: var(--accent);
  color: #06210f;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.admin-btn:hover {
  background: #35e389;
}

.admin-btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.admin-btn.ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: 0.3px;
}

.tagline {
  grid-area: tag;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.pulse-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(47, 210, 122, 0.7);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(47, 210, 122, 0.6);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(47, 210, 122, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(47, 210, 122, 0);
  }
}

.stats {
  grid-area: stats;
  display: flex;
  gap: 22px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.stats li {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stats strong {
  font-size: 22px;
  color: var(--accent);
}

.stats span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

/* ---------------- Layout ---------------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 0;
}

.map-panel {
  position: relative;
  min-height: 0;
  order: 2;
}

#map {
  position: absolute;
  inset: 0;
  background: #0c1d30; /* solid ocean beneath the country polygons */
}

.map-focus {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  background: rgba(16, 24, 37, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
}

.map-focus label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.map-focus select {
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 6px 8px;
  cursor: pointer;
}

.map-focus select:focus {
  outline: none;
  border-color: var(--accent);
}

.zoom-control {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 500;
  background: rgba(16, 24, 37, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}

#zoom-indicator {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 76px;
}

#zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 4px;
  border-radius: 999px;
  background: #33465f;
  outline: none;
  cursor: pointer;
}

#zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #06210f;
  cursor: pointer;
}

#zoom-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #06210f;
  cursor: pointer;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  background: rgba(16, 24, 37, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  margin-left: 8px;
}

.swatch.active {
  background: var(--accent);
}

.swatch.flag {
  background: transparent;
  width: auto;
  border-radius: 0;
  font-size: 13px;
  line-height: 1;
}

.swatch.inactive {
  background: #3c5474;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  order: 1;
}

.entry-form,
.community-panel,
.countries-panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.entry-form h2,
.community-panel h2,
.countries-panel h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

/* Countries represented list */
.countries-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.country-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.country-row:hover {
  border-color: var(--accent-dim);
}

.country-row.selected {
  border-color: var(--accent);
  background: #10261a;
}

.country-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.row-flag {
  width: 22px;
  height: 16px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.country-counts {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  white-space: nowrap;
}

.country-counts .cc-comm {
  font-size: 12px;
  color: var(--accent);
}

.country-counts .cc-users {
  font-size: 11px;
  color: var(--muted);
}

.entry-form label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}

.entry-form select,
.entry-form input {
  width: 100%;
  padding: 10px 12px;
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.entry-form select:focus,
.entry-form input:focus {
  outline: none;
  border-color: var(--accent);
}

#submit-btn {
  margin-top: 14px;
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #06210f;
  font-weight: 700;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

#submit-btn:hover {
  background: #35e389;
}

#submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.form-message {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 13px;
}

.form-message.success {
  color: var(--accent);
}

.form-message.error {
  color: #ff6b6b;
}

.community-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge {
  background: var(--accent-dim);
  color: #eafff2;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge:empty {
  display: none;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0 0;
}

.community-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.community-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.community-list .c-name {
  font-size: 14px;
}

.community-list .c-count {
  font-size: 12px;
  color: var(--muted);
  background: #1a2a3f;
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

/* ---------------- Buttons ---------------- */
.btn-ghost {
  margin-top: 10px;
  width: 100%;
  padding: 9px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

#clear-selection {
  margin: 0 0 6px;
}

.mini-btn {
  background: #1a2a3f;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
}

.mini-btn:hover {
  border-color: var(--accent-dim);
}

.mini-btn.danger:hover {
  border-color: #ff6b6b;
  color: #ff6b6b;
}

/* ---------------- Participation code field ---------------- */
#code-field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}

#participation-input {
  width: 100%;
  padding: 10px 12px;
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#participation-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------------- My submissions ---------------- */
.mine-panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.mine-panel h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.mine-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mine-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.mine-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.mine-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ---------------- Admin participation code panel ---------------- */
.code-panel {
  background: var(--panel-2);
  border: 1px solid var(--accent-dim);
  border-radius: 12px;
  padding: 16px;
}

.code-panel h2 {
  margin: 0;
  font-size: 16px;
}

.code-value {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  color: var(--accent);
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
}

.qr-box {
  display: flex;
  justify-content: center;
  background: #ffffff;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.qr-box img {
  display: block;
  width: 180px;
  height: 180px;
  image-rendering: pixelated;
}

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

.code-actions .admin-btn {
  flex: 1;
}

/* ---------------- Admin login modal ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(4, 8, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 380px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.modal-hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.modal label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.modal input {
  width: 100%;
  padding: 10px 12px;
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.modal input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ---------------- Account menu ---------------- */
.account {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-email {
  font-size: 13px;
  color: var(--muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- Auth pages ---------------- */
.auth-body {
  align-items: center;
  justify-content: center;
}

.auth-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.brand.center {
  justify-content: center;
  margin-bottom: 6px;
}

.auth-card h2 {
  margin: 6px 0 16px;
  font-size: 18px;
  text-align: center;
}

.auth-card label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}

.auth-card input {
  width: 100%;
  padding: 10px 12px;
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.admin-btn.full {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
}

.auth-alt {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 0;
}

.auth-alt a {
  color: var(--accent);
  text-decoration: none;
}

.auth-alt a:hover {
  text-decoration: underline;
}

.super-banner {
  background: #10261a;
  border: 1px solid var(--accent-dim);
  color: #eafff2;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 8px;
}

.field-hint {
  font-size: 11px;
  color: var(--muted);
  margin: 4px 0 0;
}

/* ---------------- Footer ---------------- */
.app-footer {
  padding: 12px 24px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  background: #111a27;
  border-top: 1px solid var(--border);
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

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

/* ---------------- Map labels ---------------- */
.country-label {
  background: transparent;
  border: none;
}

.country-label .label-inner {
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}

.country-label .count-bubble {
  display: inline-block;
  background: rgba(6, 33, 15, 0.85);
  color: #eafff2;
  border: 1px solid var(--accent);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  line-height: 1.4;
}

.country-label .user-pin {
  display: block;
  margin-top: 2px;
  color: var(--pin);
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

/* ---------------- Dashboard ---------------- */
.plan-chip {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #eafff2;
  background: var(--accent-dim);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.dash-wrap {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.dash-card,
.dash-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dash-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.dash-card h2,
.dash-section h2 {
  margin: 0;
  font-size: 17px;
}

.create-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.create-row input {
  flex: 1 1 200px;
  padding: 10px 12px;
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.create-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.create-row .admin-btn {
  flex: 0 0 auto;
}

.poll-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.poll-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.poll-card.archived {
  opacity: 0.85;
}

.poll-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.poll-card-head h3 {
  margin: 0;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.status-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-tag.active {
  color: #06210f;
  background: var(--accent);
}

.status-tag.archived,
.archived-tag {
  color: var(--muted);
  background: #1a2a3f;
  border: 1px solid var(--border);
}

.poll-desc {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.poll-meta {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.poll-code {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.code-line {
  font-size: 13px;
  color: var(--muted);
}

.code-pill {
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--accent);
  background: #0e1725;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  margin-left: 4px;
}

.qr-box.small {
  padding: 8px;
  margin: 0;
}

.qr-box.small img {
  width: 128px;
  height: 128px;
}

.poll-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

a.mini-btn {
  text-decoration: none;
  display: inline-block;
  line-height: 1.4;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 55vh auto;
  }
  .map-panel {
    order: 1;
  }
  .sidebar {
    order: 2;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .app-header {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand admin"
      "tag   admin"
      "stats stats";
    justify-items: start;
  }
  .admin-area {
    align-self: start;
  }
  .stats {
    margin-top: 8px;
  }
}
