:root {
  --color-primary: #E74C3C;
  --color-primary-dark: #C0392B;
  --color-accent: #F39C12;
  --color-bg: #FAFAFA;
  --color-surface: #FFFFFF;
  --color-text: #2C3E50;
  --color-text-light: #7F8C8D;
  --color-text-muted: #BDC3C7;
  --color-border: #E0E0E0;
  --color-error: #E74C3C;
  --color-success: #27AE60;
  --color-severity-1: #4CAF50;
  --color-severity-2: #8BC34A;
  --color-severity-3: #FFC107;
  --color-severity-4: #FF9800;
  --color-severity-5: #F44336;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
  --radius: 8px;
  --radius-sm: 4px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  color: var(--color-primary-dark);
}

/* ====== Buttons ====== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  line-height: 1.2;
}

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

.btn-primary:hover {
  background: var(--color-primary-dark);
  color: #fff;
}

.btn-secondary {
  background: var(--color-border);
  color: var(--color-text);
}

.btn-secondary:hover {
  background: #ccc;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--color-primary);
  color: var(--color-primary);
}

.btn-outline:hover {
  background: var(--color-primary);
  color: #fff;
}

.btn-danger {
  background: var(--color-error);
  color: #fff;
}

.btn-danger:hover {
  background: #c0392b;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

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

/* ====== Forms ====== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--color-text);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.2s;
}

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

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group .hint {
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 2px;
}

/* ====== Severity Selector ====== */
.severity-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.severity-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.severity-option input {
  display: none;
}

.severity-option .sev-label {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  border: 3px solid transparent;
  transition: all 0.2s;
}

.severity-option input:checked + .sev-label {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.severity-option .sev-text {
  font-size: 11px;
  color: var(--color-text-light);
}

.sev-1 { background: var(--color-severity-1); }
.sev-2 { background: var(--color-severity-2); }
.sev-3 { background: var(--color-severity-3); }
.sev-4 { background: var(--color-severity-4); }
.sev-5 { background: var(--color-severity-5); }

.severity-option input:checked + .sev-1 { border-color: var(--color-severity-1); }
.severity-option input:checked + .sev-2 { border-color: var(--color-severity-2); }
.severity-option input:checked + .sev-3 { border-color: var(--color-severity-3); }
.severity-option input:checked + .sev-4 { border-color: var(--color-severity-4); }
.severity-option input:checked + .sev-5 { border-color: var(--color-severity-5); }

/* ====== Alert / Messages ====== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}

.alert-error {
  background: #FDEDEC;
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

.alert-success {
  background: #E8F8F5;
  color: var(--color-success);
  border: 1px solid var(--color-success);
}

.alert-info {
  background: #EBF5FB;
  color: #2980B9;
  border: 1px solid #2980B9;
}

/* ====== Modal ====== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--color-text-light);
  padding: 0;
  line-height: 1;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ====== Loading Spinner ====== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

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

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  padding: 40px;
  color: var(--color-text-light);
}

/* ====== Header / Navigation ====== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  height: 56px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
}

.header-brand:hover {
  color: var(--color-primary-dark);
}

.header-brand svg {
  width: 28px;
  height: 28px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-nav .btn {
  padding: 6px 14px;
  font-size: 13px;
}

.user-badge {
  font-size: 13px;
  color: var(--color-text-light);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ====== Page Layout (non-map pages) ====== */
.page {
  padding-top: 72px;
  min-height: 100vh;
}

.page-content {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.page-content h1 {
  font-size: 24px;
  margin-bottom: 8px;
}

.page-content .subtitle {
  color: var(--color-text-light);
  margin-bottom: 24px;
}

.page-content-wide {
  max-width: 800px;
}

/* ====== Auth Page ====== */
.auth-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px;
  margin-top: 20px;
}

.auth-tabs {
  display: flex;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.auth-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* ====== Report Page ====== */
.map-picker {
  height: 300px;
  border-radius: var(--radius);
  border: 2px solid var(--color-border);
  overflow: hidden;
  margin-bottom: 12px;
}

.coord-display {
  font-size: 13px;
  color: var(--color-text-light);
  margin-bottom: 8px;
  background: var(--color-bg);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: monospace;
}

.coord-display strong {
  color: var(--color-text);
}

.use-location-btn {
  font-size: 13px;
  margin-bottom: 12px;
}

/* ====== Profile Page ====== */
.report-list {
  list-style: none;
}

.report-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.report-card .sev-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.report-card .report-info {
  flex: 1;
  min-width: 0;
}

.report-card .report-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.report-card .report-meta {
  font-size: 13px;
  color: var(--color-text-light);
}

.report-card .report-desc {
  font-size: 14px;
  margin-top: 4px;
  color: var(--color-text);
}

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

.report-card .report-actions .btn {
  padding: 4px 10px;
  font-size: 12px;
}

.report-card.has-photo {
  border-left: 4px solid var(--color-accent);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-light);
}

.empty-state p {
  font-size: 16px;
  margin-bottom: 16px;
}

/* ====== Map Page ====== */
.map-page {
  padding: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.map-page .header {
  position: relative;
}

#map {
  flex: 1;
  width: 100%;
  z-index: 1;
}

.map-controls {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 90vw;
}

.map-controls label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-text-light);
}

.map-controls input[type="date"] {
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ====== Leaflet Popup Custom ====== */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
}

.leaflet-popup-content {
  margin: 12px 16px !important;
  font-family: var(--font) !important;
  font-size: 14px !important;
  min-width: 200px;
  max-width: 280px;
}

.popup-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.popup-severity {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  flex-shrink: 0;
}

.popup-title {
  font-weight: 600;
  font-size: 15px;
}

.popup-desc {
  color: var(--color-text);
  margin-bottom: 4px;
  word-break: break-word;
}

.popup-meta {
  font-size: 12px;
  color: var(--color-text-light);
}

.popup-photo {
  margin-top: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-height: 150px;
}

.popup-photo img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
}

.popup-address {
  font-size: 12px;
  color: var(--color-text-light);
  font-style: italic;
  margin-top: 2px;
}

/* ====== Photo fullscreen viewer ====== */
.photo-viewer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 99999;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.photo-viewer.active {
  display: flex;
}

.photo-viewer img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
}

/* ====== Responsive ====== */
@media (max-width: 640px) {
  .header-brand span {
    font-size: 15px;
  }

  .header-nav .user-badge {
    display: none;
  }

  .map-controls {
    flex-direction: column;
    align-items: stretch;
    bottom: 16px;
    padding: 10px 12px;
    gap: 8px;
  }

  .map-controls .filter-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
  }

  .auth-card {
    padding: 20px;
  }

  .report-card {
    flex-direction: column;
  }

  .report-card .report-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .page-content {
    padding: 16px 12px 32px;
  }

  .severity-option .sev-label {
    width: 34px;
    height: 34px;
    font-size: 12px;
  }

  .map-picker {
    height: 220px;
  }
}

/* ====== Utility ====== */
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
