/* ── Paleta clínica: oscura, color funcional, tipografía mono para cifras (IEC 62366-1) ── */
:root {
  --bg:        #0b0f14;
  --panel:     #131a22;
  --panel-2:   #0f151c;
  --border:    #243140;
  --text:      #c7d2dc;
  --text-dim:  #7d8da0;
  --accent:    #38bdf8;   /* plasma   */
  --accent-2:  #f59e0b;   /* tejido   */
  --ok:        #2dd4a7;
  --warn:      #f5b62f;
  --crit:      #f85149;
  --mono: "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, "Roboto Mono", monospace;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
header .brand { display: flex; align-items: baseline; gap: 12px; }
header h1 { font-size: 15px; font-weight: 600; letter-spacing: .14em; margin: 0; text-transform: uppercase; }
header .sub { font-size: 11px; color: var(--text-dim); letter-spacing: .06em; }

.status { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); }
.dot.ok   { background: var(--ok);   box-shadow: 0 0 8px var(--ok); }
.dot.busy { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: pulse 1s infinite; }
.dot.err  { background: var(--crit); box-shadow: 0 0 8px var(--crit); }
@keyframes pulse { 50% { opacity: .35; } }

/* ── Cabecera: zona de usuario ── */
.user-area { display: flex; align-items: center; gap: 14px; }
.user-email { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.btn-ghost {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; font-family: var(--sans);
  transition: color .15s, border-color .15s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }

/* ── Vista de autenticación (barrera de acceso) ── */
.auth-view {
  min-height: calc(100vh - 53px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand .logo { font-size: 16px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.auth-brand .tag { font-size: 11px; color: var(--text-dim); letter-spacing: .06em; margin-top: 4px; }

.auth-tabs { display: flex; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: 16px; }
.auth-tab { flex: 1; background: var(--panel-2); color: var(--text-dim); border: none; padding: 9px; font-size: 12px; cursor: pointer; font-family: var(--sans); letter-spacing: .03em; }
.auth-tab.active { background: var(--panel); color: var(--accent); font-weight: 600; }

.auth-msg { margin-top: 14px; padding: 10px 12px; border-radius: 6px; font-size: 12px; }
.auth-msg.info { border-left: 3px solid var(--accent); background: rgba(56,189,248,.08); color: var(--text); }
.auth-msg.ok   { border-left: 3px solid var(--ok);     background: rgba(45,212,167,.08); color: var(--ok); }
.auth-msg.err  { border-left: 3px solid var(--crit);   background: rgba(248,81,73,.10);  color: var(--crit); }

/* ── Layout de la aplicación ── */
main {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1px;
  background: var(--border);
  height: calc(100vh - 53px);
}
@media (max-width: 880px) { main { grid-template-columns: 1fr; height: auto; } }

aside, section.chart-wrap { background: var(--bg); padding: 20px; overflow: auto; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 18px; }
.card + .card { margin-top: 16px; }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-dim); margin: 0 0 14px; font-weight: 600; }

.field { margin-bottom: 14px; }
label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 5px; letter-spacing: .04em; }
input {
  width: 100%; padding: 9px 11px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--mono); font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56,189,248,.18); }

button.primary, .auth-card button[type="submit"], #runBtn {
  width: 100%; margin-top: 4px; padding: 11px;
  background: var(--accent); color: #04222e; border: none; border-radius: 6px;
  font-family: var(--sans); font-weight: 700; font-size: 13px; letter-spacing: .04em;
  cursor: pointer; transition: filter .15s, opacity .15s;
}
button.primary:hover:not(:disabled), .auth-card button[type="submit"]:hover:not(:disabled), #runBtn:hover:not(:disabled) { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: progress; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.metric { background: var(--panel-2); padding: 10px 12px; }
.metric .k { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.metric .v { font-family: var(--mono); font-size: 15px; color: var(--text); margin-top: 3px; }
.metric .v.flag-ok { color: var(--ok); }
.metric .v.flag-warn { color: var(--warn); }

.warnings { margin-top: 14px; border-left: 3px solid var(--warn); background: rgba(245,182,47,.08); padding: 10px 12px; border-radius: 4px; font-size: 12px; color: var(--warn); }
.warnings ul { margin: 6px 0 0; padding-left: 18px; }

.error-box { margin-top: 14px; border-left: 3px solid var(--crit); background: rgba(248,81,73,.10); padding: 12px; border-radius: 4px; color: var(--crit); font-size: 12px; }
.error-box .t { font-weight: 700; }
.error-box .d { color: var(--text); margin-top: 4px; font-family: var(--mono); }

.hidden { display: none !important; }

section.chart-wrap { display: flex; flex-direction: column; }
.chart-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.chart-header .title { font-size: 13px; font-weight: 600; color: var(--text); }
.chart-header .meta { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.canvas-box { flex: 1; min-height: 320px; position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-family: var(--mono); font-size: 12px; }

/* ── Historial clínico (panel colapsable) ── */
.collapsible-head { display: flex; align-items: center; justify-content: space-between; }
.collapsible-head h2 { margin: 0; }
.toggle { cursor: pointer; user-select: none; }
.toggle::after { content: " ▾"; color: var(--text-dim); }
#historyCard.collapsed .toggle::after { content: " ▸"; }
#historyCard.collapsed .collapsible-body { display: none; }
.collapsible-body { margin-top: 12px; }

.btn-icon {
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 6px; width: 28px; height: 26px; cursor: pointer; font-size: 14px; line-height: 1;
  transition: color .15s, border-color .15s;
}
.btn-icon:hover { color: var(--text); border-color: var(--accent); }

.history-list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; max-height: 280px; overflow-y: auto; }
.history-item { background: var(--panel-2); padding: 9px 11px; cursor: pointer; transition: background .12s; }
.history-item:hover { background: #16202b; }
.history-item .hi-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.history-item .hi-subject { font-family: var(--mono); font-size: 12px; color: var(--text); }
.history-item .hi-drug { font-size: 12px; color: var(--accent); }
.history-item .hi-date { font-family: var(--mono); font-size: 10px; color: var(--text-dim); margin-top: 2px; }
.history-empty, .history-status { font-size: 12px; color: var(--text-dim); padding: 8px 2px; }
.history-status.err { color: var(--crit); }

/* ── Fila de botones (ejecutar + descargar) ── */
.btn-row { display: flex; gap: 8px; margin-top: 4px; }
.btn-row #runBtn, .btn-row #pdfBtn { flex: 1; width: auto; margin-top: 0; }
.btn-secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 11px;
  font-family: var(--sans); font-weight: 600; font-size: 13px; letter-spacing: .04em;
  cursor: pointer; transition: color .15s, border-color .15s;
}
.btn-secondary:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.btn-secondary:disabled { opacity: .4; cursor: not-allowed; }

/* ── Informe Clínico PDF: plantilla en BLANCO, fuera de pantalla (no se ve en la app) ── */
.report {
  position: absolute; left: -10000px; top: 0;
  width: 760px; padding: 28px 32px; box-sizing: border-box;
  background: #ffffff; color: #111827;
  font-family: var(--sans);
}
.report .report-head { display: flex; align-items: center; gap: 16px; border-bottom: 2px solid #0ea5e9; padding-bottom: 12px; margin-bottom: 18px; }
.report .report-brand { font-size: 22px; font-weight: 800; letter-spacing: .18em; color: #0c4a6e; }
.report .report-title { font-size: 14px; font-weight: 600; color: #111827; }
.report .report-date { font-size: 11px; color: #6b7280; margin-top: 2px; font-family: var(--mono); }
.report .report-h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; margin: 20px 0 8px; }
.report .report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report .report-table th, .report .report-table td { text-align: left; padding: 7px 10px; border: 1px solid #e5e7eb; }
.report .report-table th { width: 45%; background: #f3f4f6; color: #374151; font-weight: 600; }
.report .report-table td { font-family: var(--mono); color: #111827; }
.report .report-chart { margin: 18px 0 4px; }
.report .report-chart canvas { width: 720px; height: 340px; }
.report .report-warn { margin-top: 14px; font-size: 12px; color: #b45309; }
.report .report-warn:empty { display: none; }
.report .report-foot { margin-top: 24px; padding-top: 12px; border-top: 1px solid #e5e7eb; font-size: 10px; color: #9ca3af; }

/* ── Selectores ── */
select {
  width: 100%; padding: 9px 11px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--mono); font-size: 13px;
}
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56,189,248,.18); }

/* ── Bloqueo visual del formulario sin gemelo activo ── */
input:disabled, select:disabled { opacity: .45; cursor: not-allowed; }

/* ── Tarjeta "Gemelo activo" ── */
.twin-select-row { display: flex; gap: 8px; align-items: center; }
.twin-select-row select { flex: 1; }
.twin-empty { margin-top: 12px; font-size: 12px; color: var(--text-dim); border-left: 3px solid var(--border); padding: 8px 11px; }
.twin-vitals { margin-top: 14px; }
.twin-name { font-family: var(--mono); font-size: 14px; color: var(--accent); margin-bottom: 10px; }
.vitals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.vital { background: var(--panel-2); padding: 9px 11px; }
.vital .k { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.vital .v { display: block; font-family: var(--mono); font-size: 15px; color: var(--text); margin-top: 3px; }
.twin-phen { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.phen-chip { font-family: var(--mono); font-size: 11px; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 3px 8px; }
.phen-none { font-size: 11px; color: var(--text-dim); }

/* ── Modal clínico de creación de perfil ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(4,8,12,.72); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-bottom: 16px; }
.modal-sub { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-dim); margin: 18px 0 10px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .field { margin-bottom: 0; }
.grid2 + .grid2 { margin-top: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.modal-actions button { width: auto; padding: 9px 16px; margin-top: 0; }
.btn-primary { background: var(--accent); color: #04222e; border: none; border-radius: 6px; font-family: var(--sans); font-weight: 700; font-size: 13px; cursor: pointer; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
