.hmis-chat {
    --chat-blue: #005f86;
    --chat-green: #1a9956;
    --chat-orange: #f08a00;
    --chat-text: #0f172a;
    --chat-muted: #64748b;
    --chat-line: rgba(15, 23, 42, 0.12);
    direction: rtl;
    position: fixed;
    inset-inline-end: 22px;
    bottom: 22px;
    z-index: 2500;
    font-family: "Noto Sans Arabic","Segoe UI",Tahoma,Arial,system-ui,sans-serif;
}

.hmis-chat * {
    box-sizing: border-box;
}

.hmis-chat__panel {
    position: absolute;
    inset-inline-end: 0;
    bottom: 76px;
    width: min(380px, calc(100vw - 28px));
    height: min(610px, calc(100vh - 110px));
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.68);
    border-radius: 18px;
    background: linear-gradient(150deg, rgba(255, 255, 255, 0.96), rgba(245, 250, 252, 0.9));
    box-shadow: 0 20px 60px rgba(0, 45, 70, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    opacity: 0;
    transform: translateY(14px) scale(0.98);
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
}

.hmis-chat.is-open .hmis-chat__panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.hmis-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-blue), #064f6d 62%, var(--chat-green));
}

.hmis-chat__identity {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.hmis-chat__mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.28);
    font-weight: 900;
}

.hmis-chat__title {
    margin: 0;
    font-size: 15px;
    font-weight: 900;
    line-height: 1.35;
}

.hmis-chat__status {
    margin: 2px 0 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 12px;
    line-height: 1.4;
}

.hmis-chat__close,
.hmis-chat__launcher,
.hmis-chat__send {
    appearance: none;
    border: 0;
    cursor: pointer;
    font: inherit;
}

.hmis-chat__close {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 10px;
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
}

.hmis-chat__close:hover {
    background: rgba(255, 255, 255, 0.24);
}

.hmis-chat__triage {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    color: #334155;
    background: rgba(248, 250, 252, 0.88);
    font-size: 12px;
    line-height: 1.5;
}

.hmis-chat__triage span {
    display: block;
    margin-bottom: 7px;
    font-weight: 800;
    color: var(--chat-text);
}

.hmis-chat__triage-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}

.hmis-chat__triage-button {
    min-height: 34px;
    border: 1px solid rgba(0, 95, 134, 0.16);
    border-radius: 10px;
    padding: 7px 8px;
    color: #0f4f68;
    background: #fff;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.3;
}

.hmis-chat__triage-button:hover {
    border-color: rgba(26, 153, 86, 0.34);
    color: #147a47;
    transform: translateY(-1px);
}

.hmis-chat__messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding: 14px;
    background:
        linear-gradient(180deg, rgba(0, 95, 134, 0.08), transparent 28%),
        rgba(255, 255, 255, 0.42);
}

.hmis-chat__message {
    width: fit-content;
    max-width: 88%;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.hmis-chat__message--assistant {
    align-self: flex-start;
    color: var(--chat-text);
    background: #fff;
    border: 1px solid var(--chat-line);
    border-start-start-radius: 4px;
}

.hmis-chat__message--user {
    align-self: flex-end;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-blue), #004a6b);
    border-start-end-radius: 4px;
    box-shadow: 0 8px 18px rgba(0, 95, 134, 0.18);
}

.hmis-chat__message.is-thinking::after {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-inline-start: 6px;
    border-radius: 999px;
    background: var(--chat-green);
    animation: hmis-chat-pulse 900ms ease-in-out infinite;
}

.hmis-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 14px 10px;
    border-top: 1px solid rgba(15, 23, 42, 0.06);
}

.hmis-chat__suggestion {
    border: 1px solid rgba(0, 95, 134, 0.18);
    border-radius: 999px;
    padding: 7px 10px;
    color: var(--chat-blue);
    background: rgba(255, 255, 255, 0.72);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.hmis-chat__handoff {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    margin: 0 12px 10px;
    padding: 10px;
    border: 1px solid rgba(240, 138, 0, 0.28);
    border-radius: 12px;
    color: #5c3600;
    background: #fff7e8;
}

.hmis-chat__handoff[hidden] {
    display: none;
}

.hmis-chat__handoff strong {
    display: block;
    margin-bottom: 2px;
    color: #6f4100;
    font-size: 13px;
    line-height: 1.35;
}

.hmis-chat__handoff p {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
}

.hmis-chat__handoff-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hmis-chat__handoff-link {
    min-width: 76px;
    border: 1px solid rgba(111, 65, 0, 0.18);
    border-radius: 10px;
    padding: 7px 9px;
    color: #fff;
    background: #0f5f7d;
    font-size: 12px;
    font-weight: 900;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
}

.hmis-chat__handoff-link:last-child {
    background: #16834d;
}

.hmis-chat__composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid var(--chat-line);
    background: rgba(255, 255, 255, 0.86);
}

.hmis-chat__input {
    width: 100%;
    min-height: 44px;
    max-height: 118px;
    resize: none;
    border: 1px solid rgba(0, 95, 134, 0.22);
    border-radius: 14px;
    padding: 10px 12px;
    color: var(--chat-text);
    background: #fff;
    font: inherit;
    font-size: 14px;
    line-height: 1.45;
    outline: none;
}

.hmis-chat__input:focus {
    border-color: var(--chat-blue);
    box-shadow: 0 0 0 3px rgba(0, 95, 134, 0.13);
}

.hmis-chat__send {
    min-width: 48px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-orange), #db7600);
    font-weight: 900;
    box-shadow: 0 8px 18px rgba(240, 138, 0, 0.24);
}

.hmis-chat__send:disabled {
    cursor: not-allowed;
    opacity: 0.62;
    box-shadow: none;
}

.hmis-chat__launcher {
    position: relative;
    width: 62px;
    height: 62px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    color: #fff;
    background: linear-gradient(135deg, var(--chat-blue), var(--chat-green));
    box-shadow: 0 16px 34px rgba(0, 95, 134, 0.32);
}

.hmis-chat__launcher span {
    position: absolute;
    inset-block-start: -6px;
    inset-inline-start: -6px;
    width: 25px;
    height: 25px;
    display: grid;
    place-items: center;
    border: 2px solid #fff;
    border-radius: 9px;
    color: #fff;
    background: var(--chat-orange);
    box-shadow: 0 8px 16px rgba(240, 138, 0, 0.28);
}

.hmis-chat__launcher svg,
.hmis-chat__send svg,
.hmis-chat__close svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2.2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hmis-chat__launcher span svg {
    width: 14px;
    height: 14px;
}

.hmis-chat__launcher:hover {
    transform: translateY(-2px);
}

.hmis-chat__error {
    margin: 0;
    padding: 8px 14px 0;
    color: #9f1239;
    font-size: 12px;
    line-height: 1.5;
}

@keyframes hmis-chat-pulse {
    0%, 100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

@media (max-width: 640px) {
    .hmis-chat {
        inset-inline-end: 14px;
        bottom: 14px;
    }

    .hmis-chat__panel {
        width: calc(100vw - 28px);
        height: min(620px, calc(100vh - 96px));
        bottom: 70px;
    }

    .hmis-chat__launcher {
        width: 58px;
        height: 58px;
        border-radius: 18px;
    }

    .hmis-chat__triage-actions {
        grid-template-columns: 1fr;
    }

    .hmis-chat__handoff {
        grid-template-columns: 1fr;
    }

    .hmis-chat__handoff-actions {
        flex-direction: row;
    }

    .hmis-chat__handoff-link {
        flex: 1;
    }
}
