:root {
    --ink: #e8eef7;
    --muted: #93a4bd;
    --line: #2a3648;
    --panel: rgba(26, 35, 50, 0.92);
    --panel-solid: #1a2332;
    --bg-1: #0b1017;
    --bg-2: #121a24;
    --accent: #4da3ff;
    --accent-soft: rgba(77, 163, 255, 0.14);
    --ok: #2ecc71;
    --ok-bg: rgba(46, 204, 113, 0.15);
    --warning: #f39c12;
    --warning-bg: rgba(243, 156, 18, 0.15);
    --critical: #e74c3c;
    --critical-bg: rgba(231, 76, 60, 0.18);
    --offline: #7f8c8d;
    --offline-bg: rgba(127, 140, 141, 0.18);
    --invalid: #9b59b6;
    --invalid-bg: rgba(155, 89, 182, 0.18);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
    --radius: 14px;
    --font: "Instrument Sans", system-ui, sans-serif;
    --serif: "Source Serif 4", Georgia, serif;
    --mono: "IBM Plex Mono", ui-monospace, monospace;
    --surface: #101722;
    --surface-hover: rgba(255, 255, 255, 0.03);
    --input-bg: #101722;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(77, 163, 255, 0.12), transparent 36%),
        radial-gradient(circle at top right, rgba(46, 204, 113, 0.08), transparent 32%),
        linear-gradient(180deg, var(--bg-1), var(--bg-2));
    background-attachment: fixed;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.28;
    background-image:
        linear-gradient(rgba(232, 238, 247, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(232, 238, 247, 0.035) 1px, transparent 1px);
    background-size: 28px 28px;
    mask-image: linear-gradient(180deg, black, transparent 85%);
}

.page-shell {
    width: min(1180px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.75rem 0 3rem;
    position: relative;
    z-index: 1;
    animation: rise-in 420ms ease both;
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.35); opacity: 0.55; }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.brand-mark {
    margin: 0 0 0.35rem;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.brand h1,
.login-card h1,
.dialog-header h2 {
    margin: 0;
    font-family: var(--serif);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.brand h1 {
    font-size: clamp(2rem, 3vw, 2.6rem);
}

.subtitle,
.muted,
.panel-note {
    color: var(--muted);
}

.subtitle {
    margin: 0.45rem 0 0;
    max-width: 36rem;
    line-height: 1.45;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.live-pill,
.button-secondary,
.login-form button,
.icon-button,
.search-field input {
    transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    color: var(--muted);
    font-size: 0.86rem;
}

.live-pill.is-live {
    color: var(--ok);
    border-color: rgba(46, 204, 113, 0.35);
    background: var(--ok-bg);
}

.live-pill.is-error {
    color: var(--critical);
    border-color: rgba(231, 76, 60, 0.4);
    background: var(--critical-bg);
}

.live-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: currentColor;
}

.live-pill.is-live .live-dot {
    animation: pulse-dot 1.8s ease infinite;
}

.button-secondary {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel-solid);
    color: var(--ink);
    padding: 0.55rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.button-secondary:hover {
    border-color: #3d4d63;
    transform: translateY(-1px);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.85rem;
    margin-bottom: 1rem;
}

.summary-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.05rem;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--line);
}

.summary-card.ok::before { background: var(--ok); }
.summary-card.warning::before { background: var(--warning); }
.summary-card.critical::before { background: var(--critical); }
.summary-card.offline::before { background: var(--offline); }

.summary-label {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 0.45rem;
}

.summary-card strong {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.summary-card.ok strong { color: var(--ok); }
.summary-card.warning strong { color: var(--warning); }
.summary-card.critical strong { color: var(--critical); }
.summary-card.offline strong { color: var(--offline); }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 4px);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid var(--line);
}

.panel-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.panel-note {
    margin: 0.25rem 0 0;
    font-size: 0.86rem;
}

.search-field input {
    width: min(280px, 100%);
    padding: 0.7rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--input-bg);
    color: var(--ink);
    font: inherit;
}

.search-field input:focus {
    outline: none;
    border-color: rgba(77, 163, 255, 0.55);
    box-shadow: 0 0 0 3px rgba(77, 163, 255, 0.15);
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.95rem 1.15rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: rgba(16, 23, 34, 0.7);
}

tbody tr {
    animation: rise-in 320ms ease both;
}

tbody tr:hover td {
    background: var(--surface-hover);
}

.sensor-name {
    font-weight: 650;
}

.mono,
code {
    font-family: var(--mono);
    font-size: 0.82rem;
}

td code {
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0.4rem;
    padding: 0.2rem 0.4rem;
}

.metric {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.battery-cell {
    min-width: 8.5rem;
}

.battery-track {
    height: 0.4rem;
    margin-top: 0.4rem;
    border-radius: 999px;
    background: #1d2736;
    overflow: hidden;
}

.battery-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--ok);
}

.battery-fill.is-warning { background: var(--warning); }
.battery-fill.is-critical { background: var(--critical); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.28rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }
.badge.critical { background: var(--critical-bg); color: var(--critical); }
.badge.offline { background: var(--offline-bg); color: var(--offline); }
.badge.invalid { background: var(--invalid-bg); color: var(--invalid); }

.text-button {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--accent);
    cursor: pointer;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 650;
}

.text-button:hover {
    background: var(--accent-soft);
    border-color: rgba(77, 163, 255, 0.4);
}

.empty-state {
    color: var(--muted);
    text-align: center;
    padding: 2.5rem 1rem !important;
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.login-card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 6px);
    box-shadow: var(--shadow);
    padding: 2rem;
    animation: rise-in 420ms ease both;
}

.login-card h1 {
    font-size: 2rem;
}

.login-form {
    display: grid;
    gap: 1rem;
    margin-top: 1.5rem;
}

.login-form label {
    display: grid;
    gap: 0.4rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.login-form input,
.login-form button {
    padding: 0.8rem 0.95rem;
    border-radius: 0.75rem;
    border: 1px solid var(--line);
    font: inherit;
}

.login-form input {
    background: var(--input-bg);
    color: var(--ink);
}

.login-form input:focus {
    outline: none;
    border-color: rgba(77, 163, 255, 0.55);
    box-shadow: 0 0 0 3px rgba(77, 163, 255, 0.15);
}

.login-form button {
    background: var(--accent);
    color: #041018;
    border: 0;
    font-weight: 700;
    cursor: pointer;
}

.login-form button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(77, 163, 255, 0.25);
}

.alert {
    padding: 0.75rem 0.9rem;
    border-radius: 0.75rem;
    margin-top: 1rem;
}

.alert-error {
    background: var(--critical-bg);
    color: #ffb3aa;
    border: 1px solid rgba(231, 76, 60, 0.35);
}

#detail-dialog {
    width: min(980px, calc(100vw - 2rem));
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 6px);
    background: #121a24;
    color: var(--ink);
    padding: 0;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

#detail-dialog::backdrop {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
}

.dialog-form {
    padding: 1.35rem;
}

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

.dialog-kicker {
    margin: 0 0 0.35rem;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.icon-button {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font-size: 1.25rem;
    cursor: pointer;
}

.icon-button:hover {
    background: #182232;
}

.detail-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.detail-meta div {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0.9rem;
    padding: 0.9rem;
}

.detail-meta span {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 0.3rem;
}

.chart-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.9rem;
}

@media (min-width: 800px) {
    .chart-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0.9rem;
    padding: 0.95rem;
}

.chart-card h3 {
    margin: 0 0 0.75rem;
    font-size: 0.92rem;
    font-weight: 700;
}

.chart-card canvas {
    width: 100% !important;
    height: 220px !important;
}

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

    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

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

@media (max-width: 640px) {
    .panel-header {
        flex-direction: column;
        align-items: stretch;
    }

    .search-field input {
        width: 100%;
    }

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