/* Detalle rápido de una consulta de Medicina General (Liquid Glass).
   Ventana de solo lectura que abre "Ver detalle" en el Archivo clínico
   (js/modules/medicina-general-module.js → openDetail). */
#mg-detail-modal {
    --mgd-spring: cubic-bezier(.22, 1, .36, 1);
    --mgd-ink: #13283d;
    --mgd-muted: #64798b;
    position: fixed;
    inset: 0;
    z-index: 2147482500;
    display: grid;
    place-items: center;
    padding: 18px;
    font-family: "Inter", "Segoe UI", sans-serif;
    color: var(--mgd-ink);
}
#mg-detail-modal.mgd-overlay {
    background: rgba(9, 27, 43, .5);
    backdrop-filter: blur(3px);
    animation: mgd-fade .2s ease-out;
}
#mg-detail-modal .mgd-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(980px, 100%);
    max-height: min(92vh, 900px);
    padding: 0;
    overflow: hidden;
    border-radius: 24px;
    /* Fondo blanco sólido: la versión translúcida se leía mal sobre la lista */
    background: #fff;
    border: 1px solid #e2eaf0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9),
                0 30px 60px -24px rgba(15, 23, 42, .5),
                0 10px 24px -12px rgba(15, 23, 42, .25);
    animation: mgd-pop .32s var(--mgd-spring);
}
#mg-detail-modal .mgd-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    /* Solo un toque de color arriba, detrás del encabezado */
    background: radial-gradient(60% 120px at 0% 0%, rgba(34, 167, 138, .10), transparent 70%),
                radial-gradient(50% 120px at 100% 0%, rgba(56, 189, 248, .10), transparent 70%);
}
#mg-detail-modal .mgd-panel > * { position: relative; z-index: 1; }

/* Encabezado */
#mg-detail-modal .mgd-head {
    display: grid;
    /* paciente | médico que atendió | cerrar */
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: start;
    gap: 12px 16px;
    padding: 20px 22px 14px;
    border-bottom: 1px solid #edf2f6;
}
#mg-detail-modal .mgd-patient { display: flex; align-items: center; gap: 12px; min-width: 0; }
#mg-detail-modal .mgd-patient .mg-avatar {
    flex: 0 0 52px; width: 52px; height: 52px; border-radius: 15px;
    display: grid; place-items: center;
    background: rgba(22, 139, 117, .14); color: #146f5f; font-size: 16px; font-weight: 900;
}
#mg-detail-modal .mgd-patient small { color: #168b75; font-size: 10px; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
#mg-detail-modal .mgd-patient h3 { margin: 2px 0 2px; font-size: 21px; letter-spacing: -.02em; line-height: 1.15; }
#mg-detail-modal .mgd-patient p { margin: 0; color: var(--mgd-muted); font-size: 12.5px; }
#mg-detail-modal .mgd-close {
    align-self: start; width: 38px; height: 38px; border: 1px solid #e2eaf0; border-radius: 50%;
    display: grid; place-items: center; background: #f5f8fb; color: #475569; cursor: pointer;
    transition: transform .2s var(--mgd-spring), background .2s ease;
}
#mg-detail-modal .mgd-close:hover { transform: rotate(90deg); background: #eaf0f5; }
#mg-detail-modal .mgd-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#mg-detail-modal .mgd-doctor {
    display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 8px;
    border: 1px solid #d6ebe5; border-radius: 16px; background: #f4fbf8;
}
#mg-detail-modal .mgd-doctor .mg-doc-photo { flex-basis: 46px; width: 46px; height: 46px; }
/* Solo el bloque de texto: la foto (.mg-doc-photo) también es un span y
   convertirla en flex columna le descuadraba el encuadre */
#mg-detail-modal .mgd-doctor > span:not(.mg-doc-photo) { display: flex; flex-direction: column; min-width: 0; }
#mg-detail-modal .mgd-doctor small { color: #6b8a82; font-size: 9.5px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
#mg-detail-modal .mgd-doctor b { color: var(--mgd-ink); font-size: 13.5px; white-space: nowrap; }
#mg-detail-modal .mgd-doctor .mg-specialty-badge { align-self: flex-start; }
#mg-detail-modal .mgd-chip {
    display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 999px;
    background: #f3f7fb; border: 1px solid #e2eaf0;
    color: #3d5366; font-size: 11.5px; font-weight: 750;
}
#mg-detail-modal .mgd-chip:first-letter { text-transform: uppercase; }
#mg-detail-modal .mgd-chip .material-symbols-outlined { font-size: 15px; }
/* Estado con su color, igual que en la tarjeta */
#mg-detail-modal .mgd-chip.is-closed { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; font-weight: 850; }
#mg-detail-modal .mgd-chip.is-draft { background: #fff1cf; border-color: #f5d88a; color: #8b6200; font-weight: 850; }

/* Cuerpo */
#mg-detail-modal .mgd-body { flex: 1; overflow-y: auto; padding: 16px 22px 20px; }
#mg-detail-modal .mgd-alerts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
#mg-detail-modal .mgd-alert {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 12px;
    background: #fff7ed; border: 1px solid #fed7aa;
    color: #c2410c; font-size: 12.5px; font-weight: 800;
}
#mg-detail-modal .mgd-alert .material-symbols-outlined { font-size: 18px; }
#mg-detail-modal .mgd-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
#mg-detail-modal .mgd-card {
    padding: 14px 15px; border-radius: 16px;
    background: #fbfcfe; border: 1px solid #e6edf3;
    box-shadow: 0 4px 12px -10px rgba(15, 23, 42, .2);
}
#mg-detail-modal .mgd-card.is-wide { grid-column: 1 / -1; }
#mg-detail-modal .mgd-card h4 {
    display: flex; align-items: center; gap: 7px; margin: 0 0 10px;
    color: var(--mgd-ink); font-size: 13px; font-weight: 850;
}
#mg-detail-modal .mgd-card h4 .material-symbols-outlined {
    display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px;
    background: rgba(22, 139, 117, .13); color: #168b75; font-size: 17px;
}
#mg-detail-modal .mgd-rows { display: grid; grid-template-columns: minmax(96px, auto) 1fr; gap: 6px 12px; margin: 0; }
#mg-detail-modal .mgd-rows dt { color: var(--mgd-muted); font-size: 11.5px; font-weight: 750; }
#mg-detail-modal .mgd-rows dd { margin: 0; color: var(--mgd-ink); font-size: 12.5px; line-height: 1.45; }
#mg-detail-modal .mgd-vitals { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
#mg-detail-modal .mgd-vitals .mg-vital { background: #f1f5f9; }
#mg-detail-modal .mgd-vitals .mg-vital.is-alert { background: #fee2e2; }
#mg-detail-modal .mgd-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
#mg-detail-modal .mgd-list li {
    display: flex; flex-wrap: wrap; align-items: center; gap: 7px; padding: 7px 9px; border-radius: 10px;
    background: #fff; border: 1px solid #edf2f6; font-size: 12.5px;
}
#mg-detail-modal .mgd-list code {
    padding: 2px 6px; border-radius: 6px; background: #1e3a5f; color: #fff;
    font-family: inherit; font-size: 11px; font-weight: 850;
}
#mg-detail-modal .mgd-list em {
    margin-left: auto; padding: 2px 8px; border-radius: 999px;
    background: rgba(22, 139, 117, .12); color: #146f5f; font-style: normal; font-size: 10.5px; font-weight: 800;
}
#mg-detail-modal .mgd-list small { color: var(--mgd-muted); }
#mg-detail-modal .mgd-sub { flex-basis: 100%; color: #3d5366; font-size: 11.5px; }

/* Pie */
#mg-detail-modal .mgd-foot {
    display: flex; justify-content: flex-end; align-items: center; gap: 8px;
    padding: 12px 22px; border-top: 1px solid #edf2f6; background: #f8fafc;
}
#mg-detail-modal .mgd-foot .mg-quick { background: #fff; }
/* Eliminar (cerrada por error): discreto y a la izquierda, lejos de "Abrir" */
#mg-detail-modal .mgd-delete {
    display: inline-flex; align-items: center; gap: 5px; height: 36px; margin-right: auto; padding: 0 12px;
    border: 1px solid #fecdd3; border-radius: 10px; background: #fff1f2; color: #be123c;
    font: inherit; font-size: 12.5px; font-weight: 750; cursor: pointer;
}
#mg-detail-modal .mgd-delete:hover { background: #ffe4e6; }
#mg-detail-modal .mgd-delete .material-symbols-outlined { font-size: 17px; }
#mg-detail-modal .mgd-open {
    display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 18px; border: 0; border-radius: 12px;
    background: linear-gradient(135deg, #168b75, #2674d9); color: #fff; font: inherit; font-size: 13px; font-weight: 800;
    cursor: pointer; box-shadow: 0 10px 20px -10px rgba(38, 116, 217, .7);
    transition: transform .2s var(--mgd-spring), box-shadow .2s ease;
}
#mg-detail-modal .mgd-open:hover { transform: translateY(-1px); box-shadow: 0 14px 24px -10px rgba(38, 116, 217, .8); }
#mg-detail-modal .mgd-open .material-symbols-outlined { font-size: 18px; }

/* Notas aclaratorias */
#mg-detail-modal .mgd-notes-card h4 { justify-content: flex-start; }
#mg-detail-modal .mgd-note-add {
    display: inline-flex; align-items: center; gap: 4px; margin-left: auto; height: 30px; padding: 0 12px;
    border: 1px solid #fcd34d; border-radius: 9px; background: #fffbeb; color: #92400e;
    font: inherit; font-size: 12px; font-weight: 800; cursor: pointer;
    transition: transform .18s var(--mgd-spring), background .18s ease;
}
#mg-detail-modal .mgd-note-add:hover { transform: translateY(-1px); background: #fef3c7; }
#mg-detail-modal .mgd-note-add .material-symbols-outlined { width: auto; height: auto; background: none; color: inherit; font-size: 16px; }
#mg-detail-modal .mgd-empty { margin: 0; color: var(--mgd-muted); font-size: 12.5px; font-style: italic; }
#mg-detail-modal .mgd-notes { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
#mg-detail-modal .mgd-notes li { padding: 10px 12px; border: 1px solid #fde68a; border-left: 4px solid #f59e0b; border-radius: 10px; background: #fffdf5; }
#mg-detail-modal .mgd-note-meta { display: flex; align-items: center; gap: 5px; margin-bottom: 7px; color: #92400e; font-size: 11.5px; font-weight: 800; }
#mg-detail-modal .mgd-note-meta .material-symbols-outlined { font-size: 16px; }

@keyframes mgd-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mgd-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* Tema oscuro */
[data-theme="dark"] #mg-detail-modal { --mgd-ink: #e2e8f0; --mgd-muted: #94a3b8; }
[data-theme="dark"] #mg-detail-modal .mgd-panel {
    background: #0f172a;
    border-color: rgba(255, 255, 255, .12);
}
[data-theme="dark"] #mg-detail-modal .mgd-panel::before {
    background: radial-gradient(55% 45% at 6% 0%, rgba(34, 167, 138, .22), transparent 70%),
                radial-gradient(48% 40% at 100% 4%, rgba(56, 189, 248, .2), transparent 70%);
}
[data-theme="dark"] #mg-detail-modal .mgd-chip.is-closed { background: rgba(185, 28, 28, .3); border-color: rgba(248, 113, 113, .45); color: #fca5a5; }
[data-theme="dark"] #mg-detail-modal .mgd-doctor { background: rgba(22, 112, 91, .18); border-color: rgba(52, 211, 153, .25); }
[data-theme="dark"] #mg-detail-modal .mgd-chip.is-draft { background: rgba(139, 98, 0, .35); border-color: rgba(251, 191, 36, .4); color: #fcd34d; }
[data-theme="dark"] #mg-detail-modal .mgd-head,
[data-theme="dark"] #mg-detail-modal .mgd-foot { background: rgba(15, 23, 42, .35); border-color: rgba(255, 255, 255, .08); }
[data-theme="dark"] #mg-detail-modal .mgd-card,
[data-theme="dark"] #mg-detail-modal .mgd-chip,
[data-theme="dark"] #mg-detail-modal .mgd-close,
[data-theme="dark"] #mg-detail-modal .mgd-list li { background: rgba(30, 41, 59, .55); border-color: rgba(255, 255, 255, .1); color: var(--mgd-ink); }

/* La ventana de nota aclaratoria (css/nota-aclaratoria.css) usa z-index 12050,
   por debajo de las ventanas de medicina general: se sube solo aquí. */
.na-overlay.mg-na-layer { z-index: 2147483000; }

@media (max-width: 720px) {
    #mg-detail-modal .mgd-head { grid-template-columns: minmax(0, 1fr) auto; }
    #mg-detail-modal .mgd-doctor { grid-column: 1 / -1; grid-row: 2; justify-self: start; }
    #mg-detail-modal { padding: 0; place-items: end stretch; }
    #mg-detail-modal .mgd-panel { width: 100%; max-height: 94vh; border-radius: 22px 22px 0 0; }
    #mg-detail-modal .mgd-grid { grid-template-columns: 1fr; }
    #mg-detail-modal .mgd-head, #mg-detail-modal .mgd-body, #mg-detail-modal .mgd-foot { padding-left: 16px; padding-right: 16px; }
    #mg-detail-modal .mgd-rows { grid-template-columns: 1fr; gap: 2px; }
    #mg-detail-modal .mgd-rows dd { margin-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
    #mg-detail-modal, #mg-detail-modal *, #mg-detail-modal.mgd-overlay, #mg-detail-modal .mgd-panel, #mg-detail-modal .mgd-head {
        backdrop-filter: none !important;
        transition: none !important;
        animation: none !important;
    }
}
