:root {
    /* Цветовая палитра */
    --color-bg: #000000;
    --color-surface: #1a1a1a;
    --color-surface-hover: #2c2c2c;
    --color-border: #333333;
    --color-text-primary: #ffffff;
    --color-text-secondary: #888888;
    --color-accent: #ffffff; 
    --color-error: #ff4d4d;
    --color-success: #4caf50;
    --color-warning: #ff9800;

    /* Размеры */
    --header-height: 60px;
    --sidebar-width: 350px;
    
    /* Safe Area Insets */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

html {
    height: -webkit-fill-available;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    height: 100vh;
    height: -webkit-fill-available;
    width: 100vw;
    overflow: hidden;
    font-size: 16px;
    
    /* Safe area padding */
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-center { align-items: center; justify-content: center; }

/* Скроллбар */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--color-bg); }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-secondary); }

/* Кнопки */
button {
    background: var(--color-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s, transform 0.1s;
    touch-action: manipulation;
    user-select: none;
}

button:hover { background: var(--color-surface-hover); }
button:active { transform: scale(0.98); }
button.primary { background: var(--color-text-primary); color: var(--color-bg); font-weight: bold; }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

button.icon-btn { 
    border: none; 
    background: transparent; 
    padding: 10px; 
    font-size: 18px; 
    color: var(--color-text-primary);
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

button.icon-btn:hover { background: rgba(255,255,255,0.1); }
button.icon-btn:active { background: rgba(255,255,255,0.2); }

input, textarea {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    padding: 12px;
    border-radius: 8px;
    width: 100%;
    font-size: 16px;
    resize: vertical;
    font-family: inherit;
}

input:focus, textarea:focus { 
    border-color: var(--color-text-primary); 
    outline: none;
}

input:invalid { border-color: var(--color-error); }

/* LAYOUT */
#auth-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    background: var(--color-bg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    padding: 30px;
    border-radius: 16px;
    border: 1px solid var(--color-border);
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

#app-layout {
    display: flex;
    height: calc(var(--vh, 1vh) * 100);
    width: 100%;
    position: relative;
}

/* SIDEBAR (CHAT LIST) */
#sidebar {
    width: var(--sidebar-width);
    background: var(--color-bg);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 10;
}

.app-header {
    height: var(--header-height);
    padding: 0 10px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--color-bg);
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    min-width: 40px; 
    width: 40px;
}
.header-right { justify-content: flex-end; }
.header-left { justify-content: flex-start; }

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    overflow: hidden;
    white-space: nowrap;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.chat-search-container {
    padding: 10px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    user-select: none;
    touch-action: manipulation;
    position: relative;
    width: 100%;
    transition: background 0.15s ease, transform 0.1s;
}

.chat-item:hover { background: var(--color-surface); }
.chat-item.active { 
    background: var(--color-surface-hover); 
    border-left: 3px solid var(--color-text-primary);
}
.chat-item.pressing {
    background: var(--color-surface-hover);
    transform: scale(0.98);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-weight: bold;
    color: var(--color-text-secondary);
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview { 
    font-size: 13px; 
    color: var(--color-text-secondary); 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* CHAT AREA */
#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    position: relative;
    z-index: 20;
    
    height: 100%;
    overflow: hidden;
}

.messages-container {
    flex: 1 1 auto;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    position: relative;
    padding: 20px 20px 0 20px !important; /* Убираем нижний padding */
    padding-top: 20px !important;
    min-height: 0;
    contain: strict;
}

.message {
    position: absolute;
    box-sizing: border-box;
    padding: 10px 15px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 15px;
    animation: messageAppear 0.2s ease;
    max-width: 70%;
    width: auto !important; /* Важно: ширина по содержимому */
    min-width: 60px;
}

@media (prefers-reduced-motion: reduce) {
    .message { animation: none; }
}

/* Анимации */
@keyframes messageAppear {
    from { 
        opacity: 0; 
        transform: translateY(10px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

/* Свои сообщения - справа */
.message.sent {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom-right-radius: 2px;
    right: 20px !important; /* Прижимаем к правому краю */
    left: auto !important; /* Отменяем left */
    margin-left: auto;
}

/* Чужие сообщения - слева */
.message.received {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 2px;
    left: 20px !important; /* Прижимаем к левому краю */
    right: auto !important; /* Отменяем right */
    margin-right: auto;
}
.message.sending { opacity: 0.7; }
.message.error { border-color: var(--color-error); }
.message.highlighted {
    background: rgba(255, 255, 255, 0.15) !important;
    transition: background 0.3s;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 4px;
    font-size: 10px;
    color: var(--color-text-secondary);
}

.message.received .message-meta {
    justify-content: flex-start;
}

/* Текст сообщения */
.message-text {
    word-break: break-word;
    line-height: 1.4;
    white-space: pre-wrap;
}

/* Исправляем позиционирование в renderItem */
.message[style*="position: absolute"] {
    /* Эти стили уже заданы выше, но оставляем для специфичности */
}

.message-status {
    font-size: 9px;
    color: var(--color-text-secondary);
    display: inline-block;
    margin-left: 5px;
}
.message-status.delivered { color: var(--color-success); }
.message-status.read { color: var(--color-success); }
.message-status.sending { 
    color: var(--color-text-secondary); 
    animation: pulse 1s infinite;
}
.message-status.error { color: var(--color-error); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@media (prefers-reduced-motion: reduce) {
    .message-status.sending { animation: none; }
}

.message-actions {
    position: absolute;
    right: -30px;
    top: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    display: none;
    flex-direction: column;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.message:hover .message-actions,
.message:focus-within .message-actions {
    display: flex;
}

.message-action-btn {
    padding: 5px 10px;
    border: none;
    background: transparent;
    color: var(--color-text-primary);
    font-size: 12px;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    margin: 2px;
}

.message-action-btn:hover {
    background: var(--color-surface-hover);
}

/* Приветственный экран */
#welcome-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-secondary);
    text-align: center;
}
.welcome-text {
    font-size: 18px;
    margin-bottom: 10px;
    color: var(--color-text-primary);
}

.input-area {
    flex-shrink: 0; /* Не позволяет сжиматься */
    padding: 10px 15px;
    padding-bottom: calc(10px + var(--safe-area-bottom, 0px));
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--color-bg);
    position: relative;
    z-index: 100;
    width: 100%;
    box-sizing: border-box;
}

#message-input {
    resize: none;
    height: 45px; 
    max-height: 120px;
    padding-top: 12px;
    flex: 1;
}

.typing-indicator {
    font-size: 12px;
    color: var(--color-text-secondary);
    font-style: italic;
    padding: 5px 15px;
    display: none;
    flex-shrink: 0;
    background: var(--color-bg);
}

/* MODALS */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    padding: var(--safe-area-top) var(--safe-area-right) var(--safe-area-bottom) var(--safe-area-left);
}

.modal.open { opacity: 1; pointer-events: auto; }

.modal-content {
    background: var(--color-surface);
    width: 90%;
    max-width: 500px;
    padding: 25px;
    border-radius: 12px;
    border: 1px solid var(--color-border);
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { font-size: 20px; }

.settings-group { margin-bottom: 20px; border-bottom: 1px solid var(--color-border); padding-bottom: 20px; }
.settings-group:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.settings-group h3 { margin-bottom: 10px; font-size: 16px; color: var(--color-text-secondary); }

.user-checkbox-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: var(--color-bg);
    margin-bottom: 5px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
}

.user-checkbox-item input { width: auto; margin-right: 10px; }

/* Список контактов */
.contact-list {
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.contact-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid var(--color-border);
    transition: background 0.2s;
}

.contact-item:hover { background: var(--color-surface-hover); }
.contact-item:last-child { border-bottom: none; }

/* Кнопка заметок */
.notes-btn {
    width: 100%;
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
    border: 1px dashed var(--color-border);
    margin-bottom: 20px;
    padding: 15px;
    transition: all 0.2s;
}

.notes-btn:hover {
    background: var(--color-surface);
    border-style: solid;
}

/* TOAST */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 350px;
    pointer-events: none;
}

.toast {
    background: var(--color-surface);
    border-left: 4px solid var(--color-text-primary);
    color: #fff;
    padding: 12px 15px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    font-size: 14px;
    animation: slideIn 0.3s ease;
    pointer-events: auto;
    border: 1px solid var(--color-border);
}

.toast.error { border-left-color: var(--color-error); }
.toast.success { border-left-color: var(--color-success); }
.toast.warning { border-left-color: var(--color-warning); }

@keyframes slideIn { 
    from { transform: translateY(-20px); opacity: 0; } 
    to { transform: translateY(0); opacity: 1; } 
}

@media (prefers-reduced-motion: reduce) {
    .toast { animation: none; }
}

/* Контекстное меню */
.context-menu {
    position: fixed;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    z-index: 1000;
    min-width: 150px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    display: none;
    overflow: hidden;
}

.context-menu-item {
    padding: 10px 15px;
    cursor: pointer;
    color: var(--color-text-primary);
    font-size: 14px;
    transition: background 0.2s;
}

.context-menu-item:hover {
    background: var(--color-surface-hover);
}

/* Поиск */
.search-results {
    position: absolute;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
    width: calc(100% - 20px);
    z-index: 100;
    display: none;
    -webkit-overflow-scrolling: touch;
    margin-top: 5px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.search-result-item {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    transition: background 0.2s;
}

.search-result-item:hover,
.search-result-item.active {
    background: var(--color-surface-hover);
}

.search-result-item:last-child { border-bottom: none; }

/* MOBILE ADAPTATION */
@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        position: absolute;
        height: 100%;
        transform: translateX(-100%);
        left: 0;
    }
    #chat-area {
        width: 100%;
        height: 100%;
        position: absolute;
        transform: translateX(0);
        left: 0;
        transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    }
    
    body.chat-active #sidebar { transform: translateX(0); }
    body.chat-active #chat-area { transform: translateX(100%); }
    
    #sidebar-close-btn { display: flex !important; }
    
    .sidebar-header .desktop-title { display: none; }
    .sidebar-header .mobile-title { display: block; }
    
    .header-center { padding: 0 5px; }
    
    .message {
        max-width: 85%;
        padding: 8px 12px;
    }
    
    .message.sent {
        right: 10px !important;
    }
    
    .message.received {
        left: 10px !important;
    }
    
    .input-area {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
}

/* DESKTOP ADAPTATION */
@media (min-width: 769px) {
    #sidebar {
        position: relative;
        transform: none !important;
    }
    #chat-area {
        position: relative;
        transform: none !important;
    }
    
    #sidebar-close-btn { display: none !important; }
    
    .input-area {
        position: relative;
        padding-bottom: 15px !important;
    }
    
    .sidebar-header .desktop-title { display: block; }
    .sidebar-header .mobile-title { display: none; }
}

.error-text { color: var(--color-error); font-size: 12px; margin-top: 5px; display: none; }
.has-error input { border-color: var(--color-error); }
.has-error .error-text { display: block; }

.date-divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
}

.date-divider span {
    background: var(--color-surface);
    padding: 5px 15px;
    border-radius: 15px;
    font-size: 12px;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

/* Стили для виртуализированного списка */
.virtual-spacer {
    width: 100%;
    pointer-events: none;
    position: relative;
    will-change: height;
}

/* Добавляем отступ снизу для последнего сообщения через псевдоэлемент */
.messages-container::after {
    content: '';
    display: block;
    height: 20px; /* Отступ снизу */
    width: 100%;
    pointer-events: none;
}

.message.system {
    position: absolute;
    background: transparent !important;
    border: none !important;
    text-align: center;
    left: 50% !important;
    transform: translateX(-50%);
    width: auto !important;
    max-width: 80%;
    pointer-events: none;
}

/* Имя отправителя */
.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: #4CAF50; /* Зеленый для чужих */
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    opacity: 0.9;
    text-overflow: ellipsis;
}

.message.sent .message-sender {
    color: #2196F3; /* Синий для своих */
    text-align: right;
}

.system-message-content {
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 15px;
    border-radius: 15px;
    font-size: 13px;
    color: var(--color-text-secondary);
    display: inline-block;
    max-width: 80%;
    text-align: center;
}

.system-message-content i {
    margin-right: 5px;
    color: var(--color-accent);
}

.unread-highlight {
    animation: highlight 2s ease;
    border-left: 3px solid var(--color-accent) !important;
}

@keyframes highlight {
    0% { background: rgba(255, 255, 255, 0.1); }
    100% { background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
    .unread-highlight { animation: none; }
}

.load-more-btn {
    text-align: center;
    padding: 10px;
}

.message-status.pending {
    color: var(--color-text-secondary);
}

.message-status.partial {
    color: var(--color-warning);
    font-size: 8px;
}

.unread-marker {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-accent);
    color: black;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    z-index: 50;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    transition: background 0.2s;
}

.unread-marker:hover {
    background: var(--color-text-primary);
}

@keyframes pulse-indicator {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

@media (prefers-reduced-motion: reduce) {
    @keyframes pulse-indicator { 
        0%, 100% { opacity: 1; } 
    }
}

.new-message-indicator {
    animation: pulse-indicator 2s infinite;
    background: var(--color-accent) !important;
}

.user-status {
    font-size: 10px;
    color: var(--color-text-secondary);
}

.user-status.online {
    color: var(--color-success);
}

.user-status.offline {
    color: var(--color-error);
}

/* Адаптивность для мобильных */
@media (max-width: 768px) {
    .date-divider span {
        font-size: 10px;
        padding: 3px 10px;
    }
    
    .system-message-content {
        font-size: 11px;
        padding: 6px 12px;
    }
    
    #toast-container {
        top: 10px;
        width: 95%;
    }
}

/* Retry button for failed messages */
.retry-btn {
    background: var(--color-error);
    color: white;
    border: none;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    margin-left: 5px;
    cursor: pointer;
    transition: background 0.2s;
}

.retry-btn:hover {
    background: #ff3333;
}

/* Unread badge */
.unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    font-weight: bold;
}

/* Focus visible для accessibility */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Mark для поиска */
mark {
    background: var(--color-accent);
    color: black;
    padding: 0 2px;
    border-radius: 2px;
}

/* Debug Console */
.debug-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--color-accent);
    color: var(--color-bg);
    border: 2px solid var(--color-border);
    font-size: 24px;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    opacity: 0.7;
    transition: opacity 0.3s;
}

.debug-toggle:hover {
    opacity: 1;
}

.debug-console {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--color-surface);
    border: none;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    transition: all 0.3s ease;
}

.debug-console.hidden {
    display: none;
}

.debug-header {
    padding: 15px 20px;
    background: var(--color-bg);
    border-bottom: 2px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 16px;
    flex-shrink: 0;
    height: 60px;
}

.debug-header span {
    font-size: 18px;
    color: var(--color-text-primary);
}

.debug-header button {
    padding: 8px 15px;
    font-size: 14px;
    margin-left: 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--color-surface);
    color: var(--color-text-primary);
    min-width: 70px;
    font-weight: 500;
}

.debug-header button:hover {
    background: var(--color-surface-hover);
    transform: translateY(-1px);
}

.debug-header button:active {
    transform: translateY(0);
}

.debug-header button.debug-clear {
    background: var(--color-surface-hover);
    border-color: var(--color-text-secondary);
}

.debug-header button.debug-close {
    background: var(--color-error);
    color: white;
    border-color: var(--color-error);
}

.debug-header button.debug-close:hover {
    background: #ff6666;
}

.debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    background: var(--color-bg);
    scroll-behavior: smooth;
}

.debug-line {
    border-bottom: 1px solid var(--color-border);
    padding: 10px 0;
    word-break: break-all;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
}

.debug-line:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.debug-line.error {
    color: var(--color-error);
    border-left: 4px solid var(--color-error);
    padding-left: 10px;
    background: rgba(255, 77, 77, 0.1);
}

.debug-line.success {
    color: var(--color-success);
    border-left: 4px solid var(--color-success);
    padding-left: 10px;
    background: rgba(76, 175, 80, 0.1);
}

.debug-line.warning {
    color: var(--color-warning);
    border-left: 4px solid var(--color-warning);
    padding-left: 10px;
    background: rgba(255, 152, 0, 0.1);
}

.debug-line .timestamp {
    color: var(--color-text-secondary);
    font-size: 11px;
    margin-right: 10px;
    font-family: monospace;
    display: inline-block;
    min-width: 80px;
}

/* Для мобильных */
@media (max-width: 768px) {
    .debug-console {
        width: 95%;
        right: 2.5%;
        height: 250px;
    }
    
    .debug-toggle {
        bottom: 80px;
    }
}

.debug-details.expanded {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.debug-header .debug-clear {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.debug-header .debug-close {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.debug-details {
    display: none;
    margin-top: 10px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    font-size: 12px;
    font-family: monospace;
    white-space: pre-wrap;
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
}
    
.debug-detail-item {
    display: inline-block;
    margin-right: 15px;
    margin-bottom: 5px;
    color: var(--color-text-secondary);
    background: rgba(255, 255, 255, 0.1);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
}

.debug-detail-item strong {
    color: var(--color-text-primary);
    margin-right: 5px;
}
    
.debug-line.error .debug-detail-item {
    color: #ff9999;
    background: rgba(255, 77, 77, 0.2);
}

.debug-line.warning .debug-detail-item {
    color: #ffcc99;
    background: rgba(255, 152, 0, 0.2);
}
    
    .timestamp {
        color: #666;
        margin-right: 5px;
    }
    
    .line-content {
        word-break: break-word;
    }
    
    .debug-header button {
        transition: opacity 0.2s, transform 0.1s;
    }
    
    .debug-header button:hover {
        opacity: 0.8;
    }
    
    .debug-header button:active {
        transform: scale(0.95);
    }
    
/* Статистика */
.debug-stats {
    position: sticky;
    top: 0;
    background: var(--color-bg);
    padding: 10px 20px;
    border-bottom: 1px solid var(--color-border);
    z-index: 10;
    display: flex;
    gap: 20px;
    font-size: 12px;
}

.debug-stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.debug-stat-value {
    font-weight: bold;
    color: var(--color-text-primary);
}

.debug-stat-label {
    color: var(--color-text-secondary);
}

/* Поиск в debug консоли */
.debug-search {
    position: sticky;
    top: 0;
    background: var(--color-bg);
    padding: 10px 20px;
    border-bottom: 1px solid var(--color-border);
    z-index: 10;
}

.debug-search input {
    width: 100%;
    padding: 8px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    border-radius: 6px;
    font-size: 14px;
}

.debug-search input:focus {
    border-color: var(--color-accent);
    outline: none;
}

/* Для мобильных устройств */
@media (max-width: 768px) {
    .debug-console {
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    
    .debug-header {
        padding: 10px 15px;
        height: auto;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .debug-header span {
        font-size: 16px;
    }
    
    .debug-header button {
        padding: 6px 10px;
        font-size: 12px;
        min-width: 50px;
        margin-left: 5px;
    }
    
    .debug-content {
        padding: 10px;
        font-size: 12px;
    }
    
    .debug-line {
        padding: 8px 0;
    }
    
    .debug-line .timestamp {
        min-width: 70px;
        font-size: 10px;
    }
    
    .debug-details {
        padding: 8px;
        font-size: 11px;
    }
    
    .debug-detail-item {
        display: block;
        margin-right: 0;
        margin-bottom: 3px;
    }
}

/* Для очень маленьких экранов */
@media (max-width: 480px) {
    .debug-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .debug-header div {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }
    
    .debug-header button {
        flex: 1;
        min-width: 60px;
        margin: 0;
    }
}

/* Анимация появления */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.debug-console:not(.hidden) {
    animation: fadeIn 0.2s ease;
}

/* Индикаторы */
.error-badge {
    display: inline-block;
    background: var(--color-error);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    margin-left: 5px;
}

.warning-badge {
    display: inline-block;
    background: var(--color-warning);
    color: black;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    margin-left: 5px;
}

/* Полоса прокрутки для debug консоли */
.debug-content::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.debug-content::-webkit-scrollbar-track {
    background: var(--color-bg);
}

.debug-content::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

.debug-content::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

/* Подсветка при поиске */
.debug-line.highlight {
    background: rgba(255, 255, 0, 0.2);
    border-left-color: yellow;
}

/* Контекстное меню для debug строк */
.debug-line .context-actions {
    position: absolute;
    right: 10px;
    top: 5px;
    display: none;
    gap: 5px;
}

.debug-line:hover .context-actions {
    display: flex;
}

.debug-line .context-actions button {
    padding: 2px 5px;
    font-size: 10px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    cursor: pointer;
}

.debug-line .context-actions button:hover {
    background: var(--color-surface-hover);
}

/* Кнопки в хедере - цветовые стили */
.debug-header button[style*="background: #ff4d4d"] {
    background: var(--color-error) !important;
}

.debug-header button[style*="background: #4CAF50"] {
    background: var(--color-success) !important;
}

.debug-header button[style*="background: #2196F3"] {
    background: #2196F3 !important;
}

.debug-header button[style*="background: #9C27B0"] {
    background: #9C27B0 !important;
}

.debug-header button[style*="background: #ff9800"] {
    background: var(--color-warning) !important;
}

.debug-line.info {
    color: var(--color-text-secondary);
    border-left: 4px solid var(--color-text-secondary);
    padding-left: 10px;
    background: rgba(136, 136, 136, 0.1);
}

.debug-line.log {
    color: var(--color-text-primary);
    border-left: 4px solid transparent;
    padding-left: 10px;
}

.debug-line .line-content {
    word-break: break-word;
    font-size: 13px;
}
