/* OTIKA - Portal Equipo Médico - Tema OTIKA (azul #0c5a75, amarillo #fff15d) */
:root {
  --primary: #0c5a75;
  --primary-dark: #084056;
  --accent: #fff15d;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #1f2937;
  --text-dim: #6b7280;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
}

/* Vistas */
.view { display: none; min-height: 100vh; }
.view.active { display: block; }

/* Login */
#view-login {
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  padding: 20px;
}
#view-login.active { display: flex; }
.login-box {
  background: white;
  padding: 32px 28px;
  border-radius: 14px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  text-align: center;
}
.login-logo { width: 80px; height: auto; margin: 0 auto 12px; display: block; }
.login-title { color: var(--primary); margin: 0; font-size: 32px; letter-spacing: 2px; }
.login-subtitle { color: var(--text-dim); margin: 6px 0 22px; font-size: 13px; }
#login-pin {
  width: 100%;
  font-size: 28px;
  letter-spacing: 8px;
  text-align: center;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
}
#login-pin:focus { border-color: var(--primary); outline: none; }
.login-hint { color: var(--text-dim); font-size: 12px; margin-top: 12px; }
.error-msg { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* Top bar */
.top-bar {
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 32px; height: 32px; }
.brand-title { font-weight: 700; letter-spacing: 1px; font-size: 16px; }
.brand-sub { font-size: 11px; opacity: 0.85; }
.top-title { font-weight: 600; font-size: 16px; flex: 1; text-align: center; }
.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.25); }

/* Content */
.content { padding: 18px; max-width: 800px; margin: 0 auto; }
.greeting { color: var(--primary); margin: 6px 0 16px; font-size: 22px; }

/* Action grid (Home) */
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.action-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 14px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  font-family: inherit;
}
.action-card:hover { transform: translateY(-2px); box-shadow: 0 8px 16px rgba(0,0,0,0.08); }
.action-icon { font-size: 32px; margin-bottom: 8px; }
.action-label { font-weight: 600; font-size: 14px; color: var(--primary); margin-bottom: 4px; }
.action-sub { font-size: 11px; color: var(--text-dim); }
.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--danger);
  color: white;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}
.badge.hidden { display: none; }

/* Cards / fieldset */
fieldset.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
fieldset.card legend {
  padding: 0 8px;
  font-weight: 600;
  color: var(--primary);
  font-size: 14px;
}
fieldset.card.highlight {
  background: linear-gradient(135deg, #eff6ff, #ffffff);
  border-color: var(--primary);
}

/* Forms */
label.lbl, label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 8px 0 4px;
}
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: white;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(12, 90, 117, 0.1);
}
input:read-only { background: #f9fafb; color: var(--text-dim); }
textarea { resize: vertical; min-height: 44px; }

/* Layout helpers */
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.col { flex: 1; min-width: 140px; }
.col-2 { flex: 2; min-width: 220px; }
.text-dim { color: var(--text-dim); }
.small { font-size: 12px; line-height: 1.4; }
.lbl-mini { font-size: 11px; color: var(--text-dim); }

/* Buttons */
.btn {
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { filter: brightness(0.92); }
.btn-danger { background: var(--danger); color: white; }
.btn-block { display: block; width: 100%; margin-top: 16px; padding: 14px; font-size: 16px; }
.btn-small { padding: 6px 10px; font-size: 12px; }

/* List */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.li-title { font-weight: 600; color: var(--primary); font-size: 14px; }
.li-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.empty-state {
  padding: 30px 20px;
  text-align: center;
  color: var(--text-dim);
  background: white;
  border-radius: 10px;
  border: 1px dashed var(--border);
}

/* Calendar controls */
.calendar-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin: 8px 0 4px;
}
.cal-label {
  font-weight: 700;
  color: var(--primary);
  font-size: 16px;
  min-width: 180px;
  text-align: center;
  text-transform: capitalize;
}

/* Brigada card */
.brigada-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  border-left: 4px solid var(--primary);
}
.brigada-card.completa { border-left-color: var(--success); opacity: 0.85; }
.brigada-card.parcial { border-left-color: var(--warning); }
.brigada-fecha {
  display: inline-block;
  background: var(--primary);
  color: white;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}
.brigada-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; flex-wrap: wrap; }
.inscrito-pill {
  background: var(--success);
  color: white;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
}
.inscrito-pill.vacio { background: #e5e7eb; color: var(--text-dim); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: white;
  border-radius: 12px;
  padding: 20px;
  max-width: 560px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
}
.modal-box h2 { margin: 0 0 14px; color: var(--primary); font-size: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* Mensajes */
.msg { margin: 10px 0; font-size: 13px; }
.msg.ok { color: var(--success); }
.msg.error { color: var(--danger); }

/* Firma canvas */
.firma-canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 180px;
  background: white;
  border: 2px dashed var(--border);
  border-radius: 8px;
  touch-action: none;
}
.firma-actions { display: flex; justify-content: flex-end; margin-top: 4px; }

/* ============= BANNER BRIGADA ACTIVA ============= */
.brigada-banner {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 18px;
  box-shadow: 0 4px 14px rgba(12,90,117,0.15);
}
.brigada-banner.activa {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  box-shadow: 0 4px 14px rgba(22,163,74,0.2);
}
.brigada-banner-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.brigada-icon { font-size: 32px; }
.brigada-info { flex: 1; min-width: 200px; }
.brigada-titulo { font-weight: 700; font-size: 16px; }
.brigada-sub { font-size: 12px; opacity: 0.9; margin-top: 2px; }
.brigada-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.brigada-banner .btn {
  background: rgba(255,255,255,0.22);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  font-size: 12px;
  padding: 6px 12px;
}
.brigada-banner .btn:hover { background: rgba(255,255,255,0.32); }
.brigada-banner .btn.btn-primary { background: var(--accent); color: var(--primary); border-color: var(--accent); font-weight: 700; }

/* ============= SEMÁFORO IMC TIPO REGLA ============= */
.imc-card {
  background: linear-gradient(180deg, #f8fafc 0%, white 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 14px 0 4px;
}
.imc-card.hidden { display: none; }
.imc-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.imc-card-titulo {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.imc-card-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.imc-numero {
  text-align: right;
  line-height: 1;
}
.imc-num {
  font-size: 38px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -1px;
}
.imc-num-lbl { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.imc-clasif {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  margin: 8px 0 16px;
  letter-spacing: 0.5px;
  padding: 8px;
  border-radius: 8px;
  background: #f1f5f9;
  color: var(--text-dim);
  transition: all 0.3s;
}
.imc-clasif.imc-bajo      { background: rgba(37, 99, 235, 0.12); color: #1e40af; }
.imc-clasif.imc-normal    { background: rgba(22, 163, 74, 0.12); color: #15803d; }
.imc-clasif.imc-sobrepeso { background: rgba(234, 179, 8, 0.18); color: #854d0e; }
.imc-clasif.imc-ob1       { background: rgba(234, 88, 12, 0.15); color: #9a3412; }
.imc-clasif.imc-ob2       { background: rgba(220, 38, 38, 0.15); color: #991b1b; }
.imc-clasif.imc-ob3       { background: rgba(127, 29, 29, 0.18); color: #450a0a; }

/* La regla horizontal con 6 segmentos */
.imc-regla {
  position: relative;
  margin: 0 4px 30px;
}
.imc-segs {
  display: flex;
  height: 14px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.15);
}
.imc-seg {
  flex: 1;
  position: relative;
}
.imc-marker {
  position: absolute;
  top: -14px;
  left: 0%;
  transform: translateX(-50%);
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
  transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.25));
  pointer-events: none;
}
.imc-leyenda {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-top: 8px;
}
.imc-leyenda-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.3;
}
.imc-leyenda-item .dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-bottom: 2px;
}
.imc-leyenda-item small {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 9px;
}

@media (max-width: 600px) {
  .imc-leyenda { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .imc-num { font-size: 30px; }
}

/* Compat con código viejo del semáforo simple (por si queda) */
.imc-semaforo { display: none; }
.imc-bajo { background: #2563eb; }
.imc-normal { background: #16a34a; }
.imc-sobrepeso { background: #eab308; }
.imc-ob1 { background: #ea580c; }
.imc-ob2 { background: #dc2626; }
.imc-ob3 { background: #7f1d1d; }

/* ============= INFORME CORPORATIVO ============= */
.informe-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 16px;
}
.informe-header h2 { font-size: 22px; margin-bottom: 4px; font-weight: 800; }
.informe-header .meta { font-size: 13px; opacity: 0.9; }
.informe-header .empresa-tag {
  display: inline-block;
  background: var(--accent);
  color: var(--primary);
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  margin-top: 6px;
}
.informe-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 22px 0 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent);
}

/* Informe del día */
.informe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.informe-stat {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}
.informe-stat .stat-num {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.informe-stat .stat-lbl {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.informe-stat.alerta .stat-num { color: var(--danger); }
.informe-stat.ok .stat-num { color: var(--success); }
.informe-stat.warn .stat-num { color: var(--warning); }

.alertas-list {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 10px;
  padding: 14px;
  margin: 12px 0;
}
.alertas-list h4 { color: var(--danger); font-size: 14px; margin-bottom: 8px; }
.alertas-list .alerta-item {
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px dashed #fecaca;
}
.alertas-list .alerta-item:last-child { border-bottom: none; }

/* Resultado FINDRISC */
.resultado-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.big-number { font-size: 28px; font-weight: 700; color: var(--primary); }
.big-text { font-size: 18px; font-weight: 700; color: var(--primary); }
.recomendacion {
  background: #fffbeb;
  border-left: 4px solid var(--accent);
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}
.recomendacion.riesgo-bajo { background: #f0fdf4; border-color: var(--success); }
.recomendacion.riesgo-moderado { background: #fffbeb; border-color: var(--warning); }
.recomendacion.riesgo-alto { background: #fef2f2; border-color: var(--danger); }

/* FINDRISC preguntas */
.pregunta {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.pregunta-titulo { font-weight: 600; color: var(--primary); margin-bottom: 8px; font-size: 14px; }
.pregunta-opcion {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 13px;
}
.pregunta-opcion:hover { background: #f9fafb; }
.pregunta-opcion.selected { background: #eff6ff; border-color: var(--primary); }
.pregunta-opcion .puntos {
  margin-left: auto;
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 2px solid var(--border); }
.tab {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  font-family: inherit;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 200;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* Loading */
body.loading { cursor: wait; }
body.loading::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  z-index: 999;
  animation: loading-bar 1s infinite;
}
@keyframes loading-bar {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Mobile */
@media (max-width: 600px) {
  .content { padding: 14px; }
  .col, .col-2 { min-width: 100%; }
  .greeting { font-size: 18px; }
}
