:root {
    --bg: #f1f3f9;
    --surface: #ffffff;
    --border: #e3e6ee;
    --text: #1a1d29;
    --text-muted: #6b7184;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --ok: #16a34a;
    --ok-bg: #dcfce7;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
}

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: #14152b;
    color: #cdd1e8;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    flex-shrink: 0;
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: white;
    margin-bottom: 2rem;
    line-height: 1.3;
}

.brand span {
    display: block;
    font-weight: 400;
    font-size: 0.75rem;
    color: #8b90b8;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
}

.sidebar nav a {
    color: #cdd1e8;
    text-decoration: none;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    font-size: 0.92rem;
}

.sidebar nav a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

.logout-form button.ghost {
    background: transparent;
    border: 1px solid #393b5c;
    color: #cdd1e8;
    width: 100%;
}

main {
    flex: 1;
    padding: 2rem 2.5rem;
    max-width: 1100px;
}

h1 {
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
}

h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(20, 21, 43, 0.06);
}

th, td {
    text-align: left;
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    background: #fafbfd;
}

tr:last-child td {
    border-bottom: none;
}

form {
    margin: 0 0 0.75rem 0;
}

label {
    display: block;
    margin-bottom: 0.85rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

input, textarea, select {
    width: 100%;
    max-width: 420px;
    padding: 0.5rem 0.65rem;
    margin-top: 0.3rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 0.92rem;
    color: var(--text);
    background: var(--surface);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

button {
    padding: 0.5rem 1rem;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text);
}

button:hover {
    background: #f5f6fa;
}

button.primary, button[type="submit"] {
    background: var(--accent);
    color: white;
    border: none;
}

button.primary:hover, button[type="submit"]:hover {
    background: var(--accent-hover);
}

button.danger {
    background: var(--danger);
    color: white;
    border: none;
}

button.danger:hover {
    background: #b91c1c;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge-ok {
    background: var(--ok-bg);
    color: var(--ok);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-neutral {
    background: #eef0f5;
    color: var(--text-muted);
}

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

.filters {
    display: flex;
    gap: 1.5rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.filters label {
    margin-bottom: 0;
}

.filters select {
    max-width: 220px;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    font-size: 0.88rem;
}

.pagination a {
    color: var(--accent);
    text-decoration: none;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 7px;
}

.pagination a:hover {
    background: #f5f6fa;
}

.pagination a.disabled {
    pointer-events: none;
    color: var(--text-muted);
    opacity: 0.5;
}

section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin: 1.25rem 0;
    box-shadow: 0 1px 2px rgba(20, 21, 43, 0.06);
}

.overview {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.5rem;
}

.overview p {
    margin: 0;
}

.kill-switch {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.25rem 0;
}

.log-box {
    background: #0f172a;
    color: #d6dceb;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    max-height: 500px;
    font-size: 0.82rem;
    font-family: "SF Mono", Consolas, monospace;
}

/* Login page */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #14152b, #2a2c52);
}

.login-card {
    background: var(--surface);
    padding: 2.5rem;
    border-radius: 14px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-card h1 {
    margin-bottom: 0.2rem;
    font-size: 1.3rem;
}

.login-subtitle {
    color: var(--text-muted);
    margin: 0 0 1.5rem 0;
    font-size: 0.88rem;
}

.login-card button {
    width: 100%;
}

/* Remote login (noVNC) */
.remote-frame {
    width: 100%;
    height: 70vh;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: black;
}

.remote-controls {
    display: flex;
    gap: 0.75rem;
    margin: 1rem 0;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: 0 1px 2px rgba(20, 21, 43, 0.06);
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
}

.kpi-label {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: 0.25rem;
}

.chart-box {
    position: relative;
    height: 280px;
    width: 100%;
}

.chart-box-small {
    max-width: 320px;
    height: 260px;
    margin: 0 auto;
}

/* ── Responsive mobile ─────────────────────────────── */

#nav-toggle { display: none; }

.nav-hamburger {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 200;
    background: #14152b;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.65rem;
    font-size: 1.3rem;
    cursor: pointer;
    line-height: 1;
}

@media (max-width: 768px) {
    .nav-hamburger { display: block; }

    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        width: 240px;
    }

    #nav-toggle:checked ~ .layout .sidebar {
        transform: translateX(0);
    }

    #nav-toggle:checked ~ .nav-hamburger {
        left: 250px;
        content: "✕";
    }

    main {
        padding: 1rem;
        padding-top: 3.5rem;
        max-width: 100%;
    }

    h1 { font-size: 1.2rem; }

    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    input, textarea, select { max-width: 100%; }

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

    .filters {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filters select { max-width: 100%; }

    .chart-box { height: 220px; }

    .chart-box-small { max-width: 100%; height: 220px; }

    .pagination { flex-wrap: wrap; gap: 0.5rem; }
}

@media (max-width: 420px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .kpi-value { font-size: 1.4rem; }
}
