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

:root {
    --bg-primary: #0a0e27;
    --bg-secondary: #131842;
    --bg-card: #1a1f4e;
    --bg-card-hover: #222866;
    --accent-blue: #4fc3f7;
    --accent-violet: #ab47bc;
    --gradient: linear-gradient(135deg, #0a0e27 0%, #1a0a3e 50%, #0d1b3e 100%);
    --text-primary: #e8eaf6;
    --text-secondary: #9fa8da;
    --text-muted: #5c6bc0;
    --status-green: #66bb6a;
    --status-red: #ef5350;
    --status-yellow: #ffa726;
    --border: rgba(79, 195, 247, 0.15);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--gradient);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Stars */
#stars {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    animation: twinkle var(--duration) ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: var(--min-opacity); }
    50% { opacity: var(--max-opacity); }
}

/* Container */
.container {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}

header h1 {
    font-size: 2rem;
    font-weight: 300;
    letter-spacing: 2px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-violet));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Summary bar */
.summary-bar {
    display: flex;
    gap: 16px;
    margin-bottom: 32px;
    flex-wrap: wrap;
    justify-content: center;
}

.summary-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 24px;
    text-align: center;
    min-width: 140px;
    box-shadow: var(--shadow);
}

.summary-item .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-blue);
}

.summary-item .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Bots sections */
.bots-section {
    margin-bottom: 32px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
    padding-left: 8px;
    border-left: 3px solid var(--accent-violet);
}

/* Bots grid */
.bots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

/* Bot card */
.bot-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
    overflow: hidden;
}

.bot-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--bot-color, var(--accent-blue));
}

.bot-card:hover {
    transform: translateY(-2px);
    border-color: var(--bot-color, var(--accent-blue));
}

/* Paid bots - gold accent */
.bot-card-paid {
    border-color: rgba(255, 215, 0, 0.3);
}

.bot-card-paid::before {
    background: linear-gradient(90deg, #ffd700, #ffaa00);
}

.bot-card-paid:hover {
    border-color: #ffd700;
}

/* Free bots - blue accent */
.bot-card-free {
    border-color: rgba(79, 195, 247, 0.2);
}

.bot-card-free::before {
    background: linear-gradient(90deg, var(--accent-blue), #29b6f6);
}

.bot-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.bot-icon {
    font-size: 2rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.bot-info {
    flex: 1;
}

.bot-name {
    font-size: 1.1rem;
    font-weight: 600;
}

.bot-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-active {
    background: rgba(102, 187, 106, 0.15);
    color: var(--status-green);
}

.status-inactive {
    background: rgba(239, 83, 80, 0.15);
    color: var(--status-red);
}

.status-failed {
    background: rgba(255, 167, 38, 0.15);
    color: var(--status-yellow);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Stats row */
.bot-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-item {
    text-align: center;
    padding: 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-blue);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* Action buttons */
.bot-actions {
    display: flex;
    gap: 8px;
}

.btn {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-blue);
}

.btn-start {
    border-color: rgba(102, 187, 106, 0.3);
}

.btn-start:hover {
    background: rgba(102, 187, 106, 0.15);
    border-color: var(--status-green);
    color: var(--status-green);
}

.btn-stop {
    border-color: rgba(239, 83, 80, 0.3);
}

.btn-stop:hover {
    background: rgba(239, 83, 80, 0.15);
    border-color: var(--status-red);
    color: var(--status-red);
}

.btn-restart {
    border-color: rgba(255, 167, 38, 0.3);
}

.btn-restart:hover {
    background: rgba(255, 167, 38, 0.15);
    border-color: var(--status-yellow);
    color: var(--status-yellow);
}

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

/* System panel */
.system-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.system-panel h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.system-bars {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.bar-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bar-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
}

.bar-label {
    color: var(--text-secondary);
}

.bar-value {
    color: var(--accent-blue);
    font-weight: 600;
}

.bar-track {
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-violet));
}

.bar-fill.warning {
    background: linear-gradient(90deg, var(--status-yellow), var(--status-red));
}

/* ── Tabs ──────────────────────────────────────────────────────────────── */

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.tab {
    padding: 10px 20px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px 8px 0 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.tab.active {
    color: var(--accent-blue);
    border-color: var(--border);
    border-bottom-color: var(--bg-primary);
    background: rgba(79, 195, 247, 0.1);
}

.tab-badge {
    display: inline-block;
    background: #e11d48;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    margin-left: 6px;
    vertical-align: middle;
    line-height: 1.6;
}

.tab-badge-progress {
    background: #2563eb;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ── Platform Table ────────────────────────────────────────────────────── */

.platform-table {
    overflow-x: auto;
    margin-bottom: 24px;
}

.platform-table table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
}

.platform-table th,
.platform-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.platform-table th {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.platform-table td {
    color: var(--text-primary);
    font-size: 0.9rem;
}

.platform-table tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.platform-table code {
    background: rgba(79, 195, 247, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--accent-blue);
}

/* ── Bot Detail ────────────────────────────────────────────────────────── */

.bot-detail {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
}

.bot-detail h2 {
    margin-bottom: 20px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.detail-item {
    background: rgba(255, 255, 255, 0.03);
    padding: 12px;
    border-radius: 8px;
}

.detail-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.detail-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-blue);
}

.detail-config {
    margin-bottom: 24px;
}

.detail-config h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.detail-config pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.8rem;
    color: var(--text-primary);
    max-height: 300px;
    overflow-y: auto;
}

.detail-form {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.detail-form .form-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.detail-form .form-row label {
    min-width: 160px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.detail-form .form-row input,
.detail-form .form-row select {
    flex: 1;
    max-width: 200px;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.detail-form .form-row input:focus,
.detail-form .form-row select:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.detail-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn-sm {
    padding: 6px 12px;
    font-size: 0.75rem;
}

.btn-back {
    margin-bottom: 16px;
    background: transparent;
    border-color: var(--border);
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ── Empty State ───────────────────────────────────────────────────────── */

.empty {
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

/* ── Log Feature ───────────────────────────────────────────────────────── */

.log-feature {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Loading */
.loading {
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    header h1 {
        font-size: 1.4rem;
    }
    .bots-grid {
        grid-template-columns: 1fr;
    }
    .summary-bar {
        flex-direction: column;
        align-items: center;
    }
}

/* Logout button */
.logout-btn {
    padding: 6px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-decoration: none;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: rgba(239, 83, 80, 0.15);
    border-color: var(--status-red);
    color: var(--status-red);
}

/* Login page */
.login-wrapper {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px;
    text-align: center;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.login-logo {
    font-size: 3.5rem;
    margin-bottom: 16px;
    display: flex;
    justify-content: center;
}

.brand-logo {
    height: 96px;
    width: 96px;
    object-fit: contain;
    border-radius: 14px;
    vertical-align: middle;
    margin-right: 12px;
}

img.login-logo {
    display: block;
    margin: 0 auto 16px;
    max-height: 200px;
    max-width: 200px;
    object-fit: contain;
    border-radius: 50%;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 300;
    letter-spacing: 2px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-violet));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 32px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-input {
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.login-input:focus {
    border-color: var(--accent-blue);
}

.login-input::placeholder {
    color: var(--text-muted);
}

.login-btn {
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

.login-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.login-btn:active {
    transform: translateY(0);
}

.error {
    background: rgba(239, 83, 80, 0.15);
    border: 1px solid rgba(239, 83, 80, 0.3);
    border-radius: 8px;
    padding: 10px 16px;
    color: var(--status-red);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

/* Settings panel */
.settings-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
}

.settings-panel h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-secondary);
}

.settings-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-secondary);
    padding-left: 8px;
    border-left: 3px solid var(--accent-violet);
}

.settings-form {
    max-width: 400px;
}

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.settings-input {
    width: 100%;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.settings-input:focus {
    border-color: var(--accent-blue);
}

.settings-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.settings-btn:hover {
    opacity: 0.9;
}

.settings-message {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 12px;
    display: none;
}

.settings-message.error,
.settings-message.success {
    display: block;
}

.settings-message.error {
    background: rgba(239, 83, 80, 0.15);
    border: 1px solid rgba(239, 83, 80, 0.3);
    color: var(--status-red);
}

.settings-message.success {
    background: rgba(102, 187, 106, 0.15);
    border: 1px solid rgba(102, 187, 106, 0.3);
    color: var(--status-green);
}


/* Filters bar */
.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filters-bar select {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}

.filters-bar select:focus {
    outline: none;
    border-color: var(--accent-blue);
}


/* Delete button */
.btn-delete {
    background: rgba(239, 83, 80, 0.2);
    border: 1px solid rgba(239, 83, 80, 0.5);
    color: #ef5350;
}

.btn-delete:hover {
    background: rgba(239, 83, 80, 0.3);
}


/* ── Operator dialogs ─────────────────────────────────── */
.dialogs-layout { display: flex; gap: 14px; align-items: flex-start; }
.dialog-list { width: 320px; flex-shrink: 0; background: rgba(255,255,255,.05); border-radius: 10px; padding: 8px; max-height: 70vh; overflow-y: auto; }
.dialog-item { padding: 10px; border-radius: 8px; cursor: pointer; margin-bottom: 6px; background: rgba(255,255,255,.04); }
.dialog-item:hover { background: rgba(255,255,255,.1); }
.dialog-item.active { background: rgba(64,156,255,.25); outline: 1px solid rgba(64,156,255,.5); }
.dlg-head { display: flex; justify-content: space-between; gap: 8px; }
.dlg-time { font-size: 11px; color: #888; white-space: nowrap; }
.dlg-meta { font-size: 12px; color: #999; margin-top: 4px; }
.dlg-bot { color: #64b5f6; }
.dialog-chat { flex: 1; background: rgba(255,255,255,.05); border-radius: 10px; padding: 12px; min-height: 70vh; display: flex; flex-direction: column; }
.dialog-messages { flex: 1; overflow-y: auto; max-height: 58vh; padding: 8px; }
.msg { padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; max-width: 80%; }
.msg-client { background: rgba(64,156,255,.18); align-self: flex-start; }
.msg-op { background: rgba(76,175,80,.18); align-self: flex-end; margin-left: auto; }
.msg-head { font-size: 11px; color: #aaa; margin-bottom: 4px; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.dialog-reply { display: flex; gap: 8px; margin-top: 10px; }
.dialog-reply textarea { flex: 1; resize: none; border-radius: 8px; padding: 8px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.06); color: #eee; font-family: inherit; }
.dialog-reply .login-btn { align-self: stretch; }

/* Непрочитанные + действия диалога */
.dlg-unread { background:#e53935; color:#fff; border-radius:10px; padding:0 6px; font-size:11px; margin-left:4px; display:inline-block; }
.dlg-actions { margin-top:4px; }
.dlg-act { margin:4px 6px 4px 0; padding:3px 8px; border:1px solid #ccc; border-radius:6px; background:#f5f5f5; cursor:pointer; font-size:12px; }
.dlg-act:hover { background:#e8e8e8; }
.dlg-del { border-color:#e53935; color:#e53935; }
.dlg-del:hover { background:#fdecea; }
