:root {
  color-scheme: light;
  --accent: #2f94f8;
  --accent-dark: #2385e5;
  --ink: #191919;
  --muted: #6b6b66;
  --line: #deded8;
  --soft-line: #ecece7;
  --surface: #ffffff;
  --canvas: #f3f3ef;
  --control: #f8f8f5;
  --warning: #9a6700;
  --radius: 6px;
  font-family: "Microsoft YaHei UI", "PingFang SC", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font-size: 14px; letter-spacing: 0; }
body.is-auth-locked > .topbar,
body.is-auth-locked > .app-shell,
body.is-auth-locked > .mobile-nav { display: none; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(18px, calc((100vw - 1440px) / 2));
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
}

.brand-block, .top-actions, .panel-heading, .row-actions, .queue-commands, .dialog-heading { display: flex; align-items: center; }
.brand-block { gap: 10px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; background: var(--accent); color: #fff; font-weight: 800; border-radius: 4px; }
.brand-block h1 { margin: 0; font-size: 17px; line-height: 1.2; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.top-actions { gap: 8px; }
.license-command { min-height: 34px; padding: 0 10px; color: var(--accent); border-color: rgba(47, 148, 248, .45); }
.status-dot { display: flex; align-items: center; gap: 6px; margin-right: 6px; color: var(--muted); font-size: 12px; }
.status-dot i { width: 8px; height: 8px; border-radius: 50%; background: #c28a00; }
.status-dot.is-online i { background: #21844a; }
.status-dot.is-browser i { background: var(--accent); }
.status-dot.is-offline i { background: var(--accent); }

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 16px 18px 30px;
  display: grid;
  grid-template-columns: minmax(350px, 430px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.editor-panel { padding: 18px; }
.preview-panel { position: sticky; top: 80px; overflow: hidden; }
.queue-panel { grid-column: 1 / -1; overflow: hidden; }
.panel-heading { justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.preview-heading, .queue-panel > .panel-heading { padding: 17px 18px 0; }
.panel-heading h2 { margin: 2px 0 0; font-size: 18px; line-height: 1.25; }
.eyebrow { color: var(--accent); font-weight: 700; font-size: 11px; }
.row-actions, .queue-commands { gap: 6px; }

button {
  min-height: 38px;
  padding: 0 13px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #cfcfca;
  border-radius: 5px;
  font-weight: 650;
}
button:hover { border-color: #999994; background: var(--control); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid rgba(47, 148, 248, .22); outline-offset: 1px; }
button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
.icon-button, .icon-command { display: grid; place-items: center; width: 38px; padding: 0; font-size: 20px; font-weight: 500; }
.icon-command { width: 34px; min-height: 34px; }
.danger { color: var(--accent); }
.wide-command { width: 100%; margin-top: 18px; }
.wide-command span { font-size: 18px; margin-right: 4px; }

.field { min-width: 0; margin-bottom: 14px; }
.field label, .field-label, dialog > form > label { display: block; margin-bottom: 6px; color: #4d4d49; font-size: 12px; font-weight: 650; }
.full-field textarea { width: 100%; min-height: 78px; resize: vertical; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #cfcfca;
  border-radius: 5px;
}
textarea { line-height: 1.55; }
select { appearance: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
.span-2 { grid-column: span 2; }
.unit-input { position: relative; display: flex; align-items: center; }
.unit-input input { padding-right: 44px; }
.unit-input span { position: absolute; right: 10px; color: var(--muted); font-size: 11px; pointer-events: none; }
.segmented { display: grid; grid-template-columns: repeat(2, 1fr); padding: 3px; background: #ededE8; border-radius: 6px; }
.segmented button { min-height: 34px; border: 0; background: transparent; }
.segmented button.is-selected { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented.compact { grid-template-columns: repeat(3, 1fr); }
.preset-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.preset-strip button { min-height: 40px; padding: 0; font-weight: 600; }
.preset-strip button::after { content: "cm"; display: inline; margin-left: 2px; color: var(--muted); font-size: 9px; }
.preset-strip button.is-selected { color: var(--accent); border-color: var(--accent); background: #edf6ff; }

.advanced { margin: 0 -18px; padding: 0 18px; border-top: 1px solid var(--soft-line); border-bottom: 1px solid var(--soft-line); }
.advanced summary { padding: 13px 0; font-size: 12px; font-weight: 700; cursor: pointer; }
.details-grid { padding-top: 4px; }
.color-section { padding-top: 15px; }
.section-label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.section-label-row .field-label { margin: 0; }
.section-label-row span:last-child { color: var(--muted); font-size: 11px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button, .custom-color { position: relative; width: 42px; height: 42px; min-height: 42px; padding: 4px; border: 1px solid var(--line); border-radius: 5px; background: #fff; overflow: hidden; }
.swatches button i { display: block; width: 100%; height: 100%; border-radius: 3px; background: linear-gradient(135deg, var(--bg) 0 58%, var(--fg) 59% 100%); }
.custom-color { display: grid; place-items: center; cursor: pointer; font-size: 11px; font-weight: 800; }
.custom-color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.preview-stage {
  position: relative;
  height: clamp(330px, 48vh, 560px);
  display: grid;
  place-items: center;
  overflow: hidden;
  margin: 0 18px;
  padding: 22px;
  border: 1px solid var(--line);
  background-color: #e9e9e4;
  background-image: linear-gradient(45deg, #ddd 25%, transparent 25%), linear-gradient(-45deg, #ddd 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ddd 75%), linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.preview-stage img { position: absolute; inset: 22px; width: calc(100% - 44px); height: calc(100% - 44px); object-fit: contain; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .2)); }
.preview-loading { position: absolute; z-index: 2; color: var(--muted); background: rgba(255,255,255,.88); padding: 8px 12px; border-radius: 4px; }
.measurement-strip { display: grid; grid-template-columns: repeat(3, 1fr); margin: 16px 18px 0; border-top: 1px solid var(--soft-line); border-bottom: 1px solid var(--soft-line); }
.measurement-strip div { padding: 12px; border-right: 1px solid var(--soft-line); }
.measurement-strip div:last-child { border: 0; }
.measurement-strip span, .summary-bar span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.measurement-strip strong { font-size: 14px; }
.warning { margin: 12px 18px 0; padding: 9px 10px; color: var(--warning); background: #fff8dc; border-left: 3px solid #d7a900; font-size: 12px; }
.export-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 18px; }
.export-options, .export-actions { display: flex; align-items: center; gap: 12px; }
.export-options label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.export-options input { width: 16px; min-height: 16px; }

.queue-list { min-height: 90px; }
.queue-item { display: grid; grid-template-columns: 38px 50px minmax(220px, 1fr) 100px 110px 110px; align-items: center; min-height: 58px; padding: 7px 18px; border-top: 1px solid var(--soft-line); cursor: pointer; }
.queue-item:hover { background: #fafaf7; }
.queue-item.is-current { background: #edf6ff; box-shadow: inset 3px 0 var(--accent); }
.queue-item input[type="checkbox"] { width: 17px; min-height: 17px; }
.queue-index { color: var(--muted); font-variant-numeric: tabular-nums; }
.queue-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.queue-meta { color: var(--muted); font-size: 12px; text-align: right; }
.queue-empty { padding: 28px; color: var(--muted); text-align: center; }
.summary-bar { display: grid; grid-template-columns: 130px 140px minmax(190px, 240px) 1fr; align-items: end; gap: 18px; padding: 14px 18px; border-top: 1px solid var(--line); background: #fafaf7; }
.summary-bar strong { font-size: 16px; }
.price-field { margin-left: auto; }
.price-field > span { font-weight: 650; }
.price-field input { min-height: 36px; }
.total-amount { text-align: right; }
.total-amount strong { color: var(--accent); font-size: 22px; }
.batch-export { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--soft-line); }

.mobile-nav { display: none; }
.auth-gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background: #ecece7;
}
.auth-shell { width: min(920px, 100%); display: grid; grid-template-columns: minmax(240px, .82fr) minmax(360px, 1.18fr); background: #fff; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; box-shadow: 0 24px 70px rgba(0, 0, 0, .14); }
.auth-brand { display: flex; align-items: flex-start; gap: 12px; min-height: 480px; padding: 34px; color: #fff; background: var(--accent); }
.auth-brand .brand-mark { color: var(--accent); background: #fff; }
.auth-brand h1 { margin: 3px 0 0; font-size: 24px; }
.auth-brand p { margin: 7px 0 0; color: rgba(255,255,255,.82); }
.auth-content { align-self: center; padding: 42px; }
.auth-content h2 { margin: 5px 0 10px; font-size: 26px; }
.auth-lead { margin: 0 0 24px; color: var(--muted); line-height: 1.7; }
.auth-code-field { display: block; margin-bottom: 7px; color: #4d4d49; font-size: 12px; font-weight: 700; }
.activation-code { font-family: Consolas, monospace; font-size: 16px; text-transform: uppercase; }
.auth-error { margin: 9px 0 0; color: #a52a2a; font-size: 12px; }
.auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.device-row { display: flex; justify-content: space-between; gap: 14px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--soft-line); color: var(--muted); font-size: 11px; }
.device-row code { overflow-wrap: anywhere; color: var(--ink); text-align: right; }
.binding-note { margin: 12px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.purchase-dialog { width: min(760px, calc(100vw - 28px)); }
.license-summary { margin: -4px 0 16px; padding: 10px 12px; color: #225638; background: #edf8f0; border-left: 3px solid #21844a; font-size: 12px; }
.license-summary.is-expired { color: #8b4d00; background: #fff7e6; border-left-color: #c98000; }
.required-email { margin-bottom: 14px; padding: 12px; background: #f7f7f3; border: 1px solid var(--soft-line); }
.required-email > label { display: block; margin-bottom: 7px; color: #4d4d49; font-size: 12px; font-weight: 700; }
.required-email > div { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.required-email input { min-width: 0; }
.required-email .auth-error { margin-bottom: 0; }
.purchase-activation { margin-bottom: 14px; padding: 12px; background: #f7f7f3; border: 1px solid var(--soft-line); }
.purchase-activation > label { display: block; margin-bottom: 7px; color: #4d4d49; font-size: 12px; font-weight: 700; }
.purchase-activation > div { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.purchase-activation input { font-family: Consolas, monospace; text-transform: uppercase; }
.purchase-activation .auth-error { margin-bottom: 0; }
.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.plan-option { min-height: 112px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: 14px; text-align: left; }
.plan-option span { font-size: 13px; }
.plan-option strong { margin: 5px 0; color: var(--accent); font-size: 24px; }
.plan-option small { color: var(--muted); font-size: 11px; }
.plan-option.is-featured, .plan-option.is-selected { border-color: var(--accent); background: #edf6ff; box-shadow: inset 0 0 0 1px var(--accent); }
.purchase-steps { margin: 16px 0; padding: 12px; background: #f7f7f3; border-left: 3px solid var(--accent); }
.purchase-steps strong { font-size: 12px; }
.purchase-steps p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.qr-tabs { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; background: #edede8; border-radius: 6px; }
.qr-tabs button { min-height: 36px; padding: 0 6px; border: 0; background: transparent; font-size: 12px; }
.qr-tabs button.is-selected { color: var(--accent); background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.qr-stage { min-height: 310px; display: grid; place-items: center; margin-top: 12px; padding: 12px; border: 1px solid var(--soft-line); background: #fafaf7; }
.qr-stage figure { margin: 0; text-align: center; }
.qr-stage img { display: block; width: min(280px, 100%); height: 250px; margin: 0 auto; object-fit: contain; background: #fff; }
.qr-stage figcaption { margin-top: 8px; color: var(--muted); font-size: 12px; }
.purchase-actions { justify-content: space-between; }
dialog { width: min(520px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 24px 80px rgba(0,0,0,.24); }
dialog::backdrop { background: rgba(20,20,18,.54); }
dialog form { padding: 18px; }
.dialog-heading { justify-content: space-between; margin-bottom: 18px; }
.dialog-heading h2 { margin: 2px 0 0; font-size: 18px; }
dialog textarea { min-height: 220px; margin-bottom: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: 26px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); padding: 11px 15px; color: #fff; background: #20201e; border-radius: 5px; box-shadow: 0 8px 24px rgba(0,0,0,.22); opacity: 0; transform: translate(-50%, 16px); pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--accent); }

@media (max-width: 800px) {
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .topbar { height: 58px; padding: 0 12px; }
  .brand-mark { width: 31px; height: 31px; }
  .brand-block h1 { font-size: 15px; }
  .brand-block p { display: none; }
  .status-dot span { display: none; }
  .app-shell { display: block; padding: 10px 10px 18px; }
  .mobile-screen { display: none; }
  .mobile-screen.is-active { display: block; }
  .panel { border-radius: 5px; }
  .editor-panel { padding: 15px; }
  .preview-panel { position: static; }
  .queue-panel { min-height: calc(100vh - 148px); }
  .advanced { margin: 0 -15px; padding: 0 15px; }
  .preview-heading, .queue-panel > .panel-heading { padding: 15px 15px 0; }
  .preview-stage { height: clamp(260px, 48vh, 430px); margin: 0 10px; padding: 12px; }
  .preview-stage img { inset: 12px; width: calc(100% - 24px); height: calc(100% - 24px); }
  .measurement-strip { margin: 12px 10px 0; }
  .measurement-strip div { padding: 10px 7px; }
  .measurement-strip strong { font-size: 12px; white-space: nowrap; }
  .export-bar { display: block; padding: 14px 10px 15px; }
  .export-options { justify-content: space-between; margin-bottom: 12px; }
  .export-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .queue-item { grid-template-columns: 32px 38px minmax(0, 1fr) auto; min-height: 64px; padding: 8px 12px; }
  .queue-item .queue-meta:nth-last-child(2), .queue-item .queue-meta:nth-last-child(3) { display: none; }
  .queue-text { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .summary-bar { grid-template-columns: 1fr 1fr; gap: 12px; padding: 13px 12px; }
  .price-field { margin: 0; }
  .total-amount { text-align: left; }
  .batch-export { padding: 12px; }
  .batch-export button { flex: 1; }
  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.97);
    border-top: 1px solid var(--line);
  }
  .mobile-nav button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 48px; padding: 4px; color: var(--muted); border: 0; background: transparent; font-size: 11px; }
  .mobile-nav button span { font-size: 19px; line-height: 20px; }
  .mobile-nav button.is-active { color: var(--accent); }
  .mobile-nav i { position: absolute; top: 0; left: calc(50% + 9px); display: grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px; color: #fff; background: var(--accent); border-radius: 9px; font-size: 9px; font-style: normal; }
  .toast { bottom: calc(82px + env(safe-area-inset-bottom)); }
  .auth-gate { place-items: start center; padding: 12px; }
  .auth-shell { display: block; }
  .auth-brand { min-height: 0; padding: 18px; }
  .auth-brand h1 { font-size: 18px; }
  .auth-content { padding: 24px 18px 20px; }
  .auth-content h2 { font-size: 22px; }
  .plan-grid { grid-template-columns: 1fr; }
  .required-email > div { grid-template-columns: 1fr; }
  .purchase-activation > div { grid-template-columns: 1fr; }
  .plan-option { min-height: 76px; display: grid; grid-template-columns: 1fr auto; align-items: center; }
  .plan-option strong { grid-column: 2; grid-row: 1 / span 2; margin: 0; }
  .qr-stage { min-height: 280px; }
  .purchase-dialog form { padding: 14px; }
}

@media (max-width: 380px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .preset-strip { grid-template-columns: repeat(4, 1fr); }
  .measurement-strip { grid-template-columns: 1fr 1fr; }
  .measurement-strip div:last-child { grid-column: 1 / -1; border-top: 1px solid var(--soft-line); }
  .auth-actions { grid-template-columns: 1fr; }
  .qr-tabs button { font-size: 11px; }
}
