.chat-module {
    display: grid;
    gap: 14px;
}

.chat-module[data-mode="patient"] {
    position: fixed;
    right: clamp(14px, 2.4vw, 28px);
    bottom: clamp(14px, 2.4vw, 28px);
    z-index: 60;
    width: min(440px, calc(100vw - 28px));
    max-height: min(760px, calc(100vh - 28px));
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border: 1px solid rgba(102, 115, 72, 0.24);
    border-radius: 22px;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.035)),
        rgba(8, 21, 17, 0.96);
    box-shadow: 0 28px 80px rgba(63, 75, 48, 0.18);
    backdrop-filter: blur(18px);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: clamp(18px, 3vw, 28px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.035)), var(--surface);
    box-shadow: var(--shadow);
}

.chat-header h1 {
    font-size: clamp(2rem, 3vw, 3.2rem);
}

.chat-module[data-mode="patient"] .chat-header {
    padding: 14px;
    border-radius: 16px;
    box-shadow: none;
}

.chat-module[data-mode="patient"] .chat-header h1 {
    font-size: 1.18rem;
}

.chat-module[data-mode="patient"] .chat-header .lead {
    margin-top: 8px;
    font-size: 0.86rem;
}

.chat-module[data-mode="patient"] .eyebrow {
    font-size: 0.68rem;
}

.chat-status {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 6px 12px;
    border-radius: 999px;
    color: #fffaf2;
    background: var(--aqua);
    font-size: 0.78rem;
    font-weight: 900;
    text-transform: uppercase;
}

.chat-status.respondido-ia,
.conversation-item small.respondido-ia {
    background: var(--gold);
}

.chat-status.aguardando-humano,
.conversation-item small.aguardando-humano {
    background: var(--accent-soft); color: var(--olive-deep);
}

.chat-status.encaminhado-whatsapp,
.conversation-item small.encaminhado-whatsapp {
    background: var(--olive);
}

.chat-status.finalizado,
.conversation-item small.finalizado {
    background: rgba(102, 115, 72, 0.18); color: var(--olive-deep);
}

.chat-error {
    padding: 12px 14px;
    border: 1px solid rgba(241, 154, 138, 0.32);
    border-radius: var(--radius);
    color: var(--danger);
    background: rgba(241, 154, 138, 0.1);
}

.chat-messages {
    min-height: 360px;
    max-height: 620px;
    display: grid;
    align-content: start;
    gap: 12px;
    overflow-y: auto;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.48);
}

.chat-module[data-mode="patient"] .chat-messages {
    min-height: 230px;
    max-height: none;
    flex: 1 1 auto;
    padding: 12px;
    border-radius: 16px;
}

.chat-bubble {
    max-width: min(78%, 720px);
    display: grid;
    gap: 7px;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.62);
    white-space: pre-wrap;
}

.chat-module[data-mode="patient"] .chat-bubble {
    max-width: 92%;
    padding: 11px 12px;
    font-size: 0.9rem;
}

.chat-bubble.paciente {
    justify-self: end;
    border-bottom-right-radius: 4px;
    background: rgba(102, 115, 72, 0.13);
}

.chat-bubble.ia {
    justify-self: start;
    border-color: rgba(227, 198, 127, 0.28);
    border-bottom-left-radius: 4px;
    background: rgba(227, 198, 127, 0.09);
}

.chat-bubble.atendente,
.chat-bubble.medico {
    justify-self: start;
    border-color: rgba(102, 115, 72, 0.25);
    border-bottom-left-radius: 4px;
    background: rgba(102, 115, 72, 0.1);
}

.chat-bubble strong {
    color: var(--gold);
    font-size: 0.76rem;
    text-transform: uppercase;
}

.chat-bubble time {
    color: var(--muted);
    font-size: 0.74rem;
}

.chat-compose {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
}

.chat-compose textarea {
    min-height: 56px;
    max-height: 180px;
}

.chat-module[data-mode="patient"] .chat-compose {
    grid-template-columns: 1fr;
}

.chat-module[data-mode="patient"] .chat-compose textarea {
    min-height: 74px;
}

.chat-module[data-mode="patient"] .chat-actions .btn {
    flex: 1 1 180px;
}

.chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chat-grid {
    display: grid;
    grid-template-columns: minmax(240px, 330px) minmax(0, 1fr);
    gap: 14px;
}

.conversation-list,
.attendance-chat {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-strong);
}

.conversation-list-header,
.chat-patient-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.conversation-item {
    width: 100%;
    display: grid;
    gap: 6px;
    margin-bottom: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: rgba(102, 115, 72, 0.055);
    text-align: left;
    cursor: pointer;
}

.conversation-item.is-active {
    border-color: rgba(185, 120, 67, 0.42);
    background: rgba(227, 198, 127, 0.08);
}

.conversation-item small {
    width: fit-content;
    padding: 3px 7px;
    border-radius: 999px;
    color: #fffaf2;
    background: var(--aqua);
    font-weight: 800;
}

.btn.compact {
    width: auto;
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.82rem;
}

.muted {
    color: var(--muted);
}

@media (max-width: 860px) {
    .chat-header,
    .conversation-list-header,
    .chat-patient-summary {
        flex-direction: column;
        align-items: flex-start;
    }

    .chat-grid,
    .chat-compose {
        grid-template-columns: 1fr;
    }

    .chat-bubble {
        max-width: 100%;
    }
}

@media (max-width: 560px) {
    .chat-module[data-mode="patient"] {
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 92vh;
        border-right: 0;
        border-bottom: 0;
        border-left: 0;
        border-radius: 22px 22px 0 0;
    }

    .chat-module[data-mode="patient"] .chat-header {
        flex-direction: row;
        align-items: flex-start;
    }

    .chat-module[data-mode="patient"] .chat-status {
        font-size: 0.66rem;
    }
}

/* Patient widget polish */
.chat-widget[data-mode="patient"] {
    width: min(410px, calc(100vw - 28px));
    height: min(680px, calc(100vh - 28px));
    overflow: hidden;
    gap: 9px;
    padding: 10px;
    border-color: rgba(102, 115, 72, 0.28);
    border-radius: 24px;
    background:
        radial-gradient(circle at 18% 0%, rgba(143, 201, 191, 0.18), transparent 34%),
        linear-gradient(160deg, rgba(17, 44, 38, 0.98), rgba(6, 16, 13, 0.98));
}

.chat-widget .chat-launcher {
    display: none;
}

.chat-widget.is-minimized {
    width: auto;
    height: auto;
    max-height: none;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
}

.chat-widget.is-minimized > :not(.chat-launcher) {
    display: none;
}

.chat-widget.is-minimized .chat-launcher {
    display: flex;
}

.chat-launcher {
    align-items: center;
    gap: 10px;
    min-width: 236px;
    min-height: 58px;
    padding: 9px 14px 9px 9px;
    border: 1px solid rgba(102, 115, 72, 0.34);
    border-radius: 999px;
    color: var(--text);
    background: linear-gradient(135deg, rgba(19, 47, 41, 0.98), rgba(9, 25, 21, 0.98));
    box-shadow: 0 20px 54px rgba(0, 0, 0, 0.34);
    cursor: pointer;
}

.chat-launcher-mark {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fffaf2;
    background: linear-gradient(135deg, var(--olive), var(--olive-deep));
    font-weight: 900;
    font-size: 0.82rem;
}

.chat-launcher strong,
.chat-launcher small {
    display: block;
    line-height: 1.2;
    text-align: left;
}

.chat-launcher small {
    color: var(--muted);
    font-size: 0.76rem;
}

.chat-widget[data-mode="patient"] .chat-header {
    align-items: center;
    padding: 13px 13px 12px;
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.54);
}

.chat-title-group {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 11px;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(185, 120, 67, 0.28);
    border-radius: 15px;
    color: #fffaf2;
    background: linear-gradient(135deg, var(--olive), var(--olive-deep));
    font-size: 0.78rem;
    font-weight: 950;
}

.chat-widget[data-mode="patient"] .chat-header h1 {
    margin-top: 3px;
    font-family: var(--font-body);
    font-size: 1.12rem;
    font-weight: 850;
    letter-spacing: 0;
}

.chat-widget[data-mode="patient"] .chat-header .lead {
    max-width: 250px;
    margin-top: 5px;
    color: rgba(59, 70, 50, 0.68);
    font-size: 0.78rem;
    line-height: 1.35;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 7px;
}

.chat-icon-button {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 50%;
    color: var(--text);
    background: rgba(255, 255, 255, 0.62);
    font-weight: 900;
    cursor: pointer;
}

.chat-widget[data-mode="patient"] .chat-status {
    min-height: 28px;
    padding: 4px 8px;
    font-size: 0.62rem;
    white-space: nowrap;
}

.chat-intro,
.chat-guidance,
.chat-disclaimer {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid rgba(227, 198, 127, 0.18);
    border-radius: 14px;
    color: rgba(59, 70, 50, 0.76);
    background: rgba(185, 120, 67, 0.07);
    font-size: 0.8rem;
    line-height: 1.4;
}

.chat-intro strong {
    color: var(--text);
}

.chat-guidance {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
    border-color: rgba(143, 201, 191, 0.18);
    background: rgba(102, 115, 72, 0.07);
}

.chat-guidance div {
    min-width: 0;
    display: grid;
    gap: 3px;
    padding: 7px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.045);
}

.chat-guidance strong,
.chat-guidance span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.chat-guidance strong {
    color: var(--olive-deep);
    font-size: 0.68rem;
    line-height: 1.15;
}

.chat-guidance span {
    color: rgba(59, 70, 50, 0.66);
    font-size: 0.64rem;
    line-height: 1.25;
}

.chat-progress {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.chat-progress span {
    min-width: 0;
    padding: 6px 5px;
    border-radius: 999px;
    color: rgba(59, 70, 50, 0.62);
    background: rgba(255, 255, 255, 0.54);
    font-size: 0.64rem;
    font-weight: 800;
    text-align: center;
}

.chat-progress span.is-active {
    color: #fffaf2;
    background: var(--aqua);
}

.chat-progress span.is-done {
    color: rgba(248, 239, 223, 0.86);
    background: rgba(102, 115, 72, 0.16);
}

.chat-widget[data-mode="patient"] .chat-messages {
    min-height: 0;
    border-color: rgba(255, 255, 255, 0.1);
    background:
        linear-gradient(180deg, rgba(0, 0, 0, 0.08), transparent),
        rgba(255, 255, 255, 0.44);
    scrollbar-width: thin;
}

.chat-widget[data-mode="patient"] .chat-bubble {
    max-width: 88%;
    border-radius: 18px;
    border-color: rgba(255, 255, 255, 0.1);
    line-height: 1.42;
}

.chat-widget[data-mode="patient"] .chat-bubble.paciente {
    color: #0d211d;
    border-color: rgba(204, 239, 232, 0.45);
    border-bottom-right-radius: 7px;
    background: linear-gradient(135deg, #ccefe8, #9bd8cd);
}

.chat-widget[data-mode="patient"] .chat-bubble.ia {
    border-bottom-left-radius: 7px;
    background: rgba(255, 255, 255, 0.68);
}

.chat-bubble.typing {
    width: fit-content;
    min-width: 112px;
}

.chat-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 18px;
}

.chat-typing-dots i {
    width: 7px;
    height: 7px;
    display: block;
    border-radius: 50%;
    background: var(--olive);
    opacity: 0.42;
    animation: leveorTyping 1.15s ease-in-out infinite;
}

.chat-typing-dots i:nth-child(2) {
    animation-delay: 0.16s;
}

.chat-typing-dots i:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes leveorTyping {
    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.42;
    }

    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.chat-widget[data-mode="patient"] .chat-bubble.paciente strong,
.chat-widget[data-mode="patient"] .chat-bubble.paciente time {
    color: rgba(255, 250, 242, 0.78);
}

.chat-suggestions {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.chat-suggestions button {
    flex: 0 0 auto;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid rgba(102, 115, 72, 0.26);
    border-radius: 999px;
    color: var(--olive-deep);
    background: rgba(143, 201, 191, 0.09);
    font: inherit;
    font-size: 0.76rem;
    font-weight: 800;
    cursor: pointer;
}

.chat-suggestions button:hover,
.chat-icon-button:hover,
.chat-launcher:hover {
    border-color: rgba(185, 120, 67, 0.42);
}

.chat-widget[data-mode="patient"] .chat-compose {
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: end;
    gap: 8px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.54);
}

.chat-widget[data-mode="patient"] .chat-compose textarea {
    min-height: 46px;
    max-height: 116px;
    padding: 12px 10px;
    border: 0;
    background: transparent;
    resize: none;
}

.chat-send {
    min-width: 76px;
    min-height: 42px;
    padding: 0 14px;
    border: 0;
    border-radius: 999px;
    color: #fffaf2;
    background: linear-gradient(135deg, var(--olive), var(--olive-deep));
    font: inherit;
    font-weight: 900;
    cursor: pointer;
}

.chat-send:disabled {
    cursor: wait;
    opacity: 0.72;
}

.chat-widget.is-busy .chat-compose {
    border-color: rgba(227, 198, 127, 0.32);
}

.chat-widget[data-mode="patient"] .chat-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.chat-widget[data-mode="patient"] .chat-actions .btn {
    width: 100%;
    min-height: 36px;
    font-size: 0.76rem;
}

.chat-disclaimer {
    padding: 0 4px;
    border: 0;
    color: rgba(59, 70, 50, 0.56);
    background: transparent;
    font-size: 0.7rem;
    text-align: center;
}

@media (max-width: 560px) {
    .chat-widget[data-mode="patient"] {
        height: 90vh;
        max-height: 90vh;
        padding: 9px;
        border-radius: 24px 24px 0 0;
    }

    .chat-widget[data-mode="patient"] .chat-header h1 {
        font-size: 1rem;
    }

    .chat-widget[data-mode="patient"] .chat-header .lead,
    .chat-intro {
        font-size: 0.74rem;
    }

    .chat-guidance {
        grid-template-columns: 1fr;
    }

    .chat-widget[data-mode="patient"] .chat-compose {
        grid-template-columns: 1fr !important;
    }

    .chat-send {
        width: 100%;
    }
}
