/* Varvand Farm — minimal design system.
   No build step and no external requests (README §1): hand-written custom
   properties, system font stack, no webfonts, no CDN. Dark mode follows
   the OS. */

*, *::before, *::after { box-sizing: border-box; }

/* Component `display` rules outrank the UA stylesheet's [hidden] rule, so
   without this a hidden .chip still renders as an empty pill. */
[hidden] { display: none !important; }

:root {
    color-scheme: light dark;

    --bg:          #f6f6f5;
    --surface:     #ffffff;
    --surface-2:   #fafaf9;
    --border:      #e6e5e2;
    --text:        #18181b;
    --muted:       #71717a;
    --faint:       #a1a1aa;

    --accent:      #15803d;
    --accent-weak: #dcfce7;
    --danger:      #dc2626;
    --danger-weak: #fee2e2;
    --warn:        #b45309;
    --warn-weak:   #fef3c7;

    --r-sm: 6px;
    --r:    10px;
    --r-lg: 14px;

    --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 1px 3px rgb(0 0 0 / .05);

    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:          #0e0e10;
        --surface:     #17171a;
        --surface-2:   #1e1e22;
        --border:      #2a2a31;
        --text:        #f4f4f5;
        --muted:       #a1a1aa;
        --faint:       #71717a;

        --accent:      #4ade80;
        --accent-weak: #10301d;
        --danger:      #f87171;
        --danger-weak: #3a1618;
        --warn:        #fbbf24;
        --warn-weak:   #37280f;

        --shadow: none;
    }
}

body {
    margin: 0;
    padding: 0 1rem 4rem;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1080px; margin: 0 auto; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; }
p  { margin: 0; }
a  { color: inherit; }
.mono { font-family: var(--mono); font-size: .8125rem; }

/* ---- top bar ---------------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: .875rem 0;
    margin-bottom: 1.75rem;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand {
    font-weight: 650;
    letter-spacing: -0.02em;
    text-decoration: none;
    white-space: nowrap;
}
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.topbar nav a {
    padding: .3rem .6rem;
    border-radius: var(--r-sm);
    color: var(--muted);
    text-decoration: none;
    font-size: .875rem;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar nav a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.whoami { font-size: .8125rem; color: var(--muted); white-space: nowrap; }
.whoami b { color: var(--text); font-weight: 550; }

/* The bar's items are all nowrap, so on a phone their combined minimum
   width pushes the whole document wider than the viewport and clips every
   card to the right. Below this breakpoint the nav drops to its own row. */
@media (max-width: 680px) {
    .topbar { flex-wrap: wrap; gap: .5rem .75rem; padding: .75rem 0; }
    .brand { flex: 1; }
    .topbar nav { order: 3; flex: 0 0 100%; }
    .whoami { font-size: .75rem; }
}

/* ---- page header ------------------------------------------------------ */

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.page-head .sub { color: var(--muted); font-size: .875rem; margin-top: .125rem; }

.live {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}
.live::before {
    content: "";
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---- cards ------------------------------------------------------------ */

.grid {
    display: grid;
    gap: .875rem;
    grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
    /* Cards size to their own content — grid's default `stretch` would
       pad a 2-metric node card out to the height of the 9-metric gateway
       card sharing its row. */
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem 1.1rem;
    display: flex;
    flex-direction: column;
}
.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .875rem;
}
.card-title { font-size: .9375rem; }
.card-title a { text-decoration: none; }
.card-title a:hover { color: var(--accent); }
.card-sub { color: var(--faint); margin-top: .1rem; }

.card-foot {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    margin-top: auto;
    padding-top: .875rem;
    border-top: 1px solid var(--border);
    font-size: .75rem;
    color: var(--muted);
}

/* ---- metric list inside a card --------------------------------------- */

.metrics { margin: 0; display: flex; flex-direction: column; gap: .1rem; }
.metric {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .75rem;
    padding: .3rem 0;
}
.metric dt { color: var(--muted); font-size: .8125rem; }
.metric dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
    font-weight: 550;
    text-align: right;
    white-space: nowrap;
}
.metric dd .u { color: var(--faint); font-weight: 400; font-size: .8125rem; margin-left: .1rem; }

/* A failed sensor is never a number — README §7. */
.metric dd.unavailable, .unavailable { color: var(--danger); font-weight: 500; font-style: italic; }
.untrusted { color: var(--warn); }

/* Stale is deliberately quieter than unavailable: the value was real when
   it was taken, it just is not current. Muted rather than red, so a row
   the device has stopped sending stops competing with live ones — and
   stops being readable as a fresh measurement. */
.metric dd.stale { color: var(--faint); font-weight: 400; }
.metric dd.stale .u { color: var(--faint); }

/* ---- status ----------------------------------------------------------- */

.status {
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    font-size: .75rem;
    color: var(--muted);
    white-space: nowrap;
}
.status::before {
    content: "";
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--faint);
    flex: none;
}
.status.is-online { color: var(--accent); }
.status.is-online::before { background: var(--accent); }
.status.is-offline { color: var(--danger); }
.status.is-offline::before { background: var(--danger); }

/* Unknown is not Off. A relay whose position the gateway cannot read must
   not present as confirmed-shut, which is what sharing Off's unmarked
   badge did. Amber: something needs looking at, but nothing is running
   away — and it stays distinct from is-online's green at a glance. */
.status.is-unknown { color: var(--warn); }
.status.is-unknown::before { background: var(--warn); }

.chip {
    display: inline-block;
    padding: .1rem .45rem;
    border-radius: 999px;
    font-size: .6875rem;
    font-weight: 550;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    white-space: nowrap;
}
.chip.warn   { background: var(--warn-weak);   color: var(--warn);   border-color: transparent; }
a.chip { text-decoration: none; }
a.chip:hover { filter: brightness(.97); }
.chip.good   { background: var(--accent-weak); color: var(--accent); border-color: transparent; }
.chip.bad    { background: var(--danger-weak); color: var(--danger); border-color: transparent; }

.badge { font-size: .6875rem; font-weight: 550; padding: .1rem .45rem; border-radius: 999px; }
.badge:empty { display: none; }
.badge.pending   { background: var(--warn-weak);   color: var(--warn); }
.badge.confirmed { background: var(--accent-weak); color: var(--accent); }
.badge.rejected  { background: var(--danger-weak); color: var(--danger); }
.badge.unknown   { background: var(--surface-2);   color: var(--muted); }

/* ---- forms and buttons ------------------------------------------------ */

button, input, select {
    font: inherit;
    color: inherit;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    padding: .4rem .6rem;
}
input:focus-visible, button:focus-visible, select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
button {
    cursor: pointer;
    font-size: .875rem;
    font-weight: 550;
    background: var(--surface-2);
    transition: background .12s ease, border-color .12s ease;
}
button:hover { border-color: var(--faint); }
button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
@media (prefers-color-scheme: dark) { button.primary { color: #06140c; } }
button.primary:hover { filter: brightness(1.06); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .8125rem; color: var(--muted); }
.controls { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.controls input[type="number"] { width: 5.5rem; font-variant-numeric: tabular-nums; }

/* ---- relay config panel ----------------------------------------------- */

.chiprow {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: .875rem;
    min-height: 1.5rem;
}
.hint { font-size: .75rem; color: var(--faint); margin-top: .5rem; }
.faint { color: var(--faint); font-weight: 400; }

details.config {
    margin-top: auto;
    padding-top: .875rem;
    border-top: 1px solid var(--border);
}
details.config > summary {
    cursor: pointer;
    font-size: .8125rem;
    color: var(--muted);
    list-style: none;
    display: flex;
    align-items: center;
    gap: .35rem;
}
details.config > summary::-webkit-details-marker { display: none; }
details.config > summary::before {
    content: "›";
    display: inline-block;
    transition: transform .15s ease;
}
details.config[open] > summary::before { transform: rotate(90deg); }
details.config > summary:hover { color: var(--text); }
details.config form {
    display: flex;
    flex-direction: column;
    gap: .6rem;
    margin-top: .875rem;
}
.checkline {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .8125rem;
}
.checkline input { width: auto; }

/* ---- tables ----------------------------------------------------------- */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    overflow-x: auto;
}
table { border-collapse: collapse; width: 100%; font-size: .875rem; }
th, td { text-align: left; padding: .6rem .9rem; white-space: nowrap; }
th {
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}
tbody tr + tr td { border-top: 1px solid var(--border); }
tbody tr:hover td { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; }

/* ---- empty state ------------------------------------------------------ */

.empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--r-lg);
}
.empty h2 { font-size: .9375rem; margin-bottom: .25rem; }
.empty p { font-size: .875rem; }

/* ---- login ------------------------------------------------------------ */

.login-shell {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1rem;
}
.login-card {
    width: 100%;
    max-width: 21rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    padding: 1.75rem;
}
.login-card h1 { font-size: 1.25rem; margin-bottom: .25rem; }
.login-card .sub { color: var(--muted); font-size: .875rem; margin-bottom: 1.5rem; }
.login-card form { display: flex; flex-direction: column; gap: .875rem; }
.login-card input { padding: .5rem .65rem; }

.alert {
    background: var(--danger-weak);
    color: var(--danger);
    border-radius: var(--r-sm);
    padding: .5rem .65rem;
    font-size: .8125rem;
}

/* ---- refresh nudge ----------------------------------------------------- */

.nudge {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    align-items: center;
    gap: .75rem;
    max-width: calc(100vw - 2rem);
    padding: .6rem .75rem .6rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 4px 16px rgb(0 0 0 / .12);
    font-size: .8125rem;
}
.nudge button { border-radius: 999px; padding: .3rem .8rem; }

/* ---- misc ------------------------------------------------------------- */

.section { margin-top: 2rem; }
.section > h2 { margin-bottom: .75rem; }
.back { color: var(--muted); text-decoration: none; font-size: .875rem; }
.back:hover { color: var(--text); }
dl.facts { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1.25rem; margin: 0; font-size: .875rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* ---- alerts ------------------------------------------------------------ */

.alerts { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1.25rem; }
.alert-row {
    display: block;
    padding: .5rem .75rem;
    border-radius: var(--r);
    font-size: .8125rem;
    text-decoration: none;
    border: 1px solid transparent;
}
.alert-row.bad  { background: var(--danger-weak); color: var(--danger); }
.alert-row.warn { background: var(--warn-weak);   color: var(--warn); }
.alert-row:hover { filter: brightness(.98); }

/* ---- charts ------------------------------------------------------------ */

.chart-body { min-height: 190px; }
.chart-meta { font-size: .75rem; color: var(--faint); }
[data-range].active { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { [data-range].active { color: #06140c; } }
.uplot, .u-wrap { width: 100% !important; }
