/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  background: #0f172a;
  color: #e2e8f0;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Layout ─── */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 56px;
  background: #f0fdfa;
  color: #0f4c4c;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  border-bottom: 1px solid #ccfbf1;
}
.header-title { font-size: 18px; font-weight: 700; letter-spacing: 0.3px; }
.header-status { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: 0.9; flex-wrap: wrap; justify-content: flex-end; }
.modo-badge {
  border: 1px solid #99f6e4;
  background: #ecfdf5;
  color: #0f766e;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.2;
  max-width: 150px;
}
.modo-badge.modo-cloud {
  background: #fff7ed;
  border-color: #fdba74;
  color: #c2410c;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.online { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.dot.offline { background: #ef4444; }

.app-tabs {
  position: fixed; top: 56px; left: 0; right: 0; z-index: 90;
  height: 44px;
  display: flex;
  background: #0f172a;
  border-bottom: 1px solid #334155;
  padding: 0 8px;
  gap: 4px;
}
.app-tabs .tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.app-tabs .tab-btn.active {
  color: #5eead4;
  border-bottom-color: #0d7377;
}
.app-tabs.hidden { display: none; }

.app-main {
  position: fixed;
  top: 100px; bottom: 0; left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #0f172a;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
body.login-only .app-tabs { display: none; }
body.login-only .app-main { top: 56px; }

.sv-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.sv-grid input { margin-bottom: 0; }

.lab-scan-box {
  background: #0f172a;
  border: 1px dashed #475569;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}
.lab-file { display: none; }
.lab-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 10px;
  margin-top: 10px;
  background: #020617;
}
.exp-alert {
  background: #422006;
  border: 1px solid #b45309;
  color: #fde68a;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 10px;
}
.exp-dx-card { border-left: 3px solid #0d7377; }
.exp-dx-card .score { color: #94a3b8; font-size: 12px; }
label { display: block; font-size: 12px; color: #94a3b8; margin-bottom: 4px; }

/* ─── Views ─── */
.view { display: none; padding: 12px; min-height: 100%; }
.view.active { display: block; animation: fadeIn 0.2s ease; }
#view-chat { display: none; flex-direction: column; height: 100%; padding: 0; }
#view-chat.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Panels ─── */
.panel {
  background: #1e293b;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.panel h2 { font-size: 18px; margin-bottom: 8px; color: #5eead4; }
.hint { font-size: 13px; color: #94a3b8; margin-bottom: 12px; line-height: 1.5; }

/* ─── Inputs ─── */
input[type="text"], textarea, select {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px 14px;
  color: #e2e8f0;
  font-size: 16px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus, textarea:focus, select:focus { border-color: #0d7377; }
textarea { resize: none; line-height: 1.5; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='3'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

.row { display: flex; gap: 10px; align-items: stretch; }
.row input, .row select { flex: 1; margin-bottom: 0; }
.row .btn-primary { margin-bottom: 0; }

/* ─── Buttons ─── */
.btn-primary {
  background: linear-gradient(135deg, #0d7377 0%, #14919b 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform 0.1s, opacity 0.2s;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: #334155;
  color: #e2e8f0;
  border: 1px solid #475569;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:active { background: #475569; }
.btn-full { width: 100%; }

/* ─── Chat ─── */
.btn-back-salud {
  border: 1px solid #99f6e4;
  background: #ecfdf5;
  color: #0f766e;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.2;
}
.btn-back-salud:active { opacity: 0.85; }
.chat-container {
  flex: 1;
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.bot { justify-content: flex-start; }
.msg-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, #0d7377 0%, #14919b 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.bot .msg-bubble {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-bottom-left-radius: 4px;
}
.msg-meta { font-size: 11px; opacity: 0.65; margin-top: 4px; }
.msg-sources { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(148,163,184,0.2); }
.msg-sources small { display: block; color: #94a3b8; font-size: 11px; margin-top: 2px; }

.chat-input-area {
  background: #1e293b;
  border-top: 1px solid #334155;
  padding: 8px 12px;
  display: flex; gap: 8px; align-items: flex-end;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
}
.chat-input-area textarea { flex: 1; margin-bottom: 0; border-radius: 20px; padding: 10px 14px; font-size: 15px; }
.chat-input-area .btn-primary { width: 44px; height: 44px; border-radius: 50%; padding: 0; flex-shrink: 0; }

/* ─── Results / Cards ─── */
.results-panel { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: #1e293b;
  border-radius: 14px;
  padding: 14px;
  border: 1px solid #334155;
  animation: fadeIn 0.25s ease;
}
.card h3 { font-size: 15px; color: #5eead4; margin-bottom: 6px; }
.card p { font-size: 13px; color: #cbd5e1; line-height: 1.5; margin-bottom: 6px; }
.card .meta { font-size: 11px; color: #64748b; }
.card .badge {
  display: inline-block;
  background: #0d7377;
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-right: 4px;
}
.card .badge-outline {
  background: transparent;
  border: 1px solid #334155;
  color: #94a3b8;
}
.card-sublist { margin-top: 8px; padding-left: 12px; }
.card-sublist li { font-size: 12px; color: #cbd5e1; margin-bottom: 4px; list-style: disc; }

/* ─── Loading ─── */
.loading {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 20px; color: #94a3b8; font-size: 14px;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid #334155;
  border-top-color: #5eead4;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Modal ─── */
.modal {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }
.modal-content {
  background: #1e293b;
  border-radius: 20px;
  padding: 24px;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.modal-content h3 { margin-bottom: 16px; color: #5eead4; }
.modal-content label { display: block; font-size: 13px; color: #94a3b8; margin-bottom: 4px; }
.modal-content input, .modal-content select { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions button { flex: 1; }

/* ─── FAB ─── */
.fab {
  position: fixed; bottom: 80px; right: 16px; z-index: 90;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: #334155;
  border: 1px solid #475569;
  color: #e2e8f0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

/* ─── Perfil Grid ─── */
.perfil-header { text-align: center; padding: 20px 16px; }
.perfil-header h1 { font-size: 22px; color: #5eead4; margin-bottom: 8px; }
.perfil-header p { font-size: 14px; color: #94a3b8; }
.perfil-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 8px 16px 24px;
}
.perfil-btn {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid #334155;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s;
}
.perfil-btn:active { transform: scale(0.97); }
.perfil-btn:hover { border-color: #0d7377; }
.perfil-icon { font-size: 40px; line-height: 1; }
.perfil-title { font-size: 16px; font-weight: 700; color: #e2e8f0; }
.perfil-desc { font-size: 12px; color: #94a3b8; line-height: 1.4; }

/* ─── Emergencia Grid ─── */
.emergencia-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 8px;
}
.emergencia-btn {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s;
  min-height: 120px;
  text-align: center;
}
.emergencia-btn:active { transform: scale(0.96); }
.emergencia-btn:hover { border-color: #0d7377; }
.emergencia-icon { font-size: 36px; line-height: 1; }
.emergencia-label { font-size: 14px; font-weight: 600; color: #e2e8f0; line-height: 1.3; }
.emergencia-label small { font-size: 11px; color: #94a3b8; font-weight: 400; }

/* ─── Utilities ─── */
.empty-state { text-align: center; padding: 40px 20px; color: #64748b; font-size: 14px; }
.error-msg { background: rgba(239,68,68,0.15); color: #fca5a5; padding: 12px; border-radius: 10px; font-size: 13px; border: 1px solid rgba(239,68,68,0.3); }

/* ─── Diagnóstico: Toggle modo ─── */
.dx-mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.dx-mode-btn {
  flex: 1;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 10px;
  font-size: 14px;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s;
}
.dx-mode-btn.active {
  background: #0d7377;
  color: #fff;
  border-color: #0d7377;
}

/* ─── Checklist de síntomas ─── */
.checklist-cat {
  margin-bottom: 10px;
  border: 1px solid #334155;
  border-radius: 14px;
  overflow: hidden;
  background: #0f172a;
}
.checklist-cat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #1e293b;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 15px;
}
.checklist-cat-header .cat-emoji { font-size: 20px; line-height: 1; }
.checklist-cat-header .cat-arrow { margin-left: auto; font-size: 12px; transition: transform 0.2s; color: #94a3b8; }
.checklist-cat.open .cat-arrow { transform: rotate(180deg); }
.checklist-cat-body {
  display: none;
  padding: 10px;
  gap: 8px;
  flex-wrap: wrap;
}
.checklist-cat.open .checklist-cat-body { display: flex; }

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 48px;
  flex: 1 1 calc(50% - 4px);
  min-width: 140px;
}
.check-item:active { transform: scale(0.97); }
.check-item input { display: none; }
.check-item .check-box {
  width: 22px; height: 22px;
  border: 2px solid #475569;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.check-item .check-box::after {
  content: '';
  width: 10px; height: 10px;
  background: #5eead4;
  border-radius: 2px;
  transform: scale(0);
  transition: transform 0.15s;
}
.check-item.selected {
  background: rgba(13,115,119,0.15);
  border-color: #0d7377;
}
.check-item.selected .check-box { border-color: #5eead4; }
.check-item.selected .check-box::after { transform: scale(1); }
.check-item .check-label { font-size: 13px; line-height: 1.3; }

.dx-resumen {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(13,115,119,0.1);
  border: 1px dashed #0d7377;
  border-radius: 10px;
  font-size: 13px;
  color: #5eead4;
}

/* ─── Herramientas Grid ─── */
.herramientas-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 8px;
}
.herramienta-btn {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 18px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s;
  min-height: 120px;
  text-align: center;
}
.herramienta-btn:active { transform: scale(0.96); }
.herramienta-btn:hover { border-color: #0d7377; }
.herramienta-icon { font-size: 32px; line-height: 1; }
.herramienta-label { font-size: 13px; font-weight: 600; color: #e2e8f0; line-height: 1.3; }
.herramienta-label small { font-size: 11px; color: #94a3b8; font-weight: 400; }

/* ─── Calculadora pediátrica ─── */
.calc-panel {
  background: #1e293b;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid #334155;
}
.calc-panel h3 { font-size: 16px; color: #5eead4; margin-bottom: 12px; }
.calc-result {
  background: rgba(13,115,119,0.12);
  border: 1px solid #0d7377;
  border-radius: 12px;
  padding: 14px;
  margin-top: 12px;
}
.calc-result .dosis-principal { font-size: 20px; font-weight: 700; color: #5eead4; }
.calc-result .dosis-detalle { font-size: 13px; color: #cbd5e1; margin-top: 6px; line-height: 1.5; }
.calc-warning { background: rgba(234,179,8,0.12); border: 1px solid #eab308; color: #fde047; padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-top: 10px; }

/* ─── Signos de alarma ─── */
.alarm-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.alarm-cat {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 14px;
  overflow: hidden;
}
.alarm-cat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #0f172a;
  font-weight: 600;
  font-size: 14px;
}
.alarm-cat-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.alarm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.alarm-item.selected {
  background: rgba(239,68,68,0.12);
  border-color: #ef4444;
}
.alarm-item input { display: none; }
.alarm-box {
  width: 20px; height: 20px;
  border: 2px solid #475569;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.alarm-box::after {
  content: '';
  width: 10px; height: 10px;
  background: #ef4444;
  border-radius: 2px;
  transform: scale(0);
  transition: transform 0.15s;
}
.alarm-item.selected .alarm-box { border-color: #ef4444; }
.alarm-item.selected .alarm-box::after { transform: scale(1); }
.alarm-item .alarm-label { font-size: 13px; line-height: 1.3; }
.alarm-resumen {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.alarm-resumen.verde { background: rgba(34,197,94,0.15); color: #4ade80; border: 1px solid #22c55e; }
.alarm-resumen.amarillo { background: rgba(234,179,8,0.15); color: #fde047; border: 1px solid #eab308; }
.alarm-resumen.rojo { background: rgba(239,68,68,0.15); color: #fca5a5; border: 1px solid #ef4444; }

/* ─── Responsive tablet/desktop: misma columna centrada ─── */
@media (min-width: 768px) {
  .app-header,
  .app-tabs,
  .app-main {
    width: 100%;
    max-width: 480px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
  .app-main {
    border-left: 1px solid #1e293b;
    border-right: 1px solid #1e293b;
  }
  #view-chat,
  #view-chat.active,
  .chat-container,
  .chat-input-area {
    width: 100%;
    max-width: none;
    left: auto;
    transform: none;
  }
}
