body{font:16px system-ui;background:#f2f6fa;color:#17324b;margin:0}header{background:#103b58;color:white;padding:22px 5%}main{max-width:1200px;margin:28px auto;padding:16px}.panel{background:white;border-radius:12px;padding:22px;margin-bottom:18px;box-shadow:0 2px 12px #1232}input,button{padding:10px;margin:5px;border-radius:7px;border:1px solid #bccbd8}button{background:#12638b;color:white;cursor:pointer}table{border-collapse:collapse;width:100%;min-width:850px}th,td{text-align:left;padding:12px;border-bottom:1px solid #dde6ee}th{background:#eff5f9}.scroll{overflow-x:auto}.error{color:#a11}.small{font-size:13px;color:#647487}
.requestGrid{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:14px}.requestGrid label{display:block}.requestGrid input,.requestGrid select,textarea{display:block;max-width:100%;width:100%;padding:10px;box-sizing:border-box}.requestCase{border-bottom:1px solid #dce5eb;padding:16px 0}

*{box-sizing:border-box}.portalToolbar{display:flex;justify-content:space-between;align-items:center;gap:14px;flex-wrap:wrap}.portalSummary{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}.portalSummary .panel{box-shadow:none;border:1px solid #dce5ef}.portalSummary strong{display:block;font-size:27px;margin-top:6px}.portalSummary .panel:last-child strong{font-size:21px}#company{font-size:22px;font-weight:600}.historySearch{display:flex;align-items:center;gap:10px;flex-wrap:wrap;border:1px solid #dce5ef;padding:16px;border-radius:10px}.historySearch input{margin:0;max-width:100%;width:260px}.documentActions{min-width:310px}.pdfButton{display:inline-block;background:white;color:#14658c;border:1px solid #b9cee0;border-radius:7px;padding:9px 10px;margin:3px;text-decoration:none;font-size:13px}.pdfButton:disabled{color:#98afc0;border-color:#e1e8ee;cursor:default}.pdfButton:focus-visible,button:focus-visible{outline:3px solid #148b95;outline-offset:2px}.secondary{background:white;color:#17324b}td:nth-child(5){font-weight:600}h2{margin-top:0}@media(max-width:650px){.portalSummary{grid-template-columns:1fr}main{padding:10px}.panel{padding:16px}.portalSummary .panel{margin-bottom:0}.portalSummary{margin-bottom:18px}.portalToolbar>div{display:flex;flex-wrap:wrap}}

.encounterDetailDialog{width:min(900px,92vw);max-height:88vh;overflow:auto;border:1px solid #bbcad5;border-radius:12px;padding:24px}.encounterDetailDialog::backdrop{background:rgba(0,0,0,.45)}.encounterDetailDialog textarea{box-sizing:border-box;width:100%;min-height:45vh;white-space:pre-wrap}.encounterDetailDialog button{margin:8px 8px 0 0}

/* Historial único: presentación de aclaraciones existentes. */
.td-history-status{margin-top:8px}.td-history-status .td-states{display:flex;flex-wrap:wrap;gap:4px}.td-history-doctor{font-size:14px;margin:10px 3px}.td-message-box{margin:12px 0;padding:14px;border:1px solid #e2bd72;border-radius:9px;background:#fffaf0;min-width:280px}.td-message-box h3{font-size:16px;margin:0 0 8px}.td-message-box textarea{min-height:65px}.td-message-list{max-height:220px;overflow-y:auto;overflow-wrap:anywhere}.td-message-list p{font-size:14px}.td-message-box [role=status]{color:#875300}

/* Vista compacta: solo distribución del historial; conserva la lógica existente. */
section[aria-labelledby="historyTitle"]{padding:14px}
section[aria-labelledby="historyTitle"] h2{font-size:21px;margin-bottom:5px}
section[aria-labelledby="historyTitle"] .historySearch{padding:8px;gap:8px}
section[aria-labelledby="historyTitle"] table{font-size:13px;min-width:1050px}
section[aria-labelledby="historyTitle"] th,section[aria-labelledby="historyTitle"] td{padding:9px 7px;vertical-align:top}
section[aria-labelledby="historyTitle"] th:first-child{width:8%}
section[aria-labelledby="historyTitle"] th:nth-child(2){width:25%}
section[aria-labelledby="historyTitle"] th:nth-child(3){width:7%}
section[aria-labelledby="historyTitle"] th:nth-child(4){width:16%}
section[aria-labelledby="historyTitle"] th:nth-child(5){width:10%}
section[aria-labelledby="historyTitle"] th:last-child{width:34%}
section[aria-labelledby="historyTitle"] .documentActions{min-width:350px}
section[aria-labelledby="historyTitle"] .pdfButton{padding:4px 6px;margin:2px;font-size:11px;line-height:1.3}
section[aria-labelledby="historyTitle"] .td-history-status{margin-top:5px}
section[aria-labelledby="historyTitle"] .td-states{display:flex;flex-wrap:nowrap;gap:3px;margin-left:0}
section[aria-labelledby="historyTitle"] .td-state{padding:3px 5px;font-size:10px;white-space:nowrap}
section[aria-labelledby="historyTitle"] .td-history-doctor{font-size:12px;margin:5px 2px}
section[aria-labelledby="historyTitle"] .td-message-box{margin:6px 0 2px;padding:8px;min-width:0;border-radius:6px;font-size:12px}
section[aria-labelledby="historyTitle"] .td-message-box h3{font-size:13px;margin:0 0 4px}
section[aria-labelledby="historyTitle"] .td-message-list{max-height:110px}
section[aria-labelledby="historyTitle"] .td-message-list p{font-size:12px;margin:4px 0}
section[aria-labelledby="historyTitle"] .td-message-box textarea{min-height:36px;height:36px;padding:5px;font:inherit;resize:vertical}
section[aria-labelledby="historyTitle"] .td-message-box button{padding:5px 8px;margin:4px 0 0;font-size:12px}

/* Aclaraciones en franja completa y etiquetas de servicio. */
section[aria-labelledby="historyTitle"] .td-message-row>td{padding:0 8px 8px;border-top:0}
section[aria-labelledby="historyTitle"] .td-message-box{display:grid;grid-template-columns:minmax(0,1fr) minmax(260px,.8fr);gap:4px 16px;margin:0;padding:8px 12px}
section[aria-labelledby="historyTitle"] .td-message-box h3{grid-column:1;align-self:center;margin:0}
section[aria-labelledby="historyTitle"] .td-message-box>[role="status"]{grid-column:1;margin:0}
section[aria-labelledby="historyTitle"] .td-message-box>[role="status"]:empty{display:none}
section[aria-labelledby="historyTitle"] .td-message-list{grid-column:1;max-height:90px}
section[aria-labelledby="historyTitle"] .td-message-box form{grid-column:2;grid-row:1 / span 3;display:flex;gap:8px;align-items:center;margin:0}
section[aria-labelledby="historyTitle"] .td-message-box form label{flex:1;min-width:0;font-size:11px}
section[aria-labelledby="historyTitle"] .td-message-box textarea{display:block;width:100%;margin:2px 0 0;box-sizing:border-box;height:32px;min-height:32px}
section[aria-labelledby="historyTitle"] .td-message-box form button{flex:none;align-self:end;margin:0 0 1px;white-space:nowrap}
section[aria-labelledby="historyTitle"] .td-service-label{display:inline-flex;box-sizing:border-box;align-items:center;justify-content:center;width:171px;max-width:100%;min-height:58px;padding:6px 10px;border-radius:8px;text-align:center;font-weight:700;font-size:18px;line-height:1.15}
.td-service-telemedicine{background:#ffd43b;color:#382a00}
.td-service-home{padding-inline:26px}
section[aria-labelledby="historyTitle"] .td-service-center{background:#b91c1c;color:#fff}
section[aria-labelledby="historyTitle"] .td-service-home{background:#166534;color:#fff}
@media(max-width:700px){section[aria-labelledby="historyTitle"] .td-message-box{grid-template-columns:1fr}section[aria-labelledby="historyTitle"] .td-message-box form{grid-column:1;grid-row:auto}}

/* Último ajuste: aclaraciones a la mitad del ancho, conservando altura compacta. */
section[aria-labelledby="historyTitle"] .td-message-box{width:50%;box-sizing:border-box;grid-template-columns:minmax(0,1fr) minmax(0,1fr)}
@media(max-width:700px){section[aria-labelledby="historyTitle"] .td-message-box{width:100%;grid-template-columns:1fr}}

/* Resaltar únicamente acciones disponibles. */
section[aria-labelledby="historyTitle"] .documentActions a.pdfButton,
section[aria-labelledby="historyTitle"] .documentActions button:not(:disabled){background:#0756a3;color:#fff;border:1px solid #064784;font-weight:600}
section[aria-labelledby="historyTitle"] .documentActions a.pdfButton:hover,
section[aria-labelledby="historyTitle"] .documentActions button:not(:disabled):hover{background:#064480}
section[aria-labelledby="historyTitle"] .documentActions button:disabled{background:#f1f3f5;color:#788592;border-color:#d7dde3}

/* Aclaraciones a la derecha; sin divisor dentro de la misma consulta. */
section[aria-labelledby="historyTitle"] tr:has(+ .td-message-row)>td{border-bottom:0}
section[aria-labelledby="historyTitle"] .td-message-row .td-message-box{margin-left:auto;margin-right:0}

section[aria-labelledby="historyTitle"] .td-service-teleorientation{font-size:1.2em;font-weight:700}
section[aria-labelledby="historyTitle"] .td-message-row .td-message-box{width:min(100%,1050px);margin:0;padding:0;border:0;background:none;grid-template-columns:minmax(0,613px) minmax(0,390px);column-gap:24px}
section[aria-labelledby="historyTitle"] .td-message-row .td-message-box h3{display:none}
section[aria-labelledby="historyTitle"] .td-message-row .td-message-list{max-height:none}
section[aria-labelledby="historyTitle"] .td-message-box .td-doctor-unread{grid-column:1;justify-self:start;background:#ffedba;color:#67400b;border:1px solid #e6be59;border-radius:16px;font-weight:700}
section[aria-labelledby="historyTitle"] .td-doctor-unread[hidden]{display:none}
section[aria-labelledby="historyTitle"] .td-message-list .td-doctor-message{padding:14px 16px;background:#f1f7fd;border:1px solid #a7c5df;border-radius:9px}
section[aria-labelledby="historyTitle"] .td-doctor-message .td-message-body{display:block;font-size:1.55em;font-weight:700;white-space:pre-wrap;overflow-wrap:anywhere}
section[aria-labelledby="historyTitle"] .td-message-box form label{font-size:1.15em;font-weight:700}
section[aria-labelledby="historyTitle"] .td-message-box textarea{height:52px;min-height:52px}
@media(max-width:700px){section[aria-labelledby="historyTitle"] .td-message-row .td-message-box{grid-template-columns:1fr}}

section[aria-labelledby="historyTitle"] .td-older-messages{margin:4px 0 8px}
section[aria-labelledby="historyTitle"] .td-older-messages summary{cursor:pointer;color:#0c5593;font-weight:700}
section[aria-labelledby="historyTitle"] .td-older-messages>div{max-height:min(40vh,320px);overflow:auto}
