:root {
    --bg: #07080f;
    --surface: #0d0e1a;
    --card: rgba(255,255,255,0.035);
    --card-hover: rgba(255,255,255,0.06);
    --border: rgba(255,255,255,0.08);
    --border-bright: rgba(255,255,255,0.18);
    --accent: #5865F2;
    --accent-2: #7c3aed;
    --accent-glow: rgba(88,101,242,0.35);
    --text: #f2f3f5;
    --text-dim: #72767d;
    --text-mid: #b5bac1;
    --success: #23a559;
    --success-dim: rgba(35,165,89,0.15);
    --error: #f23f42;
    --error-dim: rgba(242,63,66,0.15);
    --warning: #f0b232;
    --warning-dim: rgba(240,178,50,0.15);
    --radius: 16px;
    --radius-sm: 10px;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    min-height: 100vh;
    line-height: 1.5;
}

/* ── Background ── */
.bg-orbs {
    position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
}
.bg-orbs::before {
    content: '';
    position: absolute;
    width: 700px; height: 700px;
    top: -200px; left: -150px;
    background: radial-gradient(circle, rgba(88,101,242,0.12) 0%, transparent 70%);
    border-radius: 50%;
    animation: orb1 20s ease-in-out infinite alternate;
}
.bg-orbs::after {
    content: '';
    position: absolute;
    width: 500px; height: 500px;
    bottom: -100px; right: -100px;
    background: radial-gradient(circle, rgba(124,58,237,0.1) 0%, transparent 70%);
    border-radius: 50%;
    animation: orb2 25s ease-in-out infinite alternate;
}
@keyframes orb1 { from { transform: translate(0,0) scale(1); } to { transform: translate(80px,60px) scale(1.15); } }
@keyframes orb2 { from { transform: translate(0,0) scale(1); } to { transform: translate(-60px,-40px) scale(1.2); } }

/* ── Layout ── */
.container { max-width: 1440px; margin: 0 auto; padding: 1rem; }
@media (min-width: 600px) { .container { padding: 1.5rem; } }
@media (min-width: 960px) { .container { padding: 2rem; } }

/* ── Nav ── */
nav {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.025);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    backdrop-filter: blur(20px);
    gap: 0.5rem;
}
@media (min-width: 600px) {
    nav { padding: 1rem 1.5rem; margin-bottom: 2.5rem; }
}
.logo { display: flex; align-items: center; gap: 0.75rem; font-size: 1.25rem; font-weight: 700; letter-spacing: -0.5px; }
.logo img { height: 28px; }
@media (min-width: 600px) { .logo img { height: 32px; } }
.user-pill { display: flex; align-items: center; gap: 0.5rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--accent); object-fit: cover; }
@media (min-width: 600px) { .avatar { width: 36px; height: 36px; } }
.username { font-weight: 600; font-size: 0.9rem; display: none; }
@media (min-width: 480px) { .username { display: inline; } }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: var(--accent); color: #fff;
    padding: 0.55rem 1.2rem; border-radius: var(--radius-sm);
    font-family: inherit; font-size: 0.875rem; font-weight: 600;
    border: none; cursor: pointer; text-decoration: none;
    transition: all 0.18s ease; white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); transform: translateY(-1px); box-shadow: 0 6px 24px var(--accent-glow); }
.btn:active { transform: translateY(0); }
.btn-ghost {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-mid);
}
.btn-ghost:hover { background: var(--card-hover); border-color: var(--border-bright); color: var(--text); }
.btn-danger { background: transparent; border: 1px solid var(--error-dim); color: var(--error); }
.btn-danger:hover { background: var(--error-dim); box-shadow: none; }
.btn-sm { padding: 0.4rem 0.9rem; font-size: 0.8rem; }

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
@media (min-width: 960px) { .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 1.25rem; margin-bottom: 2rem; } }

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    position: relative; overflow: hidden;
    transition: border-color 0.2s, transform 0.2s;
}
@media (min-width: 960px) { .stat-card { padding: 1.5rem; } }
.stat-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    opacity: 0;
    transition: opacity 0.2s;
}
.stat-card:hover { border-color: rgba(88,101,242,0.4); transform: translateY(-2px); }
.stat-card:hover::before { opacity: 1; }
.stat-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-dim); margin-bottom: 0.4rem; }
.stat-value { font-size: 2rem; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.stat-value.online { color: var(--success); }
.stat-subvalue { margin-top: 0.45rem; color: var(--text-dim); font-size: 0.78rem; font-weight: 600; }

/* Online dot */
.online-dot {
    display: inline-block; width: 8px; height: 8px;
    background: var(--success); border-radius: 50%;
    margin-right: 0.5rem; vertical-align: middle;
    box-shadow: 0 0 0 0 rgba(35,165,89,0.6);
    animation: pulse-dot 2.5s ease-out infinite;
}
@keyframes pulse-dot {
    0% { box-shadow: 0 0 0 0 rgba(35,165,89,0.6); }
    70% { box-shadow: 0 0 0 8px rgba(35,165,89,0); }
    100% { box-shadow: 0 0 0 0 rgba(35,165,89,0); }
}

/* ── Sync Bar ── */
.sync-bar-wrap {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.5rem;
    margin-bottom: 2rem;
    display: flex; align-items: center; gap: 1rem;
}
.sync-bar-wrap.hidden { display: none; }
.sync-bar-track { flex: 1; height: 6px; background: rgba(255,255,255,0.08); border-radius: 99px; overflow: hidden; }
.sync-bar-fill {
    height: 100%; border-radius: 99px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transition: width 0.5s ease;
    min-width: 4px;
}
.sync-label { font-size: 0.82rem; color: var(--text-mid); white-space: nowrap; }

/* ── Cards ── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap;
}
.card-title { font-size: 1.05rem; font-weight: 700; }
.card-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

/* ── Main grid ── */
.main-grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 960px) { .main-grid { grid-template-columns: 1fr 320px; } }

/* ── Alerts ── */
.alerts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 900px) {
    .alerts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .alerts-grid .card { margin-bottom: 0; }
}
.alert-input-row { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; }
input[type="text"] {
    flex: 1;
    background: rgba(255,255,255,0.045);
    border: 1px solid var(--border);
    color: var(--text); padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    font-family: inherit; font-size: 0.9rem;
    transition: border-color 0.18s, box-shadow 0.18s;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,101,242,0.18); }
input[type="text"]::placeholder { color: var(--text-dim); }

.alert-tags { display: flex; flex-wrap: wrap; gap: 0.6rem; min-height: 2rem; }
.alert-tag {
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: rgba(88,101,242,0.15); border: 1px solid rgba(88,101,242,0.3);
    color: #a5b4fc; border-radius: 99px;
    padding: 0.3rem 0.75rem; font-size: 0.82rem; font-weight: 600;
    animation: tag-in 0.15s ease;
}
@keyframes tag-in { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tag-remove { background: none; border: none; cursor: pointer; color: inherit; opacity: 0.6; font-size: 1rem; line-height: 1; padding: 0; }
.tag-remove:hover { opacity: 1; }
.empty-state { color: var(--text-dim); font-size: 0.85rem; font-style: italic; }
.tip { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 1rem; line-height: 1.5; }

@media (max-width: 520px) {
    .alert-input-row { flex-direction: column; }
    .alert-input-row .btn { justify-content: center; }
}

/* ── Channel Filter ── */
.channel-filter-row { display: flex; gap: 0.75rem; margin-bottom: 1.25rem; align-items: center; }
.channel-search { flex: 1; }

/* ── Custom Select ── */
.custom-select {
    position: relative;
    user-select: none;
    min-width: 140px;
}
.select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text-mid);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.select-trigger:hover {
    background: var(--card-hover);
    border-color: var(--border-bright);
    color: var(--text);
}
.custom-select.open .select-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88,101,242,0.15);
    color: var(--text);
}
.select-arrow {
    width: 14px;
    height: 14px;
    transition: transform 0.2s;
    opacity: 0.6;
}
.custom-select.open .select-arrow {
    transform: rotate(180deg);
    opacity: 1;
}
.select-options {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: #141526;
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-sm);
    box-shadow: 0 12px 36px rgba(0,0,0,0.5);
    z-index: 1000;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    padding: 0.35rem;
}
.custom-select.open .select-options {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.select-option {
    padding: 0.6rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-mid);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}
.select-option:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}
.select-option.selected {
    background: rgba(88,101,242,0.15);
    color: #a5b4fc;
}

/* ── Table ── */
/* ── Table (desktop) ── */
.table-wrap { width: 100%; overflow-x: auto; }
.channel-table { width: 100%; border-collapse: collapse; min-width: 680px; }
.channel-table col:nth-child(1) { width: 30%; }
.channel-table col:nth-child(2) { width: 28%; }
.channel-table col:nth-child(3) { width: 130px; }
.channel-table col:nth-child(4) { width: 160px; }
.channel-table col:nth-child(5) { width: 100px; }
th {
    text-align: left; font-size: 0.7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-dim); padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 0.85rem 0.9rem; border-bottom: 1px solid var(--border); font-size: 0.875rem; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr { transition: background 0.12s; }
tr:hover td { background: rgba(255,255,255,0.022); }

/* ── Channel cards on mobile ── */
@media (max-width: 700px) {
    /* Prevent the card from overflowing the viewport */
    #admin-panel { overflow: hidden; }

    .summary-row { gap: 0.5rem; }
    .summary-pill { min-width: 70px; padding: 0.5rem 0.75rem; }

    .table-wrap { overflow-x: hidden; }

    /* Flip table to block layout */
    .channel-table,
    .channel-table tbody,
    .channel-table tr,
    .channel-table td { display: block; width: 100%; min-width: 0; }
    .channel-table thead { display: none; }
    .channel-table colgroup { display: none; }

    /* Each row becomes a card */
    .channel-table tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.4rem 0.75rem;
        background: rgba(255,255,255,0.025);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        margin-bottom: 0.6rem;
        padding: 0.75rem 0.85rem;
        width: 100%;
        box-sizing: border-box;
    }
    .channel-table tr:last-child { margin-bottom: 0; }

    /* Channel name: full width top row */
    .channel-table td:nth-child(1) {
        flex: 0 0 100%;
        padding: 0;
        border: none;
    }
    .ch-name { white-space: normal; word-break: break-word; font-size: 0.875rem; }

    /* Status badge: left of bottom row */
    .channel-table td:nth-child(3) {
        flex: 1;
        padding: 0;
        border: none;
    }

    /* Action button: right of bottom row */
    .channel-table td:nth-child(5) {
        flex: 0;
        padding: 0;
        border: none;
        text-align: right;
    }

    /* Hide destination and activity — too cramped on mobile */
    .channel-table td:nth-child(2),
    .channel-table td:nth-child(4) { display: none; }

    .channel-filter-row { flex-direction: column; }
}

.channel-name-cell { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.ch-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-meta { font-size: 0.72rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-dest { color: var(--text-mid); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 100%; }
.ch-activity { color: var(--text-dim); font-size: 0.8rem; white-space: nowrap; }

/* ── Badges ── */
.badge {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.28rem 0.65rem; border-radius: 6px;
    font-size: 0.7rem; font-weight: 700; white-space: nowrap; letter-spacing: 0.3px;
    background: var(--success-dim); color: var(--success); border: 1px solid rgba(35,165,89,0.3);
}
.badge-dim { background: rgba(255,255,255,0.05); color: var(--text-dim); border: 1px solid var(--border); }
.badge-warning { background: var(--warning-dim); color: var(--warning); border: 1px solid rgba(240,178,50,0.3); }
.badge-error { background: var(--error-dim); color: var(--error); border: 1px solid rgba(242,63,66,0.3); }

/* ── Summary pills ── */
.summary-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.25rem; }
.summary-pill {
    display: flex; flex-direction: column; align-items: center;
    padding: 0.6rem 1rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: rgba(255,255,255,0.02);
    min-width: 80px;
}
.summary-pill strong { font-size: 1.25rem; font-weight: 800; line-height: 1; }
.summary-pill span { font-size: 0.65rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.8px; margin-top: 0.2rem; }

/* ── Right col info ── */
.info-row { margin-bottom: 1.25rem; }
.info-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.3rem; }
.info-value { font-size: 0.95rem; font-weight: 600; font-family: 'JetBrains Mono', monospace; }
.info-value.running { color: var(--warning); }

/* ── Loading ── */
.spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.12);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--text-dim); font-size: 0.82rem; }

/* Skeleton rows */
.skeleton { animation: shimmer 1.5s infinite; background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.09) 50%, rgba(255,255,255,0.04) 75%); background-size: 200% 100%; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.skeleton-row td { padding: 1rem 0.9rem; }
.skel-block { height: 14px; border-radius: 4px; }

/* ── Toast ── */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.6rem; }
.toast {
    display: flex; align-items: flex-start; gap: 0.75rem;
    background: #1a1c2e; border: 1px solid var(--border-bright);
    border-radius: var(--radius-sm); padding: 0.85rem 1.1rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    min-width: 280px; max-width: 380px;
    animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.toast-out { animation: toast-out 0.25s ease forwards; }
@keyframes toast-out { to { transform: translateX(120%); opacity: 0; } }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 700; font-size: 0.88rem; }
.toast-msg { font-size: 0.8rem; color: var(--text-mid); margin-top: 0.15rem; }
.toast.success { border-color: rgba(35,165,89,0.4); }
.toast.error { border-color: rgba(242,63,66,0.4); }
.toast.info { border-color: rgba(88,101,242,0.4); }

/* ── Modals ── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
}
.modal {
    background: #12131f; border: 1px solid var(--border-bright);
    border-radius: 20px; padding: 2.5rem; max-width: 420px; width: 90%;
    text-align: center; animation: modal-in 0.2s ease;
}
@keyframes modal-in { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-icon { font-size: 3rem; margin-bottom: 1rem; }
.modal h2 { font-size: 1.4rem; font-weight: 800; margin-bottom: 0.75rem; }
.modal p { color: var(--text-mid); margin-bottom: 1.75rem; font-size: 0.92rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: center; }

/* ── Gate views ── */
.gate {
    min-height: 100vh;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem 2rem;
}
.gate img {
    height: 52px;
    margin-bottom: 1.25rem;
}
@media (min-width: 480px) {
    .gate img { height: 72px; margin-bottom: 1.5rem; }
}
.gate h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 0.6rem; }
@media (min-width: 480px) { .gate h1 { font-size: 2rem; } }
.gate p {
    color: var(--text-mid);
    max-width: 400px;
    margin: 0 auto 1.75rem;
    font-size: 0.9rem;
    line-height: 1.6;
}
.gate-actions {
    display: flex; gap: 0.75rem;
    flex-direction: column; width: 100%; max-width: 320px;
}
.gate-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 0.85rem 1.5rem;
    font-size: 0.95rem;
}
@media (min-width: 480px) {
    .gate-actions { flex-direction: row; width: auto; max-width: none; }
    .gate-actions .btn { width: auto; }
}

/* ── Misc ── */
.hidden { display: none !important; }
.text-dim { color: var(--text-dim); }
.text-mid { color: var(--text-mid); }
.mono { font-family: 'JetBrains Mono', monospace; }

.right-col { display: flex; flex-direction: column; gap: 1rem; }
.health-status-row { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 1.1rem; }
.health-status { font-size: 0.95rem; font-weight: 700; }
.health-dot { width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--warning); box-shadow: 0 0 14px rgba(240,178,50,0.45); }
.health-dot.ok { background: var(--success); box-shadow: 0 0 14px rgba(35,165,89,0.45); }
.health-dot.bad { background: var(--error); box-shadow: 0 0 14px rgba(242,63,66,0.45); }
.health-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 0.85rem; }
.health-item .info-value { font-size: 0.82rem; overflow-wrap: anywhere; }
.health-queue-list { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.45rem; }
.health-queue-item {
    display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.6rem;
    padding: 0.55rem 0; border-top: 1px solid var(--border);
    font-size: 0.72rem; color: var(--text-mid);
}
.health-queue-item .mono { grid-column: 1 / -1; color: var(--text); overflow-wrap: anywhere; }
