:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1e242b;
  --muted: #5c6672;
  --border: #e2e6ec;
  --primary: #1d5b54;
  --primary-light: #e8f2f0;
  --accent: #2c7a7b;
  --pos: #c53030;
  --pos-bg: #fff5f5;
  --neg: #2f855a;
  --neg-bg: #f0fff4;
  --warn: #b7791f;
  --warn-bg: #fffff0;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }
.brand h1 { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.subtitle { font-size: 0.78rem; color: var(--muted); }

.topbar-actions { display: flex; align-items: center; gap: 0.6rem; }
.badge {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
}

.btn {
  border: 1px solid transparent;
  padding: 0.5rem 0.95rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #164640; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f0f2f5; }
.btn-wa { background: #1f8b4c; color: #fff; }
.btn-mail { background: #2b6cb0; color: #fff; }

.container { max-width: 1220px; margin: 1.25rem auto; padding: 0 1rem 3rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.patient-bar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 1rem;
}
@media (max-width: 720px) { .patient-bar { grid-template-columns: 1fr; } }

.field label, .search-box label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
input, select, textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.search-input-wrap { position: relative; }
.search-input-wrap input {
  padding: 0.75rem 2.2rem 0.75rem 0.9rem;
  font-size: 1rem;
  border-width: 1.5px;
}
.clear-x {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--muted);
  cursor: pointer;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.85rem;
}
.chip {
  background: #f1f4f8;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
}
.chip:hover, .chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.region-tabs {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}
.tab {
  white-space: nowrap;
  background: transparent;
  border: 1px solid var(--border);
  padding: 0.38rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--muted);
}
.tab.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}

.reasoning-banner {
  margin-top: 1rem;
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  padding: 0.9rem 1.1rem;
  border-radius: 8px;
  font-size: 0.88rem;
}
.reasoning-banner h3 { font-size: 0.98rem; color: var(--primary); margin-bottom: 0.25rem; }

.test-group { margin-top: 1.5rem; }
.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  padding-bottom: 0.45rem;
  border-bottom: 2px solid var(--border);
}
.primary-header { border-bottom-color: var(--primary); }
.comp-header { border-bottom-color: #d69e2e; }
.group-header h2 { font-size: 1.05rem; }
.pill {
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

.tests-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}

.test-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.test-card.is-pos { border-color: var(--pos); background: var(--pos-bg); }
.test-card.is-neg { border-color: var(--neg); background: var(--neg-bg); }

.card-top { display: flex; gap: 0.75rem; align-items: flex-start; margin-bottom: 0.65rem; }
.thumb-box {
  width: 68px;
  height: 68px;
  border-radius: 8px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb-box img { width: 100%; height: 100%; object-fit: cover; }

.region-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  margin-bottom: 0.25rem;
}
.test-title { font-size: 0.98rem; font-weight: 700; line-height: 1.25; }
.test-obj { font-size: 0.82rem; color: var(--muted); margin-top: 0.25rem; }

.psychometrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.55rem 0;
}
.metric-tag {
  font-size: 0.72rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  color: var(--text);
}

.eval-controls {
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.status-btns { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0.4rem; }
.status-btn {
  padding: 0.4rem 0.5rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.status-btn.active-pos { background: var(--pos); color: #fff; border-color: var(--pos); }
.status-btn.active-neg { background: var(--neg); color: #fff; border-color: var(--neg); }

.note-row { display: flex; gap: 0.4rem; }
.note-row select { width: 110px; font-size: 0.78rem; padding: 0.35rem; }
.note-row input { font-size: 0.78rem; padding: 0.35rem 0.55rem; }

/* Modales */
.hidden { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); }
.modal-card {
  position: relative;
  z-index: 101;
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 900px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.85rem;
  margin-bottom: 1rem;
}
.close-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--muted);
}

.detail-section { margin-bottom: 1rem; }
.detail-section h4 { font-size: 0.85rem; color: var(--primary); text-transform: uppercase; margin-bottom: 0.25rem; }
.detail-images { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.detail-images img { width: 100%; border-radius: 8px; border: 1px solid var(--border); max-height: 260px; object-fit: contain; background: #f8fafc; }

.report-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.printable-sheet {
  background: #fff;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.sheet-header {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}
.sheet-header h2 { font-size: 1.1rem; color: var(--primary); }
.sheet-sub { font-size: 0.8rem; color: var(--muted); }
.sheet-meta { text-align: right; font-size: 0.82rem; }
.sheet-box { margin: 0.85rem 0; }
.sheet-box label { font-size: 0.8rem; font-weight: 700; display: block; margin-bottom: 0.25rem; }

.stats-bar {
  display: flex;
  gap: 1rem;
  background: #f8fafc;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.report-item {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.55rem;
  font-size: 0.85rem;
}
.report-item.pos { border-left-color: var(--pos); background: #fffafa; }
.report-item.neg { border-left-color: var(--neg); }

@media print {
  .no-print { display: none !important; }
  .modal { position: static; padding: 0; }
  .modal-card { box-shadow: none; max-height: none; overflow: visible; padding: 0; }
  .printable-sheet { border: none; padding: 0; }
}
