:root {
    --bg: #f4f2ec;
    --panel: #ffffff;
    --panel-soft: #faf9f5;
    --ink: #202124;
    --muted: #6b6f76;
    --line: #dedbd2;
    --line-strong: #c9c4b8;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --green: #2f855a;
    --green-soft: #e7f5ec;
    --orange: #c2410c;
    --orange-soft: #fff1e8;
    --red: #b42318;
    --red-soft: #fdebea;
    --shadow: 0 12px 32px rgba(32, 33, 36, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 260px),
        var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    margin: 0;
    overflow-x: hidden;
}

a {
    color: inherit;
}

.topbar {
    align-items: center;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 22px;
    min-height: 66px;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    align-items: center;
    display: inline-flex;
    font-weight: 750;
    gap: 10px;
    margin-right: auto;
    text-decoration: none;
}

.brand-mark {
    align-items: center;
    background: var(--ink);
    border-radius: 8px;
    color: #ffffff;
    display: inline-flex;
    font-size: 14px;
    font-weight: 800;
    height: 32px;
    justify-content: center;
    width: 32px;
}

.nav-links {
    align-items: center;
    display: flex;
    gap: 6px;
}

.nav-links a {
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    padding: 9px 11px;
    text-decoration: none;
}

.nav-links a:hover {
    background: var(--panel-soft);
    color: var(--ink);
}

.logout-form {
    margin: 0;
}

button,
select,
input,
.button {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    font: inherit;
    min-height: 40px;
    padding: 9px 11px;
}

input,
select {
    background: #ffffff;
    color: var(--ink);
}

button,
.button {
    align-items: center;
    background: var(--blue);
    border-color: var(--blue);
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    font-weight: 700;
    justify-content: center;
    text-decoration: none;
}

button:hover,
.button:hover {
    background: var(--blue-dark);
    border-color: var(--blue-dark);
}

.button-secondary {
    background: #ffffff;
    border-color: var(--line);
    color: var(--ink);
}

.button-secondary:hover {
    background: var(--panel-soft);
    border-color: var(--line-strong);
}

.button-wide {
    width: 100%;
}

.page {
    margin: 0 auto;
    max-width: 1200px;
    padding: 34px 28px 48px;
}

.page-heading {
    align-items: end;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    margin-bottom: 22px;
}

.page-heading h1 {
    font-size: 34px;
    letter-spacing: 0;
    line-height: 1.08;
    margin: 0 0 7px;
}

.page-heading p {
    color: var(--muted);
    margin: 0;
}

.eyebrow {
    color: var(--orange) !important;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    margin: 0 0 8px !important;
    text-transform: uppercase;
}

.metric-strip {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    margin-bottom: 22px;
}

.metric,
.sensor-card,
.chart-shell,
.stats-table,
.empty,
.sensor-row,
.collector-card,
.login-panel,
.toolbar {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metric {
    min-height: 92px;
    padding: 16px;
}

.metric span,
.label {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 650;
    margin-bottom: 7px;
}

.metric strong {
    display: block;
    font-size: 26px;
    letter-spacing: 0;
    line-height: 1.1;
}

.collector-strip {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    margin: 0 0 22px;
}

.collector-card {
    padding: 14px 16px;
}

.collector-card span,
.collector-card small {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 650;
}

.collector-card strong {
    display: block;
    font-size: 17px;
    margin: 4px 0;
    overflow-wrap: anywhere;
}

.sensor-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(258px, 1fr));
}

.sensor-card {
    box-shadow: var(--shadow);
    padding: 18px;
}

.sensor-card__top {
    align-items: flex-start;
    display: flex;
    gap: 14px;
    justify-content: space-between;
}

.sensor-card h2 {
    font-size: 28px;
    letter-spacing: 0;
    margin: 0;
}

.sensor-card p,
.sensor-card small {
    color: var(--muted);
    font-size: 14px;
    margin: 4px 0 0;
}

.status-pill {
    border-radius: 999px;
    font-size: 12px;
    font-weight: 750;
    padding: 5px 9px;
    white-space: nowrap;
}

.status-ok {
    background: var(--green-soft);
    color: var(--green);
}

.status-muted {
    background: #eeeeea;
    color: var(--muted);
}

.status-warning {
    background: var(--orange-soft);
    color: var(--orange);
}

.reading-main {
    align-items: baseline;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 8px;
    margin: 24px 0 14px;
    padding-bottom: 16px;
}

.reading-main span {
    font-size: 46px;
    font-weight: 800;
    letter-spacing: 0;
}

.reading-meta {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0;
}

.reading-meta div {
    min-width: 0;
}

.reading-meta dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    margin-bottom: 3px;
}

.reading-meta dd {
    font-size: 14px;
    font-weight: 650;
    margin: 0;
    overflow-wrap: anywhere;
}

.signal-meta {
    text-align: center;
}

.signal-meta dd {
    align-items: center;
    display: flex;
    justify-content: center;
    min-height: 18px;
}

.signal-bars {
    align-items: end;
    display: inline-flex;
    gap: 3px;
    height: 18px;
}

.signal-bars span {
    background: #d8d5cc;
    border-radius: 2px;
    display: block;
    width: 5px;
}

.signal-bars span:nth-child(1) {
    height: 7px;
}

.signal-bars span:nth-child(2) {
    height: 12px;
}

.signal-bars span:nth-child(3) {
    height: 17px;
}

.signal-bars span.is-on {
    background: var(--green);
}

.signal-bars-low span.is-on {
    background: var(--orange);
}

.signal-bars-ok span.is-on {
    background: var(--green);
}

.value-low,
.delta-down {
    color: var(--blue);
}

.value-high,
.delta-up {
    color: var(--orange);
}

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

.toolbar {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: minmax(120px, 0.7fr) minmax(150px, 0.9fr) minmax(220px, 1.4fr) auto;
    margin-bottom: 18px;
    padding: 14px;
}

.readings-toolbar {
    grid-template-columns: minmax(220px, 1fr) minmax(120px, 0.4fr) auto;
}

.filters label,
.sensor-row label,
.login-form label {
    color: var(--muted);
    display: grid;
    font-size: 13px;
    font-weight: 650;
    gap: 5px;
}

.filters label.is-muted {
    opacity: 0.55;
}

.filters-submit {
    min-width: 84px;
}

@media (scripting: enabled) {
    .filters-submit {
        display: none;
    }
}

.chart-panel {
    display: grid;
    gap: 18px;
    margin-bottom: 18px;
}

.chart-shell {
    height: 340px;
    padding: 18px;
    position: relative;
}

.chart-shell canvas {
    height: 100% !important;
    width: 100% !important;
}

.chart-tooltip {
    background: rgba(32, 33, 36, 0.96);
    border: 1px solid #3c4043;
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(32, 33, 36, 0.18);
    color: #ffffff;
    font-size: 13px;
    min-width: 160px;
    opacity: 0;
    padding: 10px 12px;
    pointer-events: none;
    position: absolute;
    transform: translate(-50%, calc(-100% - 12px));
    transition: opacity 120ms ease;
    z-index: 3;
}

.chart-tooltip__title {
    color: #d9e2ff;
    font-weight: 750;
    margin-bottom: 7px;
}

.chart-tooltip__body {
    display: grid;
    gap: 4px;
    font-weight: 600;
}

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

.section-title {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    padding: 16px 18px;
}

.section-title h2 {
    font-size: 18px;
    margin: 0;
}

.section-title span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
}

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

th,
td {
    border-bottom: 1px solid #efede7;
    padding: 13px 18px;
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
}

tbody tr:hover {
    background: var(--panel-soft);
}

.empty {
    color: var(--muted);
    display: grid;
    gap: 5px;
    padding: 24px;
}

.empty strong {
    color: var(--ink);
}

.sensor-editor {
    display: grid;
    gap: 12px;
}

.sensor-row {
    align-items: end;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(230px, 1.4fr) minmax(150px, 1fr) minmax(150px, 1fr) minmax(88px, 0.45fr) auto auto;
    padding: 14px;
}

.sensor-identity strong {
    display: block;
    margin-bottom: 4px;
}

.sensor-row small {
    color: var(--muted);
    display: block;
    overflow-wrap: anywhere;
}

.raw-table small {
    color: var(--muted);
    display: block;
    font-size: 12px;
    margin-top: 3px;
    overflow-wrap: anywhere;
}

.checkbox {
    align-items: center;
    display: flex !important;
    gap: 8px !important;
    grid-auto-flow: column;
}

.checkbox input {
    min-height: 0;
}

.login-page {
    min-height: 100vh;
}

.login-shell {
    align-items: center;
    display: grid;
    min-height: 100vh;
    padding: 24px;
}

.login-panel {
    box-shadow: var(--shadow);
    margin: 0 auto;
    max-width: 430px;
    padding: 28px;
    width: 100%;
}

.login-brand {
    align-items: center;
    display: flex;
    gap: 14px;
    margin-bottom: 20px;
}

.login-brand h1 {
    font-size: 26px;
    letter-spacing: 0;
    margin: 0;
}

.login-copy {
    color: var(--muted);
    margin: 0 0 22px;
}

.login-form {
    display: grid;
    gap: 14px;
}

.alert {
    border-radius: 8px;
    font-size: 14px;
    font-weight: 650;
    margin-bottom: 14px;
    padding: 10px 12px;
}

.alert-error {
    background: var(--red-soft);
    color: var(--red);
}

.alert-info {
    background: var(--orange-soft);
    color: var(--orange);
}

@media (max-width: 860px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }

    .brand {
        margin-right: 0;
    }

    .nav-links {
        flex-wrap: wrap;
    }

    .logout-form {
        width: 100%;
    }

    .logout-form .button {
        width: 100%;
    }

    .page {
        padding: 22px 16px 36px;
    }

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

    .metric-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .toolbar,
    .sensor-row {
        grid-template-columns: 1fr;
    }

    .chart-shell {
        height: 300px;
    }
}

@media (max-width: 520px) {
    .metric-strip,
    .sensor-grid {
        grid-template-columns: 1fr;
    }

    .reading-main span {
        font-size: 40px;
    }

    .login-panel {
        padding: 22px;
    }
}
