:root {
    color-scheme: light dark;

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;

    color: var(--tg-theme-text-color, #111111);
    background: var(--tg-theme-bg-color, #ffffff);
}

button,
input {
    font: inherit;
}

.page {
    width: 100%;
    max-width: 720px;
    min-height: 100vh;

    margin: 0 auto;
    padding:
        calc(16px + env(safe-area-inset-top))
        16px
        calc(24px + env(safe-area-inset-bottom));
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    margin-bottom: 18px;
}

.header h1 {
    margin: 0 0 4px;
    font-size: 24px;
}

.header p {
    margin: 0;

    color: var(
        --tg-theme-hint-color,
        #777777
    );
}

.refresh-button {
    width: 44px;
    height: 44px;

    border: 0;
    border-radius: 14px;

    color: var(
        --tg-theme-button-text-color,
        #ffffff
    );

    background: var(
        --tg-theme-button-color,
        #2481cc
    );

    font-size: 24px;
    cursor: pointer;
}

.refresh-button:disabled {
    opacity: 0.55;
}

.filters {
    display: grid;
    gap: 12px;

    margin-bottom: 16px;
}

.search-input {
    width: 100%;

    padding: 13px 15px;

    border: 1px solid
        var(
            --tg-theme-section-separator-color,
            #dddddd
        );

    border-radius: 14px;

    color: var(
        --tg-theme-text-color,
        #111111
    );

    background: var(
        --tg-theme-secondary-bg-color,
        #f3f3f3
    );

    outline: none;
}

.search-input:focus {
    border-color: var(
        --tg-theme-button-color,
        #2481cc
    );
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;

    color: var(
        --tg-theme-hint-color,
        #666666
    );
}

.chat-list {
    display: grid;
    gap: 10px;
}

.chat-card {
    display: flex;
    align-items: center;
    gap: 12px;

    width: 100%;

    padding: 13px;

    border: 0;
    border-radius: 16px;

    color: inherit;
    background: var(
        --tg-theme-secondary-bg-color,
        #f3f3f3
    );

    text-align: left;
    cursor: pointer;
}

.chat-card:active {
    transform: scale(0.99);
}

.avatar {
    display: grid;
    flex: 0 0 46px;
    place-items: center;

    width: 46px;
    height: 46px;

    border-radius: 50%;

    color: var(
        --tg-theme-button-text-color,
        #ffffff
    );

    background: var(
        --tg-theme-button-color,
        #2481cc
    );

    font-size: 19px;
    font-weight: 700;
}

.chat-content {
    min-width: 0;
    flex: 1;
}

.chat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chat-row + .chat-row {
    margin-top: 6px;
}

.chat-name,
.chat-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-name {
    font-size: 16px;
}

.chat-preview {
    color: var(
        --tg-theme-hint-color,
        #777777
    );

    font-size: 14px;
}

.chat-time {
    flex-shrink: 0;

    color: var(
        --tg-theme-hint-color,
        #777777
    );

    font-size: 12px;
}

.unread-badge {
    display: grid;
    flex-shrink: 0;
    place-items: center;

    min-width: 22px;
    height: 22px;
    padding: 0 7px;

    border-radius: 999px;

    color: var(
        --tg-theme-button-text-color,
        #ffffff
    );

    background: var(
        --tg-theme-button-color,
        #2481cc
    );

    font-size: 12px;
    font-weight: 700;
}

.empty-state,
.error-state {
    padding: 30px 18px;

    border-radius: 16px;

    color: var(
        --tg-theme-hint-color,
        #777777
    );

    background: var(
        --tg-theme-secondary-bg-color,
        #f3f3f3
    );

    text-align: center;
}

.error-state {
    color: var(
        --tg-theme-destructive-text-color,
        #d14b4b
    );
}

.hidden {
    display: none !important;
}

.dialog-view {
    min-height: calc(
        100vh -
        env(safe-area-inset-top) -
        env(safe-area-inset-bottom)
    );
}

.dialog-header {
    position: sticky;
    top: 0;
    z-index: 10;

    display: flex;
    align-items: center;
    gap: 12px;

    margin: -16px -16px 16px;
    padding:
        calc(14px + env(safe-area-inset-top))
        16px
        14px;

    border-bottom: 1px solid
        var(
            --tg-theme-section-separator-color,
            #dddddd
        );

    background: var(
        --tg-theme-bg-color,
        #ffffff
    );
}

.back-button {
    display: grid;
    flex: 0 0 42px;
    place-items: center;

    width: 42px;
    height: 42px;

    border: 0;
    border-radius: 14px;

    color: var(
        --tg-theme-button-text-color,
        #ffffff
    );

    background: var(
        --tg-theme-button-color,
        #2481cc
    );

    font-size: 24px;
    cursor: pointer;
}

.dialog-heading {
    min-width: 0;
}

.dialog-heading h1 {
    overflow: hidden;

    margin: 0 0 3px;

    font-size: 19px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dialog-heading p {
    overflow: hidden;

    margin: 0;

    color: var(
        --tg-theme-hint-color,
        #777777
    );

    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-list {
    display: grid;
    gap: 10px;

    padding-bottom: 24px;
}

.message-row {
    display: flex;
    width: 100%;
}

.message-row-user {
    justify-content: flex-start;
}

.message-row-support {
    justify-content: flex-end;
}

.message-bubble {
    width: fit-content;
    max-width: min(84%, 520px);

    padding: 10px 12px;

    border-radius: 16px;

    background: var(
        --tg-theme-secondary-bg-color,
        #f2f2f2
    );
}

.message-row-user .message-bubble {
    border-bottom-left-radius: 5px;
}

.message-row-support .message-bubble {
    border-bottom-right-radius: 5px;

    color: var(
        --tg-theme-button-text-color,
        #ffffff
    );

    background: var(
        --tg-theme-button-color,
        #2481cc
    );
}

.message-sender {
    margin-bottom: 5px;

    color: var(
        --tg-theme-link-color,
        #2481cc
    );

    font-size: 12px;
    font-weight: 700;
}

.message-row-support .message-sender {
    color: inherit;
    opacity: 0.8;
}

.message-text {
    overflow-wrap: anywhere;

    font-size: 15px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.message-time {
    display: block;

    margin-top: 6px;

    font-size: 11px;
    opacity: 0.65;
    text-align: right;
}

.attachment-card {
    display: flex;
    align-items: center;
    gap: 10px;

    min-width: 210px;
    margin-top: 8px;
    padding: 10px;

    border-radius: 12px;

    background: rgba(127, 127, 127, 0.13);
}

.attachment-icon {
    font-size: 25px;
}

.attachment-content {
    display: grid;
    min-width: 0;
    gap: 3px;
}

.attachment-name {
    overflow: hidden;

    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-meta {
    overflow: hidden;

    font-size: 11px;
    opacity: 0.65;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-panel {
    position: sticky;
    bottom: 0;
    z-index: 10;

    margin: 0 -16px -24px;
    padding:
        10px
        16px
        calc(10px + env(safe-area-inset-bottom));

    border-top: 1px solid
        var(
            --tg-theme-section-separator-color,
            #dddddd
        );

    background: var(
        --tg-theme-bg-color,
        #ffffff
    );
}

.reply-form {
    display: flex;
    align-items: flex-end;
    gap: 9px;
}

.reply-input {
    display: block;
    flex: 1;

    width: 100%;
    min-height: 44px;
    max-height: 140px;

    padding: 11px 13px;

    border: 1px solid
        var(
            --tg-theme-section-separator-color,
            #dddddd
        );

    border-radius: 15px;

    color: var(
        --tg-theme-text-color,
        #111111
    );

    background: var(
        --tg-theme-secondary-bg-color,
        #f3f3f3
    );

    line-height: 1.35;
    outline: none;
    resize: none;
}

.reply-input:focus {
    border-color: var(
        --tg-theme-button-color,
        #2481cc
    );
}

.reply-button {
    flex: 0 0 44px;

    width: 44px;
    height: 44px;

    border: 0;
    border-radius: 50%;

    color: var(
        --tg-theme-button-text-color,
        #ffffff
    );

    background: var(
        --tg-theme-button-color,
        #2481cc
    );

    cursor: pointer;
}

.reply-button:disabled,
.reply-input:disabled {
    opacity: 0.55;
}

.reply-status {
    min-height: 16px;

    margin: 4px 3px 0;

    color: var(
        --tg-theme-hint-color,
        #777777
    );

    font-size: 12px;
}

.attachment-button {
    width: 100%;

    border: 0;

    color: inherit;

    font: inherit;
    text-align: left;
    cursor: pointer;
}

.attachment-button:disabled {
    opacity: 0.55;
    cursor: wait;
}

.attachment-modal-open {
    overflow: hidden;
}

.attachment-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;

    display: grid;
    place-items: center;

    padding:
        calc(18px + env(safe-area-inset-top))
        18px
        calc(18px + env(safe-area-inset-bottom));
}

.attachment-modal-backdrop {
    position: absolute;
    inset: 0;

    width: 100%;
    height: 100%;

    border: 0;

    background: rgba(0, 0, 0, 0.82);
}

.attachment-modal-content {
    position: relative;
    z-index: 1;

    display: grid;
    place-items: center;

    width: 100%;
    max-width: 900px;
    max-height: 100%;

    padding: 42px 10px 10px;
}

.attachment-modal-close {
    position: absolute;
    top: 0;
    right: 0;

    display: grid;
    place-items: center;

    width: 40px;
    height: 40px;

    border: 0;
    border-radius: 50%;

    color: #ffffff;
    background: rgba(255, 255, 255, 0.18);

    font-size: 26px;
    cursor: pointer;
}

.attachment-preview-image {
    display: block;

    max-width: 100%;
    max-height: calc(100vh - 90px);

    border-radius: 12px;

    object-fit: contain;
}

.attachment-preview-status {
    color: #ffffff;
}

.reply-attachment-button {
    display: grid;
    flex: 0 0 44px;
    place-items: center;

    width: 44px;
    height: 44px;

    border: 0;
    border-radius: 50%;

    color: var(
        --tg-theme-text-color,
        #111111
    );

    background: var(
        --tg-theme-secondary-bg-color,
        #f3f3f3
    );

    font-size: 20px;
    cursor: pointer;
}

.reply-attachment-button:disabled {
    opacity: 0.55;
    cursor: wait;
}
