:root {
    color-scheme: light dark;
    --bg: #0f172a;
    --panel-bg: rgba(15, 23, 42, 0.8);
    --panel-border: rgba(148, 163, 184, 0.2);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #38bdf8;
    --success: #4ade80;
    --warning: #facc15;
    --error: #f87171;
    --table-header: rgba(148, 163, 184, 0.12);
    --muted-bg: rgba(148, 163, 184, 0.05);
    font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: radial-gradient(circle at top, rgba(56, 189, 248, 0.18), transparent 50%), var(--bg);
    color: var(--text-primary);
}

.page {
    width: min(1200px, 100%);
    margin: 0 auto;
    padding: 2.5rem 1.5rem 3rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.brand {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.brand h1 {
    margin: 0;
    font-size: clamp(1.8rem, 2.4vw, 2.6rem);
    letter-spacing: -0.02em;
}

.brand span {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.refresh-indicator {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    text-align: right;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
    font-size: 0.8rem;
    background: var(--muted-bg);
    color: var(--accent);
}

.user-summary {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    text-align: right;
}

.btn-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
}

.btn-link:hover {
    text-decoration: underline;
}

.btn-primary,
.btn-danger,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border-radius: 999px;
    padding: 0.45rem 1rem;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn-primary {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.65), rgba(2, 132, 199, 0.85));
    color: #0f172a;
}

.btn-danger {
    background: rgba(248, 113, 113, 0.85);
    color: var(--text-primary);
}

.btn-secondary {
    background: rgba(148, 163, 184, 0.25);
    color: var(--text-primary);
}

.btn-primary:hover,
.btn-danger:hover,
.btn-secondary:hover {
    opacity: 0.9;
}

.btn-primary:active,
.btn-danger:active,
.btn-secondary:active {
    transform: scale(0.97);
}

.btn-secondary[disabled],
.btn-secondary[disabled]:hover {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.25rem;
}
.cards:not(.section-active) {
    display: none;
}

.card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    backdrop-filter: blur(12px);
    position: relative;
    overflow: hidden;
}

.card::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.12), transparent 55%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.card:hover::after {
    opacity: 1;
}

.card span {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card strong {
    font-size: clamp(1.8rem, 2.5vw, 2.4rem);
    font-weight: 600;
    letter-spacing: -0.02em;
}

.card small {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    padding: 1.5rem;
    backdrop-filter: blur(12px);
}

[data-section] {
    display: none;
}

[data-section].section-active {
    display: block;
}

.panel h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.table-wrapper {
    overflow: auto;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

thead {
    background: var(--table-header);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

th,
td {
    text-align: left;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.05);
    vertical-align: top;
}

tbody tr:hover {
    background: rgba(56, 189, 248, 0.08);
}

.status-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.actions-cell {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.text-right {
    text-align: right;
}

.status-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cell-meta {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-secondary);
}

.pill.connected {
    background: rgba(74, 222, 128, 0.15);
    color: var(--success);
}

.pill.disconnected {
    background: rgba(248, 113, 113, 0.18);
    color: var(--error);
}

.pill.limit_disconnect {
    background: rgba(250, 204, 21, 0.18);
    color: var(--warning);
}

.pill.limit_disconnect_failed {
    background: rgba(248, 113, 113, 0.25);
    color: var(--error);
}

.muted {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.status-dot {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

.status-dot.idle {
    background: var(--warning);
    box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.25);
}

.status-dot.stale {
    background: var(--error);
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.25);
}

.error-banner {
    background: rgba(248, 113, 113, 0.15);
    border: 1px solid rgba(248, 113, 113, 0.4);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.9rem;
    display: none;
}

.error-banner.visible {
    display: block;
}

.error-banner.success {
    background: rgba(74, 222, 128, 0.18);
    border-color: rgba(74, 222, 128, 0.45);
    color: var(--text-primary);
}

.footer {
    margin-top: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.table-footer {
    display: flex;
    justify-content: flex-end;
    padding: 0.85rem 0 0;
}

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.95));
    padding: 2rem;
}

.login-card {
    width: min(360px, 100%);
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 18px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: center;
    box-shadow: 0 25px 40px rgba(15, 23, 42, 0.35);
}

.login-card h1 {
    margin: 0;
    font-size: 1.8rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.login-form input {
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-primary);
}

.login-form input:focus {
    outline: none;
    border-color: rgba(56, 189, 248, 0.6);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.admin-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.admin-form .form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.admin-form label {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex: 1 1 200px;
}
.admin-form .stack {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.admin-form input,
.admin-form select {
    padding: 0.55rem 0.8rem;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.55);
    color: var(--text-primary);
}

.admin-form input:focus,
.admin-form select:focus {
    outline: none;
    border-color: rgba(56, 189, 248, 0.6);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.admin-form .checkbox {
    flex: 0 1 auto;
    align-items: center;
    flex-direction: row;
    gap: 0.45rem;
}

.admin-form .checkbox input {
    width: auto;
    accent-color: var(--accent);
}

.admin-form .checkbox span {
    color: var(--text-secondary);
}

.admin-panel {
    flex-direction: column;
    gap: 1rem;
}

@media (max-width: 720px) {
    header {
        align-items: flex-start;
    }

    .refresh-indicator {
        text-align: left;
    }

    table {
        min-width: 100%;
    }
}
.top-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 0 0 1.5rem;
}

.nav-btn {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(56, 189, 248, 0.25);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 0.45rem 1.1rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.nav-btn:hover {
    border-color: rgba(56, 189, 248, 0.6);
}

.nav-btn.active {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.65), rgba(2, 132, 199, 0.85));
    color: #0f172a;
}
[data-section].section-active {
    display: block;
}

.cards.section-active {
    display: grid;
}

.admin-panel.section-active {
    display: flex;
}

.analytics-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.analytics-chart-wide {
    margin-bottom: 1.5rem;
}
.analytics-chart-wide .chart-card {
    height: 340px;
}
.analytics-chart-pies {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    align-items: stretch;
}
.chart-card {
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chart-card h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.02em;
}
.chart-card canvas {
    flex: 1 1 auto;
    width: 100% !important;
    min-height: 200px;
    max-height: 260px;
}

.mt-1 {
    margin-top:10px;
}

.mt-2 {
    margin-top:20px;
}

.mt-3 {
    margin-top:30px;
}