/* === Палитра под бренд (чёрный + красный, как у бота и лендинга) === */
:root {
    --bg: #0a0a0a;
    --bg-elev: #0f0f0f;
    --panel: #141414;
    --panel-2: #1a1a1a;
    --border: #262626;
    --border-strong: #333333;
    --fg: #f0f0f0;
    --fg-muted: #b0b0b0;
    --muted: #707070;
    --accent: #dc2626;
    --accent-bright: #ef4444;
    --accent-deep: #991b1b;
    --green: #22c55e;
    --green-deep: #14532d;
    --amber: #f59e0b;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    --radius: 10px;
    --radius-sm: 6px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    background-image:
        radial-gradient(ellipse 800px 400px at 50% -100px, rgba(220, 38, 38, 0.08), transparent 60%);
}

.wrap {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
}

/* === Topbar === */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 20px;
    margin-bottom: 28px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.brand-logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--accent);
    text-transform: uppercase;
}

.brand-sub {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--muted);
}

.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: 99px;
    font-size: 12px;
    color: var(--fg-muted);
}

.live-pill.online .dot { background: var(--green); box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15); }
.live-pill.error .dot  { background: var(--accent); box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.2); }
.live-pill .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
    animation: pulse 2s ease-in-out infinite;
}

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

.refresh-btn {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--fg-muted);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    padding: 5px 12px;
    border-radius: 99px;
    transition: border-color 0.15s, color 0.15s;
}
.refresh-btn:hover { border-color: var(--accent); color: var(--fg); }
.refresh-btn:disabled { opacity: 0.5; cursor: default; }

/* === Warning === */
.warn {
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid var(--accent-deep);
    padding: 14px 18px;
    border-radius: var(--radius);
    color: var(--fg-muted);
    margin-bottom: 24px;
}

.warn strong { color: var(--accent-bright); }
.warn code {
    background: var(--panel);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--fg);
}

/* === Section heading === */
.section-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 32px 0 14px;
}

.section-head h2 {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.section-head .meta {
    font-size: 12px;
    color: var(--muted);
}

.section-head:first-of-type { margin-top: 0; }

/* === KPI cards === */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 8px;
}

.kpi {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
    transition: border-color 0.15s, transform 0.15s;
}

.kpi:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.kpi .label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.kpi .value {
    font-size: 30px;
    font-weight: 700;
    color: var(--fg);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

/* варианты выделения значения */
.kpi.accent .value { color: var(--accent-bright); }
.kpi.warning .value { color: var(--amber); }
.kpi.success .value { color: var(--green); }

/* статус-точка возле value */
.kpi .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
}
.kpi .status-dot.ok    { background: var(--green); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
.kpi .status-dot.alert { background: var(--accent); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25); animation: pulse 1.4s ease-in-out infinite; }

/* мини-полоска снизу карточки — псевдо-индикатор активности */
.kpi.alert::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent) 50%, transparent);
    background-size: 200% 100%;
    animation: scan 2s linear infinite;
}

@keyframes scan {
    0%   { background-position: -100% 0; }
    100% { background-position:  100% 0; }
}

/* === Chat list table === */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 8px;
}

.chats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.chats-table thead th {
    background: var(--panel);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.chats-table thead th.col-metric { text-align: right; }
.chats-table thead th.col-threshold { text-align: right; }

.chats-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
}
.chats-table tbody tr:last-child { border-bottom: none; }
.chats-table tbody tr:hover { background: var(--panel-2); }

.chats-table tbody tr.row-alert {
    background: rgba(220, 38, 38, 0.05);
}
.chats-table tbody tr.row-alert:hover {
    background: rgba(220, 38, 38, 0.09);
}

.chats-table tbody tr.row-removed {
    opacity: 0.55;
}

.chats-table td {
    padding: 10px 12px;
    vertical-align: middle;
}

/* Column widths */
.col-status    { width: 28px; padding-right: 4px !important; }
.col-name      { min-width: 160px; }
.col-type      { width: 90px; white-space: nowrap; }
.col-threshold { width: 100px; text-align: right; white-space: nowrap; }
.col-metric    { width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.col-owner     { min-width: 130px; }
.col-filters   { min-width: 120px; }

.owner-name     { font-size: 12px; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.owner-username { font-size: 11px; color: var(--fg-muted); }

.num { font-variant-numeric: tabular-nums; }

/* Status dot */
.row-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
}
.row-dot.ok      { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,0.18); }
.row-dot.alert   { background: var(--accent); box-shadow: 0 0 0 3px rgba(220,38,38,0.22); animation: pulse 1.5s ease-in-out infinite; }
.row-dot.removed { background: var(--muted); }

/* Row name */
.row-title    { font-weight: 600; color: var(--fg); line-height: 1.3; }
.row-username { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Type badge */
.type-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 99px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--muted);
    white-space: nowrap;
}
.type-badge.channel { color: #60a5fa; border-color: rgba(96,165,250,0.25); background: rgba(96,165,250,0.07); }
.type-badge.group   { color: var(--fg-muted); }

/* Metric cell colors */
td.success { color: var(--green); font-weight: 600; }
td.warn    { color: var(--amber); font-weight: 600; }
td.danger  { color: var(--accent-bright); font-weight: 600; }

/* Filter tags */
.filter-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--fg-muted);
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}
.tag-muted   { color: var(--muted); }
.tag-removed { color: var(--accent-bright); border-color: rgba(220,38,38,0.3); background: rgba(220,38,38,0.08); }
.tag-danger  { color: var(--accent-bright); border-color: rgba(220,38,38,0.5); background: rgba(220,38,38,0.15); font-weight: 700; }

/* === Removed chats section === */
.removed-section {
    margin-top: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.removed-section summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    list-style: none;
    background: var(--panel);
    color: var(--muted);
    font-size: 13px;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}
.removed-section summary::-webkit-details-marker { display: none; }
.removed-section summary:hover { background: var(--panel-2); color: var(--fg-muted); }

.removed-section[open] summary {
    border-bottom: 1px solid var(--border);
}

.removed-summary-text {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.removed-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    min-width: 22px;
    height: 20px;
    padding: 0 6px;
    border-radius: 99px;
}

.removed-summary-hint {
    font-size: 12px;
    color: var(--muted);
}

.removed-section .table-wrap {
    border: none;
    border-radius: 0;
    margin-bottom: 0;
}

.chats-table--removed thead th {
    background: rgba(10,10,10,0.6);
}

.empty {
    background: var(--panel);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    color: var(--muted);
}

/* === Footer === */
footer {
    margin-top: 40px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

footer a { color: var(--fg-muted); text-decoration: none; }
footer a:hover { color: var(--accent-bright); }

/* === Responsive === */
@media (max-width: 720px) {
    .wrap { padding: 16px; }
    .topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
    .kpi .value { font-size: 26px; }
    .table-wrap { border-radius: 0; border-left: none; border-right: none; }
    .chats-table td, .chats-table th { padding: 8px 10px; }
    .col-filters { display: none; }
    .removed-summary-hint { display: none; }
}

/* === Login page === */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background-image:
        radial-gradient(ellipse 700px 400px at 50% 20%, rgba(220, 38, 38, 0.10), transparent 60%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 32px 28px;
    box-shadow: var(--shadow);
}

.login-brand {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--accent);
    text-transform: uppercase;
    text-align: center;
}

.login-sub {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-align: center;
    margin: 4px 0 28px;
}

.login-error {
    background: rgba(220, 38, 38, 0.10);
    border: 1px solid var(--accent-deep);
    color: var(--accent-bright);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 18px;
}

.login-field {
    display: block;
    margin-bottom: 14px;
}

.login-field span {
    display: block;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.login-field input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--fg);
    font: inherit;
    transition: border-color 0.15s, background 0.15s;
}

.login-field input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-elev);
}

.login-remember {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--fg-muted);
    margin: 4px 0 22px;
    cursor: pointer;
    user-select: none;
}

.login-remember input { accent-color: var(--accent); }

.login-submit {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

.login-submit:hover {
    background: var(--accent-bright);
    box-shadow: 0 4px 16px rgba(220, 38, 38, 0.35);
}

.login-submit:active { transform: translateY(1px); }

/* Logout-button в topbar дашборда */
.logout-form {
    display: inline;
    margin: 0;
}

.logout-btn {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--fg-muted);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    padding: 5px 12px;
    border-radius: 99px;
    transition: border-color 0.15s, color 0.15s;
}

.logout-btn:hover {
    border-color: var(--accent);
    color: var(--accent-bright);
}
