* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    --bg: #0c0d12;
    --panel: #12141b;
    --panel2: #171a23;
    --panel3: #1c202b;
    --line: #242936;
    --line2: #1c2230;
    --text: #f5f7fb;
    --muted: #90a1bd;
    --muted2: #64728a;
    --blue: #0877ff;
    --blue2: #0f6fff;
    --blue-soft: #10213d;
    --telegram: #229ed9;
    --web: #20c997;
    --warning: #d79529;
    --danger: #ff5360;
    --shadow: 0 18px 48px rgba(0, 0, 0, .28);
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --panel2: #f8fbff;
    --panel3: #eef4ff;
    --line: #dbe5f4;
    --line2: #e6edf7;
    --text: #101828;
    --muted: #53657f;
    --muted2: #7c8da5;
    --blue: #0877ff;
    --blue2: #0f6fff;
    --blue-soft: #eaf2ff;
    --telegram: #1e96d4;
    --web: #0f9f75;
    --warning: #a76a10;
    --danger: #e23d4d;
    --shadow: 0 18px 48px rgba(30, 64, 175, .12);
}

html,
body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
}

[data-theme="light"] body {
    background:
        linear-gradient(rgba(8, 119, 255, .05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(8, 119, 255, .05) 1px, transparent 1px),
        radial-gradient(circle at 18% 12%, rgba(8, 119, 255, .12), transparent 30%),
        #f5f7fb;
}

body {
    margin: 0;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    background:
        linear-gradient(rgba(255, 255, 255, .028) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .028) 1px, transparent 1px),
        radial-gradient(circle at 18% 12%, rgba(8, 119, 255, .14), transparent 30%),
        #0c0d12;
    background-size: 54px 54px, 54px 54px, auto, auto;
    color: var(--text);
    font-family: Manrope, system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    border: 0;
    color: inherit;
    cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

.shell {
    position: fixed;
    inset: 0;
    width: 100%;
    height: auto;
    max-height: none;
    display: grid;
    grid-template-columns: minmax(320px, 390px) minmax(0, 1fr) minmax(260px, 330px);
    gap: 16px;
    padding: 16px;
    overflow: hidden;
}

.sidebar,
.chat,
.details {
    min-height: 0;
    height: 100%;
    max-height: none;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(18, 20, 27, .94);
    box-shadow: var(--shadow);
    overflow: hidden;
}

[data-theme="light"] .sidebar,
[data-theme="light"] .chat,
[data-theme="light"] .details {
    background: rgba(255, 255, 255, .96);
}

.sidebar {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
}

.brand,
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(18, 20, 27, .78);
    backdrop-filter: blur(18px);
}

[data-theme="light"] .brand,
[data-theme="light"] .chat-header {
    background: rgba(255, 255, 255, .82);
}

.fart-logo {
    display: inline-flex;
    align-items: baseline;
    color: #fff;
    text-decoration: none;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
}

.fart-logo b {
    color: var(--blue);
    font-size: 1.34em;
}

.fart-logo strong {
    color: #f7f8fb;
    font-size: 1em;
}

.fart-logo small {
    color: #f7f8fb;
    font-size: .56em;
    margin-left: 2px;
    font-weight: 900;
}

[data-theme="light"] .fart-logo strong,
[data-theme="light"] .fart-logo small {
    color: #101828;
}

.brand .fart-logo {
    font-size: 28px;
}

.admin-theme-toggle {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel3);
    color: var(--text);
    font-size: 18px;
    box-shadow: var(--shadow);
}

.section-title {
    padding: 20px 20px 14px;
}

.section-title h1,
.chat-header h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.15;
    font-weight: 900;
}

.section-title p,
.chat-header p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 650;
}

.auth,
.filters {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.auth label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 850;
}

.auth-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
}

.filters {
    display: grid;
    gap: 10px;
    position: relative;
    z-index: 2;
    background: rgba(18, 20, 27, .98);
}

.filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.auth input,
.filters input,
.filters select,
.composer textarea,
.note {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #1a1d27;
    color: #dbe9ff;
    outline: none;
    transition: border-color .2s, background .2s, box-shadow .2s, color .2s;
}

.auth input,
.filters input,
.filters select {
    height: 48px;
    padding: 0 14px;
    font-size: 14px;
    font-weight: 750;
}

.filters select {
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, #8998af 50%),
        linear-gradient(135deg, #8998af 50%, transparent 50%);
    background-position: calc(100% - 20px) 20px, calc(100% - 13px) 20px;
    background-size: 7px 7px, 7px 7px;
    background-repeat: no-repeat;
    padding-right: 38px;
}

.auth input:focus,
.filters input:focus,
.filters select:focus,
.composer textarea:focus,
.note:focus {
    border-color: var(--blue);
    background: #172235;
    color: #fff;
    box-shadow: 0 0 0 2px rgba(8, 119, 255, .16) inset;
}

.auth button,
.composer button {
    min-height: 48px;
    border-radius: 14px;
    background: var(--blue);
    color: #fff;
    padding: 0 18px;
    font-weight: 900;
    box-shadow: 0 10px 26px rgba(8, 119, 255, .22);
    transition: background .2s, transform .2s, box-shadow .2s;
}

.auth button:hover,
.composer button:hover {
    background: var(--blue2);
    transform: translateY(-1px);
    box-shadow: 0 14px 32px rgba(8, 119, 255, .3);
}

.conversation-list {
    min-height: 0;
    overflow: auto;
    padding: 12px;
    position: relative;
    z-index: 1;
}

.conversation {
    width: 100%;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 12px;
    border: 1px solid transparent;
    border-radius: 18px;
    background: transparent;
    color: #dbe9ff;
    padding: 12px;
    text-align: left;
    transition: background .2s, border-color .2s, transform .2s;
}

.conversation + .conversation {
    margin-top: 6px;
}

.conversation:hover,
.conversation.active {
    background: #172235;
    border-color: rgba(8, 119, 255, .46);
}

.conversation.active {
    box-shadow: 0 12px 28px rgba(8, 119, 255, .12);
}

.avatar,
.client-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #0877ff, #20c997);
    color: #fff;
    font-weight: 900;
}

.avatar {
    width: 44px;
    height: 44px;
}

.conversation-main {
    min-width: 0;
    display: grid;
    gap: 7px;
}

.conversation-top,
.conversation-meta {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.conversation strong {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #fff;
    font-size: 15px;
    font-weight: 900;
}

.conversation small,
.last {
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}

.last {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 27px;
    border-radius: 999px;
    padding: 5px 10px;
    color: #fff;
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
}

.badge.telegram {
    background: rgba(34, 158, 217, .18);
    color: #7fd4ff;
    border: 1px solid rgba(34, 158, 217, .42);
}

.badge.web {
    background: rgba(32, 201, 151, .16);
    color: #75f0c4;
    border: 1px solid rgba(32, 201, 151, .34);
}

.badge.muted {
    background: #202431;
    color: var(--muted);
}

.badge.status-new {
    background: rgba(215, 149, 41, .18);
    color: #ffd08a;
    border: 1px solid rgba(215, 149, 41, .36);
}

.badge.status-open {
    background: var(--blue-soft);
    color: #dbe9ff;
    border: 1px solid rgba(8, 119, 255, .56);
}

.badge.status-closed {
    background: #242936;
    color: #9aacce;
    border: 1px solid #384055;
}

.unread {
    background: var(--danger);
    color: #fff;
    border: 1px solid rgba(255, 83, 96, .45);
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.secondary-button {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #181b25;
    color: #dbe9ff;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 900;
    transition: background .2s, transform .2s, border-color .2s;
}

.secondary-button:hover {
    border-color: var(--blue);
    background: var(--blue-soft);
    transform: translateY(-1px);
}

.secondary-button:disabled,
.composer button:disabled,
.composer textarea:disabled {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
}

.chat {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.messages {
    min-height: 0;
    overflow: auto;
    padding: 22px;
}

.empty {
    color: var(--muted);
    text-align: center;
    margin-top: 15vh;
    font-weight: 750;
}

.day-divider {
    width: fit-content;
    margin: 4px auto 18px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #151820;
    color: var(--muted);
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 850;
}

.message {
    max-width: min(720px, 86%);
    margin: 0 0 14px;
    padding: 13px 15px;
    border-radius: 18px;
    background: #171a23;
    border: 1px solid var(--line);
    box-shadow: 0 12px 28px rgba(0, 0, 0, .12);
}

.message.support {
    margin-left: auto;
    background: var(--blue-soft);
    border-color: rgba(8, 119, 255, .42);
}

.message.system {
    max-width: min(520px, 80%);
    margin-left: auto;
    margin-right: auto;
    background: #151820;
    color: var(--muted);
    text-align: center;
}

.message-meta {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
}

.message-deleted {
    opacity: 0.5;
    background: rgba(80, 80, 90, .3) !important;
    border-color: rgba(80, 80, 90, .4) !important;
}

.message-deleted .message-body {
    color: var(--muted);
    font-style: italic;
}

.message-delete-banner {
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 800;
    color: #8d94ab;
    letter-spacing: .02em;
}

.message-delete-state {
    margin-left: 6px;
    color: #8d94ab;
}

.message-deleted-body {
    color: #8d94ab;
}

.admin-error-message {
    padding: 12px 16px;
    margin: 8px 0;
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.3);
    border-radius: 4px;
    color: #ff6b6b;
    font-size: 13px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: #f5f7fb;
    line-height: 1.48;
}

.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow: hidden;
    padding: 12px 16px 0;
    border-top: 1px solid var(--line);
    background: rgba(18, 20, 27, .9);
}

.quick-replies button {
    min-height: 36px;
    flex: 0 1 auto;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #181b25;
    color: #cfe0ff;
    padding: 0 13px;
    font-size: 13px;
    font-weight: 850;
}

.quick-replies::-webkit-scrollbar {
    display: none;
}

.quick-replies button:hover {
    border-color: rgba(8, 119, 255, .58);
    background: #172235;
}

.composer {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px 16px 16px;
    background: rgba(18, 20, 27, .9);
}

.composer textarea {
    min-height: 58px;
    max-height: 160px;
    resize: none;
    padding: 14px 16px;
    line-height: 1.4;
}

.composer-actions {
    display: flex;
    gap: 12px;
}

.icon-button {
    border: 1px solid var(--line2);
    border-radius: 8px;
    background: rgba(24, 26, 32, .8);
    color: var(--text);
    padding: 14px 16px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 46px;
}

.icon-button:hover:not(:disabled) {
    background: rgba(30, 32, 40, .9);
}

.icon-button:disabled,
.submit-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.submit-button {
    border: 0;
    border-radius: 8px;
    background: var(--blue);
    color: #fff;
    padding: 14px 16px;
    cursor: pointer;
    flex: 1;
    font-weight: 600;
}

.submit-button:hover:not(:disabled) {
    background: var(--blue2);
}

.file-preview {
    display: grid;
    gap: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(24, 26, 32, .5);
    border-radius: 4px;
    border: 1px solid var(--line2);
}

.file-name {
    flex: 1;
    word-break: break-all;
    font-size: 13px;
    color: var(--text);
}

.file-size {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.remove-file {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 0 4px;
    font-size: 14px;
}

.remove-file:hover {
    color: var(--text);
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.attachment-image {
    display: inline-block;
    max-width: 200px;
}

.attachment-image img {
    max-width: 100%;
    height: auto;
    display: block;
}

.attachment-file {
    display: inline-block;
    padding: 8px 12px;
    background: rgba(24, 26, 32, .5);
    border-radius: 4px;
    color: var(--blue);
    text-decoration: none;
    font-size: 13px;
    border: 1px solid var(--line2);
}

.attachment-file:hover {
    background: rgba(24, 26, 32, .8);
}

.details {
    min-width: 0;
    min-height: 0;
    padding: 14px;
    overflow: auto;
}

.details-card {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #151820;
    padding: 16px;
}

.details-card + .details-card {
    margin-top: 12px;
}

.client-avatar {
    width: 62px;
    height: 62px;
    margin-bottom: 14px;
    font-size: 24px;
}

.details-card h3 {
    margin: 0 0 10px;
    font-size: 15px;
    font-weight: 900;
}

.details-card p,
.details-card span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.details-card p {
    margin: 6px 0 0;
    overflow-wrap: anywhere;
}

.details-card.compact {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: 10px 12px;
}

.details-card.compact strong {
    color: #f5f7fb;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.note {
    min-height: 130px;
    resize: vertical;
    padding: 12px;
    line-height: 1.45;
}

@media (max-width: 1180px) {
    .shell {
        grid-template-columns: minmax(300px, 370px) minmax(0, 1fr);
    }

    .details {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 12px;
    }

    .details-card + .details-card {
        margin-top: 0;
    }
}

@media (max-width: 860px) {
    .shell {
        grid-template-columns: 1fr;
        padding: 10px;
        gap: 10px;
    }

    .sidebar,
    .chat,
    .details {
        border-radius: 18px;
    }

    .sidebar {
        height: 42vh;
        max-height: 42vh;
    }

    .chat {
        height: 54vh;
        min-height: 0;
    }

    .details {
        display: block;
    }

    .details-card + .details-card {
        margin-top: 12px;
    }

    .header-actions {
        justify-content: flex-start;
    }

    .composer {
        grid-template-columns: 1fr;
    }

    .composer-actions {
        width: 100%;
    }

    .submit-button {
        min-height: 42px;
    }
}

@media (max-width: 520px) {
    .filter-row,
    .auth-row,
    .action-grid {
        grid-template-columns: 1fr;
    }

    .brand,
    .chat-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .conversation {
        grid-template-columns: 38px minmax(0, 1fr);
    }

    .avatar {
        width: 38px;
        height: 38px;
    }
}

[data-theme="light"] .auth,
[data-theme="light"] .filters,
[data-theme="light"] .quick-replies,
[data-theme="light"] .composer {
    background: rgba(255, 255, 255, .92);
}

[data-theme="light"] .auth input,
[data-theme="light"] .filters input,
[data-theme="light"] .filters select,
[data-theme="light"] .composer textarea,
[data-theme="light"] .note {
    background: #f8fbff;
    color: #101828;
    border-color: #cfdcf0;
}

[data-theme="light"] .auth input:focus,
[data-theme="light"] .filters input:focus,
[data-theme="light"] .filters select:focus,
[data-theme="light"] .composer textarea:focus,
[data-theme="light"] .note:focus {
    background: #ffffff;
    color: #101828;
    border-color: var(--blue);
}

[data-theme="light"] .conversation {
    color: #243247;
    background: transparent;
}

[data-theme="light"] .conversation:hover,
[data-theme="light"] .conversation.active {
    background: #eaf2ff;
    border-color: rgba(8, 119, 255, .35);
}

[data-theme="light"] .conversation strong,
[data-theme="light"] .message-body,
[data-theme="light"] .details-card.compact strong {
    color: #101828;
}

[data-theme="light"] .conversation.active strong {
    color: #0f172a;
}

[data-theme="light"] .badge.muted,
[data-theme="light"] .badge.status-closed {
    background: #eef4ff;
    color: #53657f;
    border-color: #dbe5f4;
}

[data-theme="light"] .badge.status-open {
    background: #eaf2ff;
    color: #0f6fff;
}

[data-theme="light"] .message,
[data-theme="light"] .message.system,
[data-theme="light"] .empty,
[data-theme="light"] .details-card {
    background: #ffffff;
    color: #101828;
    border-color: #dbe5f4;
    box-shadow: 0 14px 34px rgba(30, 64, 175, .08);
}

[data-theme="light"] .message.visitor {
    background: #f8fbff;
}

[data-theme="light"] .message.support {
    background: #eaf2ff;
    border-color: rgba(8, 119, 255, .22);
}

[data-theme="light"] .message-meta,
[data-theme="light"] .details-card p,
[data-theme="light"] .details-card span,
[data-theme="light"] .conversation small,
[data-theme="light"] .conversation-meta,
[data-theme="light"] .auth label,
[data-theme="light"] .section-title p,
[data-theme="light"] .chat-header p {
    color: #53657f;
}

[data-theme="light"] .quick-replies button,
[data-theme="light"] .secondary-button,
[data-theme="light"] .file-item,
[data-theme="light"] .attachment-file {
    background: #f8fbff;
    color: #243247;
    border-color: #dbe5f4;
}

[data-theme="light"] .quick-replies button:hover,
[data-theme="light"] .secondary-button:hover,
[data-theme="light"] .attachment-file:hover {
    background: #eaf2ff;
}

[data-theme="light"] .file-preview {
    background: rgba(248, 251, 255, .86);
    border-color: #dbe5f4;
}

[data-theme="light"] .details-card h3,
[data-theme="light"] .section-title h1,
[data-theme="light"] .chat-header h2 {
    color: #101828;
}

[data-theme="light"] .client-avatar {
    color: #ffffff;
}
