:root {
  --bg: #f6f9fc;
  --card: #ffffff;
  --card-hover: #f6f8fb;
  --accent: #635bff;
  --accent-dark: #5046e5;
  --navy: #0a2540;
  --positive: #df1b41;
  --ok: #1ea672;
  --warn: #b45309;
  --text: #425466;
  --muted: #6b7c93;
  --border: #e6ebf1;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(50, 50, 93, 0.08), 0 1px 1px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 6px 18px rgba(50, 50, 93, 0.1), 0 2px 6px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 13px 27px -5px rgba(50, 50, 93, 0.18), 0 8px 16px -8px rgba(0, 0, 0, 0.12);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Ubuntu, sans-serif;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

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

h1, h2, h3 {
  color: var(--navy);
  font-weight: 600;
  letter-spacing: -0.2px;
}

.muted {
  color: var(--muted);
}

/* ---------- Navbar ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.navbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.2px;
}

.brand:hover {
  color: var(--accent);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, #635bff 0%, #8b7bff 100%);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: var(--shadow-sm);
}

.nav-links {
  display: flex;
  gap: 0.35rem;
  flex: 1;
}

.nav-links a {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-links a:hover {
  color: var(--navy);
  background: var(--bg);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-name {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.45rem;
  margin-bottom: 0.75rem;
}

.page-header .page-title {
  margin-bottom: 0;
}

.section-title {
  font-size: 1.05rem;
  margin: 1.25rem 0 0.75rem;
}

.card .section-title {
  margin-top: 0;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* ---------- Dashboard ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  text-align: left;
  margin-bottom: 0;
  border-top: 3px solid var(--accent);
}

.stat-value {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -1px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.quick-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.5rem 1.05rem;
  font-size: 0.93rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

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

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

.btn-secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--navy);
}

.btn-secondary:hover {
  border-color: #c9d2de;
  color: var(--navy);
}

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

.btn-accent:hover {
  background: #143b61;
  color: #fff;
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  box-shadow: none;
}

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

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.84rem;
}

.btn-lg {
  padding: 0.75rem 1.6rem;
  font-size: 1.02rem;
  border-radius: 9px;
}

.btn-block {
  display: block;
  width: 100%;
}

/* ---------- Forms ---------- */
label {
  display: block;
  margin: 0.75rem 0 0.3rem;
  font-size: 0.86rem;
  color: var(--navy);
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="tel"],
input[type="email"],
select,
textarea {
  width: 100%;
  background: #fff;
  color: var(--navy);
  border: 1px solid #d8dee9;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.18);
}

input[type="file"] {
  color: var(--muted);
  margin-bottom: 0.75rem;
}

textarea {
  resize: vertical;
}

.form-card {
  max-width: 720px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.25rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.search-bar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  max-width: 560px;
}

.inline-form {
  display: inline-block;
}

.upload-form button {
  margin-top: 0.25rem;
}

.reanalyze-form {
  margin-top: 1rem;
}

/* ---------- Alerts ---------- */
.alert {
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}

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

.alert-warn {
  background: #fef6e7;
  border: 1px solid #fbe1a8;
  color: #92400e;
}

/* ---------- Análisis estadístico ---------- */
.stats-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.metric {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.metric-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.5px;
}

.metric-of {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.metric-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  font-weight: 600;
}

.metric-sub {
  font-size: 0.85rem;
  color: var(--accent-dark);
  font-weight: 600;
  margin-top: 0.1rem;
}

.stats-subtitle {
  font-size: 0.98rem;
  margin: 1.1rem 0 0.6rem;
  color: var(--navy);
}

.pattern-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  background: var(--bg);
}

.pattern-alto { border-left-color: var(--positive); }
.pattern-moderado { border-left-color: var(--warn); }
.pattern-bajo { border-left-color: var(--muted); }

.pattern-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
}

.pattern-head strong {
  color: var(--navy);
  font-size: 1.02rem;
}

.pattern-comps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.comp {
  font-size: 0.8rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
}

.comp-pos {
  background: #ffe7eb;
  color: var(--positive);
}

.comp-neg {
  background: #eef2f6;
  color: var(--muted);
}

.badge-nivel-alto {
  background: #ffe7eb;
  color: var(--positive);
}

.badge-nivel-moderado {
  background: #fef3c7;
  color: #92400e;
}

.badge-nivel-bajo {
  background: #eef2f6;
  color: #5a6b7b;
}

.patterns-table td {
  vertical-align: middle;
}

.assoc-list {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.92rem;
}

.assoc-list li {
  margin-bottom: 0.3rem;
}

.stats-disclaimer {
  font-size: 0.8rem;
  margin-top: 1rem;
  font-style: italic;
}

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

td {
  color: var(--text);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg);
}

td.empty {
  text-align: center;
  color: var(--muted);
  padding: 1.5rem;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 0.14rem 0.6rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-pendiente {
  background: #eef2f6;
  color: #5a6b7b;
}

.badge-llamado {
  background: #fef3c7;
  color: #92400e;
}

.badge-analizado {
  background: #e7e5ff;
  color: var(--accent-dark);
}

.badge-informado {
  background: #d7f7c2;
  color: #0e6245;
}

.badge-positivo {
  background: #ffe7eb;
  color: var(--positive);
}

.badge-negativo {
  background: #d7f7c2;
  color: #0e6245;
}

/* ---------- Patient detail ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.detail-grid .card {
  margin-bottom: 0;
}

.data-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
}

.data-list dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.data-list dd {
  color: var(--navy);
  font-weight: 600;
}

/* ---------- Queue ---------- */
.call-panel {
  text-align: center;
  padding: 2.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(180deg, #ffffff 0%, #f8f9ff 100%);
}

.call-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-weight: 600;
}

.call-name {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.5px;
}

.call-next-form {
  margin-top: 0.5rem;
}

.queue-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.queue-grid .card {
  margin-bottom: 0;
}

/* ---------- Study result ---------- */
.study-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  font-size: 0.92rem;
  align-items: center;
}

.images-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.image-card img {
  width: 100%;
  border-radius: 8px;
  background: #0a1628;
  box-shadow: var(--shadow-sm);
}

.heatmaps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.heatmaps figure {
  margin: 0;
}

.heatmaps figcaption {
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.3rem;
}

.pathology-desc {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 0.1rem;
  max-width: 460px;
}

.findings-table .prob-cell {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 180px;
}

.prob-bar {
  flex: 1;
  height: 8px;
  background: #eef2f6;
  border-radius: 999px;
  overflow: hidden;
}

.prob-fill {
  height: 100%;
  border-radius: 999px;
}

.prob-high {
  background: var(--positive);
}

.prob-low {
  background: var(--ok);
}

.prob-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
  min-width: 3.2rem;
  text-align: right;
  color: var(--navy);
}

/* ---------- Login ---------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.25rem;
  background: linear-gradient(160deg, #f6f9fc 0%, #eef1ff 60%, #f6f9fc 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
  border: none;
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.login-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, #635bff 0%, #8b7bff 100%);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 800;
  box-shadow: 0 8px 16px rgba(99, 91, 255, 0.3);
}

.login-title {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.login-card form {
  text-align: left;
  margin-top: 1.25rem;
}

.login-card .btn-block {
  margin-top: 1.5rem;
}

/* ---------- Validación clínica ---------- */
.truth-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.4rem 1rem;
  margin: 0.75rem 0;
}

.truth-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--navy);
  margin: 0;
  cursor: pointer;
}

.truth-item input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}

.truth-none {
  margin-top: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  font-weight: 600;
}

/* ---------- Tabla de métricas ---------- */
.metrics-table th, .metrics-table td {
  text-align: center;
}
.metrics-table th:first-child, .metrics-table td:first-child {
  text-align: left;
}

.thr-input {
  width: 5rem;
  padding: 0.25rem 0.4rem;
  text-align: center;
}

/* ---------- Visor de imagen ---------- */
img.zoomable { cursor: zoom-in; }

.img-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(8, 15, 30, 0.92);
  display: flex;
  flex-direction: column;
}

.img-viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: rgba(15, 23, 42, 0.85);
  color: #e2e8f0;
  flex-wrap: wrap;
}

.img-viewer-caption {
  font-weight: 600;
  font-size: 0.95rem;
}

.img-viewer-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.img-viewer-controls label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  color: #cbd5e1;
  font-size: 0.8rem;
  font-weight: 500;
}

.img-viewer-controls input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}

.img-viewer-controls button {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 7px;
  min-width: 34px;
  height: 32px;
  padding: 0 0.6rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.img-viewer-controls button:hover {
  background: rgba(255, 255, 255, 0.25);
}

.img-viewer-stage {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-viewer-img {
  max-width: 92%;
  max-height: 100%;
  transform-origin: center center;
  transition: filter 0.1s ease;
  cursor: grab;
  user-select: none;
}

.img-viewer-img.dragging { cursor: grabbing; }

/* ---------- Overlay de análisis ---------- */
.analysis-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 37, 64, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.analysis-modal {
  background: #fff;
  border-radius: 14px;
  padding: 2rem 2.25rem;
  width: min(420px, 92vw);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.analysis-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #635bff 0%, #8b7bff 100%);
  color: #fff;
  font-weight: 800;
  margin-bottom: 0.75rem;
  animation: analysis-pulse 1.6s ease-in-out infinite;
}

@keyframes analysis-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(99, 91, 255, 0.35); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 12px rgba(99, 91, 255, 0); }
}

.analysis-title {
  font-size: 1.2rem;
  margin-bottom: 0.25rem;
}

.analysis-message {
  font-size: 0.92rem;
  min-height: 1.4em;
}

.analysis-error {
  color: var(--positive);
}

.analysis-track {
  height: 10px;
  background: #eef2f6;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 1rem;
}

.analysis-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #635bff, #8b7bff);
  transition: width 0.5s ease;
}

.analysis-percent {
  margin-top: 0.5rem;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .navbar-inner {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .nav-links {
    order: 3;
    width: 100%;
    justify-content: space-between;
    gap: 0.25rem;
  }

  .detail-grid,
  .queue-grid,
  .images-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .call-name {
    font-size: 1.6rem;
  }

  .card {
    overflow-x: auto;
  }
}
