/* ======= Root + Reset ======= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

body.app-body {
  background: radial-gradient(circle at top, #1b2440 0, #050711 55%, #020308 100%);
  color: #f9fbff;
  display: flex;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button,
select,
input {
  font-family: inherit;
}

/* ======= Layout ======= */
.background-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 0% 0%, rgba(80, 150, 255, 0.18), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(204, 76, 255, 0.2), transparent 50%);
  z-index: 0;
}

.sidebar {
  position: relative;
  z-index: 1;
  width: 260px;
  padding: 24px 18px;
  backdrop-filter: blur(18px);
  background: linear-gradient(175deg, rgba(7, 11, 24, 0.95), rgba(6, 10, 22, 0.9));
  border-right: 1px solid rgba(129, 140, 248, 0.12);
  box-shadow: 8px 0 40px rgba(3, 4, 10, 0.8);
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 20%, #60a5fa, #4c1d95);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-size: 16px;
  font-weight: 600;
}

.logo-subtitle {
  font-size: 11px;
  color: #9ca3af;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 999px;
  color: #9ca3af;
  font-size: 14px;
  transition: background 0.17s ease, color 0.17s ease, transform 0.12s ease;
}

.nav-item:hover {
  background: rgba(148, 163, 184, 0.18);
  color: #e5e7eb;
  transform: translateX(2px);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.55), rgba(129, 140, 248, 0.55));
  color: #f9fafb;
}

.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.5);
}

.nav-item.active .nav-dot {
  background: #f9fafb;
}

.sidebar-footer {
  margin-top: auto;
  font-size: 11px;
  color: #6b7280;
  padding-top: 16px;
}

.sidebar-caption {
  margin: 0;
}

.main-layout {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.page-title {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: #9ca3af;
}

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

.grid {
  display: grid;
  gap: 18px;
}

.grid-2 {
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.4fr);
}

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

.card {
  position: relative;
  padding: 20px 18px;
  border-radius: 18px;
}

.glass {
  background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), rgba(15, 23, 42, 0.96));
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.35);
  backdrop-filter: blur(18px);
}

.card-title {
  font-size: 17px;
  font-weight: 500;
  margin: 0 0 4px;
}

.card-body-text {
  margin: 0;
  font-size: 13px;
  color: #9ca3af;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

/* ======= Buttons & Pills ======= */
.btn {
  border-radius: 999px;
  padding: 8px 16px;
  border: 0;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #7c3aed);
  color: #f9fafb;
  box-shadow: 0 12px 25px rgba(37, 99, 235, 0.45);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(59, 130, 246, 0.6);
}

.btn-xs {
  padding: 4px 10px;
  font-size: 11px;
}

.btn-outline {
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.6);
  color: #e5e7eb;
}

.btn-outline:hover {
  background: rgba(30, 64, 175, 0.7);
}

.btn-ghost {
  border: 1px solid transparent;
  background: rgba(15, 23, 42, 0.4);
  color: #cbd5f5;
}

.btn-ghost:hover {
  background: rgba(31, 41, 55, 0.8);
}

.pill {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 6px;
}

.pill-success {
  background: #22c55e;
}

.pill-info {
  background: #3b82f6;
}

.pill-warning {
  background: #eab308;
}

.hero-list {
  list-style: none;
  padding: 0;
  margin: 14px 0;
  font-size: 13px;
  color: #cbd5f5;
}

.hero-list li {
  margin-bottom: 6px;
}

.hero-cta-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* ======= Hero & Metrics ======= */
.main-hero {
  align-items: stretch;
}

.hero-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hero-viz {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hero-viz-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #9ca3af;
}

.hero-label {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
}

.hero-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.7);
}

.hero-status-text {
  font-size: 12px;
}

.viewer-placeholder {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.4), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.viewer-placeholder-img {
  opacity: 0.7;
  width: 100%;
}

.scan-overlay-label {
  position: absolute;
  left: 14px;
  bottom: 14px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  font-size: 11px;
  color: #e5e7eb;
}

.mini-metrics-row {
  display: flex;
  gap: 14px;
  font-size: 12px;
}

.mini-metric {
  flex: 1;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(75, 85, 99, 0.7);
}

.mini-label {
  display: block;
  color: #6b7280;
  margin-bottom: 2px;
}

.mini-value {
  font-weight: 500;
}

.dashboard-glance .stat-card {
  min-height: 120px;
}

.stat-row {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.stat-value {
  color: #bfdbfe;
}

/* ======= Scan Viewer & Diagnosis Panel ======= */
.scan-layout {
  align-items: flex-start;
}

.scan-viewer-card {
  min-height: 360px;
}

.scan-viewer {
  position: relative;
  width: 100%;
  padding-top: 70%;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.4), rgba(15, 23, 42, 0.96));
}

.image-container img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
}

/* Hide preview/heatmap until JS sets real image (no broken icon, no alt text) */
.scan-viewer #scan-preview,
.scan-viewer #scan-heatmap,
.image-container.scan-viewer #upload-preview,
.image-container.scan-viewer #upload-heatmap {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.scan-viewer #scan-preview[src^="data:image/jpeg"],
.scan-viewer #scan-preview[src^="data:image/png"],
.image-container.scan-viewer #upload-preview[src^="data:image/jpeg"],
.image-container.scan-viewer #upload-preview[src^="data:image/png"] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.scan-viewer #scan-heatmap[src^="data:image/jpeg"],
.scan-viewer #scan-heatmap[src^="data:image/png"],
.image-container.scan-viewer #upload-heatmap[src^="data:image/jpeg"],
.image-container.scan-viewer #upload-heatmap[src^="data:image/png"] {
  opacity: 0.9;
  visibility: visible;
  pointer-events: none;
}

#scan-heatmap,
#upload-heatmap {
  mix-blend-mode: screen;
  opacity: 0.9;
  pointer-events: none;
}

.scan-placeholder {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: #6b7280;
  pointer-events: none;
}

.scan-loading::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    120deg,
    rgba(59, 130, 246, 0.12),
    rgba(129, 140, 248, 0.18),
    rgba(59, 130, 246, 0.12)
  );
  background-size: 200% 200%;
  animation: scanSweep 1.4s linear infinite;
  mix-blend-mode: soft-light;
  pointer-events: none;
}

.upload-inline {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.file-input-label {
  position: relative;
  border-radius: 999px;
  border: 1px dashed rgba(148, 163, 184, 0.8);
  padding: 6px 12px;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.8);
}

.file-input-label.large {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 12px;
  width: 100%;
  border-radius: 16px;
}

.file-input-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.model-select {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.model-select select,
.form-group select {
  background: rgba(15, 23, 42, 0.8);
  color: #e5e7eb;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  padding: 6px 24px 6px 10px;
  font-size: 13px;
}

.form-group {
  margin-bottom: 14px;
  font-size: 13px;
}

.form-group label {
  display: block;
  margin-bottom: 4px;
}

.status-line {
  margin-top: 8px;
  font-size: 12px;
  color: #9ca3af;
}

.diagnosis-panel {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.diagnosis-content {
  font-size: 13px;
}

.diagnosis-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.diagnosis-label {
  color: #9ca3af;
}

.diagnosis-value {
  font-weight: 500;
}

.progress-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  overflow: hidden;
  border: 1px solid rgba(55, 65, 81, 0.9);
  margin: 6px 0 12px;
}

.progress-bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #22c55e, #3b82f6, #7c3aed);
  transition: width 0.3s ease;
}

.diagnosis-badge {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  font-size: 11px;
}

.diagnosis-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.upload-info {
  margin-top: 16px;
  font-size: 13px;
  color: #9ca3af;
}

.info-line {
  margin-bottom: 8px;
}

/* ======= Maps & Hospital List ======= */
.map-container {
  width: 100%;
  height: 320px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.5);
}

.small-map {
  height: 240px;
}

.map-section,
.map-preview-section {
  margin-top: 4px;
}

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

.map-controls select {
  background: rgba(15, 23, 42, 0.8);
  color: #e5e7eb;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  padding: 6px 24px 6px 10px;
  font-size: 13px;
}

.map-side-panel {
  max-height: 320px;
  overflow: auto;
}

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

.hospital-card {
  padding: 10px 10px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(55, 65, 81, 0.9);
  font-size: 12px;
}

.hospital-name {
  font-weight: 500;
  margin-bottom: 2px;
}

.hospital-meta {
  color: #9ca3af;
  margin-bottom: 4px;
}

.hospital-meta span + span::before {
  content: "•";
  margin: 0 4px;
  color: #4b5563;
}

.hospital-location {
  color: #dbeafe;
  font-size: 12px;
  line-height: 1.45;
  margin-bottom: 4px;
}

.hospital-contact {
  display: flex;
  gap: 6px;
  color: #cbd5e1;
  font-size: 12px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.hospital-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(31, 41, 55, 0.9);
  border: 1px solid rgba(75, 85, 99, 0.9);
}

.rating {
  color: #fbbf24;
  font-size: 11px;
}

@keyframes scanSweep {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 200% 50%;
  }
}

/* ======= Responsive ======= */
@media (max-width: 1024px) {
  .sidebar {
    display: none;
  }

  .main-layout {
    padding: 18px 16px 24px;
  }

  .grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }

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

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .map-container,
  .small-map {
    height: 260px;
  }
}
