/**
 * TestTelega — основные стили
 * Тёмная/светлая тема, responsive layout
 */

:root {
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #1e2130;
    --border-color: #2a2d3a;
    --text-primary: #e4e6f0;
    --text-muted: #8b8fa3;
    --accent: #5288c1;
    --accent-hover: #6ba3e0;
}

[data-bs-theme="light"] {
    --bg-primary: #f5f6fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --border-color: #e2e5ed;
    --text-primary: #1a1d27;
    --text-muted: #6c757d;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.logo i { font-size: 1.5rem; }

.sidebar-nav {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: rgba(82, 136, 193, 0.1);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent);
    color: #fff;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.page-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
}

.status-badge {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.status-badge .bi-circle-fill { font-size: 0.5rem; }

.content-area {
    padding: 1.5rem;
    flex: 1;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Stat cards */
.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #fff;
}

.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); }

/* Account info */
.account-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.account-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #fff;
    flex-shrink: 0;
}

/* JSON viewer */
.json-viewer {
    background: #1e1e2e;
    border-radius: 8px;
    padding: 1rem;
    max-height: 400px;
    overflow: auto;
    font-size: 0.85rem;
    margin: 0;
}

[data-bs-theme="light"] .json-viewer {
    background: #f8f9fa;
}

/* Chat layout */
.chat-layout {
    display: flex;
    height: calc(100vh - var(--topbar-height) - 3rem);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

.chat-sidebar {
    width: 320px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
}

.chat-sidebar-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.chat-item:hover, .chat-item.active {
    background: rgba(82, 136, 193, 0.1);
}

.chat-item-title { font-weight: 600; font-size: 0.9rem; }
.chat-item-preview { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chat-main-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chat-main-active {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
}

.chat-header h5 { margin: 0; font-size: 1rem; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.message-bubble {
    max-width: 70%;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    font-size: 0.9rem;
    word-break: break-word;
}

.message-out {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-in {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message-meta {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}

.chat-input {
    padding: 0.75rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

/* Logger layout */
.logger-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height) - 3rem);
}

.logger-toolbar {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px 12px 0 0;
}

.logger-entries {
    flex: 1;
    overflow-y: auto;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.log-entry {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.log-entry:hover { background: rgba(82, 136, 193, 0.08); }
.log-entry.error { border-left: 3px solid #dc3545; }
.log-entry.success { border-left: 3px solid #198754; }

.log-entry-method {
    font-family: monospace;
    font-weight: 600;
    color: var(--accent);
    min-width: 200px;
}

.log-entry-time { color: var(--text-muted); min-width: 140px; }
.log-entry-duration { color: var(--text-muted); min-width: 60px; text-align: right; }

.logger-detail {
    border: 1px solid var(--border-color);
    border-radius: 0 0 12px 12px;
    background: var(--bg-card);
    max-height: 300px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.logger-detail-header {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logger-detail-body {
    flex: 1;
    overflow-y: auto;
}

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .chat-sidebar {
        width: 100%;
        position: absolute;
        z-index: 10;
        height: 100%;
    }
    .chat-layout {
        position: relative;
    }
}

/* Table overrides */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border-color);
}

.table-hover > tbody > tr:hover {
    --bs-table-hover-bg: rgba(82, 136, 193, 0.08);
}

/* Form overrides */
.form-control, .form-select {
    background: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
    background: var(--bg-primary);
    border-color: var(--accent);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(82, 136, 193, 0.25);
}
