:root {
    --bg: #0f172a;
    --panel: #111c33;
    --panel-2: #16233d;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.18);
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.13);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.14);
    --yellow: #f59e0b;
    --yellow-bg: rgba(245, 158, 11, 0.16);
    --blue: #38bdf8;
    --blue-bg: rgba(56, 189, 248, 0.14);
    --shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.16), transparent 32rem), var(--bg);
    color: var(--text);
}

.app-shell {
    width: min(1320px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--blue);
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 800;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
    margin-bottom: 0;
    font-size: clamp(1.8rem, 3vw, 3rem);
    line-height: 1.05;
}

h2 {
    margin-bottom: 8px;
    font-size: 1.1rem;
}

p { color: var(--muted); }

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.last-refresh, .small-note {
    color: var(--muted);
    font-size: 0.86rem;
}

.role-pill {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 7px 10px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
}

.role-pill.admin {
    color: #bfdbfe;
    background: var(--blue-bg);
}

.role-pill.user {
    color: #cbd5e1;
    background: rgba(148, 163, 184, 0.10);
}

.btn {
    appearance: none;
    border: none;
    border-radius: 12px;
    padding: 11px 15px;
    background: linear-gradient(135deg, #0284c7, #2563eb);
    color: white;
    text-decoration: none;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.28);
}

.btn:disabled {
    cursor: progress;
    opacity: 0.62;
}

.btn.secondary {
    background: rgba(148, 163, 184, 0.15);
    box-shadow: none;
    border: 1px solid var(--border);
}

.btn.danger {
    background: rgba(239, 68, 68, 0.16);
    box-shadow: none;
    border: 1px solid rgba(239, 68, 68, 0.32);
    color: #fecaca;
}

.btn.ok {
    background: rgba(34, 197, 94, 0.15);
    box-shadow: none;
    border: 1px solid rgba(34, 197, 94, 0.32);
    color: #bbf7d0;
}

.btn.monitoring {
    background: var(--blue-bg);
    box-shadow: none;
    border: 1px solid rgba(56, 189, 248, 0.32);
    color: #bae6fd;
}

.btn.ghost {
    background: transparent;
    box-shadow: none;
    border: 1px solid var(--border);
}

.btn.small {
    min-height: 34px;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 0.78rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric-card, .panel, .router-card, .login-card, .install-card {
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.015)), var(--panel);
    border-radius: 22px;
    box-shadow: var(--shadow);
}

.metric-card {
    padding: 18px;
    min-height: 116px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.metric-card span {
    color: var(--muted);
    font-weight: 700;
}

.metric-card strong {
    font-size: 2.8rem;
    line-height: 1;
}

.metric-card.ok { background: linear-gradient(180deg, var(--green-bg), transparent), var(--panel); }
.metric-card.danger { background: linear-gradient(180deg, var(--red-bg), transparent), var(--panel); }
.metric-card.stale { background: linear-gradient(180deg, var(--yellow-bg), transparent), var(--panel); }
.metric-card.total { background: linear-gradient(180deg, var(--blue-bg), transparent), var(--panel); }
.metric-card.monitoring { background: linear-gradient(180deg, var(--blue-bg), transparent), var(--panel); }

.panel {
    padding: 20px;
    margin-bottom: 18px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 16px;
}
.panel-head.wrap { flex-wrap: wrap; }

.router-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
    gap: 14px;
}

.empty-state {
    color: var(--muted);
    min-height: 76px;
    align-items: center;
}

.router-card {
    position: relative;
    overflow: hidden;
    padding: 18px;
    min-height: 178px;
}

.router-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 7px;
    background: var(--blue);
}
.router-card.ok::before { background: var(--green); }
.router-card.danger::before { background: var(--red); }
.router-card.stale::before { background: var(--yellow); }
.router-card.monitoring::before { background: var(--blue); }

.router-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
}

.router-title h3 {
    font-size: 1.08rem;
    margin: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.78rem;
    font-weight: 900;
}
.badge.ok { color: #bbf7d0; background: var(--green-bg); }
.badge.danger { color: #fecaca; background: var(--red-bg); }
.badge.stale { color: #fde68a; background: var(--yellow-bg); }
.badge.monitoring { color: #bae6fd; background: var(--blue-bg); }
.badge .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: currentColor;
}

.router-meta {
    display: grid;
    gap: 9px;
    color: var(--muted);
    font-size: 0.9rem;
}

.router-meta b { color: var(--text); }

.router-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 15px;
}

.charts-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.5fr);
    gap: 18px;
}

.chart-box {
    position: relative;
    width: 100%;
    height: 260px;
    max-height: 260px;
    overflow: hidden;
}

.chart-box-donut {
    height: 230px;
    max-height: 230px;
}

.chart-box-bar {
    height: 260px;
    max-height: 260px;
}

.chart-box-history {
    height: 300px;
    max-height: 300px;
}

.chart-box canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.filters {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

input, select {
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 9px 10px;
    background: rgba(15, 23, 42, 0.72);
    color: var(--text);
    outline: none;
}

.table-wrap {
    margin-top: 18px;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

th, td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.status-pill {
    display: inline-flex;
    border-radius: 999px;
    padding: 6px 10px;
    font-weight: 900;
    font-size: 0.8rem;
}
.status-pill.ok { background: var(--green-bg); color: #bbf7d0; }
.status-pill.danger { background: var(--red-bg); color: #fecaca; }
.status-pill.monitoring { background: var(--blue-bg); color: #bae6fd; }

.site-footer {
    margin-top: 8px;
    padding: 14px 0 0;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
    text-align: center;
}

.help-panel pre {
    overflow-x: auto;
    background: rgba(15, 23, 42, 0.82);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 15px;
    color: #dbeafe;
}

.login-wrap, .install-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card, .install-card {
    width: min(440px, 100%);
    padding: 24px;
}

.login-card input { margin-bottom: 14px; }

.ok-msg {
    background: var(--green-bg);
    color: #bbf7d0;
    border: 1px solid rgba(34, 197, 94, 0.28);
    border-radius: 12px;
    padding: 12px;
}

.error-msg {
    background: var(--red-bg);
    color: #fecaca;
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
}

.hidden { display: none; }

@media (max-width: 900px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .top-actions { justify-content: flex-start; }
    .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .app-shell { width: min(100% - 20px, 1320px); padding-top: 18px; }
    .metrics-grid { grid-template-columns: 1fr; }
    .panel, .metric-card { border-radius: 18px; }
    .filters { align-items: stretch; }
    .filters label, .filters button { width: 100%; }
}
