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

:root {
  --primary: #1a2f5a;
  --primary-hover: #253f7a;
  --white: #ffffff;
  --grey-100: #f4f5f7;
  --grey-200: #e8eaed;
  --grey-400: #9aa0a6;
  --grey-600: #5f6368;
  --grey-800: #3c4043;
  --danger: #c62828;
  --success: #2e7d32;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
  --radius: 8px;
  --header-height: 56px;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--grey-800);
  background: var(--grey-100);
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--primary);
  color: var(--white);
  z-index: 1000;
  box-shadow: var(--shadow);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 100%;
  gap: 12px;
}

.brand h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--white);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Map ─────────────────────────────────────────────────────────────────── */

#map {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

/* ── Loading ─────────────────────────────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 800;
}

.loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--grey-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--grey-200);
  color: var(--grey-800);
}

.btn-secondary:hover:not(:disabled) {
  background: #d0d3d8;
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
  font-size: 12px;
  padding: 5px 10px;
}

.btn-full {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  font-size: 15px;
}

.btn-close {
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  color: var(--grey-600);
  padding: 4px 6px;
  font-family: inherit;
}

.btn-close:hover {
  color: var(--grey-800);
}

/* ── Toggle ──────────────────────────────────────────────────────────────── */

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--white);
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--white);
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.toggle-label input:checked + .toggle-track {
  background: rgba(255, 255, 255, 0.9);
}

.toggle-label input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: var(--primary);
}

.toggle-text {
  font-size: 13px;
}

/* ── Panel ───────────────────────────────────────────────────────────────── */

.panel {
  position: fixed;
  inset: 0;
  z-index: 900;
  pointer-events: none;
}

.panel.open {
  pointer-events: all;
}

.panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.3s;
}

.panel.open .panel-backdrop {
  opacity: 1;
}

.panel-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel.open .panel-sheet {
  transform: translateY(0);
}

@media (min-width: 640px) {
  .panel-sheet {
    left: auto;
    right: 0;
    top: var(--header-height);
    bottom: 0;
    width: 380px;
    border-radius: 0;
    transform: translateX(100%);
    max-height: none;
  }

  .panel.open .panel-sheet {
    transform: translateX(0);
  }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--grey-200);
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 1;
}

.panel-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.panel-body {
  padding: 20px;
}

body.panel-open #map {
  pointer-events: none;
}

/* ── Form ────────────────────────────────────────────────────────────────── */

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--grey-600);
  margin-bottom: 6px;
}

.field select,
.field textarea,
.field input[type="file"] {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--white);
  color: var(--grey-800);
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236c757d' fill='none' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.field textarea {
  resize: vertical;
  min-height: 64px;
}

.gps-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.gps-status-text {
  font-size: 12px;
  color: var(--grey-400);
}

.gps-status-text.gps-ok {
  color: var(--success);
  font-weight: 500;
}

.gps-status-text.gps-error {
  color: var(--danger);
}

.form-error {
  background: #fdecea;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 8px;
}

.form-error.hidden {
  display: none;
}

/* ── Map markers ─────────────────────────────────────────────────────────── */

.map-marker {
  font-size: 10px;
  font-weight: 700;
  border-radius: 4px;
  padding: 3px 6px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  line-height: 1.3;
  text-align: center;
  letter-spacing: 0.2px;
}

/* ── Popup ───────────────────────────────────────────────────────────────── */

.leaflet-popup-content {
  margin: 12px 14px;
}

.popup-card {
  font-size: 13px;
  min-width: 200px;
}

.popup-party-badge {
  display: inline-block;
  font-weight: 700;
  font-size: 13px;
  border-radius: 4px;
  padding: 3px 10px;
  margin-bottom: 8px;
}

.popup-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 8px;
}

.popup-condition {
  font-weight: 500;
}

.popup-date {
  color: var(--grey-400);
  font-size: 11px;
  white-space: nowrap;
}

.popup-note {
  color: var(--grey-600);
  font-style: italic;
  margin-bottom: 8px;
  line-height: 1.4;
}

.popup-votes {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.btn-vote {
  flex: 1;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  border: 1.5px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: inherit;
  transition: background 0.15s;
}

.btn-vote.active {
  outline: 2px solid currentColor;
  outline-offset: -2px;
}

.btn-seen {
  background: #e8f5e9;
  color: #2e7d32;
  border-color: #a5d6a7;
}

.btn-seen:hover {
  background: #c8e6c9;
}

.btn-notseen {
  background: #fce4ec;
  color: #c62828;
  border-color: #f48fb1;
}

.btn-notseen:hover {
  background: #f8bbd0;
}

.vote-count {
  font-weight: 700;
}

.popup-delete {
  width: 100%;
  display: block;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--grey-800);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-error {
  background: var(--danger);
}

.toast.toast-success {
  background: var(--success);
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .toggle-text {
    display: none;
  }

  .brand h1 {
    font-size: 17px;
  }

  .btn-primary {
    padding: 8px 12px;
    font-size: 13px;
  }
}
