:root {
  --sample: #5eead4;
  --sample-bg: rgba(14, 165, 233, 0.12);
  --warn: #fb923c;
  --cri: #fb7185;
  --cri-bg: rgba(244, 63, 94, 0.12);
  --maj: #fbbf24;
  --maj-bg: rgba(245, 158, 11, 0.1);
  --min: #38bdf8;
  --min-bg: rgba(14, 165, 233, 0.1);
  --ink: var(--text);
  --label: #cbd5e1;
  --field-border: #334155;
  --surface-deep: #0f172a;
  --surface-mid: #1e293b;
  --overlay: rgba(15, 23, 42, 0.72);
}

[data-theme="light"] {
  --sample: #0f766e;
  --sample-bg: rgba(13, 148, 136, 0.16);
  --cri: #be123c;
  --maj: #b45309;
  --min: #0369a1;
  --cri-bg: rgba(254, 226, 226, 0.85);
  --maj-bg: rgba(254, 243, 199, 0.9);
  --min-bg: rgba(219, 234, 254, 0.9);
  --label: #334155;
  --field-border: #94a3b8;
  --surface-deep: #ffffff;
  --surface-mid: #f1f5f9;
  --overlay: rgba(255, 255, 255, 0.96);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, var(--ambient-a, rgba(20, 184, 166, 0.18)), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, var(--ambient-b, rgba(14, 165, 233, 0.12)), transparent),
    var(--bg);
}

.ambient::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.12;
  background-image:
    linear-gradient(rgba(20, 184, 166, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 184, 166, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent 85%);
}

/* .wrap 宽度见 brand-theme.css 流体自适应 */

.site-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.brand {
  min-width: 0;
}

.brand-kicker {
  margin: 0 0 2px;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

header h1 {
  margin: 0;
  font-size: clamp(1.65rem, 5vw, 1.95rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
  background: linear-gradient(120deg, #5eead4 0%, var(--accent2) 55%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* 顶栏标题与右侧控件同一行，手机端缩小字号 */
header.site-head .brand h1 {
  font-size: clamp(0.88rem, 3.4vw, 1.2rem);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

@media (max-width: 520px) {
  header.site-head .brand h1 {
    font-size: 0.8rem;
    letter-spacing: -0.02em;
  }
}

html[data-theme="light"] header h1 {
  background: linear-gradient(120deg, #0f766e 0%, #0369a1 55%, #0d9488 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lang {
  display: flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--overlay);
  backdrop-filter: blur(8px);
  box-shadow: none;
}

.lang-btn {
  padding: 5px 10px;
  border: none;
  background: transparent;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--muted);
  border-radius: 999px;
  transition: background 0.2s ease, color 0.2s ease;
}

.lang-btn.active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  color: #042f2e;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(67, 56, 202, 0.28);
}

.lock-banner {
  background: var(--lock-bg);
  border: 1px solid var(--lock-border);
  color: var(--lock-text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.45;
  box-shadow: none;
}

.lock-banner.hidden {
  display: none;
}

/* ── 会员 / 激活码 ── */
.license-zone {
  padding: 10px 14px;
  margin-bottom: 12px;
}

.license-zone.hidden {
  display: none;
}

.license-zone.lz-collapsed {
  padding: 8px 14px;
}

.lz-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}

.lz-label {
  flex-shrink: 0;
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
}

.license-preview {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.license-zone.lz-collapsed .license-key-row {
  display: none;
}

.license-zone:not(.lz-collapsed) .license-key-row .license-preview {
  display: none;
}

.license-key-row {
  margin-top: 8px;
}

.device-code-display {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 0;
  background: transparent;
  border: none;
}

.license-key-row #licenseKey {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 6px 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-deep);
}

.license-key-row #licenseKey:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.55);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

.lz-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.lz-action-btn {
  font-size: 0.88rem;
  line-height: 1.35;
  padding: 4px 0;
  white-space: nowrap;
}

.license-auto-hint {
  color: var(--muted);
  white-space: nowrap;
  font-size: 12px;
}

.license-auto-hint.hidden {
  display: none;
}

.license-zone.lz-collapsed .lz-extra {
  display: none;
}

.license-zone.lz-collapsed.lz-pin-extra .lz-extra {
  display: block;
  margin-top: 8px;
}

.license-zone.lz-pin-extra .hint.lz-extra {
  color: var(--lock-text, #be123c);
  font-weight: 600;
}

.license-zone.lz-pin-extra .lz-extra {
  color: var(--lock-text, #be123c);
}

.quota-shop-hint {
  margin: 0.65rem 0 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--lock-text, #be123c);
}
.quota-shop-hint.hidden { display: none; }
.quota-shop-hint a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.license-zone .hint.lz-extra {
  margin: 10px 0 0;
  font-size: 0.85rem;
  line-height: 1.45;
}

.license-zone .device-id.lz-extra {
  margin: 6px 0 0;
  font-size: 0.82rem;
  line-height: 1.45;
}

.license-zone .device-id code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  background: var(--surface-deep);
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 8px;
  line-height: 1.55;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  font-size: 0.8rem;
  padding: 0 4px;
  font-weight: 600;
}

.link-btn:hover {
  text-decoration: underline;
}

.card {
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.worksheet {
  background: var(--card-solid, var(--card));
  backdrop-filter: blur(12px);
  border: 1px solid var(--field-border, var(--border));
  border-radius: var(--radius);
  padding: 0;
  margin-bottom: 12px;
  box-shadow: 0 8px 28px rgba(2, 6, 23, 0.18);
  position: relative;
  overflow: visible;
}

html[data-theme="light"] .worksheet {
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
}

.worksheet::before {
  content: "";
  position: absolute;
  top: -50px;
  right: -40px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(20, 184, 166, 0.1) 0%, transparent 70%);
  pointer-events: none;
}

.ws-block {
  padding: 14px 15px;
  position: relative;
}

.ws-divider {
  height: 1px;
  margin: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(148, 163, 184, 0.35) 12%,
    rgba(148, 163, 184, 0.35) 88%,
    transparent
  );
}

.ws-divider-result {
  display: none;
}

.ws-divider-result.show {
  display: block;
}

.ws-foot {
  padding: 0 15px 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  background: var(--overlay);
}

.foot-notes-btn {
  margin-top: 6px;
  font-size: 0.78rem;
  padding: 0;
}

#wsTail.hidden {
  display: none;
}

.ws-tail {
  padding: 12px 15px 14px;
  background: var(--overlay);
}

.license-panel {
  padding: 0 0 8px;
}

.card-compact {
  padding: 14px 15px;
}

.card-hero {
  position: relative;
  overflow: hidden;
}

.card-hero::before {
  content: "";
  position: absolute;
  top: -40px;
  right: -30px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(14, 165, 233, 0.12) 0%, transparent 70%);
  pointer-events: none;
}

.card-aql .section-title::before {
  background: linear-gradient(180deg, var(--accent), var(--accent2));
}

.worksheet .section-title::before,
.worksheet .result-head h2::before {
  background: linear-gradient(180deg, #6366f1, #0891b2);
}

.card h2,
.section-title {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before,
.result-head h2::before {
  content: "";
  width: 4px;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  flex-shrink: 0;
}

.confirm-row {
  margin-top: 14px;
}

.confirm-btn {
  width: 100%;
  min-height: 44px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.result-head {
  margin-bottom: 8px;
}

.result-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-summary {
  margin: 0 0 10px;
  padding: 8px 10px;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--ink);
  background: rgba(20, 184, 166, 0.08);
  border: 1px solid rgba(20, 184, 166, 0.18);
  border-radius: 8px;
  word-break: break-word;
}

.result-summary.show {
  display: block;
}

.result-summary.hidden {
  display: none;
}

#mainApp.disabled {
  opacity: 1;
  filter: none;
  pointer-events: auto;
}

label,
.tool-label {
  display: block;
  font-size: 0.8rem;
  color: var(--label, var(--text));
  margin-bottom: 4px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.lot-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.lot-field,
.sample-field {
  min-width: 0;
}

.sample-label {
  display: block;
  font-size: 0.8rem;
  color: var(--label, var(--text));
  margin-bottom: 4px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sample-value {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--sample);
  background: var(--sample-bg);
  border: 1px solid var(--field-border, var(--border));
  border-radius: var(--radius-sm);
  box-shadow: none;
}

.input-lot,
.select-compact,
.aql-cell select {
  width: 100%;
  font-size: 1rem;
  font-weight: 600;
  padding: 11px 12px;
  border: 1.5px solid var(--field-border, var(--border));
  border-radius: var(--radius-sm);
  margin-bottom: 0;
  background: var(--surface-deep, var(--input-bg));
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-lot:focus,
.select-compact:focus,
.aql-cell select:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.45);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.select-compact {
  width: auto;
  min-width: 4.5rem;
  max-width: 100%;
  font-size: 0.88rem;
  padding: 9px 10px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.tool-block {
  flex: 0 0 auto;
}

.tool-grow {
  flex: 1 1 140px;
  min-width: 0;
}

.tool-scheme {
  flex: 1 1 140px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tool-scheme .tool-label {
  width: 100%;
  text-align: center;
}

.tool-scheme .seg-inline {
  width: 100%;
  max-width: 340px;
}

.seg-inline {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 4px;
  background: var(--overlay, var(--surface-mid));
  border: 1px solid var(--field-border, var(--border));
  border-radius: 999px;
}

.seg-inline label {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 8px 6px;
  text-align: center;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--label, var(--text));
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.seg-inline input {
  display: none;
}

.seg-inline label:has(input:checked) {
  background: var(--surface-mid);
  color: var(--accent2);
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.15);
}

.aql-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.aql-cell {
  padding: 10px 8px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.aql-cri {
  background: var(--cri-bg);
  border-color: rgba(190, 18, 60, 0.12);
}

.aql-maj {
  background: var(--maj-bg);
  border-color: rgba(180, 83, 9, 0.12);
}

.aql-min {
  background: var(--min-bg);
  border-color: rgba(3, 105, 161, 0.12);
}

.aql-cri label {
  color: var(--cri);
  font-weight: 800;
}

.aql-maj label {
  color: var(--maj);
  font-weight: 800;
}

.aql-min label {
  color: var(--min);
  font-weight: 800;
}

html[data-theme="light"] .aql-cri label {
  color: #be123c;
}

html[data-theme="light"] .aql-maj label {
  color: #b45309;
}

html[data-theme="light"] .aql-min label {
  color: #0369a1;
}

html[data-theme="light"] .aql-cri {
  background: rgba(254, 226, 226, 0.85);
  border-color: #fca5a5;
}

html[data-theme="light"] .aql-maj {
  background: rgba(254, 243, 199, 0.9);
  border-color: #fcd34d;
}

html[data-theme="light"] .aql-min {
  background: rgba(219, 234, 254, 0.9);
  border-color: #93c5fd;
}

.aql-cell select {
  font-size: 0.86rem;
  padding: 8px 6px;
  background: var(--surface-deep);
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover, #0d9488) 100%);
  color: #042f2e;
  box-shadow: 0 10px 24px rgba(20, 184, 166, 0.22);
}

.result-panel {
  display: none;
  padding-top: 10px;
}

.result-panel.show {
  display: block;
  animation: rise 0.35s ease;
  min-height: 48px;
}

.row-placeholder td.num {
  color: var(--muted);
}

.result {
  display: none;
}

.result.show {
  display: block;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.table-shell {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--overlay);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th,
td {
  padding: 11px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

tbody tr:last-child td {
  border-bottom: none;
}

th {
  font-weight: 700;
  color: #e2e8f0;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--surface-mid, var(--card-solid));
}

html[data-theme="light"] th {
  color: #1e3a8a;
  background: #f8fafc;
}

td {
  color: var(--text);
}

td.num {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.15rem;
}

td.num.ac {
  color: #047857;
}

td.num.re {
  color: var(--cri);
}

.row-cri td:first-child {
  color: var(--cri);
  font-weight: 700;
}

.row-maj td:first-child {
  color: var(--maj);
  font-weight: 700;
}

.row-min td:first-child {
  color: var(--min);
  font-weight: 700;
}

.banner {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  margin-bottom: 8px;
}

.banner.warn {
  background: rgba(251, 146, 60, 0.14);
  color: #fed7aa;
  border: 1px solid rgba(251, 146, 60, 0.4);
  font-weight: 600;
}

html[data-theme="light"] .banner.warn {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fdba74;
}

.foot {
  font-size: 0.78rem;
  color: var(--label, var(--muted));
  margin: 10px 0 0;
  line-height: 1.55;
}

.foot-method {
  display: none;
}

.app-notes {
  margin: 0;
  padding: 8px 0 0;
  background: transparent;
  border: none;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.app-notes summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.78rem;
  padding: 6px 0 2px;
}

.app-notes summary::-webkit-details-marker {
  display: none;
}

.app-notes summary::marker {
  content: "";
}

.notes-body {
  margin: 0;
  padding: 0 0 2px;
  line-height: 1.55;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-line;
}

@media (max-width: 560px) {
  .lz-row {
    flex-wrap: wrap;
  }
  .lz-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .license-preview {
  width: 100%;
  }
  .lz-action-btn {
    min-height: 44px;
    padding: 8px 0;
  }
  .license-auto-hint {
    width: 100%;
    text-align: right;
  }
}

@media (max-width: 380px) {
  html:not([data-aql-embed]) .wrap {
    padding-left: 12px;
    padding-right: 12px;
  }

  .aql-row {
    grid-template-columns: 1fr;
  }

  .seg-inline label {
    font-size: 0.72rem;
    padding: 7px 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .result.show {
    animation: none;
  }

  .btn:active {
    transform: none;
  }
}

#queryPanel.hidden {
  display: none;
}

body.is-reading #wsTail {
  display: none;
}

body.is-reading #licenseBar.lz-collapsed {
  display: none;
}

.reading-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(20, 184, 166, 0.35);
  background: rgba(17, 24, 39, 0.92);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

html[data-theme="light"] .reading-bar {
  background: rgba(255, 255, 255, 0.94);
}

.reading-bar.hidden {
  display: none;
}

.reading-bar-main {
  min-width: 0;
  flex: 1;
}

.reading-bar-main strong {
  display: block;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.reading-bar-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.reading-bar-actions .link-btn {
  min-height: 40px;
  padding: 8px 10px;
}
