:root {
    color-scheme: light;
    --bg: #f5f7f9;
    --surface: #ffffff;
    --surface-muted: #eef2f5;
    --text: #17212b;
    --muted: #637180;
    --border: #d9e0e6;
    --border-strong: #bcc7d1;
    --primary: #5260cb;
    --primary-dark: #3e499d;
    --green: #13795b;
    --green-bg: #e4f5ee;
    --red: #b42318;
    --red-bg: #fdecea;
    --amber: #8a5a00;
    --amber-bg: #fff2cc;
    --shadow: 0 10px 28px rgba(23, 33, 43, 0.08);
    font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 16px;
    letter-spacing: 0;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
    letter-spacing: 0;
}

button,
a,
input,
textarea {
    -webkit-tap-highlight-color: transparent;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    grid-template-rows: 60px minmax(0, 1fr);
}

.topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 0;
    padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand,
.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 700;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: var(--text);
    color: #fff;
    font-size: 15px;
    font-weight: 800;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.admin-name {
    max-width: 220px;
    overflow: hidden;
    color: var(--muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar {
    background: #202a34;
    color: #dbe3ea;
    padding: 18px 12px;
}

.sidebar nav {
    display: grid;
    gap: 4px;
}

.sidebar a {
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 0 14px;
    border-radius: 5px;
    color: #cad4dd;
}

.sidebar a:hover {
    background: #2a3743;
    color: #fff;
}

.sidebar a.active {
    background: #eef4f8;
    color: var(--text);
    font-weight: 700;
}

.content {
    min-width: 0;
    padding: 28px 32px 56px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 52px;
    margin-bottom: 24px;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 3px;
    font-size: 24px;
    line-height: 1.25;
}

h2 {
    margin-bottom: 14px;
    font-size: 16px;
    line-height: 1.35;
}

.page-header p,
.muted {
    color: var(--muted);
}

.page-header p {
    margin-bottom: 0;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
}

.button:disabled {
    cursor: wait;
    opacity: 0.7;
}

.button-primary {
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--primary-dark);
}

.button-secondary {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}

.button-secondary:hover,
.button-quiet:hover {
    background: var(--surface-muted);
}

.button-quiet {
    background: transparent;
    color: var(--muted);
}

.button-small {
    min-height: 32px;
    padding: 0 11px;
    font-size: 13px;
}

.button-block {
    width: 100%;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.metric {
    min-width: 0;
    padding: 20px 22px;
    border-right: 1px solid var(--border);
}

.metric:last-child {
    border-right: 0;
}

.metric span,
.cell-sub,
.toggle-row small {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 26px;
    line-height: 1;
}

.section-block {
    margin-top: 26px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

th,
td {
    padding: 13px 15px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    background: #f7f9fa;
    color: #50606f;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: #fafcfd;
}

.device-table td:first-child {
    min-width: 280px;
}

.action-column {
    width: 70px;
}

.cell-sub {
    margin-top: 3px;
}

.table-link {
    color: var(--primary);
    font-weight: 600;
}

.mono {
    font-family: "Cascadia Mono", Consolas, monospace;
    font-size: 12px;
    letter-spacing: 0;
}

.nowrap {
    white-space: nowrap;
}

.break-all {
    word-break: break-all;
}

.status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.status-ok {
    background: var(--green-bg);
    color: var(--green);
}

.status-bad {
    background: var(--red-bg);
    color: var(--red);
}

.status-off {
    background: var(--surface-muted);
    color: #5d6873;
}

.empty {
    height: 90px;
    color: var(--muted);
    text-align: center;
}

.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.search-bar input {
    width: min(520px, 100%);
}

.field input,
.field textarea,
.search-bar input {
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text);
    outline: 0;
}

.field input,
.search-bar input {
    height: 40px;
    padding: 0 11px;
}

.field textarea {
    width: 100%;
    min-height: 98px;
    padding: 10px 11px;
    resize: vertical;
}

.field input:focus,
.field textarea:focus,
.search-bar input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(23, 105, 170, 0.12);
}

.field label {
    display: block;
    margin-bottom: 6px;
    color: #394856;
    font-weight: 650;
}

.field input {
    width: 100%;
}

.field-error {
    margin-top: 5px;
    color: var(--red);
    font-size: 12px;
}

.device-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.form-section {
    padding: 22px 24px;
    border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
    border-bottom: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 22px;
}

.field-wide {
    grid-column: 1 / -1;
}

.product-section {
    background: #fbfcfd;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 40px;
    cursor: pointer;
}

.toggle-row input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.toggle-control {
    position: relative;
    flex: 0 0 38px;
    width: 38px;
    height: 22px;
    border-radius: 999px;
    background: #aeb9c3;
    transition: background 120ms ease;
}

.toggle-control::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
    transition: transform 120ms ease;
}

.toggle-row input:checked + .toggle-control {
    background: var(--green);
}

.toggle-row input:checked + .toggle-control::after {
    transform: translateX(16px);
}

.toggle-row input:focus-visible + .toggle-control {
    outline: 3px solid rgba(23, 105, 170, 0.2);
    outline-offset: 2px;
}

.form-actions {
    display: flex;
    gap: 8px;
    padding: 18px 24px;
    background: #f7f9fa;
}

.notice {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid;
    border-radius: 5px;
}

.notice ul {
    margin: 7px 0 0;
    padding-left: 20px;
}

.notice-success {
    border-color: #9ed8c1;
    background: var(--green-bg);
    color: #0e5e47;
}

.notice-error {
    border-color: #f2b8b2;
    background: var(--red-bg);
    color: #8f1b12;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    margin-top: 16px;
    color: var(--muted);
}

.pagination a {
    color: var(--primary);
    font-weight: 600;
}

.pagination .disabled {
    color: #a4adb6;
}

.system-list {
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.system-list > div {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 18px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.system-list > div:last-child {
    border-bottom: 0;
}

.system-list dt {
    color: var(--muted);
}

.system-list dd {
    margin: 0;
}

.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background: #edf1f4;
}

.login-panel {
    width: min(400px, 100%);
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login-brand {
    margin-bottom: 26px;
}

.login-brand strong,
.login-brand span {
    display: block;
}

.login-brand div > span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.form-stack {
    display: grid;
    gap: 18px;
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: 58px auto minmax(0, 1fr);
    }

    .topbar {
        padding: 0 16px;
    }

    .sidebar {
        padding: 8px 12px;
        overflow-x: auto;
    }

    .sidebar nav {
        display: flex;
        width: max-content;
    }

    .sidebar a {
        min-height: 36px;
        padding: 0 12px;
    }

    .content {
        padding: 22px 18px 48px;
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metric:nth-child(2) {
        border-right: 0;
    }

    .metric:nth-child(-n+2) {
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 620px) {
    .admin-name {
        display: none;
    }

    .page-header {
        align-items: flex-start;
    }

    h1 {
        font-size: 21px;
    }

    .search-bar {
        flex-wrap: wrap;
    }

    .search-bar input {
        width: 100%;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .field-wide {
        grid-column: auto;
    }

    .form-section {
        padding: 20px 16px;
    }

    .system-list > div {
        grid-template-columns: 1fr;
        gap: 5px;
    }
}
