:root {
    color-scheme: light;
    --paper: #f7f6f2;
    --panel: #ffffff;
    --ink: #272c31;
    --muted: #626a70;
    --line: #e5e3dc;
    --navy: #163b63;
    --navy-deep: #102e4d;
    --navy-soft: #e8eef4;
    --orange: #b94a16;
    --orange-deep: #96380c;
    --green: #2e7d5b;
    --green-soft: #e7f2ed;
    --red: #a84539;
    --red-soft: #f8e9e6;
    --amber: #a66a14;
    --amber-soft: #f8efdc;
    --focus: #0b69c7;
    --shadow: 0 12px 28px rgba(22, 59, 99, 0.08);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: "Microsoft YaHei UI", "Noto Sans SC", sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid rgba(11, 105, 199, 0.28);
    outline-offset: 2px;
}
::selection { color: #fff; background: var(--navy); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #aab3bb; border: 2px solid var(--paper); border-radius: 8px; }

.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.muted { color: var(--muted); }

.button {
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    padding: 10px 16px;
    font-weight: 760;
    cursor: pointer;
    transition: background-color 160ms ease-out, color 160ms ease-out, transform 160ms ease-out;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none; }
.button.primary { color: #fff; background: var(--orange); }
.button.primary:hover { background: var(--orange-deep); }
.button.secondary { color: var(--navy); background: var(--navy-soft); }
.button.danger { color: #fff; background: var(--red); }
.button.text-button { color: var(--navy); background: transparent; padding-inline: 8px; }
.button.full { width: 100%; display: block; text-align: center; text-decoration: none; margin-top: 18px; }

.notice {
    margin: 0 0 18px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--navy-soft);
    color: var(--navy-deep);
}
.notice.success { background: var(--green-soft); color: #1f6045; }
.notice.danger { background: var(--red-soft); color: #8f332a; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: var(--navy); }
.auth-shell {
    width: min(920px, 100%);
    display: grid;
    grid-template-columns: 1.08fr .92fr;
    overflow: hidden;
    border-radius: 16px;
    box-shadow: 0 28px 70px rgba(0, 0, 0, .24);
}
.auth-shell.compact { width: min(820px, 100%); }
.auth-copy { color: #fff; padding: 52px; background: var(--navy-deep); }
.auth-copy h1 { margin: 28px 0 12px; font-size: clamp(2rem, 4vw, 3.4rem); line-height: 1.08; letter-spacing: -.025em; }
.auth-copy p { max-width: 46ch; color: #cbd9e5; }
.auth-copy ul { margin: 30px 0 0; padding: 0; list-style: none; }
.auth-copy li { padding: 10px 0 10px 24px; position: relative; color: #e8eff5; }
.auth-copy li::before { content: ""; position: absolute; left: 0; top: 18px; width: 8px; height: 8px; background: var(--orange); border-radius: 50%; }
.brand-mark { font-weight: 900; letter-spacing: .08em; }
.auth-panel { padding: 48px; background: var(--panel); }
.auth-panel h2 { margin: 0 0 8px; font-size: 1.6rem; }
.auth-panel form { margin-top: 22px; }
label { display: block; font-weight: 700; color: #384047; }
input, select, textarea {
    width: 100%;
    margin: 7px 0 17px;
    border: 1px solid #cfd4d8;
    border-radius: 9px;
    padding: 11px 12px;
    color: var(--ink);
    background: #fff;
}
textarea { resize: vertical; }

.app-page { min-height: 100vh; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.side-rail {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 28px 20px;
    color: #fff;
    background: var(--navy);
}
.brand-block { padding: 0 12px 34px; }
.brand-block .brand-mark { display: block; font-size: 1.35rem; }
.brand-block small { color: #b8c9d8; }
.side-rail nav { display: grid; gap: 6px; }
.nav-item {
    width: 100%;
    border: 0;
    border-radius: 10px;
    padding: 13px 14px;
    display: flex;
    align-items: center;
    gap: 11px;
    color: #c3d1de;
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.nav-item.active { color: var(--navy); background: #fff; font-weight: 800; }
.nav-icon { width: 9px; height: 9px; border: 2px solid currentColor; border-radius: 2px; }
.rail-footer { margin-top: auto; display: grid; gap: 14px; padding: 18px 12px 0; border-top: 1px solid rgba(255,255,255,.16); }
.security-seal { color: #cde7da; font-size: .8rem; }
.rail-footer a { color: #c3d1de; text-underline-offset: 4px; }

.workspace { min-width: 0; padding: 32px 36px 44px; overflow: hidden; }
.workspace-header { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-bottom: 24px; }
.workspace-header h1 { margin: 0; font-size: clamp(1.8rem, 3vw, 2.25rem); letter-spacing: -.025em; line-height: 1.2; }
.workspace-header p { margin: 7px 0 0; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.last-refresh { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.view { display: none; }
.view.active { display: block; }

.summary-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin-bottom: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--panel);
    box-shadow: var(--shadow);
}
.summary-board div { padding: 18px 20px; border-right: 1px solid var(--line); }
.summary-board div:last-child { border-right: 0; }
.summary-board strong { display: block; font-size: 1.85rem; line-height: 1; font-variant-numeric: tabular-nums; }
.summary-board span { display: block; margin-top: 8px; color: var(--muted); font-size: .84rem; }

.registration-panel { margin-bottom: 20px; overflow: hidden; border: 1px solid #ead8b7; }
.registration-panel .panel-heading { background: #fffaf0; }
.registration-panel .panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: .8rem; font-weight: 400; }
.registration-list { padding: 0 20px; }
.registration-row { display: grid; grid-template-columns: minmax(170px, .8fr) minmax(240px, 1.2fr) auto; gap: 18px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.registration-row:last-child { border-bottom: 0; }
.registration-row small { display: block; margin-top: 3px; color: var(--muted); }
.registration-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.registration-actions .button { min-height: 38px; padding: 7px 12px; }

.device-workbench { display: grid; grid-template-columns: minmax(620px, 1fr) 310px; gap: 18px; align-items: start; }
.work-panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.device-list-panel { min-width: 0; overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar label { margin: 0; }
.toolbar input, .toolbar select { margin: 0; background: var(--paper); border-color: transparent; }
.device-import-form { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.device-import-form .button { margin: 0; white-space: nowrap; }
.search-field { flex: 1; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: #626a70; font-size: .75rem; font-weight: 750; background: #fbfaf7; }
tbody tr { cursor: pointer; transition: background-color 140ms ease-out; }
tbody tr:hover { background: #f7f8f8; }
tbody tr.selected-row { background: #edf2f7; }
tbody tr.changed-row { animation: row-change 2.2s ease-out; }
@keyframes row-change { 0%, 25% { background: #fbe6d8; } 100% { background: transparent; } }
.check-col { width: 42px; }
.device-check { width: 20px; height: 20px; margin: 0; accent-color: var(--navy); }
.device-open { border: 0; padding: 2px 0; color: var(--ink); background: transparent; font-weight: 850; cursor: pointer; }
.device-open:hover { color: var(--navy); text-decoration: underline; text-underline-offset: 3px; }
.device-mac { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; }
.state-label { display: inline-flex; align-items: center; gap: 7px; font-weight: 800; }
.state-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #8a9299; }
.state-online { color: var(--green); }
.state-online::before { background: var(--green); }
.state-degraded { color: var(--amber); }
.state-degraded::before { background: var(--amber); }
.state-offline, .state-failed { color: var(--red); }
.state-offline::before, .state-failed::before { background: var(--red); }
.version-chip {
    display: inline-block;
    padding: 4px 7px;
    border-radius: 7px;
    color: var(--navy);
    background: var(--navy-soft);
    font-size: .78rem;
    font-weight: 750;
}
.device-sheet { position: sticky; top: 24px; padding: 22px; min-height: 360px; }
.device-sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet-empty { padding: 56px 12px; text-align: center; color: var(--muted); }
.sheet-empty h2 { color: var(--ink); }
.sheet-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; padding-bottom: 16px; }
.sheet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; padding: 16px 0; border-top: 1px solid var(--line); }
.sheet-grid span { display: block; color: var(--muted); font-size: .72rem; }
.sheet-grid b { display: block; margin-top: 3px; word-break: break-word; }
.security-stamp {
    margin: 16px 0;
    border: 2px solid var(--green);
    border-radius: 8px;
    padding: 10px;
    color: var(--green);
    text-align: center;
    font-weight: 900;
    letter-spacing: .04em;
    transform: rotate(-1deg);
}
.ota-step { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.ota-step b { color: var(--navy); font-variant-numeric: tabular-nums; }
.ota-step small { color: var(--muted); }

.loading-row { padding: 30px !important; color: var(--muted); text-align: center !important; }
.empty-state { padding: 56px 24px; text-align: center; }
.empty-state h2 { margin: 0 0 7px; }
.empty-state p { margin: 0; color: var(--muted); }

.section-intro { display: flex; justify-content: space-between; align-items: end; margin-bottom: 18px; }
.section-intro h2, .panel-heading h2, .upload-panel h2 { margin: 0; font-size: 1.3rem; }
.section-intro p { margin: 5px 0 0; color: var(--muted); }
.release-layout { display: grid; grid-template-columns: minmax(360px, .72fr) minmax(420px, 1.28fr); gap: 18px; align-items: start; }
.upload-panel { padding: 22px; }
.upload-panel form { margin-top: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { margin: -2px 0 14px; color: var(--muted); font-size: .78rem; line-height: 1.55; }
.release-list-panel { overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-heading span { color: var(--muted); font-size: .82rem; }
.release-row { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.release-row:last-child { border-bottom: 0; }
.release-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.release-head h3 { margin: 0; }
.release-meta { color: var(--muted); font-size: .78rem; }
.release-hash { margin: 12px 0; overflow-wrap: anywhere; color: #5e666d; font: .72rem Consolas, monospace; }
.release-progress { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin: 12px 0; background: var(--line); border: 1px solid var(--line); }
.release-progress span { padding: 8px; background: #faf9f6; text-align: center; font-size: .75rem; }
.release-progress b { display: block; font-size: 1rem; }
.release-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.profile-label { display: inline-block; padding: 4px 7px; border-radius: 7px; background: #eeeae0; font-size: .72rem; font-weight: 800; }
.profile-standard { color: var(--navy); background: var(--navy-soft); }
.profile-oldcar { color: #6c4b17; background: var(--amber-soft); }

.exception-list, .history-list { padding: 4px 20px 18px; }
.exception-row, .history-row { display: grid; grid-template-columns: minmax(160px, 1fr) 1fr auto; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--line); align-items: center; }
.exception-row p, .history-row p { margin: 3px 0 0; color: var(--muted); }

dialog { border: 0; padding: 0; background: transparent; }
dialog::backdrop { background: rgba(15, 30, 44, .55); }
.dialog-card { width: min(560px, calc(100vw - 28px)); max-height: calc(100vh - 36px); overflow: auto; padding: 24px; border-radius: 16px; background: #fff; box-shadow: 0 24px 60px rgba(0, 0, 0, .28); }
.dialog-card h2 { margin: 0 0 4px; }
.dialog-close { float: right; min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--muted); padding: 6px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
fieldset { margin: 18px 0; padding: 0; border: 0; }
legend { margin-bottom: 8px; font-weight: 850; }
.radio-row { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 9px; padding: 11px 0; border-top: 1px solid var(--line); cursor: pointer; }
.radio-row input { width: 17px; height: 17px; margin: 0; accent-color: var(--navy); }
.radio-row small { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 8px; }
.device-push-button { margin-top: 8px; }
.push-device-name { color: var(--navy); font-weight: 700; overflow-wrap: anywhere; }
.push-device-preview { margin: 12px 0; line-height: 1.6; overflow-wrap: anywhere; }
#push-device-dialog .radio-row { grid-template-columns: 22px minmax(0, 1fr); }
#push-device-dialog select { min-width: 0; max-width: 100%; }

.monitor-summary { display: flex; flex-wrap: wrap; gap: 12px 30px; margin: 0 0 20px; color: var(--muted); font-variant-numeric: tabular-nums; }
.monitor-summary strong { color: var(--ink); margin-inline: 4px; }
.monitor-summary span:first-child { color: var(--navy); }
.monitor-panel { overflow: hidden; }
.monitor-caption { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 12px 16px; color: var(--muted); font-size: .8rem; }
.monitor-note { margin: 16px 0; color: var(--muted); font-size: .82rem; line-height: 1.7; }
.monitor-error { margin: 0; padding: 12px 16px; color: var(--red); background: var(--red-soft); }
.monitor-table td { font-size: .85rem; }
.monitor-table td small { display: block; margin-top: 5px; color: var(--muted); font-size: .75rem; }
.monitor-table td .monitor-warning { color: var(--red); }
.monitor-table tbody tr { cursor: default; }
.monitor-table th { position: sticky; top: 0; z-index: 1; }
.monitor-table-wrap { max-height: 65vh; }
.monitor-table .state-degraded { color: #795110; }
.monitor-table td:last-child { white-space: normal; min-width: 110px; }
.monitor-expand { display: grid; gap: 3px; min-height: 44px; padding: 3px 0; border: 0; color: var(--navy); background: transparent; text-align: left; cursor: pointer; }
.monitor-expand span { font-size: .75rem; text-decoration: underline; text-underline-offset: 3px; }
.monitor-expand:hover { color: var(--navy-deep); }
.monitor-table .monitor-expanded { background: var(--navy-soft); }
.monitor-table .monitor-details-row { background: #fbfaf7; }
.monitor-table .monitor-details-row > td { padding: 22px 20px; white-space: normal; }
.monitor-detail-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 20px; }
.monitor-detail-heading h2 { margin: 0; color: var(--navy); font-size: 1rem; }
.monitor-detail-heading span { color: var(--muted); font-size: .75rem; }
.monitor-detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.monitor-detail-grid h3 { margin: 0 0 12px; font-size: 1rem; }
.monitor-detail-grid dl { margin: 0; }
.monitor-detail-grid dl > div { padding: 9px 0; border-top: 1px solid var(--line); }
.monitor-detail-grid dt { color: var(--muted); font-size: .75rem; }
.monitor-detail-grid dd { margin: 4px 0 0; overflow-wrap: anywhere; }
.monitor-detail-grid p { margin: 14px 0 0; color: var(--muted); font-size: .75rem; line-height: 1.7; }

@media (max-width: 1100px) {
    .workspace { padding-inline: 24px; }
    .device-workbench { grid-template-columns: 1fr; }
    .device-sheet { position: static; }
    .release-layout { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .app-shell { display: block; padding-bottom: 70px; }
    .side-rail {
        position: fixed;
        z-index: 10;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 66px;
        padding: 7px 8px;
        display: block;
        box-shadow: 0 -10px 28px rgba(22,59,99,.16);
    }
    .brand-block, .rail-footer { display: none; }
    .side-rail nav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
    .nav-item { display: grid; place-items: center; gap: 2px; padding: 7px 3px; font-size: .72rem; text-align: center; }
    .nav-icon { width: 8px; height: 8px; }
    .workspace { padding: 22px 14px 30px; }
    .workspace-header { align-items: start; }
    .header-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .last-refresh { grid-column: 1 / -1; text-align: right; }
    .summary-board { grid-template-columns: 1fr 1fr; }
    .summary-board div:nth-child(2) { border-right: 0; }
    .summary-board div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
    .toolbar { align-items: stretch; flex-wrap: wrap; }
    .search-field { flex-basis: 100%; }
    .toolbar label:not(.search-field) { flex: 1; }
    .toolbar .text-button { width: 100%; }
    .device-import-form { width: 100%; margin-left: 0; }
    .device-import-form .button { flex: 1; }
    .table-wrap { max-height: 480px; }
    .device-table th:nth-child(5), .device-table td:nth-child(5),
    .device-table th:nth-child(6), .device-table td:nth-child(6),
    .device-table th:nth-child(7), .device-table td:nth-child(7) { display: none; }
    .form-grid { grid-template-columns: 1fr; }
    .exception-row, .history-row { grid-template-columns: 1fr; gap: 5px; }
    .registration-row { grid-template-columns: 1fr; gap: 7px; }
    .registration-actions { justify-content: flex-start; flex-wrap: wrap; }
    .monitor-summary { gap: 10px 20px; }
    .monitor-caption { display: grid; }
    .monitor-table-wrap { max-height: none; }
    .monitor-table, .monitor-table tbody { display: block; }
    .monitor-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .monitor-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px 12px; padding: 20px 16px; border-top: 1px solid var(--line); }
    .monitor-table td { display: block; padding: 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
    .monitor-table td::before { content: attr(data-label); display: block; margin-bottom: 5px; color: var(--muted); font-size: .72rem; }
    .monitor-table td:last-child { min-width: 0; }
    .monitor-table .monitor-details-row { display: block; padding: 0; }
    .monitor-table .monitor-details-row > td { padding: 20px 16px; }
    .monitor-table .monitor-details-row > td::before { display: none; }
    .monitor-detail-heading { display: block; }
    .monitor-detail-heading span { display: block; margin-top: 6px; }
    .monitor-detail-grid { grid-template-columns: 1fr; gap: 24px; }
    .monitor-detail-grid dl { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 16px; }
}

@media (max-width: 560px) {
    .auth-page { padding: 0; align-items: stretch; }
    .auth-shell, .auth-shell.compact { display: block; min-height: 100vh; border-radius: 0; }
    .auth-copy, .auth-panel { padding: 30px 24px; }
    .auth-copy h1 { margin-top: 18px; }
    .workspace-header { display: block; }
    .header-actions { margin-top: 16px; }
    .header-actions .button { padding-inline: 10px; }
    .device-table th:nth-child(4), .device-table td:nth-child(4) { display: none; }
    .device-table th:nth-child(8), .device-table td:nth-child(8) { display: none; }
    .device-table th, .device-table td { padding-inline: 10px; }
    .release-progress { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
