:root,
[data-bs-theme="dark"] {
    color-scheme: dark;

    --background: #000000;
    --panel: #141414;
    --panel-hover: #242424;
    --foreground: #ffffff;
    --muted: #b5b5b5;
    --border: #383838;

    --green: #39d98a;
    --red: #ff6666;
    --yellow: #ffcf57;
    --blue: #65aaff;

    --bs-body-bg: var(--background);
    --bs-body-color: var(--foreground);
    --bs-border-color: var(--border);
}

[data-bs-theme="light"] {
    color-scheme: light;

    --background: #ffffff;
    --panel: #f4f4f4;
    --panel-hover: #e7e7e7;
    --foreground: #000000;
    --muted: #555555;
    --border: #c9c9c9;

    --green: #087b38;
    --red: #c21d30;
    --yellow: #956500;
    --blue: #075fbd;
}

[data-contrast="true"] {
    --background: #000000;
    --panel: #000000;
    --panel-hover: #222222;
    --foreground: #ffffff;
    --muted: #ffffff;
    --border: #ffffff;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--background);
    color: var(--foreground);
}

body,
button,
select {
    font-family: system-ui, -apple-system, sans-serif;
}

#dashboard {
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 20px;
    overflow: hidden;
}

.masthead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: 15px;
}

.eyebrow {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .16em;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    margin-top: 3px;
    font-size: clamp(20px, 2vw, 32px);
    font-weight: 800;
    letter-spacing: -.035em;
}

h1 span {
    font-weight: 300;
}

.appearance {
    width: 145px;
    flex-shrink: 0;
}

.appearance label {
    font-size: 11px;
    color: var(--muted);
}

.appearance select {
    color: var(--foreground);
    background-color: var(--panel);
    border-color: var(--border);
}

.overview {
    border: 1px solid var(--border);
    background: var(--panel);
    padding: 12px 16px;
    border-radius: 7px;
    flex-shrink: 0;
}

.overview-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.overview-heading h2 {
    font-size: clamp(16px, 1.5vw, 23px);
    font-weight: 700;
}

#subline {
    color: var(--muted);
    font-size: 12px;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.metric {
    border-top: 1px solid var(--border);
    padding-top: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.metric strong {
    font-size: clamp(20px, 2vw, 30px);
    line-height: 1.1;
}

.metric small {
    color: var(--muted);
    font-size: 12px;
}

.online {
    color: var(--green);
}

.offline {
    color: var(--red);
}

.impacted {
    color: var(--yellow);
}

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

.updates {
    color: var(--blue);
}

.inventory-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.inventory-heading h2 {
    font-size: 18px;
    font-weight: 700;
}

#last {
    color: var(--muted);
    font-size: 11px;
    text-align: right;
}

#inventory {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.device-grid {
    --columns: 4;

    height: 100%;
    display: grid;
    grid-template-columns:
        repeat(var(--columns), minmax(0, 1fr));
    grid-auto-rows: minmax(72px, 1fr);
    gap: 8px;
}

.device-card {
    min-width: 0;
    min-height: 0;
    width: 100%;
    overflow: hidden;

    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;

    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--foreground);

    border-radius: 6px;
    padding: 7px 11px;
    text-align: left;
    cursor: pointer;
}

.device-card:hover {
    background: var(--panel-hover);
    border-color: var(--muted);
}

.device-card:focus-visible,
.control:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 2px solid var(--foreground);
    outline-offset: -3px;
}

.device-category {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.1;
}

.device-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    font-size: 13px;
    line-height: 1.2;
}

.device-bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 3px 7px;
    font-size: 11px;
    line-height: 1.2;
}

.state {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    font-weight: 700;
}

.state::before,
.update-label::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.update-label {
    color: var(--blue);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
}

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

#pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 18px;
    flex-shrink: 0;
    font-size: 12px;
}

#pagination[hidden] {
    display: none;
}

.control {
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--foreground);
    border-radius: 5px;
    padding: 6px 13px;
    min-height: 32px;
}

.control:hover {
    background: var(--panel-hover);
}

.control:disabled {
    opacity: .4;
    cursor: default;
}

footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 10px;
    flex-shrink: 0;
}

.modal {
    --bs-modal-bg: var(--background);
    --bs-modal-color: var(--foreground);
    --bs-modal-border-color: var(--border);
    --bs-modal-header-border-color: var(--border);
    --bs-modal-footer-border-color: var(--border);
}

.modal-content {
    color: var(--foreground);
    background: var(--background);
}

.modal-header,
.modal-footer {
    background: var(--panel);
    border-color: var(--border);
    padding: 16px 24px;
}

.modal-title {
    font-size: clamp(22px, 4vw, 40px);
    font-weight: 750;
}

.modal-body {
    padding: clamp(12px, 3vw, 36px);
    overflow-y: auto;
}

.detail-banner {
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 8px;
    background: var(--panel);
    margin-bottom: 18px;
    font-size: 24px;
}

.detail-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(min(280px, 100%), 1fr));
    gap: 14px;
}

.detail-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 20px;
}

.detail-card h3 {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 10px;
}

.detail-card p {
    font-size: 18px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.detail-card a {
    color: var(--foreground);
    text-decoration: underline;
}

.modal-footer {
    justify-content: space-between;
    color: var(--muted);
    font-size: 12px;
}

@media (min-width: 1600px) {
    .device-grid {
        --columns: 5;
    }
}

@media (max-width: 1150px) {
    .device-grid {
        --columns: 3;
    }
}

@media (max-width: 800px) {
    .device-grid {
        --columns: 2;
    }

    #dashboard {
        padding: 10px;
        gap: 8px;
    }

    .metric {
        display: block;
    }

    .metric small {
        display: block;
        font-size: 10px;
    }

    footer {
        display: block;
    }

    footer span:last-child {
        display: none;
    }
}

@media (max-width: 420px) {
    .appearance {
        width: 112px;
    }

    .eyebrow {
        font-size: 8px;
        letter-spacing: .08em;
    }

    .overview {
        padding: 9px;
    }

    .device-card {
        padding: 6px 8px;
    }

    .device-name {
        font-size: 12px;
    }

    .device-category,
    .device-bottom {
        font-size: 10px;
    }

    .modal-header,
    .modal-footer {
        padding: 12px;
    }
}

@media (max-height: 540px) {
    #dashboard {
        padding: 6px 10px;
        gap: 5px;
    }

    .eyebrow,
    footer,
    #subline {
        display: none;
    }

    .overview {
        padding: 6px 10px;
    }

    .metrics {
        margin-top: 4px;
    }
}
