/* =========================================================================
   IMED · Capa de identidad sobre Bootstrap 5
   -------------------------------------------------------------------------
   Identidad: azul tinta (la pantalla del ecógrafo) y verde azulado clínico.
   Superficies elevadas, sin bordes duros: la jerarquía la dan la sombra y el
   espacio. Escala de 8 puntos. Números tabulares en órdenes, documentos y
   fechas, que son datos y se leen en columna.
   ========================================================================= */

:root {
    --tinta: #0f1b2a;
    --tinta-suave: #1c2c40;
    --papel: #eef2f7;
    --tarjeta: #ffffff;
    --linea: #e3e8ef;
    --linea-suave: #eef1f6;

    --texto: #16233a;
    --apagado: #61708a;
    --tenue: #8a97ab;

    --acento: #0e7c7b;
    --acento-fuerte: #0a6362;
    --acento-claro: #e4f2f1;
    --ambar: #b45309;
    --ambar-claro: #fdf2e3;
    --indigo: #4338ca;
    --indigo-claro: #ecebfb;
    --verde: #15803d;
    --verde-claro: #e7f4ec;
    --rojo: #b3261e;
    --rojo-claro: #fdecea;

    --e1: 4px;  --e2: 8px;  --e3: 12px; --e4: 16px;
    --e5: 24px; --e6: 32px; --e7: 48px;

    --radio: 14px;
    --radio-chico: 10px;
    --nivel1: 0 1px 2px rgba(16, 35, 58, .06), 0 1px 3px rgba(16, 35, 58, .08);
    --nivel2: 0 2px 6px rgba(16, 35, 58, .08), 0 6px 16px -8px rgba(16, 35, 58, .18);
    --nivel3: 0 8px 28px -10px rgba(16, 35, 58, .30);
}

/* ------------------------------------------------------------------ base */
body {
    background: var(--papel);
    color: var(--texto);
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5 { letter-spacing: -.01em; }

.numero-tabular,
.tabla-estudios td:first-child,
.orden,
.codigo-acceso,
.dato-valor {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.rotulo {
    font-size: 10.5px;
    letter-spacing: .12em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--apagado);
}
.rotulo-acento { color: var(--acento); }
.titulo-pantalla { font-size: 21px; font-weight: 700; margin: 0; }

/* --------------------------------------------------------- barra superior */
.barra-superior {
    background: var(--tinta);
    color: #eaf0f7;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--nivel2);
}
.barra-superior .navbar-brand {
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
}
/* Se conserva por compatibilidad con pantallas que todavía lo usan. */
.marca-punto {
    width: 11px; height: 11px;
    border-radius: 3px;
    background: var(--acento);
    display: inline-block;
    margin-right: var(--e2);
    transform: rotate(45deg);
    box-shadow: 0 0 0 4px rgba(14, 124, 123, .18);
}
.barra-superior .nav-link {
    color: #b6c4d6;
    font-weight: 500;
    padding: var(--e2) var(--e3);
    border-radius: var(--radio-chico);
    transition: background .15s, color .15s;
}
.barra-superior .nav-link:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.barra-superior .nav-link.activo {
    color: #fff;
    background: rgba(14, 124, 123, .35);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .10);
}
.barra-superior .dropdown-menu {
    border: 0;
    box-shadow: var(--nivel3);
    border-radius: var(--radio-chico);
}

/* --------------------------------------------------------------- tarjetas */
.panel {
    background: var(--tarjeta);
    border: 0;
    border-radius: var(--radio);
    box-shadow: var(--nivel1);
    overflow: hidden;
}
.panel + .panel { margin-top: var(--e4); }
.panel-cabecera {
    padding: var(--e3) var(--e5);
    border-bottom: 1px solid var(--linea-suave);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--e3);
    flex-wrap: wrap;
    min-height: 52px;
    background: #fcfdfe;
}
.panel-cuerpo { padding: var(--e5); }

/* ------------------------------------------------------------------ chips */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 1.2;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-pendiente { background: #eef2f7; color: #4a5a72; border-color: #e0e6ee; }
.chip-borrador  { background: var(--ambar-claro); color: var(--ambar); border-color: #f4dfc4; }
.chip-cerrado   { background: var(--indigo-claro); color: var(--indigo); border-color: #dbd9f8; }
.chip-completo  { background: var(--acento-claro); color: var(--acento); border-color: #cbe4e3; }
.chip-entregado { background: var(--verde-claro); color: var(--verde); border-color: #cbe7d5; }

/* -------------------------------------------- riel del circuito (elemento
   distintivo): cinco tramos que dicen en qué punto real está el estudio. */
.riel { display: flex; gap: 3px; align-items: center; }
.riel span {
    display: block;
    height: 5px;
    width: 20px;
    border-radius: 3px;
    background: #dde4ed;
    transition: background .2s;
}
.riel span.hecho { background: var(--acento); }
.riel span.actual { background: var(--ambar); box-shadow: 0 0 0 3px var(--ambar-claro); }
.riel-grande { width: 100%; gap: var(--e1); }
.riel-grande span { height: 7px; width: 100%; }
.riel-etiquetas {
    display: flex;
    justify-content: space-between;
    margin-top: var(--e2);
    font-size: 10.5px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--tenue);
}
.riel-etiquetas span { flex: 1; text-align: center; }
.riel-etiquetas span:first-child { text-align: left; }
.riel-etiquetas span:last-child { text-align: right; }

/* --------------------------------------------------------------- métricas */
.metricas {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--e3);
}
.metrica {
    position: relative;
    background: var(--tarjeta);
    border: 0;
    border-radius: var(--radio);
    box-shadow: var(--nivel1);
    padding: var(--e4) var(--e4) var(--e3);
    cursor: pointer;
    text-align: left;
    transition: box-shadow .18s, transform .18s;
    overflow: hidden;
}
.metrica::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: transparent;
    transition: background .18s;
}
.metrica:hover { box-shadow: var(--nivel2); transform: translateY(-1px); }
.metrica.activa { box-shadow: var(--nivel2); }
.metrica.activa::before { background: var(--acento); }
.metrica .valor {
    font-size: 30px;
    font-weight: 700;
    line-height: 1.05;
    font-variant-numeric: tabular-nums;
}
.metrica .etiqueta {
    display: block;
    margin-top: var(--e1);
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--apagado);
    font-weight: 600;
}
@media (max-width: 992px) { .metricas { grid-template-columns: repeat(2, 1fr); } }

/* ----------------------------------------------------------------- tablas */
.tabla-estudios { width: 100%; border-collapse: separate; border-spacing: 0; }
.tabla-estudios thead th {
    font-size: 10.5px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--apagado);
    font-weight: 700;
    padding: var(--e3) var(--e4);
    background: #f7f9fc;
    border-bottom: 1px solid var(--linea);
    white-space: nowrap;
}
.tabla-estudios tbody td {
    padding: var(--e3) var(--e4);
    border-bottom: 1px solid var(--linea-suave);
    vertical-align: middle;
}
.tabla-estudios tbody tr { cursor: pointer; transition: background .12s; }
.tabla-estudios tbody tr:hover { background: #f6f9fc; }
.tabla-estudios tbody tr:last-child td { border-bottom: 0; }
.tabla-estudios tbody tr:focus-visible { outline: 2px solid var(--acento); outline-offset: -2px; }
.paciente { font-weight: 600; }
.sub { color: var(--apagado); font-size: 12.5px; }
.tabla-simple th {
    font-size: 10.5px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--apagado);
}

.lista-movil { display: none; }
@media (max-width: 992px) {
    .tabla-envoltorio { display: none; }
    .lista-movil { display: block; }
}
.tarjeta-estudio {
    border: 0;
    border-radius: var(--radio);
    background: #fff;
    box-shadow: var(--nivel1);
    padding: var(--e4);
    margin-bottom: var(--e3);
    display: block;
    text-decoration: none;
    color: inherit;
    transition: box-shadow .15s, transform .15s;
}
.tarjeta-estudio:active { transform: scale(.995); box-shadow: var(--nivel2); }

/* ----------------------------------------------------------------- editor */
.editor-rico {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--linea);
    border-radius: var(--radio);
    background: #fff;
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
}
.editor-rico:focus-within {
    border-color: var(--acento);
    box-shadow: 0 0 0 3px rgba(14, 124, 123, .14);
}
.editor-barra {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: var(--e2) var(--e3);
    border-bottom: 1px solid var(--linea-suave);
    background: #f8fafc;
    flex: 0 0 auto;
}
.editor-boton {
    border: 0;
    background: transparent;
    color: var(--apagado);
    width: 34px;
    height: 32px;
    border-radius: var(--radio-chico);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: background .12s, color .12s;
}
.editor-boton:hover { background: #e9eef4; color: var(--texto); }
.editor-boton.activo { background: var(--acento-claro); color: var(--acento); }
.editor-separador { width: 1px; height: 20px; background: var(--linea); margin: 0 6px; }
.editor-colores { display: flex; gap: 5px; margin-left: auto; padding-left: var(--e2); }
.editor-color {
    width: 21px; height: 21px; border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(16, 35, 58, .18);
    cursor: pointer; padding: 0;
    transition: transform .12s;
}
.editor-color:hover { transform: scale(1.15); }
.editor-area {
    flex: 1 1 auto;
    min-height: 220px;
    max-height: 60vh;
    padding: var(--e5);
    outline: none;
    font-size: 15.5px;
    line-height: 1.7;
    overflow-y: auto;
    -webkit-user-select: text;
    user-select: text;
    overscroll-behavior: contain;
    word-break: break-word;
}
.editor-area:empty::before,
.editor-area p:only-child:empty::before {
    content: attr(data-placeholder);
    color: var(--tenue);
}

.editor-area h3, .informe-rico h3 {
    font-size: 12.5px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--acento);
    font-weight: 700;
    margin: var(--e5) 0 var(--e2);
}
.editor-area h3:first-child, .informe-rico h3:first-child { margin-top: 0; }
.editor-area h4, .informe-rico h4 { font-size: 14.5px; font-weight: 700; margin: var(--e4) 0 var(--e1); }
.editor-area p, .informe-rico p { margin: 0 0 var(--e2); }
.editor-area ul, .editor-area ol,
.informe-rico ul, .informe-rico ol { margin: 0 0 var(--e3); padding-left: var(--e5); }
.editor-area li, .informe-rico li { margin-bottom: var(--e1); }

.informe-rico {
    background: #fbfcfe;
    border: 1px solid var(--linea-suave);
    border-radius: var(--radio);
    padding: var(--e5);
    line-height: 1.7;
}
.informe-cerrado {
    white-space: pre-wrap;
    line-height: 1.7;
    background: #fbfcfe;
    border: 1px solid var(--linea-suave);
    border-radius: var(--radio);
    padding: var(--e5);
}
.sello-bloqueo {
    display: inline-flex; align-items: center; gap: var(--e2);
    background: var(--indigo-claro); color: var(--indigo);
    border-radius: var(--radio-chico);
    padding: var(--e2) var(--e3);
    font-size: 13px; font-weight: 600;
}
.estado-guardado { font-size: 12.5px; color: var(--apagado); }
.grabando { color: var(--rojo) !important; animation: latido 1.2s infinite; }
@keyframes latido { 50% { opacity: .35; } }

/* --------------------------------------------------------------- imágenes */
.grilla-imagenes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--e3);
}
.miniatura {
    border: 0;
    border-radius: var(--radio-chico);
    overflow: hidden;
    background: #fff;
    position: relative;
    box-shadow: var(--nivel1);
    transition: box-shadow .15s;
}
.miniatura:hover { box-shadow: var(--nivel2); }
.miniatura .lienzo {
    aspect-ratio: 4 / 3;
    background: #0d1520;
    display: flex; align-items: center; justify-content: center;
    cursor: zoom-in;
}
.miniatura img { width: 100%; height: 100%; object-fit: contain; }
.miniatura .pie { padding: var(--e2) var(--e3); font-size: 12.5px; }
.miniatura .indice {
    position: absolute; top: var(--e2); left: var(--e2);
    background: rgba(13, 21, 32, .82); color: #fff;
    font-size: 11px; font-weight: 700;
    padding: 2px 8px; border-radius: 999px;
    font-variant-numeric: tabular-nums;
}
.miniatura[draggable="true"] { cursor: grab; }
.miniatura.arrastrando { opacity: .45; }

.visor { background: rgba(8, 14, 23, .97); }
.visor .modal-content { background: transparent; border: 0; box-shadow: none; }
.visor-lienzo { height: 78vh; display: flex; align-items: center; justify-content: center; overflow: auto; }
.visor-lienzo img, .visor-lienzo video {
    max-width: 100%; max-height: 78vh;
    transition: transform .12s ease-out;
    transform-origin: center center;
}
.visor-barra {
    color: #cfd8e3;
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--e3); padding: var(--e3) var(--e1);
}
.visor-titulo { color: #fff; font-weight: 600; }

/* ----------------------------------------------------------------- portal */
.portal { background: var(--papel); min-height: 100vh; }
.portal-caja { max-width: 760px; margin: 0 auto; padding: var(--e5) var(--e4) var(--e7); }
.portal-encabezado {
    background: var(--tinta);
    color: #fff;
    padding: var(--e5) 0;
    box-shadow: var(--nivel2);
}
.codigo-acceso { font-size: 32px; letter-spacing: 12px; text-align: center; font-weight: 700; }
.entrada-codigo {
    font-size: 26px; letter-spacing: 10px; text-align: center; font-weight: 700;
    padding: var(--e3); border-radius: var(--radio-chico);
}

/* -------------------------------------------------------------- controles */
.btn {
    border-radius: var(--radio-chico);
    font-weight: 600;
    padding: 9px 18px;
    transition: background .15s, box-shadow .15s, transform .08s;
}
.btn:active { transform: translateY(1px); }
.btn-lg { padding: 12px 24px; }
.btn-sm { padding: 6px 12px; border-radius: 9px; }
.btn-acento {
    background: var(--acento); border-color: var(--acento); color: #fff;
    box-shadow: 0 1px 2px rgba(14, 124, 123, .30);
}
.btn-acento:hover, .btn-acento:focus {
    background: var(--acento-fuerte); border-color: var(--acento-fuerte); color: #fff;
    box-shadow: var(--nivel2);
}
.btn-tinta { background: var(--tinta); border-color: var(--tinta); color: #fff; }
.btn-tinta:hover { background: var(--tinta-suave); border-color: var(--tinta-suave); color: #fff; }
.btn-outline-secondary { border-color: var(--linea); color: var(--apagado); }
.btn-outline-secondary:hover { background: #eef2f7; border-color: #cfd8e4; color: var(--texto); }

.form-control, .form-select {
    border-radius: var(--radio-chico);
    border-color: var(--linea);
    padding: 9px 12px;
    min-height: 42px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--acento);
    box-shadow: 0 0 0 3px rgba(14, 124, 123, .14);
}
.form-label { font-size: 13px; font-weight: 600; color: var(--texto); margin-bottom: var(--e1); }
.form-text { color: var(--apagado); }
.input-group-text { border-radius: var(--radio-chico); border-color: var(--linea); }

.nav-tabs { border-bottom: 1px solid var(--linea); gap: var(--e1); }
.nav-tabs .nav-link {
    color: var(--apagado);
    font-weight: 600;
    border: 0;
    border-bottom: 2px solid transparent;
    padding: var(--e3) var(--e4);
    border-radius: var(--radio-chico) var(--radio-chico) 0 0;
}
.nav-tabs .nav-link:hover { background: rgba(14, 124, 123, .06); color: var(--texto); }
.nav-tabs .nav-link.active {
    color: var(--acento);
    border-bottom-color: var(--acento);
    background: transparent;
}

.modal-content { border: 0; border-radius: var(--radio); box-shadow: var(--nivel3); }
.modal-header, .modal-footer { border-color: var(--linea-suave); padding: var(--e4) var(--e5); }
.modal-body { padding: var(--e5); }

/* ------------------------------------------------------------- utilidades */
.enlace-discreto { color: var(--acento); text-decoration: none; font-weight: 600; }
.enlace-discreto:hover { text-decoration: underline; }
.dato-etiqueta {
    font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
    color: var(--apagado); font-weight: 600;
}
.dato-valor { font-weight: 600; }
.vacio { text-align: center; padding: var(--e7) var(--e4); color: var(--apagado); }
.vacio i { font-size: 34px; color: #b9c5d4; display: block; margin-bottom: var(--e2); }
.alert { border: 0; border-radius: var(--radio-chico); box-shadow: var(--nivel1); }
.alert-danger { background: var(--rojo-claro); color: var(--rojo); }
.alert-warning { background: var(--ambar-claro); color: var(--ambar); }
:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }

#avisos {
    position: fixed; right: var(--e4); bottom: var(--e4); z-index: 1080;
    display: flex; flex-direction: column; gap: var(--e2);
    max-width: min(92vw, 400px);
}
.aviso {
    background: var(--tinta); color: #fff;
    padding: var(--e3) var(--e4); border-radius: var(--radio-chico);
    box-shadow: var(--nivel3); font-size: 14px;
    display: flex; gap: var(--e2); align-items: flex-start;
    animation: entra .18s ease-out;
}
.aviso.error { background: var(--rojo); }
.aviso.ok { background: var(--acento); }
@keyframes entra { from { opacity: 0; transform: translateY(8px); } }

/* ----------------------------------------------------- teléfono y tablets */
@media (max-width: 992px) {
    .panel-cuerpo { padding: var(--e4); }
    .panel-cabecera { padding: var(--e3) var(--e4); }
    .titulo-pantalla { font-size: 19px; }
    #raizInformar .editor-area { min-height: 46vh !important; max-height: none !important; }
    #raizInformar .panel-cabecera { position: static; }
    #raizInformar #referenciaClinica { gap: var(--e4) !important; }
}
@media (max-width: 576px) {
    .editor-colores { margin-left: 0; width: 100%; padding-top: var(--e2); }
    .editor-area { max-height: none; padding: var(--e4); }
    .metrica { padding: var(--e3); }
    .metrica .valor { font-size: 24px; }
    #avisos { right: var(--e2); left: var(--e2); bottom: var(--e2); max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, .metrica, .btn, .aviso, .riel span { transition: none !important; animation: none !important; }
}

@media print {
    .barra-superior, .no-imprimir, #avisos { display: none !important; }
    body { background: #fff; }
    .panel { box-shadow: none; border: 1px solid var(--linea); }
}

/* Selectores de tipografía dentro de la barra del editor */
.editor-selector {
    border: 1px solid var(--linea);
    background: #fff;
    color: var(--texto);
    border-radius: 8px;
    font-size: 12.5px;
    height: 30px;
    padding: 0 6px;
    max-width: 150px;
    cursor: pointer;
}
.editor-selector:focus { outline: 2px solid var(--acento); outline-offset: 1px; }

/* La ventana de plantillas nunca debe tapar el botón de guardar: el cuerpo
   desplaza y el pie queda siempre a la vista. */
.modal-dialog-scrollable .modal-content { max-height: calc(100vh - 3rem); }
.modal-dialog-scrollable .modal-body { overflow-y: auto; }
.modal-footer { position: sticky; bottom: 0; background: #fff; z-index: 2; }
@media (max-height: 760px) {
    #modalPlantilla .editor-area { max-height: 26vh; min-height: 140px; }
}

/* Ventana encima de otra ventana: la de campos se abre desde la de plantillas
   y tiene que quedar por delante, junto con su fondo oscurecido. */
#modalCampos { z-index: 1075; }
.modal-backdrop.sobre-modal { z-index: 1070; }

/* ------------------------------------------------------- marca de la plataforma
   El isotipo (la nube con el 7) va sobre el azul tinta de la barra: el logo
   completo llevaría texto oscuro y se perdería contra el fondo. El nombre se
   arma con letra ancha y un degradado que retoma los colores del logo. */
.marca {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    padding: 2px 0;
}
/* En el acceso, el nombre va debajo del logo y más discreto: el protagonista
   ahí es el logo completo. */
.marca-apilada { display: block; text-align: center; }
.marca-apilada .marca-nombre { font-size: 15px; letter-spacing: .16em; }
.marca-icono {
    height: 30px;
    width: auto;
    display: block;
    flex: 0 0 auto;
    /* Margen además del gap: los navegadores viejos no soportan gap en flex. */
    margin-right: 10px;
}
.marca-nombre {
    font-family: "Segoe UI Semibold", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: .06em;
    line-height: 1.1;
    background: linear-gradient(96deg, #4fd1c5 0%, #59a5e8 55%, #ffffff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: #ffffff;                     /* respaldo si el navegador no recorta */
    -webkit-text-fill-color: transparent;
}
/* Sobre fondo claro el degradado se invierte para conservar el contraste. */
.marca-clara .marca-nombre {
    background: linear-gradient(96deg, #0e7c7b 0%, #2f6fb5 60%, #16233a 100%);
    color: var(--tinta);
}
.marca-completa {
    display: block;
    margin: 0 auto;
    width: min(280px, 74%);
    height: auto;
}
.barra-superior .marca:hover .marca-nombre { filter: brightness(1.12); }

@media (max-width: 576px) {
    .marca-icono { height: 26px; }
    .marca-nombre { font-size: 16px; letter-spacing: .04em; }
}
