:root {
  --fondo: #f3f5f4;
  --tarjeta: #ffffff;
  --texto: #1d2a27;
  --tenue: #5f6f6b;
  --borde: #dfe5e3;
  --acento: #0f6e68;
  --acento-oscuro: #0b5650;
  --acento-suave: #e3f1ef;
  --rojo: #b3261e;
  --rojo-suave: #fbeaea;
  --ambar-suave: #fff6e0;
  --radio: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--texto);
  background: var(--fondo);
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
.tenue { color: var(--tenue); font-weight: 400; }
.error { color: var(--rojo); background: var(--rojo-suave); padding: .5rem .75rem; border-radius: 6px; margin: 0; }

input, select, button { font: inherit; }
input, select {
  border: 1px solid var(--borde);
  border-radius: 6px;
  padding: .45rem .6rem;
  background: #fff;
  color: var(--texto);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--acento); outline-offset: 1px; }
label { display: grid; gap: .25rem; font-size: .85rem; color: var(--tenue); }

.boton {
  border: 1px solid var(--borde);
  background: #fff;
  color: var(--texto);
  border-radius: 6px;
  padding: .5rem .9rem;
  cursor: pointer;
}
.boton:hover { background: #f6f8f7; }
.boton:disabled { opacity: .55; cursor: progress; }
.boton--primario { background: var(--acento); border-color: var(--acento); color: #fff; font-weight: 600; }
.boton--primario:hover { background: var(--acento-oscuro); }
.boton--grande { padding: .75rem 1.2rem; font-size: 1rem; width: 100%; }
.boton--chico { padding: .3rem .6rem; font-size: .82rem; }
.boton--fantasma { background: transparent; border-color: rgba(255,255,255,.4); color: #fff; }
.boton--fantasma:hover { background: rgba(255,255,255,.12); }

.tarjeta {
  background: var(--tarjeta);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 1.1rem 1.25rem;
}

/* --- Ingreso --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login__caja { width: min(360px, 100%); display: grid; gap: .9rem; text-align: center; padding: 2rem 1.75rem; }
.login__caja label { text-align: left; }
.login__caja p { margin: 0; }
.login__logo { height: 56px; justify-self: center; }

/* --- Barra superior --- */
.barra {
  background: var(--acento);
  color: #fff;
  display: flex; justify-content: space-between; align-items: center;
  padding: .6rem 1.25rem;
}
.barra__marca { display: flex; align-items: center; gap: .7rem; font-weight: 600; }
.barra__marca img { height: 30px; background: #fff; border-radius: 6px; padding: 2px 4px; }
.barra__usuario { display: flex; align-items: center; gap: .8rem; font-size: .9rem; }

.contenido { max-width: 1400px; margin: 0 auto; padding: 1.25rem; display: grid; gap: 1rem; }

/* --- Consulta --- */
.consulta h2 { margin-bottom: .8rem; }
.consulta__grilla { display: grid; grid-template-columns: minmax(280px, 1.3fr) minmax(260px, 1fr); gap: 1.5rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: .5rem; }
.medicos__acciones { display: flex; gap: .4rem; margin-bottom: .5rem; }
.medicos__acciones input { flex: 1; min-width: 0; }
.medicos__lista {
  list-style: none; margin: 0; padding: .25rem;
  border: 1px solid var(--borde); border-radius: 6px;
  max-height: 260px; overflow: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 2px;
}
.medicos__lista label {
  display: flex; align-items: center; gap: .5rem;
  padding: .4rem .5rem; border-radius: 5px; cursor: pointer;
  color: var(--texto); font-size: .9rem;
}
.medicos__lista label:hover { background: #f4f7f6; }
.medicos__lista input { accent-color: var(--acento); width: 16px; height: 16px; }
.medicos__lista small { color: var(--tenue); margin-left: auto; }
.periodo { display: grid; gap: 1rem; align-content: start; }
.periodo__fechas { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.periodo__rapidos { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }

/* --- Avance --- */
.avance { display: grid; gap: .6rem; }
.avance__cabeza { display: flex; justify-content: space-between; gap: 1rem; }
.barra-progreso { height: 8px; background: var(--acento-suave); border-radius: 99px; overflow: hidden; }
#avance-barra { height: 100%; width: 0; background: var(--acento); transition: width .4s; }
#avance-log { max-height: 220px; overflow: auto; background: #1e2524; color: #d6e2df; padding: .75rem; border-radius: 6px; font-size: .78rem; margin: .5rem 0 0; white-space: pre-wrap; }
summary { cursor: pointer; color: var(--tenue); font-size: .85rem; }

/* --- Resultado --- */
#resultado { display: grid; gap: 1rem; }
.resultado__cabeza { display: flex; justify-content: space-between; align-items: end; gap: 1rem; }
.resultado__cabeza p { margin: .2rem 0 0; }
.alerta { padding: .65rem .9rem; border-radius: 6px; font-size: .88rem; margin: 0 0 .5rem; }
.alerta--error { background: var(--rojo-suave); color: var(--rojo); }
.alerta--aviso { background: var(--ambar-suave); color: #6b4e00; }
.alerta--info { background: #eef3f2; color: #3b4a46; }
.alerta ul { margin: .3rem 0 0; padding-left: 1.2rem; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.kpi { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: .9rem 1.1rem; display: grid; gap: .25rem; }
.kpi span { color: var(--tenue); font-size: .82rem; }
.kpi strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.kpi strong.negativo { color: var(--rojo); }

.tabla-tarjeta { padding: 0; overflow: hidden; }
.filtros { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; padding: 1rem 1.25rem; border-bottom: 1px solid var(--borde); }
.filtros select { max-width: 280px; }
.filtros__buscar { flex: 1; min-width: 200px; }

.pestanas { display: flex; gap: .25rem; padding: 0 1.25rem; border-bottom: 1px solid var(--borde); }
.pestanas button {
  border: 0; background: none; padding: .75rem .9rem; cursor: pointer; color: var(--tenue);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.pestanas button[aria-selected="true"] { color: var(--acento); border-bottom-color: var(--acento); font-weight: 600; }
.pestanas span { background: #eef2f1; border-radius: 99px; padding: .05rem .5rem; font-size: .78rem; margin-left: .2rem; }

.tabla-envoltura { overflow: auto; max-height: 62vh; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { padding: .45rem .7rem; text-align: left; white-space: nowrap; border-bottom: 1px solid #edf1f0; }
thead th { position: sticky; top: 0; background: #f7f9f8; z-index: 1; font-weight: 600; color: #3b4a46; border-bottom: 1px solid var(--borde); }
tbody tr:hover { background: #f8fbfa; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.negativo { color: var(--rojo); }
td.largo { white-space: normal; min-width: 260px; }
tfoot td { position: sticky; bottom: 0; background: var(--acento-suave); font-weight: 600; border-top: 1px solid var(--borde); }
.tabla-vacia { text-align: center; color: var(--tenue); padding: 2rem; white-space: normal; }
.tabla-pie { padding: .6rem 1.25rem; margin: 0; font-size: .82rem; }
#btn-mas { margin: 0 1.25rem 1rem; }

@media (max-width: 860px) {
  .consulta__grilla { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .barra__marca span { display: none; }
}
