/* 🔥 ГЛАВНОЕ: Чтобы ничего не вылезало за экран */
*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    /* --- СВЕТЛАЯ ТЕМА (DEFAULT) --- */
    --bg-body: #f1f5f9;
    --bg-sidebar: #0f172a;
    --bg-card: rgba(255, 255, 255, 0.8);
    --bg-input: rgba(255, 255, 255, 0.6);
    
    --text-main: #1e293b;
    --text-sec: #64748b;
    --text-inverse: #ffffff;
    
    --border: 1px solid rgba(226, 232, 240, 0.8);
    --border-focus: #3b82f6;
    
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: rgba(37, 99, 235, 0.1);
    
    --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 20px 40px -10px rgba(0, 0, 0, 0.1);
    
    --glass-blur: blur(20px);
}

/* --- ТЕМНАЯ ТЕМА --- */
[data-theme="dark"] {
    --bg-body: #0b1120;
    --bg-sidebar: #020617;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-input: rgba(15, 23, 42, 0.6);
    
    --text-main: #f8fafc;
    --text-sec: #94a3b8;
    --text-inverse: #ffffff;
    
    --border: 1px solid rgba(51, 65, 85, 0.5);
    --border-focus: #60a5fa;
    
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: rgba(59, 130, 246, 0.2);
    
    --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --shadow-hover: 0 20px 40px -10px rgba(0, 0, 0, 0.7);
}

/* --- БАЗА (ТВОИ ГРАДИЕНТЫ) --- */
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    background-image: radial-gradient(at 0% 0%, var(--primary-light) 0px, transparent 50%),
                      radial-gradient(at 100% 100%, var(--primary-light) 0px, transparent 50%);
    background-attachment: fixed;
    margin: 0;
    color: var(--text-main);
    height: 100vh;
    display: flex;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- САЙДБАР --- */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    flex-shrink: 0;
    z-index: 100;
    border-right: var(--border);
    transition: transform 0.3s ease;
}

.brand { font-size: 22px; font-weight: 700; margin-bottom: 40px; display: flex; align-items: center; gap: 12px; padding-left: 12px; letter-spacing: -0.5px; color: var(--text-inverse); }

.menu { display: flex; flex-direction: column; gap: 6px; flex-grow: 1; }

.menu-item {
    padding: 12px 16px;
    border-radius: 12px;
    text-decoration: none;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
}
.menu-item i { width: 20px; text-align: center; font-size: 16px; }
.menu-item:hover { background: rgba(255,255,255,0.05); color: var(--text-inverse); }
.menu-item.active { background: var(--primary-light); color: var(--primary); border: 1px solid rgba(59, 130, 246, 0.1); }
.menu-item.logout { color: #ef4444; margin-top: auto; }
.menu-item.logout:hover { background: rgba(239, 68, 68, 0.15); color: #f87171; }

/* --- MAIN --- */
.main-content { 
    flex-grow: 1; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    position: relative;
    width: 100%;
}

.top-bar {
    height: 80px;
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 40px; flex-shrink: 0;
    transition: background-color 0.3s ease;
}

.page-title h2 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.5px; color: var(--text-main); }
.page-title p { margin: 4px 0 0; color: var(--text-sec); font-size: 14px; }
.top-actions { display: flex; align-items: center; gap: 15px; }

/* --- UI КАРТОЧКИ --- */
.scroll-area { padding: 40px; overflow-y: auto; flex-grow: 1; scroll-behavior: smooth; }

.card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--border);
    border-radius: 20px;
    padding: 30px;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s;
    box-shadow: var(--shadow-card);
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; }

/* --- ЭЛЕМЕНТЫ ФОРМ --- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--text-main); margin-top: 20px; }

input, select, textarea {
    width: 100%; padding: 14px 16px; 
    border: var(--border); 
    border-radius: 12px;
    background: var(--bg-input);
    color: var(--text-main);
    font-family: inherit; font-size: 15px; box-sizing: border-box;
    transition: 0.2s;
}
input::placeholder { color: var(--text-sec); opacity: 0.7; }
input:focus, select:focus, textarea:focus { 
    background: var(--bg-card); 
    border-color: var(--border-focus); 
    outline: none; 
    box-shadow: 0 0 0 4px var(--primary-light); 
}

/* --- КНОПКИ --- */
.btn { 
    width: 100%; padding: 14px; border-radius: 12px; border: none; 
    font-weight: 600; font-size: 15px; cursor: pointer; transition: all 0.3s; 
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 15px var(--primary-light); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-2px); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-sec); }
.btn-ghost:hover { border-color: var(--text-main); color: var(--text-main); background: var(--bg-input); }

/* --- ТЕМНЫЙ ПЕРЕКЛЮЧАТЕЛЬ --- */
.theme-toggle-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-main);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.3s;
    font-size: 18px;
}
.theme-toggle-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* --- ПРОФИЛЬ --- */
.profile-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, #60a5fa, #2563eb);
    color: white; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; cursor: pointer;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

/* =========================================
   💰 ТАРИФЫ
   ========================================= */
.tariffs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    padding-bottom: 120px;
}

.tariff-card {
    position: relative;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    height: 100%;
    background: var(--bg-card);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--shadow-card);
}

.tariff-card.selected {
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 4px var(--primary-light);
    transform: translateY(-7px);
    z-index: 2;
}

.badge-popular, .badge-trial {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    z-index: 5;
    white-space: nowrap;
}
.badge-popular { background: var(--primary); color: white; box-shadow: 0 4px 10px rgba(37, 99, 235, 0.4); }
.badge-trial { background: #10b981; color: white; box-shadow: 0 4px 10px rgba(16, 185, 129, 0.4); }

.price-block { margin: 20px 0; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.price-value { font-size: 36px; font-weight: 800; color: var(--text-main); }
.price-period { font-size: 14px; color: var(--text-sec); }

.features-list { list-style: none; padding: 0; margin: 0; flex-grow: 1; }
.features-list li { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; color: var(--text-main); font-size: 15px; }
.features-list i { color: #10b981; font-size: 14px; }
.features-list li.disabled { color: var(--text-sec); opacity: 0.6; text-decoration: line-through; }
.features-list li.disabled i { color: var(--text-sec); }

.checkout-bar {
    position: fixed; bottom: -100px; left: 260px; right: 0;
    background: var(--bg-card);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: var(--border);
    padding: 20px 40px;
    display: flex; align-items: center; justify-content: space-between;
    transition: bottom 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 50; box-shadow: 0 -10px 30px rgba(0,0,0,0.05);
}
.checkout-bar.visible { bottom: 0; }
.checkout-info div:first-child { font-size: 14px; color: var(--text-sec); }
.checkout-info div:last-child { font-size: 20px; font-weight: 700; color: var(--text-main); }

/* =========================================
   💬 СТИЛИ ЧАТОВ
   ========================================= */
.chats-wrapper { display: flex; flex-grow: 1; overflow: hidden; height: calc(100vh - 80px); width: 100%; }

.chat-list-col { 
    width: 350px; min-width: 350px; 
    border-right: var(--border); 
    overflow-y: auto; 
    background: transparent; 
    padding: 15px; 
    display: flex; flex-direction: column; gap: 8px; 
}
.chat-window-col { flex-grow: 1; display: flex; flex-direction: column; background: var(--bg-card); min-width: 0; height: 100%; position: relative; }

.chat-card { 
    padding: 14px 16px; cursor: pointer; border-radius: 12px; 
    background: transparent; border: 1px solid transparent; 
    transition: all 0.2s ease; display: flex; flex-direction: column; gap: 4px; 
}
.chat-card:hover { background: var(--bg-card); border-color: var(--border); }

.chat-card.active { 
    background: var(--bg-card); 
    border-color: var(--primary-light);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
}
.chat-card.active::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0;
    width: 4px; background: var(--primary);
}

.chat-header { display: flex; justify-content: space-between; align-items: center; }
.chat-name { font-weight: 600; font-size: 15px; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.chat-time { font-size: 11px; color: var(--text-sec); }
.chat-preview { font-size: 13px; color: var(--text-sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.8; display: flex; align-items: center; gap: 6px; }

.chat-window-header {
    height: 70px; padding: 0 20px; border-bottom: var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--bg-card); backdrop-filter: blur(10px); flex-shrink: 0;
}
#messagesArea {
    flex-grow: 1; overflow-y: auto; padding: 20px 10%;
    display: flex; flex-direction: column; gap: 14px;
    background-image: radial-gradient(var(--border) 1px, transparent 1px);
    background-size: 40px 40px;
    background-color: var(--bg-body);
}

.bubble { max-width: 70%; padding: 12px 18px; border-radius: 18px; font-size: 15px; line-height: 1.5; position: relative; word-wrap: break-word; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.bubble.client { 
    background: var(--bg-card); color: var(--text-main); 
    align-self: flex-start; border-bottom-left-radius: 4px; border: var(--border);
}
.bubble.bot, .bubble.operator { 
    background: var(--primary); color: white; 
    align-self: flex-end; border-bottom-right-radius: 4px; 
}
.bubble.bot { background: linear-gradient(135deg, #3b82f6, #2563eb); } 
.bubble.operator { background: #1e293b; color: white; }

.time-text { font-size: 10px; margin-top: 4px; display: block; text-align: right; opacity: 0.7; }

.chat-input-area { 
    padding: 15px 20px; background: var(--bg-card); border-top: var(--border); 
    display: flex; gap: 10px; align-items: center; flex-shrink: 0; 
}
.chat-input-area input { margin: 0; border-radius: 20px; background: var(--bg-input); border-color: transparent; }
.chat-input-area input:focus { background: var(--bg-card); border-color: var(--primary); }

.control-btn { 
    border: 1px solid var(--border); background: transparent; color: var(--text-sec); 
    padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; 
    transition: 0.2s; display: flex; align-items: center; gap: 8px; 
}
.control-btn:hover { background: var(--bg-input); color: var(--text-main); }
.control-btn.active { background: rgba(239,68,68,0.1); color: #ef4444; border-color: rgba(239,68,68,0.2); }

/* --- ЭЛЕМЕНТЫ УПРАВЛЕНИЯ --- */
.btn-icon { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 8px; border: none; background: transparent; color: var(--text-sec); cursor: pointer; transition: 0.2s; }
.btn-edit:hover { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.btn-delete:hover { background: rgba(239, 68, 68, 0.1); color: #ef4444; }

.danger-zone {
    margin-top: 15px; padding: 12px; background: rgba(239, 68, 68, 0.1); border-radius: 8px; border: 1px solid rgba(239, 68, 68, 0.2);
}

/* 🔥 ВОССТАНОВЛЕННЫЕ СТИЛИ АВТОРИЗАЦИИ 🔥 */
body.auth-page { justify-content: center; align-items: center; }
.auth-container {
    width: 400px;
    background: var(--bg-card);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: var(--border);
    padding: 40px; border-radius: 24px;
    text-align: center;
    box-shadow: var(--shadow-card);
}
.error-box {
    background-color: #fee2e2; border: 1px solid #ef4444; color: #b91c1c;
    padding: 12px; border-radius: 8px; font-size: 14px;
    margin-bottom: 20px; display: none; text-align: left; width: 100%;
}
[data-theme="dark"] .error-box { background-color: #450a0a; border-color: #7f1d1d; color: #fca5a5; }

/* 🔥 МОБИЛЬНЫЙ АДАПТИВ */
.hamburger-btn, .back-btn, .sidebar-close-btn, .sidebar-overlay { display: none; }

@media (max-width: 768px) {
    .hamburger-btn, .back-btn, .sidebar-close-btn { display: block; background:none; border:none; font-size:20px; color:var(--text-main); cursor:pointer; }
    
    .sidebar { position: fixed; left: -100%; top: 0; height: 100%; box-shadow: 20px 0 50px rgba(0,0,0,0.3); transition: 0.3s; }
    .sidebar.open { left: 0; }
    .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 50; opacity: 0; visibility: hidden; transition: 0.3s; }
    .sidebar-overlay.active { opacity: 1; visibility: visible; }
    
    .chat-list-col { width: 100%; border-right: none; }
    .chat-window-col { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 200; transform: translateX(100%); transition: 0.3s; }
    .has-chat .chat-window-col { transform: translateX(0); }
    
    .top-bar { padding: 0 15px; }
    .bubble { max-width: 85%; }

    .page-title { margin-left: 20px; display: flex; flex-direction: column; justify-content: center; }
    .page-title h2 { font-size: 18px; line-height: 1.2; }
    .page-title p { font-size: 12px; margin-top: 2px; }

    .scroll-area { padding-bottom: 120px !important; }
    #messagesArea { padding-bottom: 100px !important; }
    .checkout-bar { position: fixed; bottom: 0; left: 0; right: 0; flex-direction: column; gap: 15px; padding: 15px; box-shadow: 0 -5px 20px rgba(0,0,0,0.1); z-index: 100; }
}

#messagesArea::-webkit-scrollbar, .chat-list-col::-webkit-scrollbar { width: 6px; }
#messagesArea::-webkit-scrollbar-thumb, .chat-list-col::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 10px; }
