﻿* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        sans-serif;
    background: #f5f6f8;
    color: #1e2430;
}

button,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app {
    height: 100vh;
    display: grid;
    grid-template-columns: 330px minmax(420px, 1fr) 300px;
    overflow: hidden;
}


/* LEFT */

.sidebar {
    background: white;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand {
    height: 76px;
    padding: 15px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #edf0f4;
}

.logo {
    width: 42px;
    height: 42px;
    background: #3468f5;
    color: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 21px;
}

.brand-title {
    font-weight: 700;
    font-size: 17px;
}

.brand-subtitle {
    font-size: 12px;
    margin-top: 3px;
    color: #89919f;
}

.search-box {
    padding: 14px 14px 8px;
}

.search-box input {
    width: 100%;
    border: 1px solid #e2e6ec;
    background: #f6f7f9;
    padding: 11px 13px;
    border-radius: 10px;
    outline: none;
}

.search-box input:focus {
    border-color: #9fb6fb;
    background: white;
}

.filters {
    display: flex;
    gap: 5px;
    padding: 5px 14px 12px;
    overflow-x: auto;
}

.filter {
    border: 0;
    border-radius: 7px;
    padding: 7px 10px;
    background: #f0f2f5;
    white-space: nowrap;
    font-size: 12px;
}

.filter.active {
    color: white;
    background: #3468f5;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conversation {
    display: grid;
    grid-template-columns: 46px 1fr auto;
    gap: 10px;
    padding: 13px 14px;
    border-bottom: 1px solid #f0f1f3;
    cursor: pointer;
}

.conversation:hover {
    background: #f7f9fd;
}

.conversation.active {
    background: #eef3ff;
}

.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #e7ecf7;
    color: #31405c;
    font-weight: 700;
}

.conversation-main {
    min-width: 0;
}

.conv-name {
    font-size: 14px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-child {
    font-size: 11px;
    color: #7b8492;
    margin-top: 2px;
}

.conv-last {
    margin-top: 5px;
    color: #687282;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-meta {
    text-align: right;
}

.conv-time {
    color: #8d95a2;
    font-size: 11px;
}

.badge {
    display: inline-flex;
    min-width: 20px;
    height: 20px;
    margin-top: 8px;
    padding: 0 6px;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    color: white;
    background: #3468f5;
    font-size: 11px;
}

.channel {
    display: inline-block;
    font-size: 10px;
    padding: 2px 5px;
    margin-top: 4px;
    border-radius: 5px;
}

.channel.telegram {
    background: #e9f4ff;
    color: #2584c7;
}

.channel.vk {
    background: #ebf2ff;
    color: #2864ba;
}

.channel.whatsapp {
    background: #e9f8ef;
    color: #168a47;
}


/* CENTER */

.chat {
    display: flex;
    flex-direction: column;
    background: #f3f5f8;
    min-width: 0;
}

.chat-header {
    min-height: 76px;
    padding: 13px 20px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-name {
    font-weight: 700;
    font-size: 16px;
}

.chat-status {
    margin-top: 3px;
    font-size: 12px;
    color: #808998;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.secondary-button {
    border: 1px solid #dfe3e9;
    background: white;
    padding: 8px 11px;
    border-radius: 8px;
    color: #515a68;
    font-size: 12px;
}

.secondary-button:hover {
    background: #f6f7f9;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 25px max(25px, 6%);
}

.message {
    max-width: 72%;
    margin-bottom: 16px;
}

.message.incoming {
    margin-right: auto;
}

.message.outgoing {
    margin-left: auto;
}

.message.internal {
    margin-left: auto;
    margin-right: auto;
    max-width: 82%;
}

.message-info {
    font-size: 11px;
    color: #7c8593;
    margin: 0 7px 5px;
}

.outgoing .message-info {
    text-align: right;
}

.bubble {
    padding: 11px 14px;
    border-radius: 15px;
    line-height: 1.4;
    font-size: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.bubble.deleted {
    color: #737b8c;
    font-style: italic;
}

.message-attachment {
    display: block;
    margin-bottom: 6px;
}

.message-attachment img,
.message-attachment video {
    display: block;
    max-width: min(420px, 100%);
    max-height: 360px;
    border-radius: 14px;
    background: #e7ebf2;
}

.message-attachment audio {
    display: block;
    max-width: 100%;
}

.attachment-file {
    padding: 12px 14px;
    border: 1px solid #cfd8e7;
    border-radius: 10px;
    background: #fff;
    color: #255de0;
    overflow-wrap: anywhere;
}

.incoming .bubble {
    background: white;
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.outgoing .bubble {
    background: #dce7ff;
    border-bottom-right-radius: 5px;
}

.internal .bubble {
    background: #fff5cc;
    border: 1px solid #f0df91;
    color: #554b1e;
}

.internal .message-info {
    text-align: center;
}

.composer {
    background: white;
    border-top: 1px solid #e0e3e8;
    padding: 9px 16px 12px;
}

.mode-switch {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.mode-button {
    border: 0;
    border-radius: 7px;
    padding: 5px 9px;
    background: transparent;
    color: #7a8390;
    font-size: 11px;
}

.mode-button.active {
    background: #edf2ff;
    color: #315fd1;
}

.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.attach-button {
    width: 39px;
    height: 39px;
    border: 0;
    background: #f0f2f5;
    border-radius: 9px;
    font-size: 22px;
    color: #657080;
}

textarea {
    flex: 1;
    resize: none;
    max-height: 130px;
    min-height: 39px;
    padding: 10px 12px;
    border: 1px solid #dde1e7;
    border-radius: 10px;
    outline: none;
}

textarea:focus {
    border-color: #91acf9;
}

.send-button {
    min-height: 39px;
    border: 0;
    background: #3468f5;
    color: white;
    padding: 0 17px;
    border-radius: 9px;
}

.send-button:hover {
    background: #2858dc;
}

.composer-hint {
    margin-top: 6px;
    padding-left: 48px;
    font-size: 10px;
    color: #a0a6af;
}


/* RIGHT */

.contact-panel {
    background: white;
    border-left: 1px solid #e5e7eb;
    overflow-y: auto;
}

.user-box {
    height: 76px;
    padding: 12px 17px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #edf0f4;
}

.user-avatar {
    width: 39px;
    height: 39px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1f2937;
    color: white;
    border-radius: 50%;
    font-weight: 700;
}

.user-name {
    font-size: 13px;
    font-weight: 650;
}

.user-role {
    font-size: 10px;
    color: #8a929f;
    margin-top: 2px;
}

.contact-card {
    padding: 26px 20px;
}

.contact-avatar {
    margin: 0 auto 11px;
    width: 68px;
    height: 68px;
    background: #e7ecf7;
    color: #33415c;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 23px;
    font-weight: 700;
}

.contact-card h2 {
    text-align: center;
    font-size: 17px;
    margin: 0;
}

.contact-child {
    text-align: center;
    color: #818a98;
    margin: 5px 0 25px;
    font-size: 12px;
}

.contact-section {
    margin-bottom: 17px;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.contact-section .label {
    color: #989faa;
    font-size: 10px;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.contact-buttons {
    display: grid;
    gap: 7px;
    margin-top: 24px;
}

.contact-buttons button {
    border: 1px solid #dde1e8;
    background: white;
    border-radius: 8px;
    padding: 9px;
}

.contact-buttons button:hover {
    background: #f7f8fa;
}


/* RESPONSIVE */

@media (max-width: 1050px) {
    .app {
        grid-template-columns: 300px 1fr;
    }

    .contact-panel {
        display: none;
    }
}

@media (max-width: 700px) {
    .app {
        grid-template-columns: 110px 1fr;
    }

    .brand-title,
    .brand-subtitle,
    .search-box,
    .filters,
    .conversation-main,
    .conv-meta {
        display: none;
    }

    .sidebar {
        align-items: stretch;
    }

    .conversation {
        display: flex;
        justify-content: center;
    }

    .chat-header-actions {
        display: none;
    }

    .message {
        max-width: 88%;
    }
}

/* ================================
   STEP 1.2
   Inbox controls
================================ */

.inbox-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px 14px 4px;
}

.summary-item {
    background: #f5f7fb;
    border: 1px solid #edf0f5;
    border-radius: 9px;
    padding: 8px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: #727c8a;
}

.summary-item strong {
    color: #202938;
    font-size: 14px;
}

.filter-section {
    padding: 4px 14px 5px;
}

.filter-title {
    font-size: 10px;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 6px;
}

.filter-section .filters {
    padding: 0;
    flex-wrap: wrap;
}

.channel-filter-section {
    padding-bottom: 11px;
    border-bottom: 1px solid #edf0f4;
}

.channel-filter {
    border: 0;
    border-radius: 7px;
    padding: 6px 9px;
    background: #f0f2f5;
    white-space: nowrap;
    font-size: 11px;
}

.channel-filter.active {
    background: #2d3748;
    color: white;
}

.conversation-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.conversation-tags {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 4px;
}

.responsible-tag {
    display: inline-block;
    font-size: 9px;
    color: #687386;
    background: #f0f2f5;
    border-radius: 5px;
    padding: 2px 5px;
}

.mini-status {
    font-size: 8px;
    border-radius: 4px;
    padding: 2px 4px;
    text-transform: uppercase;
    white-space: nowrap;
}

.mini-status.open {
    color: #16794d;
    background: #e7f7ef;
}

.mini-status.waiting {
    color: #856404;
    background: #fff5cc;
}

.mini-status.closed {
    color: #69717d;
    background: #e9ebef;
}

.chat-name-row {
    display: flex;
    align-items: center;
    gap: 9px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 20px;
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
}

.status-badge.open {
    background: #e6f7ee;
    color: #147348;
}

.status-badge.waiting {
    background: #fff2bf;
    color: #826300;
}

.status-badge.closed {
    background: #eceef2;
    color: #626a75;
}

.conversation-info-bar {
    min-height: 36px;
    display: flex;
    align-items: center;
    gap: 25px;
    padding: 0 20px;
    background: #fafbfc;
    border-bottom: 1px solid #e8ebef;
    color: #7a8492;
    font-size: 11px;
}

.conversation-info-bar strong {
    color: #444d5a;
}

.secondary-button:disabled {
    opacity: .55;
    cursor: default;
}

.empty-list {
    padding: 30px 20px;
    text-align: center;
    color: #9aa2ad;
    font-size: 12px;
}

@media (max-width: 1250px) {

    .chat-header-actions {
        gap: 4px;
    }

    .secondary-button {
        padding: 7px 8px;
        font-size: 11px;
    }

}


/* ====================================
   SETTINGS / MODALS
==================================== */

.primary-action {
    border: 0;
    background: #3468f5;
    color: white;
    padding: 9px 15px;
    border-radius: 8px;
    cursor: pointer;
}

.primary-action:hover {
    background: #2858dc;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    background: rgba(20, 27, 38, .45);
    backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    width: 100%;
    max-width: 520px;

    background: white;

    border-radius: 14px;

    box-shadow:
        0 25px 60px rgba(0, 0, 0, .22);

    overflow: hidden;
}

.modal-header {
    padding: 17px 20px;

    display: flex;
    justify-content: space-between;
    align-items: center;

    border-bottom: 1px solid #e9ebef;
}

.modal-header h2 {
    margin: 0;
    font-size: 17px;
}

.modal-close {
    width: 34px;
    height: 34px;

    border: 0;
    background: transparent;

    font-size: 25px;
    color: #7c8490;
}

.modal-body {
    padding: 20px;

    display: grid;
    gap: 15px;
}

.modal-body label {
    display: grid;
    gap: 6px;

    font-size: 12px;
    color: #626b78;
}

.modal-body input,
.modal-body select,
.modal-body textarea {
    width: 100%;

    border: 1px solid #dfe3e8;

    border-radius: 8px;

    padding: 9px 11px;

    background: white;
}

.modal-body input:focus,
.modal-body textarea:focus,
.modal-body select:focus {
    outline: none;
    border-color: #91acf9;
}

.modal-footer {
    padding: 14px 20px;

    display: flex;
    justify-content: flex-end;
    gap: 8px;

    background: #f8f9fb;

    border-top: 1px solid #e9ebef;
}

.modal-description {
    margin: 0 0 5px;

    color: #7d8591;
    font-size: 12px;
}


/* SETTINGS PAGE */

.settings-page {
    min-height: 100vh;
    background: #f5f6f8;
}

.settings-header {
    min-height: 90px;

    background: white;

    border-bottom: 1px solid #e3e6eb;

    padding: 18px 30px;

    display: flex;
    align-items: center;
    gap: 24px;
}

.settings-header h1 {
    margin: 0;

    font-size: 20px;
}

.settings-header p {
    margin: 4px 0 0;

    color: #89919d;
    font-size: 12px;
}

.settings-header .primary-action {
    margin-left: auto;
}

.back-link {
    text-decoration: none;

    color: #556070;

    padding: 8px 11px;

    background: #f3f4f6;

    border-radius: 8px;
}

.settings-content {
    max-width: 1100px;

    margin: 0 auto;

    padding: 35px 25px;
}

.settings-card {
    background: white;

    border: 1px solid #e3e6eb;

    border-radius: 12px;

    overflow: hidden;
}


/* USERS */

.users-table {
    width: 100%;

    border-collapse: collapse;
}

.users-table th {
    text-align: left;

    padding: 13px 16px;

    background: #f8f9fb;

    color: #818996;

    font-size: 11px;
    font-weight: 600;
}

.users-table td {
    padding: 14px 16px;

    border-top: 1px solid #edf0f3;

    font-size: 13px;
}

.table-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.small-avatar {
    width: 34px;
    height: 34px;

    border-radius: 50%;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #e7ecf7;

    font-weight: 700;
}

.role-badge {
    padding: 4px 7px;

    border-radius: 5px;

    background: #edf2ff;

    color: #315fd1;

    font-size: 10px;
}

.user-status {
    font-size: 11px;
}

.user-status.active {
    color: #157347;
}

.user-status.inactive {
    color: #a83b3b;
}


/* INTEGRATIONS */

.integration-grid {
    display: grid;
    gap: 14px;
}

.integration-card {
    background: white;

    border: 1px solid #e2e5ea;

    border-radius: 12px;

    padding: 18px;

    display: grid;

    grid-template-columns:
        52px
        1fr
        auto
        auto;

    align-items: center;

    gap: 15px;
}

.integration-icon {
    width: 50px;
    height: 50px;

    border-radius: 12px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #edf2ff;

    color: #315fd1;

    font-weight: 700;
}

.integration-info h3 {
    margin: 0;

    font-size: 15px;
}

.integration-info p {
    margin: 4px 0 0;

    color: #8b929d;

    font-size: 11px;
}

.integration-status {
    padding: 5px 8px;

    border-radius: 20px;

    font-size: 10px;
}

.integration-status.disabled {
    background: #f0f1f3;
    color: #69717e;
}

.integration-status.future {
    background: #fff1c5;
    color: #80620c;
}


.owner-links {
    margin-top: 4px;
    font-size: 10px;
}

.owner-links a {
    color: #3468f5;
    text-decoration: none;
}

.owner-links a:hover {
    text-decoration: underline;
}

.owner-links span {
    color: #adb3bc;
    margin: 0 2px;
}

.inbox-notice {
    position: fixed;
    z-index: 120;
    top: 78px;
    left: 50%;
    transform: translateX(-50%);
    width: min(620px, calc(100% - 32px));
    padding: 12px 14px;
    border: 1px solid #e8b4b8;
    border-radius: 9px;
    background: #fff1f2;
    color: #8f2430;
    box-shadow: 0 8px 24px rgba(24, 40, 62, 0.16);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.inbox-notice[hidden] {
    display: none;
}

.inbox-notice button {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 20px;
    cursor: pointer;
}

.load-error-action {
    margin-top: 12px;
}

