/* MINIMALIST DARK & TRUE BLACK THEME - DESIGN TOKENS */
:root {
    /* DEFAULT THEME: Modern Deep Dark (Slate/Zinc hybrid) */
    --bg-body: #0d0d10;       /* Rich, non-gray black */
    --bg-surface: #151518;    /* Unified panels */
    --bg-hover: #222227;      
    --bg-active: #2b2b31;     
    
    --border-light: #151518;
    --border-main: #222226;   /* Extremely thin and minimal */
    --border-dark: #32323a;   
    
    --text-primary: #f4f4f5;  
    --text-secondary: #a1a1aa;
    --text-muted: #61616a;    
    --text-inverse: #0d0d10;  
    
    --primary: #ffffff;       
    --primary-hover: #e4e4e7;  
    
    --danger: #f87171;
    --danger-hover: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    
    --success: #34d399;
    --warning: #fbbf24;
    
    /* Layout & Shadows */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* BLACK THEME: OLED Absolute Deep Black */
.theme-black {
    --bg-body: #000000;       /* Perfect OLED black background */
    --bg-surface: #000000;    /* Sidebar and panels are also absolute black */
    --bg-hover: #121212;      /* Distinct hover only */
    --bg-active: #181818;     
    
    --border-light: #000000;
    --border-main: #141414;   /* Minimal division line contrast */
    --border-dark: #222222;
    
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;
}

/* RESET */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-family);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

/* UTILS */
.hidden { display: none !important; }
.screen { width: 100%; height: 100vh; }
.screen.active { display: flex; }

/* TYPOGRAPHY */
h1, h2, h3, h4 { font-weight: 600; color: var(--text-primary); }

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    outline: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; padding: 10px; }

.btn-primary {
    background-color: var(--primary);
    color: var(--text-inverse);
}
.btn-primary:not(:disabled):hover { background-color: var(--primary-hover); }

.btn-outline {
    background-color: transparent;
    border-color: var(--border-dark);
    color: var(--text-primary);
}
.btn-outline:not(:disabled):hover { background-color: var(--bg-hover); }

.btn-danger {
    background-color: var(--danger-bg);
    border-color: transparent;
    color: var(--danger);
}
.btn-danger:not(:disabled):hover { background-color: var(--danger); color: var(--text-inverse); }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: 0.2s;
}
.btn-icon:not(:disabled):hover { background-color: var(--bg-hover); color: var(--text-primary); }
.btn-icon.primary { color: var(--primary); }
.btn-icon.primary:not(:disabled):hover { background-color: var(--bg-hover); }
.btn-icon:disabled { color: var(--border-dark); cursor: not-allowed; }

/* FORMS & INPUTS */
.input-field {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-field:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}
.input-field::placeholder { color: var(--text-muted); }
.input-field:disabled { background-color: var(--bg-hover); cursor: not-allowed; }

/* SCROLLBARS */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ================= LOGIN SCREEN ================= */
#login-screen {
    justify-content: center;
    align-items: center;
    background-color: var(--bg-body);
}

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    padding: 40px;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.brand-logo {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.login-card h2 { margin-bottom: 8px; font-size: 20px; }
.login-card .subtitle { color: var(--text-secondary); margin-bottom: 32px; font-size: 14px; }

.input-group { text-align: left; margin-bottom: 20px; }
.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.input-group input { 
    width: 100%; 
    padding: 10px 14px; 
    border: 1px solid var(--border-dark); 
    border-radius: var(--radius-md); 
    background: var(--bg-body);
    color: var(--text-primary);
    outline: none;
    transition: 0.2s;
}
.input-group input:focus { border-color: var(--primary); }

.error-msg {
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 16px;
    background: var(--danger-bg);
    padding: 10px;
    border-radius: var(--radius-sm);
}

/* ================= DASHBOARD SCREEN ================= */
#dashboard-screen { display: flex; }

/* SIDEBAR */
.sidebar {
    width: 300px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-main);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand-small {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.5px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--danger); }

.ticket-filters {
    display: flex;
    padding: 12px 20px;
    gap: 8px;
    border-bottom: 1px solid var(--border-light);
}

.filter-btn {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    padding: 6px 0;
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: 0.2s;
}
.filter-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.filter-btn.active { background: var(--bg-hover); color: var(--text-primary); font-weight: 600; border-color: var(--border-main); }

.ticket-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
}

.ticket-empty {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.ticket-item {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}
.ticket-item:hover { background: var(--bg-hover); }
.ticket-item.active { background: var(--bg-hover); border-left-color: var(--primary); }

.ticket-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.ticket-user {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.ticket-date { font-size: 11px; color: var(--text-muted); }
.ticket-meta { display: flex; }

.badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 500;
    display: inline-block;
}
.badge-waiting { background: var(--warning); color: #000; }
.badge-in_progress { background: var(--primary); color: var(--text-inverse); }
.badge-closed { background: var(--bg-active); color: var(--text-secondary); }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.admin-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 14px;
}

.avatar {
    width: 28px;
    height: 28px;
    background: var(--bg-active);
    color: var(--text-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
}

.footer-actions {
    display: flex;
    gap: 8px;
}

/* MAIN CHAT AREA */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-body);
    position: relative;
    transition: background-color 0.25s ease;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-align: center;
}

.empty-icon {
    color: var(--border-dark);
    margin-bottom: 16px;
}

.empty-state h3 { margin-bottom: 8px; font-size: 18px; color: var(--text-primary);}
.empty-state p { font-size: 14px; max-width: 300px; line-height: 1.5; }

.chat-interface {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
    height: 70px;
    flex-shrink: 0;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.chat-title { display: flex; align-items: center; gap: 12px; }
.chat-title h2 { font-size: 16px; margin: 0; }

.chat-actions { display: flex; gap: 8px; }

.messages-container {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.msg-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 65%;
}

.msg-user { align-self: flex-start; }
.msg-admin { align-self: flex-end; }
.msg-system { align-self: center; text-align: center; max-width: 100%; margin: 8px 0;}

.msg-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-break: break-word;
}

/* Изолированный контейнер для картинок (без рамок и заднего фона) */
.msg-bubble:has(.chat-image) {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.chat-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius-md);
    object-fit: contain;
    cursor: zoom-in;
    display: block;
    margin-bottom: 8px;
    border: 1px solid var(--border-main);
}

.msg-text { white-space: pre-wrap; }
.msg-document { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 13px; margin-bottom: 4px; }

/* Сообщения клиента: Темно-серые */
.msg-user .msg-bubble {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

/* Сообщения оператора: Премиальный темно-синий/индиго тон (без дешевого белого) */
.msg-admin .msg-bubble {
    background: #1e293b;       /* Slate 800 */
    border: 1px solid #334155; /* Slate 700 */
    color: #f8fafc;            /* Slate 50 */
    border-bottom-right-radius: 4px;
}

/* Сообщения оператора в режиме OLED-черного */
.theme-black .msg-admin .msg-bubble {
    background: #0f172a;       /* Deep slate black */
    border-color: #1e293b;
}

.msg-system .msg-bubble {
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    padding: 4px 12px;
}

.msg-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    padding: 0 4px;
}
.msg-admin .msg-meta { justify-content: flex-end; }

.msg-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
    border-radius: 4px;
    transition: color 0.15s ease, background-color 0.15s ease;
}
.msg-delete-btn:hover { background-color: var(--danger-bg); color: var(--danger); }

/* CHAT INPUT */
.chat-input-area {
    padding: 16px 24px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-main);
    flex-shrink: 0;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.message-form {
    display: flex;
    gap: 12px;
    align-items: center;
}

.message-form .input-field {
    flex: 1;
    border-radius: 20px;
    padding: 12px 18px;
    background: var(--bg-body);
    border-color: transparent;
    color: var(--text-primary);
}
.message-form .input-field:focus {
    background: var(--bg-surface);
    border-color: var(--border-dark);
    box-shadow: var(--shadow-sm);
}

/* ================= MODAL ================= */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    padding: 24px;
    border-radius: var(--radius-lg);
    width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    margin-bottom: 16px;
    font-size: 18px;
    text-align: center;
}

.modal-preview-wrapper {
    background: var(--bg-body);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 16px;
    display: flex;
    justify-content: center;
    border: 1px dashed var(--border-dark);
}

#modal-preview {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-sm);
}

#modal-caption { margin-bottom: 24px; }

.modal-actions {
    display: flex;
    gap: 12px;
}
.modal-actions button { flex: 1; }
