:root {
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --canvas: #f5f7fa;
  --surface: #ffffff;
  --nav: #101828;
  --blue: #155eef;
  --blue-soft: #eff4ff;
  --green: #067647;
  --green-soft: #ecfdf3;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --red: #b42318;
  --red-soft: #fef3f2;
  --shadow: 0 18px 45px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(21, 94, 239, .26); outline-offset: 2px; }
[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; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(circle at 20% 15%, rgba(21, 94, 239, .24), transparent 30%),
    radial-gradient(circle at 82% 85%, rgba(18, 183, 106, .16), transparent 28%),
    #0b1220;
}
.login-card { width: min(470px, 100%); padding: 44px; border-radius: 24px; background: rgba(255,255,255,.98); box-shadow: 0 32px 90px rgba(0,0,0,.34); }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 15px; color: white; font-weight: 800; letter-spacing: -.04em; background: linear-gradient(145deg, #2970ff, #0040c1); box-shadow: 0 10px 25px rgba(21, 94, 239, .28); }
.brand-mark.small { width: 42px; height: 42px; border-radius: 12px; font-size: 14px; box-shadow: none; }
.eyebrow, .section-kicker { margin: 20px 0 7px; font-size: 11px; line-height: 1; font-weight: 800; letter-spacing: .15em; color: var(--blue); }
.section-kicker { margin-top: 0; }
.section-kicker.danger { color: var(--red); }
.login-card h1 { margin: 0; font-size: 32px; letter-spacing: -.04em; }
.login-copy { margin: 12px 0 28px; color: var(--muted); line-height: 1.65; }
label { display: block; margin: 16px 0 8px; font-size: 13px; font-weight: 700; color: #344054; }
input, textarea, select { width: 100%; border: 1px solid #d0d5dd; border-radius: 10px; padding: 11px 13px; background: white; color: var(--ink); transition: border .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { border-color: #84adff; box-shadow: 0 0 0 4px #eff4ff; outline: 0; }
.token-field { position: relative; }
.token-field input { padding-right: 74px; }
.icon-button { position: absolute; right: 5px; top: 5px; height: calc(100% - 10px); padding: 0 12px; border: 0; border-radius: 7px; color: var(--blue); background: #eff4ff; font-weight: 700; }
.primary-button, .secondary-button, .danger-button { min-height: 40px; padding: 9px 15px; border-radius: 9px; border: 1px solid transparent; font-weight: 750; transition: transform .15s, box-shadow .15s, background .15s; }
.primary-button { color: white; background: var(--blue); box-shadow: 0 4px 12px rgba(21, 94, 239, .2); }
.primary-button:hover { background: #004eeb; transform: translateY(-1px); }
.secondary-button { color: #344054; background: white; border-color: #d0d5dd; }
.secondary-button:hover { background: #f9fafb; }
.danger-button { color: white; background: var(--red); }
.danger-button:hover { background: #912018; }
.wide { width: 100%; margin-top: 18px; }
.security-note { display: flex; gap: 9px; align-items: flex-start; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.55; }
.status-dot { width: 8px; height: 8px; flex: 0 0 8px; margin-top: 5px; border-radius: 50%; background: #98a2b3; box-shadow: 0 0 0 4px rgba(152,162,179,.12); }
.status-dot.online, .status-dot.secure { background: #12b76a; box-shadow: 0 0 0 4px rgba(18,183,106,.12); }
.status-dot.error { background: #f04438; box-shadow: 0 0 0 4px rgba(240,68,56,.12); }
.field-error { min-height: 18px; margin: 7px 0 0; color: var(--red); font-size: 12px; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; width: 244px; display: flex; flex-direction: column; padding: 24px 16px; color: white; background: var(--nav); }
.brand-row { display: flex; gap: 12px; align-items: center; padding: 0 8px 26px; border-bottom: 1px solid rgba(255,255,255,.09); }
.brand-row strong, .brand-row span { display: block; }
.brand-row strong { font-size: 14px; letter-spacing: .08em; }
.brand-row span { margin-top: 3px; color: #98a2b3; font-size: 12px; }
nav { display: grid; gap: 5px; margin-top: 22px; }
.nav-item { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 9px; color: #98a2b3; text-decoration: none; }
.nav-item span { font-size: 10px; font-variant-numeric: tabular-nums; opacity: .66; }
.nav-item b { font-size: 13px; font-weight: 650; }
.nav-item em { min-width: 20px; padding: 2px 6px; border-radius: 999px; color: white; background: var(--red); font-size: 10px; font-style: normal; text-align: center; }
.nav-item:hover, .nav-item.active { color: white; background: rgba(255,255,255,.08); }
.sidebar-footer { margin-top: auto; padding: 18px 8px 0; border-top: 1px solid rgba(255,255,255,.09); }
.mode-chip { display: inline-flex; padding: 5px 8px; border-radius: 6px; color: #b2ddff; background: rgba(46,144,250,.13); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.text-button { display: block; margin-top: 14px; padding: 0; border: 0; color: #98a2b3; background: transparent; font-size: 12px; }
.text-button:hover { color: white; }

main { margin-left: 244px; }
.topbar { position: sticky; top: 0; z-index: 8; min-height: 88px; display: flex; align-items: center; justify-content: space-between; padding: 16px 34px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.93); backdrop-filter: blur(18px); }
.topbar .eyebrow { margin: 0 0 5px; }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -.025em; }
.top-actions { display: flex; gap: 9px; align-items: center; }
.health-pill { display: flex; gap: 9px; align-items: center; min-height: 40px; padding: 0 13px; border: 1px solid var(--line); border-radius: 9px; background: white; color: #344054; font-size: 12px; font-weight: 650; }
.content { max-width: 1440px; margin: 0 auto; padding: 34px; }
.section-block { scroll-margin-top: 110px; margin-bottom: 52px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; }
.section-heading.compact { align-items: center; }
.section-heading h2 { margin: 0; font-size: 24px; letter-spacing: -.035em; }
.updated-at { margin: 0; color: var(--muted); font-size: 12px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.metric-card { position: relative; min-height: 142px; padding: 20px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 1px 2px rgba(16,24,40,.03); }
.metric-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.metric-card::after { content: ""; position: absolute; width: 90px; height: 90px; right: -32px; top: -42px; border-radius: 50%; background: var(--soft); }
.accent-blue { --accent: var(--blue); --soft: var(--blue-soft); }
.accent-amber { --accent: #f79009; --soft: var(--amber-soft); }
.accent-red { --accent: #f04438; --soft: var(--red-soft); }
.accent-green { --accent: #12b76a; --soft: var(--green-soft); }
.metric-label { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-card strong { display: block; margin: 15px 0 4px; font-size: 36px; line-height: 1; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.metric-card small { color: var(--muted); font-size: 11px; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 14px; margin-top: 14px; }
.panel, .table-card { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 1px 2px rgba(16,24,40,.03); }
.panel { padding: 22px; }
.panel-heading { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.panel-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.panel h3 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.volume-badge { padding: 4px 8px; border-radius: 6px; color: var(--blue); background: var(--blue-soft); font-size: 11px; font-weight: 750; }
.capacity-track { height: 10px; margin-top: 30px; overflow: hidden; border-radius: 99px; background: #eaecf0; }
.capacity-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #155eef, #53b1fd); transition: width .4s ease; }
.capacity-track span.warning { background: linear-gradient(90deg, #f79009, #fdb022); }
.capacity-track span.critical { background: linear-gradient(90deg, #d92d20, #f97066); }
.capacity-labels { display: flex; justify-content: space-between; margin-top: 9px; color: var(--muted); font-size: 11px; }
.panel-note { margin: 23px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.55; }
.event-list { display: grid; gap: 14px; margin-top: 18px; }
.event-item { display: grid; grid-template-columns: 9px 1fr auto; gap: 11px; align-items: start; }
.event-marker { width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: #98a2b3; }
.event-marker.danger { background: #f04438; }
.event-marker.success { background: #12b76a; }
.event-body strong { display: block; font-size: 12px; }
.event-body span { display: block; max-width: 520px; margin-top: 3px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-time { color: #98a2b3; font-size: 10px; white-space: nowrap; }

.recovery-banner { margin-bottom: 14px; padding: 15px 17px; border: 1px solid #fecdca; border-radius: 12px; color: #7a271a; background: var(--red-soft); font-size: 13px; line-height: 1.55; }
.recovery-banner.ok { border-color: #abefc6; color: #05603a; background: var(--green-soft); }
.recovery-list { display: grid; gap: 12px; }
.recovery-card { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; padding: 20px; border: 1px solid #fecdca; border-left: 4px solid #f04438; border-radius: 12px; background: white; }
.recovery-card h3 { margin: 0 0 7px; font-size: 15px; }
.recovery-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted); font-size: 11px; }

.search-field { margin: 0; }
.search-field input { width: 270px; padding-left: 36px; background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23667085' stroke-width='1.7'%3E%3Ccircle cx='7' cy='7' r='4.5'/%3E%3Cpath d='m10.5 10.5 4 4'/%3E%3C/svg%3E") no-repeat 12px center; }
.table-card { overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 16px; color: var(--muted); background: #f9fafb; font-size: 10px; font-weight: 750; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
td { padding: 14px 16px; border-top: 1px solid var(--line); color: #344054; font-size: 12px; vertical-align: middle; }
td strong { color: var(--ink); }
.mono { font-family: Consolas, "SFMono-Regular", monospace; font-size: 11px; }
.subtle { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.state-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 99px; color: #344054; background: #f2f4f7; font-size: 10px; font-weight: 750; white-space: nowrap; }
.state-badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: #98a2b3; }
.state-badge.active { color: #175cd3; background: var(--blue-soft); }
.state-badge.active::before { background: #2e90fa; }
.state-badge.success { color: var(--green); background: var(--green-soft); }
.state-badge.success::before { background: #12b76a; }
.state-badge.danger { color: var(--red); background: var(--red-soft); }
.state-badge.danger::before { background: #f04438; }
.state-badge.muted { color: #475467; background: #f2f4f7; }
.empty-state { padding: 44px 20px; color: var(--muted); text-align: center; }

.catalog-state { padding: 6px 9px; border-radius: 7px; color: var(--green); background: var(--green-soft); font-size: 11px; font-weight: 700; }
.catalog-state.error { color: var(--red); background: var(--red-soft); }
.catalog-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.firmware-card { padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.firmware-card.default { border-color: #b2ccff; box-shadow: inset 0 0 0 1px #d1e0ff; }
.firmware-card-header { display: flex; justify-content: space-between; gap: 12px; }
.firmware-card h3 { margin: 0; font-size: 15px; }
.firmware-card .package-id { margin: 5px 0 0; color: var(--muted); font-size: 10px; font-family: Consolas, monospace; }
.default-badge { align-self: flex-start; padding: 4px 7px; border-radius: 6px; color: var(--blue); background: var(--blue-soft); font-size: 9px; font-weight: 800; }
.file-row { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; margin-top: 17px; padding-top: 14px; border-top: 1px solid var(--line); }
.file-role { color: var(--muted); font-size: 10px; font-weight: 800; }
.file-name { min-width: 0; }
.file-name strong, .file-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name strong { font-size: 11px; }
.file-name span { margin-top: 3px; color: var(--muted); font-size: 9px; }
.file-ready { color: var(--green); font-size: 10px; font-weight: 750; }
.file-ready.missing { color: var(--red); }
.enrollment-panel { display: flex; justify-content: space-between; gap: 30px; align-items: center; }
.enrollment-panel p { max-width: 680px; margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.activation-form { display: grid; grid-template-columns: minmax(180px, 1.2fr) 130px 130px minmax(190px, 1fr) auto; gap: 14px; align-items: end; margin-bottom: 14px; }
.activation-form label { margin: 0; }
.activation-form label span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; }
.activation-form input, .activation-form select { min-height: 40px; padding: 8px 10px; }
.activation-table-card table { min-width: 1050px; }
.activation-table-card { overflow-x: auto; }

dialog { width: min(560px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 30px 90px rgba(16,24,40,.28); }
dialog::backdrop { background: rgba(16,24,40,.58); backdrop-filter: blur(4px); }
.dialog-card { padding: 28px; }
.dialog-card h2 { margin: 16px 0 8px; font-size: 21px; }
.dialog-card > p { margin: 0 0 20px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.dialog-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; font-weight: 850; }
.dialog-icon.success { color: var(--green); background: var(--green-soft); }
.dialog-icon.warning { color: var(--red); background: var(--red-soft); }
.copy-field { display: grid; grid-template-columns: 1fr auto; overflow: hidden; border: 1px solid #b2ccff; border-radius: 10px; background: #f5f8ff; }
.copy-field code { padding: 13px; overflow: auto; color: #1849a9; font-size: 12px; white-space: nowrap; }
.copy-field button { border: 0; border-left: 1px solid #b2ccff; padding: 0 16px; color: var(--blue); background: transparent; font-weight: 750; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 24px; }
.review-details { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; border-radius: 10px; background: #f9fafb; }
.review-details div { min-width: 0; }
.review-details dt { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.review-details dd { margin: 4px 0 0; overflow: hidden; color: #344054; font: 10px Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 30; max-width: 380px; padding: 12px 16px; border-radius: 10px; color: white; background: #101828; box-shadow: var(--shadow); font-size: 12px; transform: translateY(30px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #7a271a; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar { position: static; width: auto; padding: 14px; }
  .brand-row { padding-bottom: 14px; }
  .sidebar nav { display: flex; overflow-x: auto; margin-top: 12px; }
  .nav-item { grid-template-columns: auto; min-width: max-content; padding: 0 12px; }
  .nav-item span, .nav-item em, .sidebar-footer { display: none; }
  main { margin-left: 0; }
  .topbar { min-height: auto; padding: 14px 18px; }
  .topbar h1 { font-size: 17px; }
  .health-pill { display: none; }
  .content { padding: 24px 16px; }
  .metric-grid, .catalog-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; gap: 16px; }
  .section-heading.compact { flex-direction: column; align-items: stretch; }
  .search-field input { width: 100%; }
  .table-card { overflow-x: auto; }
  table { min-width: 760px; }
  .recovery-card, .enrollment-panel { grid-template-columns: 1fr; display: grid; }
  .activation-form { grid-template-columns: 1fr; }
  .enrollment-panel .primary-button { width: 100%; }
  .login-card { padding: 30px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
