:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --surface-soft: #eef3f2;
    --line: #d8e0df;
    --text: #1e2528;
    --muted: #6a7478;
    --nav: #172126;
    --nav-soft: #223138;
    --teal: #008b84;
    --green: #1b8a52;
    --amber: #b16a00;
    --red: #b83b3b;
    --indigo: #3f4db8;
    --shadow: 0 18px 40px rgba(18, 31, 34, 0.10);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font: inherit;
}

.auth-body {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(0, 139, 132, 0.08), transparent 45%),
        linear-gradient(315deg, rgba(63, 77, 184, 0.10), transparent 40%),
        var(--bg);
}

.auth-main {
    width: min(980px, 100%);
}

.login-shell {
    display: grid;
    grid-template-columns: minmax(320px, 430px) minmax(280px, 1fr);
    min-height: 620px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.login-panel {
    padding: 48px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 28px;
}

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

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: inline-block;
    background:
        linear-gradient(135deg, var(--teal), var(--indigo));
    position: relative;
    flex: 0 0 auto;
}

.brand-mark::before,
.brand-mark::after {
    content: "";
    position: absolute;
    border-radius: 999px;
    background: #ffffff;
}

.brand-mark::before {
    width: 8px;
    height: 8px;
    left: 8px;
    top: 8px;
}

.brand-mark::after {
    width: 12px;
    height: 4px;
    right: 7px;
    bottom: 9px;
}

.brand-mark.large {
    width: 46px;
    height: 46px;
}

.login-brand h1,
.top-bar h1,
.panel h2,
.device-hero h2 {
    margin: 0;
}

.login-brand h1 {
    font-size: 34px;
    line-height: 1.1;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--teal);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0;
}

.login-aside {
    background:
        linear-gradient(135deg, rgba(23, 33, 38, 0.94), rgba(26, 45, 49, 0.96)),
        var(--nav);
    display: grid;
    place-items: center;
    padding: 42px;
}

.signal-board {
    width: min(420px, 100%);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.signal-board span {
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.signal-board span::after {
    content: "";
    position: absolute;
    inset: auto 16px 16px 16px;
    height: 8px;
    border-radius: 999px;
    background: #21c7a8;
    box-shadow: 0 0 28px rgba(33, 199, 168, 0.7);
}

.signal-board span:nth-child(2)::after,
.signal-board span:nth-child(5)::after {
    background: #ffb84d;
    box-shadow: 0 0 28px rgba(255, 184, 77, 0.6);
}

.form-stack {
    display: grid;
    gap: 18px;
}

.form-stack label,
.search-box {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px 13px;
    color: var(--text);
    background: #ffffff;
    outline: none;
    min-height: 44px;
}

input:focus,
select:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(0, 139, 132, 0.12);
}

.password-field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    align-items: stretch;
}

.password-field input {
    border-radius: 6px 0 0 6px;
    border-right: 0;
}

.password-toggle {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 0 6px 6px 0;
    background: #ffffff;
    cursor: pointer;
    display: grid;
    place-items: center;
}

.password-toggle span {
    width: 21px;
    height: 14px;
    border: 2px solid var(--muted);
    border-radius: 999px / 700px;
    position: relative;
}

.password-toggle span::after {
    content: "";
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--muted);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.password-toggle.is-visible span::before {
    content: "";
    position: absolute;
    left: -4px;
    right: -4px;
    top: 5px;
    height: 2px;
    background: var(--red);
    transform: rotate(-28deg);
}

.button {
    border: 1px solid transparent;
    border-radius: 6px;
    min-height: 42px;
    padding: 10px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text);
    background: #ffffff;
    cursor: pointer;
    font-weight: 750;
    white-space: nowrap;
}

.button.primary {
    background: var(--teal);
    color: #ffffff;
}

.button.warning {
    background: #fff6e8;
    color: #7a4900;
    border-color: #f2cf95;
}

.button.danger {
    background: #fff0f0;
    color: #8a2f2f;
    border-color: #efc5c5;
}

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

.button.full {
    width: 100%;
}

.button:disabled {
    opacity: 0.55;
    cursor: wait;
}

.notice {
    border-radius: 6px;
    padding: 12px 14px;
    background: #edf7f4;
    border: 1px solid #bfddd5;
    color: #1c5f52;
    font-weight: 650;
}

.notice.error {
    background: #fff0f0;
    color: #8a2f2f;
    border-color: #efc5c5;
}

.notice[hidden] {
    display: none;
}

.app-body {
    display: grid;
    grid-template-columns: 268px minmax(0, 1fr);
}

.side-nav {
    min-height: 100vh;
    background: var(--nav);
    color: #ffffff;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    position: sticky;
    top: 0;
}

.brand {
    min-height: 48px;
}

.brand strong,
.side-footer strong {
    display: block;
}

.brand small,
.side-footer small {
    color: rgba(255, 255, 255, 0.65);
    display: block;
    margin-top: 3px;
    overflow-wrap: anywhere;
}

.nav-links {
    display: grid;
    gap: 8px;
}

.nav-links a {
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, 0.78);
}

.nav-links a.active,
.nav-links a:hover {
    background: var(--nav-soft);
    color: #ffffff;
}

.nav-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.10);
    display: grid;
    place-items: center;
    font-weight: 800;
}

.side-footer {
    margin-top: auto;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.app-main {
    min-width: 0;
}

.top-bar {
    min-height: 92px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 22px 34px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
    backdrop-filter: blur(14px);
}

.top-bar h1 {
    font-size: 27px;
    line-height: 1.2;
}

.workspace {
    padding: 28px 34px 46px;
    display: grid;
    gap: 22px;
}

.workspace.two-column {
    grid-template-columns: minmax(320px, 450px) minmax(0, 1fr);
    align-items: start;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    gap: 14px;
}

.stat-card,
.panel,
.device-hero,
.device-table-wrap {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 10px 26px rgba(18, 31, 34, 0.06);
}

.stat-card {
    padding: 17px;
    display: grid;
    gap: 8px;
    border-top: 4px solid var(--indigo);
}

.stat-card small {
    color: var(--muted);
    font-weight: 750;
}

.stat-card strong {
    font-size: 32px;
    line-height: 1;
}

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

.accent-commissioning {
    border-top-color: var(--amber);
}

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

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
}

.search-box {
    width: min(420px, 100%);
}

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

.device-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.device-table th,
.device-table td {
    padding: 15px 16px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.device-table th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
}

.device-table tr[data-href] {
    cursor: pointer;
}

.device-table tr[data-href]:hover td {
    background: #f9fbfb;
}

.device-table td strong {
    display: block;
}

.device-table td small,
.muted {
    color: var(--muted);
}

.empty-row,
.empty-state {
    color: var(--muted);
    text-align: center;
    padding: 28px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 28px;
    padding: 5px 10px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
}

.status-pill::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: currentColor;
}

.status-online {
    color: #176d43;
    background: #e8f8ef;
}

.status-offline {
    color: #8a2f2f;
    background: #fff0f0;
}

.status-commissioning,
.status-decommissioning,
.status-preprovisioned {
    color: #805000;
    background: #fff6e8;
}

.status-suspended {
    color: #464a55;
    background: #eceff3;
}

.commission-code {
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    padding: 5px 8px;
    border-radius: 6px;
    background: #fff6e8;
    color: #704300;
    font-weight: 850;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.action-cell {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.panel {
    padding: 20px;
    display: grid;
    gap: 18px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.wrap-heading {
    flex-wrap: wrap;
}

.panel h2 {
    font-size: 21px;
}

.queue-list,
.event-list {
    display: grid;
    gap: 10px;
}

.queue-item,
.event-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    display: grid;
    gap: 10px;
    background: #ffffff;
}

.queue-item-main,
.event-item-main {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.queue-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.device-hero {
    padding: 22px;
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 20px;
    border-left: 5px solid var(--teal);
}

.device-hero-side,
.commissioning-callout {
    display: grid;
    justify-items: end;
    gap: 9px;
}

.commissioning-callout {
    margin-top: 8px;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    gap: 22px;
    align-items: start;
}

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

.metric-tile {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 15px;
    min-height: 106px;
    display: grid;
    align-content: space-between;
    background: #fbfcfc;
}

.metric-tile small {
    color: var(--muted);
    overflow-wrap: anywhere;
}

.metric-tile strong {
    font-size: 28px;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.widget-form {
    display: grid;
    grid-template-columns: repeat(6, minmax(120px, 1fr));
    gap: 12px;
    align-items: end;
    padding: 14px;
    background: #f8fbfa;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.widget-form label,
.compact-form label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
}

.widget-form[hidden] {
    display: none;
}

.widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 14px;
    align-items: stretch;
}

.dashboard-widget {
    min-height: 210px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 15px;
    background: #ffffff;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 12px;
}

.dashboard-widget.is-dragging {
    opacity: 0.55;
}

.widget-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 10px;
}

.widget-head strong {
    overflow-wrap: anywhere;
}

.widget-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.rename-inline {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
}

.rename-inline input {
    min-height: 36px;
    padding: 8px 10px;
}

.mini-button {
    min-height: 30px;
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--muted);
    cursor: pointer;
    font-weight: 750;
}

.widget-value {
    font-size: 38px;
    line-height: 1;
    font-weight: 850;
    align-self: center;
    overflow-wrap: anywhere;
}

.dial-widget {
    width: 150px;
    aspect-ratio: 1 / 1;
    border-radius: 999px;
    place-self: center;
    display: grid;
    place-items: center;
    background: #ffffff;
    position: relative;
}

.dial-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.dial-widget strong {
    position: relative;
    z-index: 1;
    font-size: 28px;
}

.chart-widget {
    width: 100%;
    height: 150px;
}

.output-list {
    display: grid;
    gap: 10px;
}

.output-item {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfc;
}

.output-item-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.output-control {
    display: flex;
    gap: 10px;
    align-items: center;
}

.output-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.output-control input[type="range"] {
    padding: 0;
}

.switch {
    width: 54px;
    height: 30px;
    border-radius: 999px;
    border: 0;
    background: #c9d3d2;
    padding: 3px;
    cursor: pointer;
}

.switch span {
    display: block;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: #ffffff;
    transition: transform 160ms ease;
}

.switch.is-on {
    background: var(--green);
}

.switch.is-on span {
    transform: translateX(24px);
}

.split-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

@media (max-width: 980px) {
    .app-body {
        grid-template-columns: 1fr;
    }

    .side-nav {
        min-height: auto;
        position: static;
        padding: 14px 18px;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    .nav-links {
        grid-auto-flow: column;
    }

    .side-footer {
        display: none;
    }

    .workspace.two-column,
    .detail-grid,
    .login-shell,
    .widget-form {
        grid-template-columns: 1fr;
    }

    .login-aside {
        display: none;
    }
}

@media (max-width: 720px) {
    .auth-body {
        padding: 14px;
    }

    .login-panel,
    .workspace,
    .top-bar {
        padding: 20px;
    }

    .top-bar {
        align-items: start;
        flex-direction: column;
    }

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

    .toolbar,
    .device-hero,
    .queue-item-main,
    .event-item-main {
        align-items: stretch;
        flex-direction: column;
    }

    .search-box,
    .toolbar .button {
        width: 100%;
    }
}
