:root {
    --bg: #080d18;
    --panel: #101827;
    --panel2: #151f31;
    --border: #243149;

    --text: #f4f7fb;
    --muted: #91a0b8;

    --green: #38d996;
    --red: #ff647c;
    --yellow: #f6c85f;
    --blue: #5ea7ff;

    --radius: 16px;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    margin: 0;

    background:
        radial-gradient(
            circle at top right,
            rgba(94,167,255,.08),
            transparent 35%
        ),
        var(--bg);

    color: var(--text);

    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    line-height: 1.5;
}

button {
    font: inherit;
}

.app-shell {
    width: min(1500px, calc(100% - 40px));
    margin: 0 auto;
    padding: 30px 0 60px;
}


/* ========================================================= */
/* HEADER */
/* ========================================================= */

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 30px;

    margin-bottom: 32px;
}

.brand h1 {
    margin: 2px 0 8px;

    font-size: clamp(30px, 4vw, 46px);
    line-height: 1.05;

    letter-spacing: -1.5px;
}

.brand p {
    margin: 0;

    color: var(--muted);

    max-width: 650px;
}

.eyebrow {
    color: var(--blue);

    font-size: 11px;
    font-weight: 800;

    letter-spacing: 1.6px;
    text-transform: uppercase;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.refresh-status {
    display: flex;
    align-items: center;
    gap: 8px;

    color: var(--muted);

    font-size: 13px;
}

.live-dot {
    width: 8px;
    height: 8px;

    border-radius: 50%;

    background: var(--green);

    box-shadow:
        0 0 0 4px rgba(56,217,150,.1);
}


/* ========================================================= */
/* BUTTONS */
/* ========================================================= */

.button {
    border: 1px solid var(--border);

    border-radius: 9px;

    background: #1a2538;
    color: var(--text);

    padding: 9px 14px;

    cursor: pointer;

    transition:
        background .15s,
        border-color .15s,
        transform .15s;
}

.button:hover {
    background: #22304a;
    border-color: #3a4b69;
}

.button:active {
    transform: translateY(1px);
}

.button.secondary {
    background: transparent;
}

.button.danger {
    color: #ff9aaa;
    border-color: rgba(255,100,124,.25);
}

.button.danger:hover {
    background: rgba(255,100,124,.1);
}


/* ========================================================= */
/* METRICS */
/* ========================================================= */

.overview-grid {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: 15px;

    margin-bottom: 42px;
}

.metric-card {
    padding: 20px;

    background: var(--panel);

    border: 1px solid var(--border);

    border-radius: var(--radius);
}

.metric-label {
    color: var(--muted);

    font-size: 12px;
    font-weight: 700;

    text-transform: uppercase;
    letter-spacing: 1px;
}

.metric-value {
    margin-top: 8px;

    font-size: 30px;
    font-weight: 800;

    letter-spacing: -.8px;
}

.metric-detail {
    margin-top: 3px;

    color: var(--muted);

    font-size: 13px;
}

.online-text {
    color: var(--green);
}

.offline-text {
    color: var(--red);
}


/* ========================================================= */
/* SECTIONS */
/* ========================================================= */

.section {
    margin-top: 42px;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;

    margin-bottom: 16px;
}

.section-heading h2 {
    margin: 3px 0 0;

    font-size: 23px;

    letter-spacing: -.4px;
}

.section-description {
    margin: 8px 0 0;

    max-width: 700px;

    color: var(--muted);

    font-size: 14px;
}

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


/* ========================================================= */
/* SERVICES */
/* ========================================================= */

.services-grid {
    display: grid;

    grid-template-columns:
        repeat(2, minmax(0, 1fr));

    gap: 16px;
}

.service-card {
    padding: 22px;

    background: var(--panel);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    transition:
        border-color .2s,
        background .2s;
}

.service-card.offline {
    border-color:
        rgba(255,100,124,.35);
}

.service-header {
    display: flex;

    align-items: flex-start;
    justify-content: space-between;

    gap: 20px;
}

.service-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.service-title-row h3 {
    margin: 0;

    font-size: 18px;
}

.service-name {
    margin-top: 3px;

    color: var(--muted);

    font-family: monospace;
    font-size: 12px;
}

.status-dot {
    width: 10px;
    height: 10px;

    border-radius: 50%;

    background: var(--muted);
}

.status-dot.online {
    background: var(--green);

    box-shadow:
        0 0 0 5px rgba(56,217,150,.1);
}

.status-dot.offline {
    background: var(--red);

    box-shadow:
        0 0 0 5px rgba(255,100,124,.1);
}

.status-pill {
    padding: 5px 9px;

    border-radius: 999px;

    background: rgba(145,160,184,.1);

    color: var(--muted);

    font-size: 10px;
    font-weight: 800;

    letter-spacing: .8px;
}

.status-pill.online {
    color: var(--green);
    background: rgba(56,217,150,.1);
}

.status-pill.offline {
    color: var(--red);
    background: rgba(255,100,124,.1);
}

.service-info {
    display: grid;

    grid-template-columns:
        repeat(3, 1fr);

    gap: 12px;

    margin-top: 22px;
}

.service-info div {
    padding: 12px;

    border-radius: 10px;

    background: var(--panel2);
}

.service-info span {
    display: block;

    color: var(--muted);

    font-size: 10px;

    text-transform: uppercase;
    letter-spacing: .8px;
}

.service-info strong {
    display: block;

    margin-top: 3px;

    overflow: hidden;
    text-overflow: ellipsis;

    font-family: monospace;

    font-size: 12px;
}

.service-actions {
    display: flex;

    gap: 8px;

    margin-top: 18px;
}


/* ========================================================= */
/* STREAMS */
/* ========================================================= */

.streams-grid {
    display: grid;

    grid-template-columns:
        repeat(2, minmax(0, 1fr));

    gap: 16px;
}

.stream-card {
    overflow: hidden;

    background: var(--panel);

    border: 1px solid var(--border);

    border-radius: var(--radius);
}

.stream-header {
    display: flex;

    justify-content: space-between;

    padding: 20px 20px 8px;
}

.stream-service {
    color: var(--blue);

    font-size: 10px;
    font-weight: 800;

    letter-spacing: 1px;
    text-transform: uppercase;
}

.stream-header h3 {
    margin: 3px 0 0;

    font-size: 21px;
}

.live-badge {
    align-self: flex-start;

    padding: 5px 8px;

    border-radius: 7px;

    color: var(--green);

    background: rgba(56,217,150,.1);

    font-size: 10px;
    font-weight: 800;

    letter-spacing: .8px;
}

.stream-route {
    padding: 0 20px 16px;

    color: var(--muted);

    font-family: monospace;
    font-size: 12px;
}

.stream-stats {
    display: grid;

    grid-template-columns:
        repeat(3, 1fr);

    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.stream-stats div {
    padding: 13px 15px;

    border-right: 1px solid var(--border);
}

.stream-stats div:nth-child(3n) {
    border-right: 0;
}

.stream-stats span {
    display: block;

    color: var(--muted);

    font-size: 10px;

    text-transform: uppercase;
    letter-spacing: .6px;
}

.stream-stats strong {
    display: block;

    margin-top: 2px;

    font-size: 13px;
}

.stream-footer {
    display: flex;

    justify-content: space-between;

    gap: 15px;

    padding: 13px 20px;

    color: var(--muted);

    font-size: 11px;
}

.stream-footer span:last-child {
    overflow: hidden;

    text-overflow: ellipsis;

    white-space: nowrap;

    font-family: monospace;
}


/* ========================================================= */
/* TABLE */
/* ========================================================= */

.table-wrap {
    overflow: auto;

    background: var(--panel);

    border: 1px solid var(--border);

    border-radius: var(--radius);
}

table {
    width: 100%;

    border-collapse: collapse;

    min-width: 800px;
}

th {
    padding: 13px 16px;

    text-align: left;

    color: var(--muted);

    background: var(--panel2);

    font-size: 10px;

    text-transform: uppercase;
    letter-spacing: .8px;
}

td {
    padding: 15px 16px;

    border-top: 1px solid var(--border);

    font-size: 13px;
}

.mono {
    font-family: monospace;
}

.service-badge {
    display: inline-block;

    padding: 4px 7px;

    border-radius: 6px;

    background: rgba(94,167,255,.1);

    color: var(--blue);

    font-size: 10px;
    font-weight: 700;
}

.client-state {
    color: var(--muted);
}

.client-state.publisher {
    color: var(--green);
}

.empty-cell {
    padding: 35px;

    text-align: center;

    color: var(--muted);
}


/* ========================================================= */
/* FEATURES */
/* ========================================================= */

.feature-grid {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: 15px;
}

.feature-card {
    position: relative;

    padding: 20px;

    min-height: 185px;

    background: var(--panel);

    border: 1px solid var(--border);

    border-radius: var(--radius);
}

.feature-icon {
    display: flex;

    align-items: center;
    justify-content: center;

    width: 36px;
    height: 36px;

    border-radius: 9px;

    background: rgba(94,167,255,.1);

    color: var(--blue);

    font-weight: 800;
}

.feature-card h3 {
    margin: 16px 0 6px;

    font-size: 16px;
}

.feature-card p {
    margin: 0;

    color: var(--muted);

    font-size: 13px;
}

.coming-soon {
    position: absolute;

    bottom: 18px;
    left: 20px;

    color: var(--blue);

    font-size: 9px;
    font-weight: 800;

    letter-spacing: 1px;
}


/* ========================================================= */
/* EMPTY */
/* ========================================================= */

.empty-state {
    display: flex;

    grid-column: 1 / -1;

    flex-direction: column;
    align-items: center;
    justify-content: center;

    min-height: 180px;

    padding: 30px;

    color: var(--muted);

    background: var(--panel);

    border: 1px dashed var(--border);

    border-radius: var(--radius);

    text-align: center;
}

.empty-state strong {
    margin-top: 10px;

    color: var(--text);
}

.empty-icon {
    font-size: 30px;
}


/* ========================================================= */
/* TOASTS */
/* ========================================================= */

#toast-container {
    position: fixed;

    right: 24px;
    bottom: 24px;

    display: flex;

    flex-direction: column;

    gap: 10px;

    z-index: 1000;
}

.toast {
    max-width: 380px;

    padding: 12px 15px;

    background: #172235;

    border: 1px solid var(--border);

    border-radius: 10px;

    box-shadow: 0 15px 40px rgba(0,0,0,.35);

    color: var(--text);

    font-size: 13px;

    animation: toast-in .2s ease;
}

.toast.error {
    border-color: rgba(255,100,124,.4);
    color: #ffb2bf;
}

.toast.hide {
    opacity: 0;
    transform: translateY(8px);

    transition:
        opacity .2s,
        transform .2s;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ========================================================= */
/* RESPONSIVE */
/* ========================================================= */

@media (max-width: 1100px) {

    .overview-grid {
        grid-template-columns:
            repeat(2, 1fr);
    }

    .feature-grid {
        grid-template-columns:
            repeat(2, 1fr);
    }

}

@media (max-width: 850px) {

    .topbar {
        flex-direction: column;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .services-grid,
    .streams-grid {
        grid-template-columns: 1fr;
    }

}

@media (max-width: 600px) {

    .app-shell {
        width: min(100% - 24px, 1500px);
        padding-top: 18px;
    }

    .overview-grid {
        grid-template-columns: 1fr;
    }

    .feature-grid {
        grid-template-columns: 1fr;
    }

    .service-info {
        grid-template-columns: 1fr;
    }

    .stream-stats {
        grid-template-columns:
            repeat(2, 1fr);
    }

    .stream-stats div:nth-child(3n) {
        border-right: 1px solid var(--border);
    }

    .stream-stats div:nth-child(2n) {
        border-right: 0;
    }

}

/* ==============================
   SYSTEM HEALTH
   ============================== */

.system-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.system-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    min-width: 0;
}

.system-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.system-card-header span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.system-card-header strong {
    font-size: 22px;
    font-weight: 700;
}

.progress-track {
    height: 7px;
    background: var(--panel2);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: var(--blue);
    border-radius: inherit;
    transition: width .35s ease;
}

.system-detail {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

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

@media (max-width: 1100px) {
    .system-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 650px) {
    .system-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   STREAM DETAIL INTERACTION
   ============================================================ */

.stream-card.clickable {
    cursor: pointer;
    transition:
        transform 160ms ease,
        border-color 160ms ease,
        box-shadow 160ms ease;
}

.stream-card.clickable:hover {
    transform: translateY(-2px);
}

.stream-card.clickable:active {
    transform: translateY(0);
}

.stream-card.clickable:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

body.modal-open {
    overflow: hidden;
}

/* Modal backdrop */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 180ms ease;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-backdrop.open {
    opacity: 1;
}

/* Modal */

.stream-modal {
    width: min(900px, calc(100vw - 32px));
    max-height: min(820px, calc(100vh - 48px));
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 18px;
    background: var(--panel, #11151c);
    box-shadow: 0 30px 100px rgba(0, 0, 0, 0.45);
    transform: translateY(12px) scale(0.985);
    transition: transform 180ms ease;
}

.modal-backdrop.open .stream-modal {
    transform: translateY(0) scale(1);
}

.stream-modal-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: var(--panel, #11151c);
}

.stream-modal-header h2 {
    margin: 5px 0 0;
}

.modal-subtitle {
    margin-top: 5px;
    color: var(--muted, #8b93a7);
    font-size: 0.9rem;
}

.modal-close {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    color: inherit;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.10);
}

.modal-close:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Detail layout */

.stream-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: 24px;
}

.detail-section {
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.025);
}

.detail-section-wide {
    grid-column: 1 / -1;
}

.detail-section-title {
    margin-bottom: 12px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.55;
}

.detail-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 20px;
    padding: 9px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.055);
}

.detail-row:last-child {
    border-bottom: 0;
}

.detail-row span {
    flex: 0 0 auto;
    color: var(--muted, #8b93a7);
    font-size: 12px;
}

.detail-row strong {
    min-width: 0;
    max-width: 70%;
    overflow-wrap: anywhere;
    text-align: right;
    font-size: 12px;
}

.detail-online {
    color: #52d273;
}

.detail-mono {
    max-width: 70%;
    overflow-wrap: anywhere;
    font-family:
        ui-monospace,
        SFMono-Regular,
        Menlo,
        Monaco,
        Consolas,
        monospace;
    font-size: 0.82rem;
}

.detail-copy-row {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 70%;
}

.detail-copy-row .detail-mono {
    max-width: none;
    flex: 1;
}

.detail-copy-button {
    flex: 0 0 auto;
    padding: 6px 9px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}

.detail-copy-button:hover {
    background: rgba(255, 255, 255, 0.10);
}

.stream-detail-hint {
    margin-top: 14px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.65;
}

/* Mobile */

@media (max-width: 700px) {
    .modal-backdrop {
        padding: 10px;
    }

    .stream-modal {
        width: calc(100vw - 20px);
        max-height: calc(100vh - 20px);
    }

    .stream-modal-header {
        padding: 18px;
    }

    .stream-detail-grid {
        grid-template-columns: 1fr;
        padding: 14px;
    }

    .detail-section-wide {
        grid-column: auto;
    }

    .detail-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .detail-row strong,
    .detail-copy-row {
        max-width: 100%;
        text-align: left;
    }

    .detail-copy-row {
        width: 100%;
    }

    .detail-mono {
        max-width: 100%;
    }
}

/* ============================================================
   LIVE STREAM DETAIL POLISH
   ============================================================ */

.stream-card.clickable {
    transition:
        transform 160ms ease,
        border-color 160ms ease,
        box-shadow 160ms ease;
}

.stream-card.clickable:hover {
    transform: translateY(-2px);
}

.stream-card.clickable:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

.detail-section-title {
    user-select: none;
}

.detail-online {
    font-weight: 800;
}

.detail-copy-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
}

.detail-copy-row .detail-mono {
    flex: 1 1 auto;
    max-width: none;
    text-align: left;
}

.detail-copy-button {
    flex: 0 0 auto;
    padding: 7px 10px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 8px;
    background: rgba(255,255,255,.05);
    color: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.detail-copy-button:hover {
    background: rgba(255,255,255,.10);
}

@media (max-width: 700px) {
    .detail-copy-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .detail-copy-button {
        width: 100%;
    }
}


/* ============================================================
   STREAM DETAIL EMPTY STATE
   ============================================================ */

.detail-empty {
    padding: 18px 0 4px;
    color: var(--muted, #8b93a7);
    font-size: 13px;
    line-height: 1.5;
}


/* ============================================================
   CONNECTED CLIENT INTERACTION
   ============================================================ */

.client-row {
    cursor: pointer;
    transition:
        background 140ms ease,
        transform 140ms ease;
}

.client-row:hover {
    background: rgba(255,255,255,.025);
}

.client-row:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -2px;
}

.client-row-action {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border: 1px solid rgba(255,255,255,.09);
    border-radius: 7px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.client-row:hover .client-row-action {
    color: inherit;
    background: rgba(255,255,255,.05);
}

.client-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 0 24px 24px;
}

.danger-button {
    border: 1px solid rgba(255, 90, 90, .28);
    border-radius: 10px;
    padding: 10px 14px;
    background: rgba(255, 70, 70, .08);
    color: #ff8585;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.danger-button:hover {
    background: rgba(255, 70, 70, .14);
}

@media (max-width: 700px) {
    .client-modal-actions {
        padding: 0 14px 14px;
    }
}

