:root {
  --bg: #f5f7fb; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { margin: 0 0 4px; font-size: 1.7rem; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 20px; }

.topbar { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.marca { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.topbar nav { display: flex; gap: 16px; align-items: center; }
.topbar nav a.activo { font-weight: 700; }

.boton, button { display: inline-block; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-size: .95rem; }
.boton:hover, button:hover { filter: brightness(1.08); text-decoration: none; }
button.peligro { background: transparent; color: var(--bad); padding: 4px 6px; }
input, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }

.aviso { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.aviso-ok { background: #dcfce7; color: #166534; }
.aviso-error { background: #fee2e2; color: #991b1b; }

.vacio { background: var(--card); padding: 32px; border-radius: 12px; text-align: center; }

.tabla-wrap { overflow-x: auto; background: var(--card); border-radius: 12px; border: 1px solid var(--line); }
.tabla { width: 100%; border-collapse: collapse; }
.tabla th, .tabla td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tabla th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.tabla tr:last-child td { border-bottom: 0; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla.compacta th, .tabla.compacta td { padding: 6px 8px; }
.nota { color: var(--muted); font-size: .85rem; margin-left: 18px; }
.punto { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }
.acciones { white-space: nowrap; }
form.en-linea { display: inline-flex; gap: 6px; align-items: center; }
form.en-linea input { width: 120px; padding: 6px 8px; }
form.en-linea button { padding: 6px 10px; }

.etiqueta { padding: 3px 9px; border-radius: 999px; font-size: .85rem; font-weight: 600; white-space: nowrap; }
.etiqueta-ok { background: #dcfce7; color: #166534; }
.etiqueta-bajo { background: #fef3c7; color: #92400e; }
.etiqueta-critico { background: #ffedd5; color: #9a3412; }
.etiqueta-agotado { background: #fee2e2; color: #991b1b; }
.etiqueta-ok-txt { color: var(--ok); }
.etiqueta-bajo-txt, .etiqueta-critico-txt { color: var(--warn); }
.etiqueta-agotado-txt { color: var(--bad); }

.formulario { background: var(--card); padding: 24px; border-radius: 12px; max-width: 640px; display: grid; gap: 16px; }
.formulario label { display: grid; gap: 6px; font-weight: 600; }
.formulario small { font-weight: 400; color: var(--muted); }
.formulario .fila { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.botones { display: flex; gap: 16px; align-items: center; }

.resumen { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin: 16px 0 20px; }
.tarjeta { background: var(--card); border-radius: 10px; padding: 12px 14px; border-left: 5px solid; }
.tarjeta-nombre { font-weight: 600; }
.tarjeta-dias { font-size: 1.8rem; font-weight: 700; }
.tarjeta-dias span { font-size: .9rem; font-weight: 500; }
.tarjeta-detalle { color: var(--muted); font-size: .85rem; }

.cal-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.cal, .panel { background: var(--card); border-radius: 12px; padding: 16px; border: 1px solid var(--line); }
.cal-nav { display: flex; justify-content: space-between; align-items: center; }
.cal-nav a { font-size: 1.6rem; padding: 0 12px; }
.cal-nav h2 { margin: 0; }
.cal-hoy { display: block; text-align: center; font-size: .85rem; margin: 2px 0 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-cab { text-align: center; font-size: .75rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-dia { min-height: 82px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; display: flex; flex-direction: column; gap: 3px;
  color: var(--text); overflow: hidden; }
a.cal-dia:hover { border-color: var(--accent); text-decoration: none; background: #eff6ff; }
.cal-dia .n { font-weight: 600; font-size: .9rem; }
.cal-dia.fuera { opacity: .45; }
.cal-dia.pasado { background: #f3f4f6; color: #9ca3af; }
.cal-dia.hoy { border: 2px solid var(--accent); }
.cal-dia.hoy .n { color: var(--accent); }
.cal-dia.seleccionado { background: #dbeafe; border: 2px solid #1d4ed8; }
.barras { display: flex; gap: 2px; flex-wrap: wrap; }
.barra { display: inline-block; height: 6px; flex: 1 1 8px; min-width: 6px; border-radius: 3px; }
.barra.llena { background: var(--c); }
.barra.vacia { background: transparent; border: 1px dashed var(--c); opacity: .5; }
.barra.muestra { width: 22px; flex: none; vertical-align: middle; }
.fin { font-size: .7rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leyenda { color: var(--muted); font-size: .85rem; margin-bottom: 0; }

.panel .total { margin-top: 14px; padding: 10px; background: #fef3c7; border-radius: 8px; }
.panel .total.ok { background: #dcfce7; }
.falta { color: var(--bad); }
.ok { color: var(--ok); }
.panel form.en-linea input { width: auto; }

@media (max-width: 860px) {
  .cal-layout { grid-template-columns: 1fr; }
  .formulario .fila { grid-template-columns: 1fr; }
  .cal-dia { min-height: 56px; padding: 2px 3px; }
  .fin { display: none; }
}

/* Sesión y usuarios */
.sesion { display: inline-flex; gap: 10px; align-items: center; padding-left: 12px; border-left: 1px solid var(--line); }
button.enlace { background: transparent; color: var(--muted); padding: 4px 6px; }
button.enlace:hover { color: var(--bad); }
.caja-auth { max-width: 420px; margin: 40px auto; }
.caja-auth .formulario { max-width: none; }
.nota-auth { color: var(--muted); font-size: .9rem; text-align: center; }
.encabezado { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.etiqueta-admin { background: #e0e7ff; color: #3730a3; }
.formulario fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px 16px; display: grid; gap: 12px; }
.formulario legend { font-weight: 600; padding: 0 6px; }
.formulario label.casilla { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.formulario label.casilla input { width: auto; }
@media (max-width: 860px) {
  .topbar nav { flex-wrap: wrap; }
  .sesion { border-left: 0; padding-left: 0; }
}

/* Citas */
.cal-celda { position: relative; display: flex; }
.cal-celda > .cal-dia { flex: 1; min-width: 0; }
.cita-chip { font-size: .7rem; background: #ede9fe; color: #5b21b6; border-radius: 4px; padding: 1px 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-dia.pasado .cita-chip { background: #e5e7eb; color: #6b7280; }
.cal-dia.con-citas { border-color: #c4b5fd; }
.cal-tip { display: none; position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; width: 260px;
  background: #1f2937; color: #f9fafb; border-radius: 10px; padding: 10px 12px; font-size: .85rem;
  box-shadow: 0 10px 25px rgba(0,0,0,.2); pointer-events: none; }
.cal-celda.tip-izq .cal-tip { left: auto; right: 0; }
.cal-celda:hover .cal-tip, .cal-celda:focus-within .cal-tip { display: block; }
.cal-tip-fecha { font-size: .75rem; color: #9ca3af; text-transform: capitalize; margin-bottom: 6px; }
.cal-tip-cita + .cal-tip-cita { border-top: 1px solid #374151; margin-top: 8px; padding-top: 8px; }
.cal-tip-lugar { color: #d1d5db; margin-top: 2px; }
.cal-tip-nota { margin-top: 4px; white-space: pre-line; color: #e5e7eb; }
.panel-citas { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.panel-citas.separado { margin: 20px 0 0; padding: 16px 0 0; border-bottom: 0; border-top: 1px solid var(--line); }
.panel-citas .encabezado h2 { margin: 0; }
.boton.chico { padding: 4px 10px; font-size: .85rem; }
.lista-citas { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.lista-citas li { background: #f5f3ff; border-left: 4px solid #7c3aed; border-radius: 6px; padding: 8px 10px; font-size: .9rem; }
.cita-lugar { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.cita-nota { margin-top: 4px; white-space: pre-line; font-size: .85rem; }
.eliminar-cita { margin-top: 12px; }
@media (max-width: 860px) {
  .cita-txt { display: none; }
  .cal-tip { width: 220px; }
}

/* Mediciones */
[hidden] { display: none !important; }
select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
.med-chips { display: flex; flex-wrap: wrap; gap: 2px; }
.med-chip { font-size: .65rem; line-height: 1.3; border-radius: 4px; padding: 0 4px; white-space: nowrap;
  background: var(--mbg, #f3f4f6); color: var(--mfg, #374151); font-variant-numeric: tabular-nums; }
.med-chip b { font-weight: 700; }
.med-chip sup { font-size: .55rem; margin-left: 1px; }
.med-presion { --mbg: #fee2e2; --mfg: #991b1b; --mborde: #dc2626; }
.med-pulso { --mbg: #fce7f3; --mfg: #9d174d; --mborde: #db2777; }
.med-glucosa { --mbg: #fef3c7; --mfg: #92400e; --mborde: #d97706; }
.med-saturacion { --mbg: #e0f2fe; --mfg: #075985; --mborde: #0284c7; }
.med-temperatura { --mbg: #ffedd5; --mfg: #9a3412; --mborde: #ea580c; }
.med-peso { --mbg: #dcfce7; --mfg: #166534; --mborde: #16a34a; }
.lista-meds li { background: var(--mbg); border-left-color: var(--mborde); }
.cal-tip-meds { border-top: 1px solid #374151; margin-top: 8px; padding-top: 8px; display: grid; gap: 4px; }
.cal-tip-fecha + .cal-tip-meds { border-top: 0; margin-top: 0; padding-top: 0; }
.cal-tip-hora { color: #9ca3af; font-variant-numeric: tabular-nums; }
.form-medicion { padding: 12px 0 0; gap: 10px; max-width: none; background: none; }
.form-medicion .medicion-campos { display: grid; gap: 10px; }
.form-medicion .fila { gap: 10px; }
.medicion-campos { display: grid; gap: 16px; }
.casillas { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; }
.sub.chico { font-size: .8rem; margin: 10px 0 0; }
@media (max-width: 860px) {
  .med-chip { font-size: .6rem; padding: 0 2px; }
  .med-chip b { display: none; }
}
