/*
 * WG Panel. No build step: plain CSS, light/dark from the system setting.
 * Servers are drawn as rack units: a status rail on the left edge and a row of
 * port LEDs, one per client, lit when that client has a fresh handshake.
 */

:root {
    --bg: #eef1f4;
    --surface: #ffffff;
    --surface-sunk: #f6f8fa;
    --ink: #1b2733;
    --muted: #5b6b7a;
    --line: #d5dce3;
    --accent: #0e7c86;
    --accent-ink: #ffffff;
    --up: #1e9e5a;
    --warn: #c77700;
    --down: #c2362b;
    --idle: #9aa5b1;
    --port-off: #e2e7ec;
    --focus: #0e7c86;

    --font-label: Bahnschrift, "DIN Alternate", "DIN Next", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;

    --radius: 6px;
    --rail: 6px;
    --gap: 1rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #10161d;
        --surface: #18212b;
        --surface-sunk: #131b23;
        --ink: #e3e9ef;
        --muted: #8a99a8;
        --line: #2a3643;
        --accent: #3fb8c2;
        --accent-ink: #0c1a1d;
        --up: #3ccf7f;
        --warn: #f0a531;
        --down: #f0675b;
        --idle: #5d6b79;
        --port-off: #24303c;
        --focus: #3fb8c2;
    }
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 var(--font-body);
}

[x-cloak] {
    display: none !important;
}

a {
    color: var(--accent);
}

h1,
h2 {
    font-family: var(--font-label);
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.15;
    margin: 0;
}

h1 {
    font-size: 1.75rem;
}

h2 {
    font-size: 1.25rem;
}

code,
.mono {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 0.8rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* Top bar */

.topbar {
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: 0.6rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink);
    font-family: var(--font-label);
    font-size: 1.1rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.brand-mark {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
}

.brand-mark .led {
    fill: var(--up);
    stroke: none;
}

.signout {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.who {
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Search */

.search {
    position: relative;
    flex: 0 1 26rem;
}

.search input {
    width: 100%;
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
    max-height: 22rem;
    overflow-y: auto;
}

.search-result {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    color: var(--ink);
    text-decoration: none;
}

.search-result:hover,
.search-result:focus-visible {
    background: var(--surface-sunk);
}

.search-empty {
    margin: 0;
    padding: 0.75rem;
}

/* Page */

.page {
    max-width: 72rem;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 4rem;
}

.page-narrow {
    max-width: 24rem;
    padding-top: 12vh;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    margin: 1.75rem 0 1rem;
}

.page-head:first-child {
    margin-top: 0;
}

.empty {
    padding: 2.5rem 1.5rem;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
}

.empty p {
    margin: 0 auto 1rem;
    max-width: 36rem;
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.95rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: 500 0.9rem/1.2 var(--font-body);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover {
    border-color: var(--muted);
}

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

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.btn-primary:hover {
    border-color: var(--accent);
    filter: brightness(1.08);
}

.btn-quiet {
    background: transparent;
    border-color: transparent;
}

.btn-quiet:hover {
    border-color: var(--line);
}

.btn-danger {
    color: var(--down);
}

.btn-danger:hover {
    border-color: var(--down);
}

.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* Forms */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-sunk);
    color: var(--ink);
    font: inherit;
}

input:disabled {
    color: var(--muted);
}

textarea {
    resize: vertical;
    line-height: 1.45;
}

input.mono,
textarea.mono {
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

.form {
    display: grid;
    gap: 1.25rem;
}

.stack {
    display: grid;
    gap: 1rem;
}

.panel {
    margin: 0;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: grid;
    gap: 1rem;
    min-width: 0;
}

.panel legend {
    padding: 0 0.4rem;
    font-family: var(--font-label);
    font-size: 1.05rem;
    font-weight: 600;
}

.grid-2,
.grid-3 {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

.field {
    display: grid;
    gap: 0.3rem;
    align-content: start;
}

.field > span:first-child {
    font-size: 0.85rem;
    font-weight: 600;
}

.hint {
    color: var(--muted);
    font-size: 0.8rem;
}

.field-error {
    display: block;
    color: var(--down);
    font-size: 0.85rem;
}

.check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.check input {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.segmented {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    justify-self: start;
}

.segment input {
    position: absolute;
    opacity: 0;
}

.segment span {
    display: block;
    padding: 0.45rem 0.95rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.segment + .segment span {
    border-left: 1px solid var(--line);
}

.segment input:checked + span {
    background: var(--accent);
    color: var(--accent-ink);
}

.segment input:focus-visible + span {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
}

.install,
.test-connection {
    display: grid;
    gap: 0.6rem;
}

.install p {
    margin: 0;
}

.copy {
    display: flex;
    gap: 0.4rem;
}

.copy input {
    flex: 1;
    min-width: 0;
}

.fingerprint {
    padding: 0.85rem 1rem;
    border-left: var(--rail) solid var(--warn);
    background: var(--surface-sunk);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.fingerprint p {
    margin: 0 0 0.4rem;
}

.fingerprint-value {
    font-size: 1rem;
    word-break: break-all;
}

.facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
    margin: 0;
}

.facts dt {
    color: var(--muted);
}

.facts dd {
    margin: 0;
}

.facts-inline {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, max-content 1fr);
}

/* Banners */

.banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 0 0 1rem;
    padding: 0.7rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: var(--rail) solid var(--accent);
    border-radius: var(--radius);
}

.banner > span {
    flex: 1;
}

.banner > .stack {
    flex: 1 1 18rem;
    min-width: 0;
}

.banner-ok {
    border-left-color: var(--up);
}

.banner-warn {
    border-left-color: var(--warn);
}

.banner-error {
    border-left-color: var(--down);
}

.banner-close {
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}

/* Rack units: the overview rows and the server page header */

.rack {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.5rem;
}

.unit {
    --state: var(--idle);
    display: grid;
    grid-template-columns: minmax(10rem, 1.2fr) minmax(8rem, 0.8fr) minmax(8rem, 1.5fr) auto;
    align-items: center;
    gap: 0.5rem 1.25rem;
    padding: 0.9rem 1.1rem 0.9rem calc(1.1rem + var(--rail));
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
}

.unit::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--rail);
    background: var(--state);
}

.unit-up {
    --state: var(--up);
}

.unit-warn {
    --state: var(--warn);
}

.unit-down {
    --state: var(--down);
}

.unit-unknown {
    --state: var(--line);
}

.unit-name {
    display: grid;
    color: var(--ink);
    text-decoration: none;
    min-width: 0;
}

.unit-name strong {
    font-family: var(--font-label);
    font-size: 1.2rem;
    font-weight: 600;
}

a.unit-name:hover strong {
    color: var(--accent);
}

.unit-state {
    display: grid;
    font-size: 0.9rem;
}

.state {
    font-family: var(--font-label);
    font-weight: 600;
}

.state-up {
    color: var(--up);
}

.state-down {
    color: var(--down);
}

.state-idle {
    color: var(--muted);
}

.unit-numbers {
    display: grid;
    justify-items: end;
    font-size: 0.85rem;
    white-space: nowrap;
}

.unit-note {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
    padding-top: 0.5rem;
    border-top: 1px solid var(--line);
    font-size: 0.875rem;
}

.unit-note > span {
    flex: 1;
}

.unit-note-down {
    color: var(--down);
}

.unit-note-warn strong {
    color: var(--warn);
}

.unit-head {
    grid-template-columns: 1fr auto auto;
    margin-bottom: 1rem;
}

.unit-head h1 {
    font-size: 1.9rem;
}

.head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-end;
}

.head-key {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: max-content 1fr;
    align-items: center;
    gap: 1rem;
}

/* Port LEDs */

.ports {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-content: center;
}

.port {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: var(--idle);
    opacity: 0.45;
}

.port-on {
    background: var(--up);
    opacity: 1;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--up) 25%, transparent);
}

.port-off {
    background: var(--port-off);
    opacity: 1;
}

/* Clients table */

.clients {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.clients th {
    padding: 0.55rem 0.75rem;
    text-align: left;
    font-family: var(--font-label);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
}

.clients td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.clients tr:last-child td {
    border-bottom: 0;
}

.clients tr:target td {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.clients .num {
    text-align: right;
    white-space: nowrap;
}

.clients td.num .small {
    display: block;
}

.clients td:nth-child(2) .muted {
    display: block;
}

.row-off td:not(:last-child) {
    color: var(--muted);
}

.row-actions {
    display: flex;
    gap: 0.3rem;
    justify-content: flex-end;
}

.tag {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0 0.4rem;
    border: 1px solid var(--accent);
    border-radius: 3px;
    color: var(--accent);
    font-size: 0.72rem;
    vertical-align: 1px;
}

/* Toggle switch */

.switch {
    position: relative;
    display: inline-block;
    width: 2.3rem;
    height: 1.3rem;
}

.switch input {
    position: absolute;
    inset: 0;
    opacity: 0;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}

.switch span {
    position: absolute;
    inset: 0;
    border-radius: 1rem;
    background: var(--port-off);
    border: 1px solid var(--line);
    transition: background 0.15s;
}

.switch span::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(1.3rem - 6px);
    height: calc(1.3rem - 6px);
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    transition: transform 0.15s;
}

.switch input:checked + span {
    background: var(--up);
    border-color: var(--up);
}

.switch input:checked + span::after {
    transform: translateX(1rem);
}

.switch input:focus-visible + span {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* Modal */

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgb(10 16 22 / 0.55);
}

.modal-body {
    width: min(32rem, 100%);
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    display: grid;
    gap: 1rem;
    padding: 1.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);
}

.modal-qr {
    justify-items: center;
    text-align: center;
}

.modal-qr img {
    width: min(360px, 100%);
    height: auto;
    background: #ffffff;
    padding: 12px;
    border-radius: var(--radius);
}

.modal-qr p {
    margin: 0;
}

/* Danger zone */

.danger-zone {
    margin-top: 3rem;
    padding: 1.25rem;
    border: 1px solid color-mix(in srgb, var(--down) 45%, var(--line));
    border-radius: var(--radius);
}

.danger-zone p {
    margin: 0.4rem 0 1rem;
}

/* Login */

.login {
    display: grid;
    gap: 0.5rem;
}

.login-title {
    font-size: 2rem;
}

.login p {
    margin: 0 0 1rem;
}

/* Small screens */

@media (max-width: 760px) {
    .topbar {
        flex-wrap: wrap;
        padding: 0.6rem 0.9rem;
    }

    .search {
        order: 3;
        flex-basis: 100%;
    }

    .page {
        padding: 1rem 0.9rem 3rem;
    }

    .unit,
    .unit-head {
        grid-template-columns: 1fr auto;
    }

    .ports {
        grid-column: 1 / -1;
    }

    .unit-numbers {
        grid-column: 1 / -1;
        justify-items: start;
        grid-auto-flow: column;
        gap: 1rem;
    }

    .head-actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .facts-inline {
        grid-template-columns: max-content 1fr;
    }

    .head-key {
        grid-template-columns: 1fr;
        gap: 0.3rem;
    }

    .clients thead {
        display: none;
    }

    .clients,
    .clients tbody,
    .clients tr,
    .clients td {
        display: block;
    }

    .clients tr {
        display: grid;
        grid-template-columns: auto 1fr auto;
        gap: 0.2rem 0.75rem;
        padding: 0.75rem;
        border-bottom: 1px solid var(--line);
    }

    .clients td {
        padding: 0;
        border: 0;
    }

    .clients td:first-child {
        grid-row: 1;
        grid-column: 1;
        padding-top: 0.35rem;
    }

    .clients td[data-label="Name"] {
        grid-row: 1;
        grid-column: 2;
        min-width: 0;
    }

    .clients td[data-label="Enabled"] {
        grid-row: 1;
        grid-column: 3;
    }

    .clients td[data-label="Address"],
    .clients td[data-label="Last handshake"],
    .clients td.num {
        grid-column: 2 / -1;
        text-align: left;
    }

    .clients td.num::before,
    .clients td[data-label="Last handshake"]::before {
        content: attr(data-label) " ";
        color: var(--muted);
        font-family: var(--font-body);
    }

    .clients td.num .small {
        display: inline;
        margin-left: 0.5rem;
    }

    .clients td.actions-cell {
        grid-column: 1 / -1;
    }

    .row-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
        padding-top: 0.4rem;
    }

    .clients.plain tr {
        display: block;
    }

    .clients.plain td,
    .clients.plain td:first-child {
        display: flex;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.15rem 0;
        text-align: right;
    }

    .clients.plain td[data-label]::before {
        content: attr(data-label);
        flex: none;
        color: var(--muted);
        font-weight: 400;
        text-align: left;
    }

    .clients.plain td:first-child {
        font-weight: 600;
    }

    .clients.plain td:nth-child(2) .muted {
        display: inline;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
    }
}

.test-connection > .btn {
    justify-self: start;
}

.admin-nav {
    display: flex;
    gap: 0.25rem;
}

.share {
    display: grid;
    gap: 1rem;
    justify-items: center;
    text-align: center;
    max-width: 30rem;
    margin: 0 auto;
}

.share-qr svg {
    width: min(320px, 80vw);
    height: auto;
    background: #ffffff;
    padding: 12px;
    border-radius: var(--radius);
}

.share-steps {
    text-align: left;
    margin: 0;
    padding-left: 1.25rem;
}

.share-link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.new-key {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.new-key .field {
    flex: 1;
}
