:root {
  --bg: #f7f8fa;
  --panel: #fff;
  --panel-2: #f1f4f5;
  --line: #dce2e5;
  --text: #19212f;
  --muted: #596574;
  --accent: #285cc4;
  --ok: #087653;
  --warn: #8b5900;
  --bad: #b43238;
  --radius: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
}

.hidden { display: none !important; }

.whoami { color: var(--muted); font-size: 12px; }

.privacy {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.app { padding: 20px; }
.app h1 { font-size: 20px; margin: 0 0 4px; }
.app h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 500; }
.subtitle { color: var(--muted); margin: 0 0 16px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card .k { color: var(--muted); font-size: 12px; }
.card .v { font-size: 24px; font-weight: 600; margin-top: 4px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
tbody tr:hover { background: var(--panel-2); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.pill.ONLINE, .pill.OK, .pill.ACKED { color: var(--ok); border-color: rgba(55,201,139,.5); }
.pill.DEGRADED, .pill.STALE, .pill.MAINTENANCE, .pill.PENDING { color: var(--warn); border-color: rgba(240,180,41,.5); }
.pill.OFFLINE, .pill.FAILED, .pill.DISABLED, .pill.FROZEN, .pill.RETIRED { color: var(--bad); border-color: rgba(239,91,91,.5); }

.btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--bad); border-color: rgba(239,91,91,.5); }
.btn.active { color: var(--ok); border-color: rgba(55,201,139,.6); }

.select {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
}
.select:focus { outline: 1px solid var(--accent); }
.btn.small { padding: 3px 9px; font-size: 12px; }

.row-actions { display: flex; gap: 6px; }

.error { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 18px; }

.empty { color: var(--muted); padding: 18px 0; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* ---- pairing QR -------------------------------------------------------- */
.pill.ACTIVE, .pill.RESOLVED, .pill.MANUFACTURED, .pill.QA_PASSED { color: var(--ok); border-color: rgba(55,201,139,.5); }
.pill.SHIPPED { color: var(--muted); }
.pill.REVOKED, .pill.RETIRED { color: var(--bad); border-color: rgba(239,91,91,.5); }
.pill.SUPERSEDED, .pill.LEGACY_UNRESOLVED, .pill.RMA { color: var(--warn); border-color: rgba(240,180,41,.5); }

.qr-cell { display: flex; flex-direction: column; gap: 6px; }
.qr-cell-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(24, 35, 43, .4);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow: auto; z-index: 50;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(560px, 100%); box-shadow: 0 24px 60px rgba(24, 39, 43, .16);
  display: flex; flex-direction: column;
  /* The backdrop pads 48px top and bottom, so cap to the remaining height. */
  max-height: calc(100vh - 96px);
}
@supports (height: 100dvh) {
  .modal { max-height: calc(100dvh - 96px); }
}
.modal.wide { width: min(920px, 100%); }
.modal-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 15px; }
.modal-body { flex: 1 1 auto; min-height: 0; padding: 16px 18px; overflow: auto; overflow-wrap: anywhere; }

.qr-grid { display: grid; grid-template-columns: 300px 1fr; gap: 20px; }
@media (max-width: 760px) { .qr-grid { grid-template-columns: 1fr; } }
.qr-visual { text-align: center; }
.qr-image {
  width: 100%; max-width: 300px; background: #fff; padding: 10px;
  border-radius: var(--radius); border: 1px solid var(--line);
}
.qr-caption { color: var(--muted); font-size: 12px; margin-top: 8px; }
.qr-meta { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.qr-meta .warn { margin: 0; color: var(--warn); font-size: 12px; line-height: 1.6; }
.qr-meta .hint, .hint { color: var(--muted); font-size: 12px; }
.qr-meta .countdown { margin: 0; font-size: 15px; font-weight: 600; color: var(--ok); }
.qr-meta .countdown.expired { color: var(--bad); }

table.kv { width: 100%; font-size: 13px; }
table.kv th {
  text-align: left; color: var(--muted); font-weight: 500; width: 130px;
  padding: 4px 8px 4px 0; vertical-align: top;
}
table.kv td { padding: 4px 0; word-break: break-all; }

.qr-payload-label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; }
.qr-payload-label textarea {
  width: 100%; box-sizing: border-box; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px; resize: vertical;
}
.qr-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- box status / remote operations ------------------------------------ */
.box-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
}
.input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px; font: inherit; font-size: 13px; min-width: 220px;
}
.input:focus { outline: 1px solid var(--accent); }
.remote-status { display: flex; flex-direction: column; gap: 10px; }
.remote-status .kv { margin: 0; }
.modal-body h3 {
  margin: 22px 0 8px; font-size: 14px; color: var(--text);
  padding-top: 16px; border-top: 1px solid var(--line);
}
.remote-form { display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.remote-form label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; }
.remote-form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.remote-fields { display: flex; flex-wrap: wrap; gap: 12px; }
.remote-fields.hidden { display: none; }
.remote-history { max-height: 260px; overflow: auto; }

.toast {
  position: fixed; right: 20px; bottom: 20px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  padding: 10px 14px; border-radius: var(--radius); max-width: 420px;
}
.toast.error { border-left-color: var(--bad); }

/* ---- small screens ------------------------------------------------------ */
@media (max-width: 720px) {
  .privacy { margin: 10px 12px 0; }
  .app { padding: 12px; }
  .modal-backdrop { padding: 16px 10px; }
  .modal { max-height: calc(100vh - 32px); }
  .toast { right: 12px; left: 12px; bottom: 12px; max-width: none; }
}
@supports (height: 100dvh) {
  @media (max-width: 720px) {
    .modal { max-height: calc(100dvh - 32px); }
  }
}
.card-form { display:flex; flex-wrap:wrap; align-items:end; gap:12px; margin:16px 0; }
.card-form label { display:flex; flex-direction:column; gap:6px; min-width:180px; }
.card-form .card-check { flex-direction:row; align-items:center; }
.card-form input,.card-form select { padding:8px; max-width:100%; }
.cards-page pre { overflow:auto; white-space:pre-wrap; }


/* Shared device artwork and companion */
:root { color-scheme: light; --ink: #192527; --mint: #deeee6; --rail: 212px; }
button, input, select { font-family: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #3268e8; outline-offset: 3px;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); font-size: 21px; font-weight: 750; letter-spacing: -.045em; }
.brand small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: .035em; }
.brand-mark {
  display: inline-grid; place-items: center; width: 39px; height: 39px; flex: none;
  background: #20332d; border-radius: 13px; overflow: hidden;
}
.brand-mark i { width: 4px; height: 16px; background: #d5f1e2; transform: skew(-18deg); box-shadow: -7px 3px #d5f1e2, 7px -3px #d5f1e2; border-radius: 2px; }
.eyebrow, .product-caption { font: 600 11px/1.3 ui-monospace, Consolas, monospace; letter-spacing: .14em; }
.eyebrow { color: #506860; }
.device-scene { position: relative; isolation: isolate; }
.hardware { width: 80%; position: absolute; left: 10%; bottom: 14%; }
.hardware img { position: relative; display: block; width: 100%; height: auto; filter: drop-shadow(0 17px 12px #405f4c30); }
.orbit {
  position: absolute; inset: 0; opacity: .85;
  background: repeating-radial-gradient(ellipse at 62% 76%, transparent 0 47px, #53856a27 48px, transparent 49px 81px);
  mask-image: linear-gradient(145deg, transparent 6%, #000 57%);
}
.companion, .mini-bot {
  display: inline-flex; justify-content: center; align-items: center;
  background: radial-gradient(circle at 33% 24%, #e0f7e9, #b5e4ce 55%, #85c6ac);
  border-radius: 48% 52% 46% 50%; color: #234d44;
}
.companion { width: 18%; aspect-ratio: 1; gap: 13%; position: absolute; bottom: 95%; left: 62%; box-shadow: inset -4px -5px 12px #43785a19, 0 6px 4px #34553f1a; animation: bob 5s ease-in-out infinite; }
.companion i, .mini-bot::before, .mini-bot::after { content: ""; width: 10%; height: 21%; border-radius: 8px; background: currentColor; }
.companion i { animation: blink 5s infinite; }
.companion i + i { height: 26%; }
.entry:has(#password:focus) .companion i { height: 4%; animation: none; }
.entry:has(#username:focus) .companion { rotate: 6deg; }
.mini-bot { width: 26px; height: 26px; gap: 3px; flex: none; }
@keyframes bob { 50% { transform: translateY(-4%) rotate(-5deg); } }
@keyframes blink { 0%, 47%, 51%, 100% { transform: scaleY(1); } 49% { transform: scaleY(.12); } }
@media (prefers-reduced-motion: reduce) { .companion, .companion i { animation: none; } }
.guide-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; border: 1px solid #dae3dd; border-radius: 24px; background: white; padding: 7px 14px 7px 8px; color: #274237; font-size: 13px; font-weight: 600; cursor: pointer; }
.guide-button:hover { background: #eff8f3; }

/* Staff sign-in */
.app:has(.entry) { padding: 0; }
.entry { width: min(1232px, calc(100% - 96px)); margin: 0 auto; }
.entry-head { display: flex; align-items: center; justify-content: space-between; padding: 28px 0; border-bottom: 1px solid var(--line); }
.entry-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 22px; margin: clamp(30px, 8vh, 100px) 0 40px; }
.product, .login { border-radius: 28px; overflow: hidden; }
.product { min-height: 480px; position: relative; background: linear-gradient(135deg, #f0f6ee, #deeee4 51%, #c3dfcf); border: 1px solid #cedfd2; }
.product-title { position: relative; z-index: 1; padding: clamp(26px, 3.3vw, 50px); pointer-events: none; }
.product-title .eyebrow { color: #304f42; }
.product-title h2 { margin: 9px 0 0; color: #243c31; font-weight: 650; font-size: clamp(40px, 4vw, 64px); letter-spacing: -.045em; line-height: 1.18; }
.product .device-scene { position: absolute; inset: 0; }
.product .hardware { bottom: 17%; }
.product-caption { position: absolute; left: 7%; right: 7%; bottom: 6%; border-top: 1px solid #668f7652; padding-top: 12px; display: flex; justify-content: space-between; color: #476051; font-size: 10px; }
.login { display: flex; flex-direction: column; justify-content: center; background: white; border: 1px solid var(--line); padding: clamp(28px, 4vw, 62px); }
.login h1 { font-size: clamp(30px, 3vw, 42px); letter-spacing: -.045em; margin: 12px 0 8px; line-height: 1.25; }
.login .subtitle { margin: 0 0 26px; }
.login label { font-size: 13px; font-weight: 650; margin: 0 0 7px; }
.login input { background: #f7f8fa; color: var(--text); border: 1px solid #d9dfe2; border-radius: 12px; height: 47px; padding: 0 14px; font-size: 15px; min-width: 0; }
.login input + label { margin-top: 19px; }
.login input:focus { background: white; }
.login .error { min-height: 0; margin: 0; }
.login .error:not(:empty) { margin-top: 10px; }
.enter { margin-top: 24px; padding: 13px 18px; display: flex; align-items: center; justify-content: space-between; font-weight: 650; font-size: 15px; background: var(--ink); border-radius: 13px; }
.enter span { font-size: 20px; line-height: 1; }
.enter:disabled { opacity: .65; cursor: wait; }
.audit-note { color: var(--muted); font-size: 12px; margin-top: 17px; }

/* Signed-in workspace */
.topbar { position: fixed; inset: 0 auto 0 0; width: var(--rail); background: white; border-right: 1px solid var(--line); z-index: 5; padding: 24px 16px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; }
.topbar .brand { padding: 0 8px; }
.topbar .guide-button { margin-top: auto; align-self: start; }
.nav { display: grid; gap: 17px; }
.nav-group { display: grid; gap: 2px; }
.nav-label { padding: 0 12px 5px; font-size: 11px; font-weight: 600; color: #697586; }
.nav button { background: transparent; border: 0; border-radius: 10px; padding: 8px 12px; text-align: left; cursor: pointer; font-size: 14px; color: #45505a; }
.nav button:hover { background: var(--panel-2); }
.nav button.active { background: var(--mint); color: #204d39; font-weight: 700; }
.topbar:not(.hidden) + .workspace { margin-left: var(--rail); padding: 0 clamp(16px, 3.3vw, 60px) 24px; }
.session { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.workspace > .app:not(:has(.entry)) { padding: 24px 0 0; }
.workspace:has(.hidden.session) > .app:not(:has(.entry)) { padding: 24px; }
.overview-cover { display: flex; justify-content: space-between; align-items: center; overflow: hidden; position: relative; min-height: 156px; background: linear-gradient(110deg, #edf5ef, #cce5d4); border: 1px solid #d4e2d8; border-radius: 23px; margin: 0 0 20px; padding: 22px 4%; }
.overview-cover > div:first-child { z-index: 1; }
.overview-cover h1 { font-size: 30px; margin: 6px 0; }
.overview-cover .subtitle { margin: 0; }
.overview-cover .device-scene { align-self: stretch; width: 35%; max-width: 260px; }
.overview-cover .hardware { bottom: 0; }
.overview-cover .orbit { inset: -50px; }
.cards { grid-template-columns: repeat(auto-fit,minmax(min(150px,100%),1fr)); }
.card, .panel { padding: 18px; }
.panel h2 { color: var(--text); font-weight: 650; }
th { background: #f6f8f8; }
.privacy { margin: 4px 0; background: transparent; border: 0; padding: 4px 0; }
.guide-intro, .guide-query { display: flex; align-items: center; gap: 10px; }
.guide-query input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); padding: 10px; border-radius: 10px; color: var(--text); }
.guide-results { margin-top: 15px; }
.guide-results button { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 10px 6px; text-align: left; color: var(--ink); background: white; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.guide-results button:hover { background: #eff7f2; }
.guide-results small { display: block; margin-top: 2px; color: var(--muted); }
.toast { z-index: 60; }
@media (min-width: 1600px) { .entry-grid { margin-top: 12vh; } }
@media (max-width: 920px) {
  .entry { width: calc(100% - 40px); }
  .entry-grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .topbar { position: static; width: auto; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
  .topbar .brand { padding: 0; font-size: 17px; }
  .topbar .guide-button { margin: 0 0 0 auto; }
  .nav { order: 3; display: flex; width: 100%; overflow-x: auto; gap: 8px; }
  .nav-group { display: flex; flex: none; }
  .nav-label { display: none; }
  .nav button { white-space: nowrap; }
  .topbar:not(.hidden) + .workspace { margin: 0; padding: 0 16px 18px; }
}
@media (max-width: 680px) {
  .entry { width: min(100% - 28px, 500px); }
  .entry-head { padding: 14px 0; }
  .entry-grid { grid-template-columns: 1fr; gap: 12px; margin: 15px 0 24px; }
  .product, .login { border-radius: 22px; }
  .product { min-height: 0; height: clamp(146px, 42vw, 194px); }
  .product-title { padding: 17px; }
  .product-title h2 { font-size: 31px; }
  .product .hardware { width: 52%; left: auto; right: 6%; bottom: 14%; }
  .product-caption { left: 18px; right: auto; bottom: 17px; border: 0; padding: 0; }
  .product-caption span + span { display: none; }
  .login { padding: 24px; }
  .login .subtitle { margin-bottom: 19px; }
  .session { justify-content: flex-start; }
  .overview-cover { min-height: 145px; padding: 16px; }
  .overview-cover h1 { font-size: 25px; }
  .overview-cover .subtitle { max-width: 16em; font-size: 12px; }
  .overview-cover .device-scene { min-width: 84px; }
  .overview-cover .hardware { bottom: 16%; width: 100%; left: 0; }
}
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 14px; margin-bottom: 18px; }
.summary-grid .summary { margin: 0; }
.summary dl { margin: 6px 0 0; }
.summary dl > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding: 9px 0; }
.summary dl > div:last-child { padding-bottom: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.account-link { display: inline-block; color: #285cc4; border-radius: 6px; padding: 5px; text-decoration: none; }
.account-link:hover { text-decoration: underline; }
.account-settings { max-width: 620px; margin-inline: auto; }
.settings-head, .settings-account-head, .settings-account dl > div { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.settings-head { margin: 3px 2px 22px; }
.settings-head h1 { margin: 5px 0 0; font-size: 34px; line-height: 1.2; }
.settings-brand { font-weight: 700; letter-spacing: .12em; text-align: right; }
.settings-brand small { display: block; color: var(--muted); font: 10px/1.6 ui-monospace, Consolas, monospace; letter-spacing: .2em; }
.settings-device, .settings-account, .settings-logout { border: 1px solid var(--line); border-radius: 22px; background: white; }
.settings-device { display: flex; align-items: center; gap: clamp(16px,4vw,30px); padding: 23px; }
.settings-device img { width: 31%; height: auto; }
.settings-device p { color: var(--muted); margin: 3px 0 8px; }
.settings-device a { color: var(--accent); text-decoration: none; }
.account-settings h2 { margin: 0; font-weight: 680; font-size: 18px; color: var(--text); }
.settings-account { padding: 20px 22px 8px; margin-top: 14px; }
.settings-account-head span { color: #176647; background: #e9f5ee; font-size: 12px; border-radius: 20px; padding: 3px 10px; white-space: nowrap; }
.settings-account dl { margin: 12px 0 0; }
.settings-account dl > div { border-top: 1px solid var(--line); padding: 11px 0; }
.settings-account dt { color: var(--muted); flex: none; }
.settings-account dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; min-width: 0; }
.settings-logout { width: 100%; padding: 13px; margin: 12px 0 20px; color: var(--ink); font-size: 15px; font-weight: 650; cursor: pointer; }
.settings-logout:hover { background: #f0f4f2; }
.workspace:has(.account-settings) #logout { display: none; }
