:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #232733;
    --border: #2d3140;
    --text: #e4e6ed;
    --text2: #8b8fa3;
    --accent: #6c5ce7;
    --accent2: #a29bfe;
    --green: #00b894;
    --red: #e17055;
    --orange: #fdcb6e;
    --blue: #74b9ff;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Login */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    width: 360px;
}

.login-box h1 { color: var(--accent2); margin-bottom: 8px; }
.login-box p { color: var(--text2); margin-bottom: 24px; }

.login-box input {
    width: 100%;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    margin-bottom: 12px;
}

.login-box button {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    cursor: pointer;
}

.login-box button:hover { background: var(--accent2); }

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.header-left h1 { font-size: 18px; color: var(--accent2); }
.header-right { display: flex; align-items: center; gap: 12px; }

/* Tabs */
.tabs {
    display: flex;
    padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    gap: 4px;
}

.tab {
    padding: 12px 20px;
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    font-size: 14px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent2); border-bottom-color: var(--accent); }

.tab-content { display: none; padding: 24px; }
.tab-content.active { display: block; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card h3 { color: var(--text); margin-bottom: 16px; font-size: 15px; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.stat-card .bot-name { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.stat-card .bot-username { color: var(--text2); font-size: 13px; margin-bottom: 12px; }

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 14px;
}

.stat-row .label { color: var(--text2); }
.stat-row .value { font-weight: 500; }
.stat-row .value.green { color: var(--green); }

/* Chart */
.chart {
    height: 120px;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding-top: 10px;
}

.chart-bar {
    flex: 1;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    position: relative;
    transition: background 0.2s;
}

.chart-bar:hover { background: var(--accent2); }
.chart-bar .chart-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--text2);
    white-space: nowrap;
}

.chart-bar .chart-value {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--text2);
    display: none;
}

.chart-bar:hover .chart-value { display: block; }

/* Toolbar */
.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

/* Inputs */
input[type="text"], input[type="password"], select, textarea {
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}

input[type="text"]:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}

select { cursor: pointer; }

textarea {
    width: 100%;
    resize: vertical;
}

/* Buttons */
.btn-primary {
    padding: 8px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}

.btn-primary:hover { background: var(--accent2); }

.btn-text {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    font-size: 14px;
}

.btn-text:hover { color: var(--text); }

.btn-sm {
    padding: 4px 12px;
    font-size: 13px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
}

.btn-sm:hover { background: var(--border); }

.btn-danger { background: var(--red); color: white; border-color: var(--red); }
.btn-success { background: var(--green); color: white; border-color: var(--green); }

/* Table */
.table-container { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text2);
    font-weight: 500;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

tr:hover { background: var(--surface2); }
tr { cursor: pointer; }

/* Tags */
.tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 12px;
    color: var(--accent2);
    margin: 2px;
}

.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-cloud-item {
    padding: 4px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 16px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.tag-cloud-item:hover { border-color: var(--accent); }
.tag-count { color: var(--text2); font-size: 11px; margin-left: 4px; }

/* Pagination */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 16px;
}

.pagination button {
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
}

.pagination button.active { background: var(--accent); border-color: var(--accent); }
.pagination button:hover:not(.active) { background: var(--surface2); }

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text2);
    font-size: 24px;
    cursor: pointer;
}

/* Messages */
.messages-container {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 16px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.msg {
    margin-bottom: 8px;
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-in {
    background: var(--surface2);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.msg-out {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.msg-time {
    font-size: 11px;
    color: var(--text2);
    margin-top: 4px;
}

.msg-out .msg-time { color: rgba(255,255,255,0.6); }

/* Dialogs layout */
.dialogs-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 16px;
    height: calc(100vh - 160px);
}

.dialogs-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.dialogs-sidebar input {
    margin: 8px;
    width: calc(100% - 16px);
}

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

.contact-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.contact-item:hover { background: var(--surface2); }
.contact-item.active { background: var(--surface2); border-left: 3px solid var(--accent); }
.contact-item .name { font-weight: 500; font-size: 14px; }
.contact-item .preview { font-size: 12px; color: var(--text2); margin-top: 2px; }

.dialogs-chat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 500;
}

.chat-messages {
    display: flex;
    flex-direction: column;
}

/* Broadcast */
.broadcast-form { display: flex; flex-direction: column; gap: 12px; }
.broadcast-filters { display: flex; gap: 12px; }
.broadcast-filters input { flex: 1; }
.broadcast-actions { display: flex; gap: 12px; }

.broadcast-item {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bc-info { flex: 1; }
.bc-info .bc-text { font-size: 14px; margin-bottom: 4px; }
.bc-info .bc-meta { font-size: 12px; color: var(--text2); }
.bc-status { padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.bc-status.running { background: var(--blue); color: var(--bg); }
.bc-status.completed { background: var(--green); color: var(--bg); }
.bc-status.draft { background: var(--surface2); color: var(--text2); }
.bc-status.cancelled { background: var(--red); color: white; }
.bc-status.scheduled { background: var(--orange); color: var(--bg); }

/* Insights */
.insight-item {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.insight-item h4 { font-size: 14px; color: var(--accent2); margin-bottom: 4px; }
.insight-item .insight-date { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.insight-item .insight-content { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }

/* Contact detail */
.contact-info { margin-bottom: 16px; }
.contact-info h2 { margin-bottom: 8px; }
.contact-info .info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 14px;
}

.info-label { color: var(--text2); }

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
}

.badge-green { background: rgba(0,184,148,0.2); color: var(--green); }
.badge-red { background: rgba(225,112,85,0.2); color: var(--red); }

/* Error */
.error { color: var(--red); font-size: 14px; margin-top: 8px; }
.hidden { display: none; }

/* Bot settings */
.bot-settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.settings-form { display: flex; flex-direction: column; gap: 8px; }
.settings-form label { font-size: 13px; color: var(--text2); margin-top: 4px; }
.settings-form textarea { font-family: monospace; font-size: 13px; line-height: 1.5; }
.settings-actions { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.save-status { font-size: 13px; }

/* Chat reply */
.chat-reply {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.chat-reply input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
}

.chat-reply input:focus { outline: none; border-color: var(--accent); }

/* Tag remove */
.tag-remove:hover { color: var(--red); }

/* Modal wide */
.modal-wide { max-width: 800px; }

/* Responsive */
@media (max-width: 768px) {
    .stats-grid { grid-template-columns: 1fr; }
    .dialogs-layout { grid-template-columns: 1fr; height: auto; }
    .dialogs-sidebar { height: 200px; }
    .broadcast-filters { flex-direction: column; }
    .modal-content { width: 95%; padding: 16px; }
}
