:root {
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  color: #202a2b;
  background: #f5f7f6;
  font-synthesis: none;
  --ink: #202a2b;
  --muted: #657274;
  --line: #dce2e0;
  --surface: #fff;
  --red: #b83635;
  --red-dark: #942a2b;
  --teal: #157464;
  --amber: #946715;
}
* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; min-height: 100vh; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
button:focus-visible, input:focus-visible { outline: 2px solid #187665; outline-offset: 3px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.eyebrow { margin: 0 0 7px; color: var(--red); font-size: 11px; font-weight: 700; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 9px 16px; border: 1px solid transparent; border-radius: 4px; font-size: 13px; font-weight: 700; line-height: 1.4; transition: background .15s, border-color .15s, color .15s; }
.button-primary { color: white; background: var(--ink); }
.button-primary:hover:not(:disabled) { background: #39494a; }
.button-outline { color: var(--ink); background: #fff; border-color: #aebbb8; }
.button-outline:hover:not(:disabled) { background: #f4f7f6; border-color: #586968; }
.button-danger { color: white; background: var(--red); }
.button-danger:hover:not(:disabled) { background: var(--red-dark); }
.button:disabled { opacity: .48; }

/* Sign in */
.login-page { display: grid; place-items: center; padding: 24px; background: linear-gradient(90deg, #e9eeee 0 7px, #f5f7f6 7px 100%); }
.login-shell { width: min(100%, 410px); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; color: #435453; font-size: 12px; font-weight: 700; }
.brand-mark { display: inline-grid; flex: none; place-items: center; width: 34px; height: 34px; border-radius: 3px; color: #fff; background: var(--red); font-size: 17px; font-weight: 800; }
.brand-rule { width: 1px; height: 22px; background: #b6c3c0; }
.login-panel { padding: 36px; border: 1px solid var(--line); border-top: 3px solid var(--red); background: #fff; }
.login-panel h1 { margin: 0; font-size: 25px; line-height: 1.35; }
.login-subtitle { margin: 10px 0 28px; color: var(--muted); font-size: 12px; }
.login-error { margin: 0 0 18px; padding: 10px 12px; color: #972f30; background: #fff0ef; border-left: 3px solid var(--red); font-size: 12px; line-height: 1.6; }
.login-form { display: grid; gap: 9px; }
.login-form label { font-size: 12px; font-weight: 700; }
.login-form input { width: 100%; height: 42px; margin-bottom: 12px; padding: 0 12px; border: 1px solid #bfcac7; border-radius: 3px; background: #fff; color: var(--ink); }
.login-form input:hover { border-color: #839491; }
.login-submit { width: 100%; margin-top: 8px; }
.login-footnote { margin: 18px 0 0; color: #74817e; font-size: 11px; line-height: 1.6; text-align: center; }

/* Application frame */
.dashboard-page { background: #f7f9f8; }
.topbar { background: #243233; color: #fff; }
.topbar-inner { display: flex; justify-content: space-between; align-items: center; width: min(100% - 48px, 1480px); min-height: 62px; margin: auto; }
.identity { display: flex; gap: 11px; align-items: center; min-width: 0; }
.identity .brand-mark { width: 32px; height: 32px; }
.identity > div { display: grid; gap: 2px; }
.identity-title { font-size: 14px; font-weight: 700; white-space: nowrap; }
.identity-sub { color: #aebfbb; font-size: 10px; }
.account { display: flex; align-items: center; gap: 17px; color: #d7e1df; font-size: 12px; }
.account-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-button { border: 0; padding: 5px 0; background: none; color: #fff; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { color: #ffe2df; }
.workspace { width: min(100% - 48px, 1480px); margin: 0 auto; padding: 28px 0 52px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-heading h1 { margin: 0; font-size: 24px; line-height: 1.3; }
.page-meta { margin: 0 0 2px; color: var(--muted); font-size: 11px; line-height: 1.6; text-align: right; }
.page-meta strong { color: var(--ink); font-weight: 700; }
.meta-divider { display: inline-block; width: 1px; height: 11px; margin: 0 11px; background: #c8d0ce; vertical-align: -1px; }
.page-message { margin: 0 0 16px; padding: 11px 14px; border-left: 3px solid var(--red); color: #852e2f; background: #fff1ef; font-size: 12px; line-height: 1.6; }
.page-message.is-success { color: #126657; border-left-color: var(--teal); background: #eaf6f2; }
.status-band { display: grid; grid-template-columns: minmax(165px,1.2fr) repeat(3,minmax(125px,1fr)) 42px; align-items: stretch; min-height: 90px; border: 1px solid var(--line); background: var(--surface); }
.status-primary, .status-cell { display: flex; flex-direction: column; justify-content: center; min-width: 0; padding: 17px 21px; border-right: 1px solid var(--line); }
.status-primary { flex-direction: row; justify-content: flex-start; align-items: center; gap: 14px; }
.status-primary > div { display: grid; gap: 4px; }
.status-cell { gap: 4px; }
.status-label { color: var(--muted); font-size: 11px; }
.status-primary strong { font-size: 18px; line-height: 1.3; }
.status-cell strong { overflow: hidden; color: var(--ink); font-size: 13px; font-weight: 650; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.connection-indicator { width: 12px; height: 12px; flex: none; border: 3px solid #a8b3af; border-radius: 50%; }
.connection-indicator.online { border-color: var(--teal); background: var(--teal); box-shadow: 0 0 0 4px #dcefe9; }
.connection-indicator.offline { border-color: var(--red); background: var(--red); box-shadow: 0 0 0 4px #fae5e2; }
.mode-badge { width: fit-content; max-width: 100%; padding: 3px 7px; border-radius: 2px; color: #667371 !important; background: #edf0ef; font-size: 11px !important; }
.mode-badge.simulator { color: #855d0d !important; background: #fff4d9; }
.mode-badge.live { color: #a02e2e !important; background: #ffeded; }
.icon-button { display: grid; place-items: center; width: 42px; height: 42px; align-self: center; border: 0; background: transparent; color: #526462; font-size: 23px; line-height: 1; }
.icon-button:hover { color: var(--teal); }
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 316px; gap: 28px; margin-top: 33px; }
.events-section, .side-column { min-width: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; min-height: 49px; margin-bottom: 13px; }
.section-heading h2 { margin: 0; font-size: 17px; line-height: 1.3; }
.section-count { padding-bottom: 2px; color: var(--muted); font-size: 11px; white-space: nowrap; }

/* Device receiver settings */
.receiver-section { margin-top: 28px; }
.receiver-heading { margin-bottom: 12px; }
.receiver-state { color: var(--muted); font-size: 11px; }
.receiver-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 300px); border-top: 2px solid #435958; background: var(--surface); }
.receiver-form { min-width: 0; padding: 20px 23px 21px; }
.receiver-mode { display: flex; gap: 10px; margin: 0 0 19px; padding: 0; border: 0; }
.receiver-mode legend { margin-bottom: 9px; color: #52635f; font-size: 11px; font-weight: 700; }
.receiver-mode label { display: flex; flex: 1; align-items: flex-start; gap: 9px; min-width: 0; padding: 11px 12px; border: 1px solid var(--line); border-radius: 3px; cursor: pointer; }
.receiver-mode label:has(input:checked) { border-color: #5d8f82; background: #eef6f2; }
.receiver-mode input { flex: none; margin: 2px 0 0; accent-color: var(--teal); }
.receiver-mode span { font-size: 12px; font-weight: 700; }
.receiver-mode small { display: block; margin-top: 3px; color: #63736e; font-size: 10px; font-weight: 400; line-height: 1.5; }
.receiver-fields { display: grid; grid-template-columns: minmax(120px, 1.5fr) minmax(100px, .7fr) minmax(170px, 1.5fr); gap: 12px; align-items: end; }
.receiver-field[hidden] { display: none; }
.receiver-field { min-width: 0; }
.receiver-fields label { display: block; color: #42514e; font-size: 11px; font-weight: 700; }
.field-hint { display: block; margin-top: 3px; color: #70807b; font-size: 10px; font-weight: 400; line-height: 1.5; }
.receiver-fields input { width: 100%; height: 39px; min-width: 0; margin-top: 6px; padding: 0 10px; border: 1px solid #bfcac7; border-radius: 3px; color: var(--ink); background: #fff; font-family: Consolas, "Microsoft YaHei UI", monospace; font-size: 12px; }
.receiver-fields input:hover { border-color: #839491; }
.receiver-cidr-help { margin: 5px 0 0; }
.receiver-actions { display: flex; align-items: center; gap: 12px; margin-top: 17px; }
.receiver-feedback { color: var(--teal); font-size: 11px; line-height: 1.5; }
.receiver-feedback.is-error { color: var(--red); }
.receiver-summary { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; min-width: 0; padding: 22px 24px; border-left: 1px solid var(--line); background: #f0f5f2; }
.summary-kicker { color: #637873; font-size: 11px; font-weight: 700; }
.receiver-address { margin: 10px 0 12px; color: #214a42; font-family: Consolas, "Microsoft YaHei UI", monospace; font-size: clamp(16px, 1.7vw, 21px); line-height: 1.4; overflow-wrap: anywhere; }
.receiver-copy { padding: 4px 0; border: 0; background: transparent; color: var(--teal); font-size: 11px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.receiver-copy:disabled { color: #8b9b96; }
.receiver-summary p { margin: 15px 0 0; color: #62736e; font-size: 11px; line-height: 1.7; }

/* Event stream */
.table-wrap { overflow-x: auto; border-top: 2px solid #435958; background: var(--surface); }
.events-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
.events-table th { height: 39px; padding: 9px 12px; border-bottom: 1px solid var(--line); color: #6a7976; font-size: 11px; font-weight: 600; text-align: left; }
.events-table th:nth-child(1) { width: 150px; }
.events-table th:nth-child(2) { width: 30%; }
.events-table th:nth-child(4) { width: 94px; }
.events-table th:nth-child(5) { width: 44px; }
.events-table td { padding: 12px; border-bottom: 1px solid #e9eeec; vertical-align: middle; line-height: 1.45; overflow-wrap: anywhere; }
.events-table tbody tr:hover:not(.detail-row) { background: #f8faf9; }
.event-title { font-weight: 700; color: var(--ink); }
.event-code { display: block; margin-top: 3px; color: #7d8a87; font-size: 10px; }
.event-location { color: #43514f; }
.event-time { color: #586865; font-variant-numeric: tabular-nums; }
.status-tag { display: inline-block; padding: 3px 6px; border-radius: 2px; color: #366a5e; background: #e9f4ef; font-size: 10px; white-space: nowrap; }
.status-tag.warn { color: #8a651b; background: #fff3da; }
.status-tag.bad { color: #a23737; background: #fdeceb; }
.detail-toggle { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 3px; background: #fff; color: #62726e; font-size: 16px; line-height: 1; }
.detail-toggle:hover { border-color: #7b9290; color: var(--ink); }
.detail-row td { padding: 0; background: #f2f6f4; }
.detail-content { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; padding: 15px 17px; border-bottom: 1px solid #dde6e2; }
.detail-content > div { min-width: 0; }
.detail-label { display: block; margin-bottom: 5px; color: #687b76; font-size: 10px; }
.detail-value { color: var(--ink); font-size: 11px; overflow-wrap: anywhere; }
.raw-hex { grid-column: 1 / -1; margin: 0; padding: 11px; overflow-x: auto; border: 1px solid #dbe5e0; background: #fff; color: #293b38; font-family: Consolas, "Courier New", monospace; font-size: 11px; line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; }
.empty-cell { height: 122px; color: var(--muted); text-align: center; }

/* Controls and audit */
.side-column { padding-left: 25px; border-left: 1px solid var(--line); }
.controls-section { padding-bottom: 25px; border-bottom: 1px solid var(--line); }
.control-explainer { min-height: 36px; margin: 4px 0 15px; color: #61716e; font-size: 12px; line-height: 1.6; }
.control-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.control-actions .button { width: 100%; }
.control-footnote { margin: 12px 0 0; color: #71807c; font-size: 11px; line-height: 1.6; }
.commands-section { margin-top: 25px; }
.commands-list { margin: 0; padding: 0; list-style: none; }
.commands-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 7px 10px; padding: 12px 0; border-top: 1px solid #e5eae8; font-size: 12px; }
.commands-list li:first-child { border-top: 2px solid #435958; }
.command-name { font-weight: 700; }
.command-time { display: block; margin-top: 4px; color: #74837f; font-size: 10px; font-variant-numeric: tabular-nums; }
.command-status { color: #6a7673; font-size: 11px; white-space: nowrap; }
.command-status.sent { color: var(--teal); }
.command-status.failed { color: var(--red); }
.empty-list { color: var(--muted); line-height: 1.6; }

/* Confirmation */
.confirm-dialog { width: min(100% - 32px, 440px); max-height: min(90vh, 620px); padding: 26px; border: 1px solid #b8c6c1; border-top: 3px solid var(--red); border-radius: 4px; background: #fff; box-shadow: 0 20px 60px #14292733; color: var(--ink); }
.confirm-dialog::backdrop { background: #101d1ccc; }
.confirm-dialog h2 { margin: 0; font-size: 20px; }
.dialog-description { margin: 14px 0 18px; color: #50625d; font-size: 13px; line-height: 1.7; }
.dialog-device { padding: 11px 13px; border: 1px solid #dbe5e0; background: #f7faf8; font-size: 12px; }
.dialog-device strong { margin-left: 8px; }
.confirm-check { display: flex; align-items: flex-start; gap: 9px; margin: 20px 0; font-size: 12px; line-height: 1.6; cursor: pointer; }
.confirm-check input { flex: none; width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--red); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; }

@media (max-width: 1000px) {
  .receiver-layout { grid-template-columns: 1fr; }
  .receiver-summary { border-top: 1px solid var(--line); border-left: 0; }
  .content-grid { grid-template-columns: minmax(0,1fr) 265px; gap: 19px; }
  .side-column { padding-left: 19px; }
  .status-primary, .status-cell { padding-left: 14px; padding-right: 14px; }
}
@media (max-width: 760px) {
  .receiver-fields { grid-template-columns: 1fr 1fr; }
  .receiver-field:nth-child(3) { grid-column: 1 / -1; }
  .topbar-inner, .workspace { width: min(100% - 32px, 620px); }
  .workspace { padding-top: 22px; }
  .page-heading { align-items: start; }
  .page-heading h1 { font-size: 21px; }
  .page-meta { max-width: 145px; }
  .meta-divider { display: none; }
  .meta-clock { display: block; }
  .status-cell strong { white-space: normal; overflow-wrap: anywhere; }
  .status-band { grid-template-columns: 1fr 1fr 42px; min-height: 0; }
  .status-primary { grid-column: 1 / 3; min-height: 73px; border-bottom: 1px solid var(--line); }
  .refresh-button { grid-column: 3; grid-row: 1; }
  .status-cell { min-height: 67px; padding: 11px 14px; border-top: 1px solid var(--line); }
  .status-cell:nth-child(2) { grid-column: 1; }
  .status-cell:nth-child(3) { grid-column: 2 / 4; border-right: 0; }
  .status-cell:nth-child(4) { grid-column: 1 / 4; border-right: 0; }
  .content-grid { display: block; margin-top: 27px; }
  .side-column { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 30px; padding: 0; border-left: 0; border-top: 1px solid var(--line); }
  .controls-section, .commands-section { margin-top: 19px; padding: 0; border-bottom: 0; }
}
@media (max-width: 560px) {
  .receiver-form { padding: 17px 15px; }
  .receiver-mode { display: grid; }
  .receiver-fields { display: block; }
  .receiver-field { margin-top: 12px; }
  .receiver-cidr-help { margin-top: 5px; }
  .receiver-summary { padding: 18px 15px; }
  .topbar-inner { min-height: 58px; }
  .identity-title { font-size: 12px; }
  .identity-sub { display: none; }
  .account { gap: 10px; }
  .account-name { max-width: 72px; }
  .page-heading { gap: 8px; }
  .page-meta { font-size: 10px; }
  .side-column { display: block; }
  .commands-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
  .events-table, .events-table tbody, .events-table tr, .events-table td { display: block; width: 100%; }
  .events-table thead { display: none; }
  .events-table tbody > tr:not(.detail-row) { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 5px 8px; position: relative; padding: 13px 42px 13px 12px; border-bottom: 1px solid var(--line); }
  .events-table tbody > tr:not(.detail-row) td { padding: 0; border: 0; }
  .events-table tbody > tr:not(.detail-row) td:nth-child(1) { grid-column: 1 / -1; grid-row: 1; font-size: 10px; }
  .events-table tbody > tr:not(.detail-row) td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .events-table tbody > tr:not(.detail-row) td:nth-child(3) { grid-column: 1; grid-row: 3; font-size: 11px; }
  .events-table tbody > tr:not(.detail-row) td:nth-child(4) { grid-column: 2; grid-row: 3; }
  .events-table tbody > tr:not(.detail-row) td:nth-child(5) { position: absolute; right: 10px; top: 17px; width: auto; }
  .events-table tbody > tr:not(.detail-row) td.empty-cell { grid-column: 1 / -1; height: auto; min-height: 90px; display: grid; place-items: center; }
  .detail-content { gap: 12px; padding: 13px; }
  .login-panel { padding: 27px 22px; }
}
@media (prefers-reduced-motion: reduce) { .button { transition: none; } }
.month-control { display: inline-flex; align-items: center; gap: 8px; color: #52635f; font-size: 12px; white-space: nowrap; }
.month-control input { min-height: 34px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: inherit; font: inherit; }
@media (max-width: 640px) { .month-control { width: 100%; margin-top: 8px; } }
