.appointment-chat-modal[hidden] {
    display: none;
}

.appointment-chat-modal {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(30, 25, 22, 0.48);
    backdrop-filter: blur(5px);
}

.appointment-chat-dialog {
    width: min(620px, 100%);
    height: min(720px, calc(100dvh - 40px));
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(178, 139, 83, 0.25);
    border-radius: 24px;
    background: #fffdf9;
    box-shadow: 0 24px 70px rgba(51, 37, 27, 0.28);
}

.appointment-chat-header {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 22px 24px 18px;
    border-bottom: 1px solid rgba(178, 139, 83, 0.18);
    background: linear-gradient(135deg, #fffaf1, #f8efe2);
}

.appointment-chat-eyebrow {
    display: block;
    margin-bottom: 5px;
    color: #a3783f;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.appointment-chat-header h2 {
    margin: 0;
    color: #3c3028;
    font-size: clamp(20px, 4vw, 26px);
}

.appointment-chat-header p {
    margin: 6px 0 0;
    color: #7d7067;
    font-size: 14px;
}

.appointment-chat-close {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    color: #5f4d41;
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 5px 15px rgba(70, 51, 38, 0.12);
    cursor: pointer;
    font-size: 17px;
}

.appointment-chat-state,
.appointment-chat-readonly,
.appointment-chat-error {
    margin: 0;
    font-size: 14px;
}

.appointment-chat-state {
    flex: 0 0 auto;
    padding: 12px 24px 0;
    color: #887a70;
}

.appointment-chat-state:empty {
    display: none;
}

.appointment-chat-messages {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow-y: auto;
    padding: 20px 24px;
    scroll-behavior: smooth;
}

.appointment-chat-empty {
    display: grid;
    height: 100%;
    min-height: 160px;
    place-items: center;
    color: #94867b;
    text-align: center;
}

.appointment-chat-message {
    align-self: flex-start;
    width: fit-content;
    max-width: min(82%, 430px);
    margin: 0 0 12px 0;
    padding: 11px 14px 9px;
    border-radius: 16px 16px 16px 5px;
    color: #43362e;
    background: #f0e7dc;
}

.appointment-chat-message.is-own {
    align-self: flex-end;
    margin: 0 0 12px auto;
    border-radius: 16px 16px 5px 16px;
    background: linear-gradient(135deg, #d7b77f, #c99d5b);
    color: #fff;
}

.appointment-chat-message-author {
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 700;
    opacity: 0.82;
}

.appointment-chat-message-text {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.appointment-chat-message-time {
    margin-top: 5px;
    font-size: 11px;
    opacity: 0.7;
    text-align: right;
}

.appointment-chat-readonly {
    flex: 0 0 auto;
    margin: 0 24px 18px;
    padding: 11px 14px;
    border-radius: 12px;
    color: #735f4e;
    background: #f4ece2;
}

.appointment-chat-form {
    position: relative;
    z-index: 2;
    flex: 0 0 auto;
    padding: 16px 24px 20px;
    border-top: 1px solid rgba(178, 139, 83, 0.18);
    background: #fffdf9;
    box-shadow: 0 -8px 22px rgba(72, 52, 38, 0.05);
}

.appointment-chat-form[hidden] {
    display: none;
}

.appointment-chat-form > label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.appointment-chat-compose {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.appointment-chat-compose textarea {
    flex: 1;
    min-height: 48px;
    max-height: 130px;
    resize: vertical;
    padding: 12px 14px;
    border: 1px solid #decdb9;
    border-radius: 14px;
    color: #43362e;
    background: #fff;
    font: inherit;
}

.appointment-chat-compose textarea:focus {
    outline: 2px solid rgba(196, 151, 83, 0.25);
    border-color: #c49753;
}

.appointment-chat-compose button {
    min-height: 48px;
    padding: 0 18px;
    border: 0;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, #b98949, #d2aa6e);
    cursor: pointer;
    font-weight: 700;
}

.appointment-chat-compose button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.appointment-chat-error {
    margin-top: 8px;
    color: #b44646;
}

.appointment-chat-button {
    position: relative;
    display: inline-grid;
    width: 42px;
    min-width: 42px;
    height: 42px;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(177, 132, 69, 0.3);
    border-radius: 12px;
    color: #5e4631;
    background: #fff8ed;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    text-decoration: none;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.appointment-chat-unread {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 11px;
    height: 11px;
    border: 2px solid #fffdf9;
    border-radius: 50%;
    background: #e53935;
    box-shadow: 0 2px 7px rgba(180, 24, 24, 0.42);
}

.appointment-chat-unread[hidden] {
    display: none;
}

.appointment-chat-button.has-unread {
    box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.1);
}

.appointment-chat-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 7px 18px rgba(123, 87, 44, 0.16);
}

.appointment-footer {
    align-items: center;
    gap: 10px;
}

.modal-master .appointment-chat-button {
    margin-left: auto;
}

.appointment-master-with-chat {
    display: flex;
    align-items: center;
    gap: 10px;
}

.appointment-master-with-chat .appointment-chat-button {
    margin-left: auto;
}

body.appointment-chat-open {
    overflow: hidden;
}

@media (max-width: 640px) {
    .appointment-chat-modal {
        padding: 0;
        place-items: end stretch;
    }

    .appointment-chat-dialog {
        width: 100%;
        height: min(86dvh, 720px);
        border-radius: 22px 22px 0 0;
    }

    .appointment-chat-header,
    .appointment-chat-messages {
        padding-left: 16px;
        padding-right: 16px;
    }

    .appointment-chat-form {
        padding: 13px 16px max(14px, env(safe-area-inset-bottom));
    }

    .appointment-chat-readonly {
        margin-right: 16px;
        margin-left: 16px;
    }

    .appointment-chat-compose {
        align-items: stretch;
        flex-direction: column;
    }
}
