:root {
    /* Colors — Premium Dark */
    --bg-primary: #0f0f14;
    --bg-secondary: #16161e;
    --bg-tertiary: #1c1c28;
    --bg-elevated: #22222f;
    --bg-hover: #282838;
    --bg-active: #2d2d40;
    --bg-accent: #7c3aed;
    --bg-accent-hover: #6d28d9;
    --bg-accent-subtle: rgba(124, 58, 237, 0.12);
    --bg-success: rgba(34, 197, 94, 0.12);
    --bg-warning: rgba(251, 191, 36, 0.12);
    --bg-danger: rgba(239, 68, 68, 0.12);

    --text-primary: #f1f1f6;
    --text-secondary: #9898ad;
    --text-tertiary: #6b6b80;
    --text-accent: #a78bfa;
    --text-success: #4ade80;
    --text-warning: #fbbf24;
    --text-danger: #f87171;
    --text-link: #818cf8;

    --border-color: #2a2a3b;
    --border-subtle: #1f1f2e;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);

    /* Spacing */
    --sidebar-width: 340px;
    --header-height: 56px;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-full: 999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ============================================ */
/* LAYOUT                                       */
/* ============================================ */

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* NAV — Левая панель иконок */
.nav {
    width: 60px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    flex-shrink: 0;
}

.nav-logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #7c3aed, #3b82f6);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: white;
    margin-bottom: 20px;
}

.nav-item {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
    margin-bottom: 4px;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-accent-subtle);
    color: var(--text-accent);
}

.nav-item .badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 16px;
    height: 16px;
    background: #ef4444;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.nav-spacer { flex: 1; }

/* SIDEBAR — Список чатов */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-title .count {
    font-size: 12px;
    background: var(--bg-accent);
    color: white;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-weight: 500;
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 0 12px;
    border: 1px solid transparent;
    transition: border-color var(--transition-fast);
}

.search-box:focus-within {
    border-color: var(--bg-accent);
}

.search-box svg {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 13px;
    padding: 9px 10px;
    font-family: inherit;
}

.search-box input::placeholder {
    color: var(--text-tertiary);
}

/* Filter tabs */
.filter-tabs {
    display: flex;
    padding: 8px 12px;
    gap: 4px;
    border-bottom: 1px solid var(--border-subtle);
    overflow-x: auto;
}

.filter-tab {
    padding: 5px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    background: none;
    border: none;
}

.filter-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.filter-tab.active {
    background: var(--bg-accent-subtle);
    color: var(--text-accent);
}

/* Chat list */
.chat-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.chat-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-subtle);
    gap: 12px;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--bg-active);
    border-left: 3px solid var(--bg-accent);
    padding-left: 13px;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    color: white;
    flex-shrink: 0;
    position: relative;
}

.chat-avatar .online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border: 2px solid var(--bg-secondary);
    border-radius: var(--radius-full);
}

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

.chat-info-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.chat-name {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 11px;
    color: var(--text-tertiary);
    flex-shrink: 0;
    margin-left: 8px;
}

.chat-preview {
    font-size: 12.5px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-unread {
    min-width: 18px;
    height: 18px;
    background: var(--bg-accent);
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    margin-left: 8px;
    padding: 0 5px;
}

.chat-platform {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    margin-left: 6px;
}

.platform-whatsapp {
    background: rgba(37, 211, 102, 0.15);
    color: #25d366;
}

.platform-telegram {
    background: rgba(0, 136, 204, 0.15);
    color: #0088cc;
}

/* ============================================ */
/* MAIN — Область чата                          */
/* ============================================ */

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Chat header */
.chat-header {
    height: var(--header-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
}

.chat-header-name {
    font-weight: 600;
    font-size: 14px;
}

.chat-header-status {
    font-size: 12px;
    color: var(--text-tertiary);
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.header-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.header-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Messages area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.message-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}

.message {
    max-width: 65%;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: messageIn 200ms ease;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.incoming {
    background: var(--bg-elevated);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message.outgoing {
    background: linear-gradient(135deg, #6d28d9, #7c3aed);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.6;
}

.message-time {}

.message-status {
    display: flex;
    align-items: center;
}

.date-divider {
    text-align: center;
    padding: 12px 0;
}

.date-divider span {
    font-size: 11px;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    padding: 4px 14px;
    border-radius: var(--radius-full);
}

/* Composer */
.composer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.composer-input-wrap {
    flex: 1;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: flex-end;
    padding: 4px 4px 4px 14px;
    border: 1px solid transparent;
    transition: border-color var(--transition-fast);
}

.composer-input-wrap:focus-within {
    border-color: var(--bg-accent);
}

.composer-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    min-height: 36px;
    padding: 8px 0;
    line-height: 1.4;
}

.composer-input::placeholder {
    color: var(--text-tertiary);
}

.composer-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.composer-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.composer-send {
    background: var(--bg-accent);
    color: white;
    border-radius: var(--radius-md);
}

.composer-send:hover {
    background: var(--bg-accent-hover);
}

.composer-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============================================ */
/* EMPTY STATE                                  */
/* ============================================ */

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    gap: 16px;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 13px;
    max-width: 300px;
    text-align: center;
    line-height: 1.5;
}

/* ============================================ */
/* AUTH SCREEN                                  */
/* ============================================ */

.auth-screen {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

.auth-card {
    width: 400px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 32px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.auth-card h1 {
    font-size: 22px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.auth-card .subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition-fast);
}

.form-input:focus {
    border-color: var(--bg-accent);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
    gap: 8px;
}

.btn-primary {
    width: 100%;
    background: var(--bg-accent);
    color: white;
}

.btn-primary:hover {
    background: var(--bg-accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.auth-toggle {
    text-align: center;
    margin-top: 16px;
    font-size: 12.5px;
    color: var(--text-secondary);
}

.auth-toggle a {
    color: var(--text-accent);
    cursor: pointer;
    text-decoration: none;
}

.auth-toggle a:hover {
    text-decoration: underline;
}

.toast {
    position: fixed;
    top: 16px;
    right: 16px;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    z-index: 9999;
    animation: slideIn 250ms ease;
    box-shadow: var(--shadow-md);
}

@keyframes slideIn {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast-success { background: #166534; color: #bbf7d0; border: 1px solid #22c55e33; }
.toast-error { background: #7f1d1d; color: #fecaca; border: 1px solid #ef444433; }
.toast-info { background: #1e3a5f; color: #bfdbfe; border: 1px solid #3b82f633; }

/* Status badges */
.status-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-open { background: var(--bg-success); color: var(--text-success); }
.status-pending { background: var(--bg-warning); color: var(--text-warning); }
.status-resolved { background: var(--bg-accent-subtle); color: var(--text-accent); }
.status-closed { background: var(--bg-hover); color: var(--text-tertiary); }

/* Loading */
.loading-dots {
    display: inline-flex;
    gap: 4px;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: dotPulse 1.2s infinite ease-in-out;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

/* Typing indicator */
.typing-indicator {
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-tertiary);
    font-style: italic;
}
