html {
    --app-bg: #f4f6f8;
    --app-surface: #ffffff;
    --app-surface-alt: #fafbfc;
    --app-text: #17212b;
    --app-heading: #1a2a33;
    --app-muted: #5f6f79;
    --app-border: #d9e0e7;
    --app-subtle-border: #e5eaee;
    --app-row-border: #eef1f4;
    --app-hover: #eef8f5;
    --app-selected: #d9f0ea;
    --app-accent: #0f6c5f;
    --app-link: #0b6f84;
    --app-warning: #d89a16;
    --app-reaction-bg: #f0e6c7;
    --app-reaction-text: #5d4711;
    --app-danger: #b42318;
    --app-danger-text: #7a1d16;
    --app-chat-header-bg: #0d6efd;
    --app-chat-header-text: #ffffff;
    --app-chat-header-muted: #e7f1ff;
    --app-login-bg: linear-gradient(135deg, #eef6f4 0%, #f8fbfd 56%, #edf2f7 100%);
}

html[data-bs-theme="dark"] {
    --app-bg: #151a1e;
    --app-surface: #20272c;
    --app-surface-alt: #252d33;
    --app-text: #edf2f6;
    --app-heading: #f7fafc;
    --app-muted: #aebbc5;
    --app-border: #35424a;
    --app-subtle-border: #313c44;
    --app-row-border: #2d373f;
    --app-hover: #233832;
    --app-selected: #24473f;
    --app-accent: #0f6c5f;
    --app-link: #65c8d8;
    --app-warning: #d89a16;
    --app-reaction-bg: #4b3d1a;
    --app-reaction-text: #ffe7a3;
    --app-danger: #ef695f;
    --app-danger-text: #ffd3ce;
    --app-chat-header-bg: #0b5ed7;
    --app-chat-header-text: #ffffff;
    --app-chat-header-muted: #dbeafe;
    --app-login-bg: linear-gradient(135deg, #141d1b 0%, #1d242a 56%, #151a1e 100%);
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--app-bg);
    color: var(--app-text);
}

a {
    color: var(--app-link);
}

.app-shell {
    min-height: 100vh;
}

.page-title {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0;
}

.messenger-page,
.management-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.messenger-page {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

.messenger-appbar.e-appbar,
.management-appbar.e-appbar {
    min-height: 64px;
    padding-inline: 12px;
    background: var(--app-accent);
    color: #ffffff;
}

.appbar-heading {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 190px;
}

.appbar-caption {
    font-size: 0.78rem;
    opacity: 0.88;
}

.ban-selector {
    width: min(320px, 28vw);
    min-width: 220px;
}

.messenger-workspace {
    position: relative;
    flex: 1;
    height: calc(100vh - 64px);
    min-height: 0;
    display: flex;
    overflow: hidden;
}

.messenger-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    padding: 12px;
    box-sizing: border-box;
}

.contacts-sidebar.e-sidebar {
    border-right: 1px solid var(--app-border);
    background: var(--app-surface);
}

.contacts-pane {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    box-sizing: border-box;
}

.contact-search {
    flex: 0 0 auto;
}

.contacts-list {
    flex: 1;
    min-height: 0;
    border: 0;
}

.contacts-list .e-list-parent,
.contacts-list .e-list-container {
    height: auto;
}

.contacts-list .e-list-item {
    height: auto !important;
    min-height: 0;
    padding: 0 !important;
    line-height: normal;
}

.contacts-list .e-list-item .e-list-text {
    display: block;
    padding: 0;
    white-space: normal;
}

.contact-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px 12px 11px;
    border-bottom: 1px solid var(--app-row-border);
    cursor: pointer;
    min-height: 82px;
    overflow: hidden;
}

.contact-item:hover {
    background: var(--app-hover);
}

.contact-item.selected {
    background: var(--app-selected);
    border-left: 4px solid var(--app-accent);
}

.contact-name {
    font-weight: 700;
    font-size: 0.96rem;
    line-height: 1.25;
    color: var(--app-heading);
    overflow-wrap: anywhere;
}

.contact-company,
.contact-company-action {
    font-size: 0.78rem;
    line-height: 1.25;
}

.contact-company {
    color: var(--app-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contact-company-action.e-btn.e-link {
    align-self: flex-start;
    height: auto;
    min-height: 0;
    padding: 0;
}

.contact-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 8px;
    font-size: 0.74rem;
    line-height: 1.2;
    color: var(--app-muted);
}

.contact-meta span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.unread-badge {
    flex: 0 0 auto;
    min-width: 24px;
    height: 24px;
    padding: 0 7px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--app-warning);
    color: #ffffff;
    font-weight: 700;
}

.chat-surface {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
}

.chat-context {
    min-height: 58px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--app-subtle-border);
    background: var(--app-chat-header-bg);
    color: var(--app-chat-header-text);
}

.chat-contact-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--app-chat-header-text);
}

.chat-contact-caption,
.policy-link {
    font-size: 0.78rem;
    color: var(--app-chat-header-muted);
}

.chat-tools {
    position: absolute;
    left: 22px;
    right: 66px;
    bottom: 14px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0;
    pointer-events: none;
}

.chat-tools-start,
.chat-tools-end {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.composer-attachment-input {
    display: none;
}

.composer-attachment-button,
.composer-icon-button.e-btn {
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    line-height: 1;
}

.composer-attachment-button {
    border-color: transparent;
    background: transparent;
    color: var(--app-muted);
    font-size: 1.75rem;
    font-weight: 300;
    cursor: pointer;
}

.composer-attachment-button:hover,
.composer-attachment-button:focus {
    background: var(--app-hover);
    color: var(--app-accent);
}

.composer-recording-button.e-btn,
.composer-recording-button.e-btn:hover,
.composer-recording-button.e-btn:focus {
    border-color: #20c463;
    background: #20c463;
    color: #051b11;
}

.composer-recording-button.e-btn.is-recording,
.composer-recording-button.e-btn.is-recording:hover,
.composer-recording-button.e-btn.is-recording:focus {
    border-color: var(--app-accent);
    background: var(--app-accent);
    color: #ffffff;
}

.composer-cancel-button.e-btn,
.composer-cancel-button.e-btn:hover,
.composer-cancel-button.e-btn:focus {
    border-color: var(--app-danger);
    background: var(--app-danger);
    color: #ffffff;
}

.whatsapp-chat {
    flex: 1;
    min-height: 0;
    border: 0;
}

.whatsapp-chat.e-chat-ui .e-footer {
    padding-left: 68px;
    padding-right: 118px;
}

.chat-surface.is-recording .whatsapp-chat.e-chat-ui .e-footer {
    padding-right: 168px;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: min(520px, 74vw);
    overflow-wrap: anywhere;
}

.message-content.sent {
    align-items: flex-end;
}

.message-content.received {
    align-items: flex-start;
}

.message-origin {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--app-accent);
}

.message-text {
    white-space: pre-wrap;
    line-height: 1.36;
}

.message-image {
    width: min(340px, 68vw);
    max-height: 360px;
    object-fit: contain;
    border-radius: 6px;
}

.message-video {
    width: min(360px, 70vw);
    max-height: 360px;
    border-radius: 6px;
}

.message-audio {
    width: min(320px, 64vw);
}

.message-document {
    display: inline-flex;
    color: var(--app-link);
    font-weight: 700;
}

.message-reaction {
    align-self: flex-end;
    padding: 2px 7px;
    border-radius: 10px;
    background: var(--app-reaction-bg);
    color: var(--app-reaction-text);
    font-size: 0.78rem;
}

.message-failed {
    color: var(--app-danger);
    font-weight: 700;
    font-size: 0.78rem;
}

.empty-chat {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--app-muted);
    text-align: center;
    padding: 24px;
}

.empty-chat.full {
    flex: 1;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--app-login-bg);
}

.login-panel {
    width: min(420px, 100%);
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 28px;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.login-logo {
    width: min(100%, 340px);
    height: auto;
    display: block;
    padding: 10px 12px;
    border: 1px solid var(--app-subtle-border);
    border-radius: 6px;
    background: #ffffff;
    object-fit: contain;
}

.login-subtitle {
    color: var(--app-muted);
    font-size: 0.88rem;
}

.login-fields,
.login-actions,
.dialog-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.management-content {
    flex: 1;
    min-height: 0;
    padding: 16px;
}

.template-name {
    font-weight: 700;
    color: var(--app-accent);
}

.company-selector {
    padding: 16px;
    max-width: 420px;
}

.e-toast-danger .e-toast-message {
    color: var(--app-danger-text);
}

#blazor-error-ui {
    background: var(--app-danger);
    bottom: 0;
    color: #ffffff;
    display: none;
    left: 0;
    padding: 0.75rem 1rem;
    position: fixed;
    width: 100%;
    z-index: 10000;
}

#blazor-error-ui .reload {
    color: #ffffff;
    font-weight: 700;
    margin-left: 1rem;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
}

@media (max-width: 760px) {
    .messenger-appbar.e-appbar {
        gap: 6px;
        flex-wrap: wrap;
        min-height: 112px;
    }

    .ban-selector {
        width: 100%;
        min-width: 100%;
        order: 5;
    }

    .contacts-pane {
        height: 100%;
    }

    .messenger-workspace {
        height: calc(100vh - 112px);
    }

    .messenger-body {
        min-height: 0;
        height: 100%;
        padding: 8px;
    }

    .chat-surface {
        height: 100%;
    }

    .chat-context {
        align-items: flex-start;
        flex-direction: column;
    }

    .chat-tools {
        left: 16px;
        right: 58px;
        bottom: 12px;
    }

    .composer-attachment-button,
    .composer-icon-button.e-btn {
        width: 38px;
        min-width: 38px;
        height: 38px;
    }

    .whatsapp-chat.e-chat-ui .e-footer {
        padding-left: 58px;
        padding-right: 108px;
    }

    .chat-surface.is-recording .whatsapp-chat.e-chat-ui .e-footer {
        padding-right: 150px;
    }

    .message-content {
        max-width: 82vw;
    }
}
