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

:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --text: #1a202c;
  --text-muted: #64748b;
  --primary: #0066cc;
  --primary-light: #e8f0fe;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);

  --vermelho: #dc2626;
  --laranja: #ea580c;
  --amarelo: #ca8a04;
  --verde: #16a34a;
  --azul: #2563eb;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: linear-gradient(135deg, #0066cc 0%, #0047ab 100%);
  color: white;
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
}

.logo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.logo {
  flex-shrink: 0;
}

.header-content h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin-top: 0.25rem;
  opacity: 0.85;
  font-size: 0.95rem;
}

/* Main */
main {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  flex: 1;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

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

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb-sep {
  margin: 0 0.4rem;
  color: var(--border);
}

/* Page heading */
.page-heading {
  margin-bottom: 1rem;
}

.page-heading h2 {
  font-size: 1.35rem;
  font-weight: 700;
}

.page-heading p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

/* Header link */
.header-link {
  color: inherit;
  text-decoration: none;
}

/* Hospital links */
.hospital-link {
  color: inherit;
  text-decoration: none;
}

.hospital-link:hover {
  color: var(--primary);
}

.hospital-district-link {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
}

.hospital-district-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* District links grid */
.district-links {
  margin-top: 2rem;
}

.district-links h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.district-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.district-link {
  padding: 0.4rem 0.85rem;
  background: var(--surface);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--primary);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.district-link:hover {
  box-shadow: var(--shadow-lg);
}

/* Search */
.search-section {
  margin-bottom: 1rem;
}

.search-container {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

#city-input {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 2.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
  transition: border-color 0.2s;
}

#city-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,102,204,.15);
}

.clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.clear-btn:hover {
  color: var(--text);
}

.location-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.location-btn:hover {
  background: #0055aa;
}

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

.location-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Filters */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.filter-bar select {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--surface);
  cursor: pointer;
}

.filter-bar select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Legend */
.legend-section {
  margin-bottom: 1rem;
}

.legend {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.legend-title {
  font-weight: 600;
  color: var(--text);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.vermelho { background: var(--vermelho); }
.dot.laranja  { background: var(--laranja); }
.dot.amarelo  { background: var(--amarelo); }
.dot.verde    { background: var(--verde); }
.dot.azul     { background: var(--azul); }

/* Source status */
.source-status {
  background: #fff8e1;
  color: #f57f17;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.75rem;
  border: 1px solid #fff0b3;
}

/* Status bar */
.status-bar {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  font-weight: 500;
}

/* Loading */
.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.8s linear infinite;
}

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

/* Error */
.error-msg {
  background: #fef2f2;
  color: #991b1b;
  padding: 1rem;
  border-radius: var(--radius);
  text-align: center;
  margin-bottom: 1rem;
}

/* Results */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.results-header span:first-child {
  font-weight: 600;
  color: var(--text);
}

.last-sync {
  font-size: 0.8rem;
}

/* Hospital cards */
.hospital-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.hospital-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.hospital-card:hover {
  box-shadow: var(--shadow-lg);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem 1rem 0.5rem;
  gap: 1rem;
}

.hospital-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hospital-name {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.35;
}

.hospital-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 4px;
  flex-wrap: wrap;
}

.tipo-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.tipo-badge.publico {
  background: #e8f5e9;
  color: #2e7d32;
}

.tipo-badge.privado {
  background: #fff3e0;
  color: #e65100;
}

.network-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}

.hospital-district-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.hospital-distance {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.queue-badge {
  flex-shrink: 0;
  background: var(--bg);
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.urgency-sections {
  padding: 0.5rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.urgency-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.85rem;
}

.urgency-type {
  font-weight: 500;
  min-width: 130px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.triage-times {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  flex: 1;
}

.triage-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
}

.triage-chip.vermelho { background: var(--vermelho); }
.triage-chip.laranja  { background: var(--laranja); }
.triage-chip.amarelo  { background: var(--amarelo); }
.triage-chip.verde    { background: var(--verde); }
.triage-chip.azul     { background: var(--azul); }

.triage-chip.empty {
  opacity: 0.25;
}

.wait-main {
  flex-shrink: 0;
  text-align: right;
  min-width: 70px;
}

.wait-time {
  font-size: 1.1rem;
  font-weight: 700;
}

.wait-time.short   { color: var(--verde); }
.wait-time.medium  { color: var(--amarelo); }
.wait-time.long    { color: var(--laranja); }
.wait-time.vlong   { color: var(--vermelho); }

.wait-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* No data */
.no-data-row {
  justify-content: center;
}

.no-data-text {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
}

/* Contact section */
.contact-section {
  max-width: 800px;
  width: 100%;
  margin: 2rem auto 0;
  padding: 0 1rem;
}

.contact-section h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.contact-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.contact-form {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.form-group input,
.form-group textarea {
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--bg);
  transition: border-color 0.2s;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,102,204,.15);
}

.contact-submit {
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  align-self: flex-start;
}

.contact-submit:hover {
  background: #0055aa;
}

.contact-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.contact-feedback {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
}

.contact-feedback.success {
  background: #e8f5e9;
  color: #2e7d32;
}

.contact-feedback.error {
  background: #fef2f2;
  color: #991b1b;
}

/* Footer */
footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

footer p + p {
  margin-top: 0.25rem;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 600px) {
  header {
    padding: 1.5rem 1rem 1rem;
  }

  .header-content h1 {
    font-size: 1.35rem;
  }

  .search-container {
    flex-direction: column;
  }

  .location-btn {
    justify-content: center;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar select {
    width: 100%;
  }

  .legend {
    font-size: 0.7rem;
    gap: 0.5rem;
  }

  .urgency-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .urgency-type {
    min-width: unset;
  }

  .card-header {
    flex-direction: column;
    gap: 0.5rem;
  }
}
