/* ==========================================================================
   刷价助手 · Production SaaS Design System
   Zero external CDN dependencies · Crisp Light-Mode Neutral Slate + Indigo/Blue
   ========================================================================== */

:root {
  /* Surface Hierarchy */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --surface-hover: #f8fafc;

  /* Borders */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-subtle: #f1f5f9;

  /* Ink / Typography */
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  /* Brand Palette (Refined Indigo-Blue) */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-soft-hover: #dbeafe;
  --primary-border: #bfdbfe;
  --brand-indigo: #4f46e5;
  --ring: rgba(37, 99, 235, 0.22);

  /* Semantic Status Tokens */
  --ok: #047857;
  --ok-strong: #059669;
  --ok-bg: #ecfdf5;
  --ok-border: #a7f3d0;

  --bad: #be123c;
  --bad-strong: #e11d48;
  --bad-bg: #fff1f2;
  --bad-border: #fecdd3;

  --warn: #b45309;
  --warn-strong: #d97706;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;

  --tip: #0369a1;
  --tip-strong: #0284c7;
  --tip-bg: #f0f9ff;
  --tip-border: #bae6fd;

  /* Legacy Token Aliases (backward-compatible) */
  --b: var(--primary);
  --b2: var(--primary-hover);
  --card: var(--surface);
  --line: var(--border);
  --mut: var(--text-muted);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  /* Shape & Elevation */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 48px -12px rgba(15, 23, 42, 0.22), 0 8px 20px -8px rgba(15, 23, 42, 0.12);

  --transition: 150ms cubic-bezier(0.2, 0, 0, 1);
}

/* ---------- Base Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Tabular Numerals for Financial / Operational Alignment */
.num,
.big,
.kpi .v,
.stat-val,
.ana-stat-val,
input[type="number"],
table.grid td,
.clean-table td.num,
.chart text {
  font-variant-numeric: tabular-nums;
}

/* Inline SVG Icon Utilities */
.icon {
  display: inline-block;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  vertical-align: -0.18em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm {
  width: 13px;
  height: 13px;
}

.icon-lg {
  width: 20px;
  height: 20px;
}

/* ---------- Top Navigation Header ---------- */
header,
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

/* Fallback padding if bare <header> is rendered without .header-inner */
header:not(.app-header) {
  padding: 12px 24px;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 0;
}

.brand-logo {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.22);
}

.brand-text {
  min-width: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
  white-space: nowrap;
}

.sop-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--brand-indigo);
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  white-space: nowrap;
}

header .sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
  line-height: 1.3;
  white-space: nowrap;
}

/* Navigation Tab Bar */
nav,
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

nav::-webkit-scrollbar,
.nav-tabs::-webkit-scrollbar {
  display: none;
}

nav button,
.nav-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 7px 14px;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.2;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

nav button:hover,
.nav-tabs button:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
}

nav button.on,
.nav-tabs button.on {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  border-color: rgba(226, 232, 240, 0.9);
  box-shadow: var(--shadow-xs);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
}

.help-btn:hover {
  background: var(--primary-soft-hover);
  border-color: #93c5fd;
  color: var(--primary-hover);
}

.header-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.meta-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok-strong);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.14);
}

/* ---------- Main Container & Tabs ---------- */
main,
.app-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

.tab {
  display: none;
}

.tab.on {
  display: block;
  animation: tabFadeIn 160ms ease-out;
}

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

/* ---------- Grid Layouts & Cards ---------- */
.grid2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.card h2,
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.card-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon {
  color: var(--primary);
}

.card-tag {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.card-sub-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 18px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 6px;
}

.full {
  grid-column: 1 / -1;
}

/* Form Row Grids — Bottom-Aligned Inputs Prevent Label-Wrap Misalignment */
.row,
.row3,
.row4 {
  display: grid;
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}

.row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.row > div,
.row3 > div,
.row4 > div,
.field {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 0;
}

.field {
  margin-bottom: 10px;
}

.row .field,
.row3 .field,
.row4 .field {
  margin-bottom: 0;
}

.col-span-2 {
  grid-column: span 2;
}

.field-check {
  min-height: 36px;
  display: flex;
  align-items: center;
}

.field-hint {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-subtle);
  margin-left: 4px;
}

/* ---------- Form Controls ---------- */
label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0 0 5px;
  line-height: 1.35;
}

label .req {
  color: var(--bad-strong);
  margin-left: 2px;
}

label.inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.4;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-subtle);
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: #94a3b8;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  min-height: 0;
  padding: 0;
  margin: 0;
  border-radius: 4px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

textarea {
  min-height: 68px;
  resize: vertical;
}

/* Search Input With Leading Icon */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 248px;
}

.search-wrap .search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-subtle);
  pointer-events: none;
  display: inline-flex;
  align-items: center;
}

.search-wrap input {
  padding-left: 32px;
}

/* ---------- Buttons ---------- */
button,
.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: #ffffff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition);
}

button:hover:not(:disabled),
.btn-link:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

button:active:not(:disabled),
.btn-link:active {
  transform: translateY(0.5px);
}

button:focus-visible,
.btn-link:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

button:disabled,
button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--surface-subtle);
  color: var(--text-muted);
  border-color: var(--border);
  box-shadow: none;
  transform: none;
}

button:disabled:hover,
button[disabled]:hover {
  background: var(--surface-subtle);
  color: var(--text-muted);
  border-color: var(--border);
  box-shadow: none;
  transform: none;
}

button.sec {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

button.sec:hover {
  background: var(--surface-subtle);
  border-color: #94a3b8;
  color: var(--text);
}

button.ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

button.ghost:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

button.warnbtn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

button.warnbtn:hover {
  background: #fef3c7;
  border-color: #fcd34d;
}

button.danger {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: var(--bad-border);
}

button.danger:hover {
  background: #ffe4e6;
  border-color: #fda4af;
}

button.okbtn {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}

button.okbtn:hover {
  background: #d1fae5;
  border-color: #6ee7b7;
}

button.mini {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: var(--radius-xs);
  gap: 4px;
}

button.icon-btn {
  padding: 6px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

button.icon-btn:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

/* ---------- Semantic Text, Result Panels & Callouts ---------- */
.ok { color: var(--ok); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.warn { color: var(--warn); font-weight: 500; }
.tip { color: var(--tip); font-weight: 500; }
.mut { color: var(--text-muted); font-size: 12.5px; line-height: 1.5; }

.res {
  margin-top: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  line-height: 1.75;
  font-size: 13.5px;
}

.modal-body > .res:first-child {
  margin-top: 0;
}

.res > .callout:first-child {
  margin-top: 0;
}

.card > p.mut {
  margin: 8px 0 12px;
}

.res-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin-bottom: 6px;
}

.big {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary);
  line-height: 1.15;
}

.big.ok { color: var(--ok); }
.big.bad { color: var(--bad); }

.callout {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 11px;
  border-radius: var(--radius-xs);
  font-size: 12.5px;
  line-height: 1.5;
  border: 1px solid transparent;
}

.callout .icon {
  margin-top: 2px;
}

.callout-tip { background: var(--tip-bg); border-color: var(--tip-border); color: var(--tip); }
.callout-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }
.callout-bad { background: var(--bad-bg); border-color: var(--bad-border); color: var(--bad); }
.callout-ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }

.note-foot {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

.card-actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ---------- Context / Info Strip (Calc & Settings) ---------- */
.context-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}

.context-bar label {
  margin: 0;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.context-bar select {
  width: auto;
  min-width: 148px;
}

.meta-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.meta-chip strong {
  color: var(--text);
  font-weight: 600;
}

/* ---------- SKU Ledger: Tiered KPI Grid ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(156px, 1.32fr) minmax(176px, 1.42fr);
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  box-shadow: var(--shadow-xs);
  cursor: default;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition), background var(--transition);
}

.kpi.click {
  cursor: pointer;
}

.kpi.click:hover {
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Active Filter Ring State */
.kpi.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px var(--ring);
}

.kpi.active.kpi-ok {
  border-color: var(--ok-strong);
  background: var(--ok-bg);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.16);
}

.kpi.active.kpi-bad {
  border-color: var(--bad-strong);
  background: var(--bad-bg);
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.16);
}

.kpi.active.kpi-warn {
  border-color: var(--warn-strong);
  background: var(--warn-bg);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.16);
}

.kpi.active.kpi-tip {
  border-color: var(--tip-strong);
  background: var(--tip-bg);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.16);
}

/* Financial Metric Cards (Visual Tier Separation) */
.kpi.kpi-metric {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border-color: var(--border-strong);
  padding-left: 16px;
}

.kpi.kpi-metric::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--ok-strong);
}

.kpi.kpi-metric.kpi-tip::before {
  background: var(--tip-strong);
}

.kpi.kpi-metric.kpi-bad::before {
  background: var(--bad-strong);
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.kpi .k {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--border-strong);
}

.kpi-dot.ok { background: var(--ok-strong); }
.kpi-dot.bad { background: var(--bad-strong); }
.kpi-dot.warn { background: var(--warn-strong); }
.kpi-dot.tip { background: var(--tip-strong); }

.kpi .v {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-top: 6px;
  color: var(--text);
}

.kpi .v.ok { color: var(--ok); }
.kpi .v.bad { color: var(--bad); }
.kpi .v.warn { color: var(--warn); }
.kpi .v.tip { color: var(--tip); }

.kpi .v.kpi-multi {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 5px;
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.kpi-curr-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-curr-line.ok { color: var(--ok); }
.kpi-curr-line.bad { color: var(--bad); }
.kpi-curr-line.tip { color: var(--tip); }

.kpi-curr-code {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 1.5;
  flex-shrink: 0;
}

.kpi-sub {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Toolbar & Bulk Action Bar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 12px;
}

.toolbar-group,
.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 132px;
}

.toolbar .search-wrap input {
  width: 256px;
}

.toolbar .sp {
  flex: 1 1 auto;
}

.bulk {
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.bulk:empty {
  display: none;
}

.bulk-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-hover);
  margin-right: 4px;
}

.bulk select {
  min-width: 124px;
  min-height: 30px;
  padding: 3px 8px;
  font-size: 12px;
}

/* ---------- Modern Horizontal-Line Data Tables ---------- */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

th,
td {
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

tbody tr:hover td {
  background: #f8fafc;
}

th.num, td.num { text-align: right; }
th.c, td.c { text-align: center; }
td.l { text-align: left; }

tr.hl td {
  background: var(--primary-soft);
  font-weight: 600;
}

tr.hl td:first-child {
  box-shadow: inset 3px 0 0 var(--primary);
}

tr.hl-ok td {
  background: var(--ok-bg);
  font-weight: 600;
}

tr.hl-ok td:first-child {
  box-shadow: inset 3px 0 0 var(--ok-strong);
}

/* Compact inline price input inside 反推 table */
input.oP {
  width: 96px;
  min-height: 30px;
  padding: 4px 8px;
  font-size: 13px;
  text-align: right;
}

/* Main Ledger Table Wrapper & Grid */
.tblwrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: auto;
  max-width: 100%;
  max-height: calc(100vh - 260px);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

table.grid {
  min-width: 1180px;
}

table.grid th {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 10px 7px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

table.grid th:first-child,
table.grid td:first-child {
  padding-left: 12px;
}

table.grid th:last-child,
table.grid td:last-child {
  padding-right: 12px;
}

table.grid th[data-sort] {
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

table.grid th[data-sort]:hover {
  background: #e2e8f0;
  color: var(--text);
}

table.grid th.sorted {
  color: var(--primary);
}

table.grid th.nosort {
  cursor: default;
}

.sort-ind {
  display: inline-block;
  margin-left: 3px;
  font-size: 10px;
  color: var(--primary);
}

table.grid td {
  padding: 9px 7px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background var(--transition);
}

table.grid tbody tr:last-child td {
  border-bottom: 0;
}

table.grid tbody tr:hover td {
  background: #f8fafc;
}

/* Left Priority Accent Strip */
table.grid tr.lv-bad td:first-child {
  box-shadow: inset 3px 0 0 var(--bad-strong);
}

table.grid tr.lv-warn td:first-child {
  box-shadow: inset 3px 0 0 var(--warn-strong);
}

table.grid tr.lv-ok td:first-child {
  box-shadow: inset 3px 0 0 var(--ok-strong);
}

/* Structured Ledger Cell Styles */
.sku-code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.sku-name {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  max-width: 155px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-name {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.plat-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
}

.price-cell {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  white-space: nowrap;
}

.link-ext {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}

.link-ext:hover {
  background: var(--primary-soft);
  color: var(--primary);
  text-decoration: none;
}

.cell-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Status Pill Badges & Pill-Styled Inline Status Select */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}

.s-todo { background: #f1f5f9; color: #334155; border-color: #cbd5e1; }
.s-wait { background: var(--tip-bg); color: var(--tip); border-color: var(--tip-border); }
.s-ok   { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.s-bad  { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-border); }
.s-mut  { background: #f8fafc; color: var(--text-muted); border-color: var(--border); }

table.grid select.st {
  width: auto;
  min-width: 88px;
  max-width: 128px;
  min-height: 28px;
  padding: 3px 6px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-full);
  cursor: pointer;
}

table.grid select.st.s-todo { background: #f1f5f9; color: #334155; border-color: #cbd5e1; }
table.grid select.st.s-wait { background: var(--tip-bg); color: var(--tip); border-color: var(--tip-border); }
table.grid select.st.s-ok   { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
table.grid select.st.s-bad  { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-border); }
table.grid select.st.s-mut  { background: #f8fafc; color: var(--text-muted); border-color: var(--border); }

/* Structured Alert Pills */
.alerts {
  text-align: left;
  font-size: 12px;
  min-width: 185px;
  max-width: 270px;
  line-height: 1.45;
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.alert-pill {
  display: inline-flex;
  align-items: flex-start;
  gap: 5px;
  padding: 3px 7px;
  border-radius: var(--radius-xs);
  font-size: 11.5px;
  line-height: 1.4;
  border: 1px solid transparent;
  width: fit-content;
  max-width: 100%;
}

.alert-pill .icon {
  margin-top: 2px;
  width: 12px;
  height: 12px;
}

.alert-pill.bad  { background: var(--bad-bg); border-color: var(--bad-border); color: var(--bad); font-weight: 500; }
.alert-pill.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); font-weight: 500; }
.alert-pill.tip  { background: var(--tip-bg); border-color: var(--tip-border); color: var(--tip); font-weight: 500; }
.alert-pill.ok   { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); font-weight: 600; }

/* Row Action Cluster */
.ops {
  white-space: nowrap;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 4px;
  justify-content: center;
  margin: 0 auto;
}

.ops button {
  margin: 0;
}

.ops-grid button.mini {
  padding: 3px 7px;
  font-size: 11.5px;
}

/* ---------- Empty State ---------- */
.empty,
.empty-state {
  padding: 52px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}

.empty-desc {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 420px;
  margin: 0 auto 18px;
  line-height: 1.6;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* ---------- Modal Dialog (Backdrop Blur + Sticky Header & Footer) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  overflow: hidden;
  animation: modalFade 150ms ease-out;
}

.modal.hidden {
  display: none;
}

@keyframes modalFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(1140px, 100%);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.modal-box.modal-sm {
  width: min(620px, 100%);
}

.modal-box.modal-md {
  width: min(820px, 100%);
}

/* Graceful fallback if legacy modal content omits .modal-body */
.modal-box:not(:has(.modal-body)) {
  padding: 20px 24px;
  overflow-y: auto;
}

.modal-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.modal-head h3,
.modal-box > h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 22px;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.modal-foot {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 13px 22px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.modal-box:not(:has(.modal-body)) .modal-foot {
  padding: 14px 0 0;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

/* Modal Form Layout & Section Cards */
.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.form-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.form-section,
fieldset {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 0;
  box-shadow: var(--shadow-xs);
  min-width: 0;
}

fieldset + fieldset {
  margin-top: 14px;
}

legend {
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
  padding: 0 6px;
}

.form-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.form-section-title .title-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.form-section-title .icon {
  color: var(--primary);
}

.form-section-sub {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-muted);
}

/* Live Analysis Summary Panel inside Modal */
.ana-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.ana-stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}

.ana-stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
}

.ana-stat-val {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
}

.ana-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
}

.ana-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px dashed var(--border-subtle);
}

.ana-row:last-child {
  border-bottom: 0;
}

.ana-k {
  color: var(--text-muted);
  flex-shrink: 0;
}

.ana-v {
  color: var(--text);
  font-weight: 500;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ana-advice {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  background: var(--surface-subtle);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Checklist & Progress Bar */
.chk-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.chk-bar {
  height: 6px;
  width: 100%;
  background: var(--surface-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 12px;
}

.chk-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 200ms ease, background 200ms ease;
}

.chk-fill.complete {
  background: var(--ok-strong);
}

.chk-fill.step-0 { width: 0%; }
.chk-fill.step-1 { width: 12.5%; }
.chk-fill.step-2 { width: 25%; }
.chk-fill.step-3 { width: 37.5%; }
.chk-fill.step-4 { width: 50%; }
.chk-fill.step-5 { width: 62.5%; }
.chk-fill.step-6 { width: 75%; }
.chk-fill.step-7 { width: 87.5%; }
.chk-fill.step-8 { width: 100%; }

progress.chk-meter {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 6px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
  overflow: hidden;
  margin-bottom: 12px;
}

progress.chk-meter::-webkit-progress-bar {
  background: var(--surface-subtle);
  border-radius: var(--radius-full);
}

progress.chk-meter::-webkit-progress-value {
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 200ms ease;
}

progress.chk-meter.complete::-webkit-progress-value {
  background: var(--ok-strong);
}

ul.chk {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

ul.chk li {
  margin: 0;
}

ul.chk label {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-secondary);
  margin: 0;
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--transition);
}

ul.chk label:hover {
  background: var(--bg);
}

ul.chk input[type="checkbox"] {
  margin-top: 2px;
}

/* Status Log List inside Modal */
.log-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}

.log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border-subtle);
}

.log-item:last-child {
  border-bottom: 0;
}

.log-date {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Ask / Copy Modal Pre Block */
pre.ask {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin: 0;
  max-height: 55vh;
  overflow: auto;
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text);
}

/* ---------- Elastic Tab: Stat Strip & SVG Chart ---------- */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stat-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  min-width: 0;
}

.stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
  white-space: nowrap;
}

.chart-wrap {
  position: relative;
  margin-top: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px 10px;
}

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

.chart-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

.legend-swatch.curve   { background: var(--primary); }
.legend-swatch.point   { width: 8px; height: 8px; border-radius: 50%; background: #ffffff; border: 2px solid var(--warn-strong); }
.legend-swatch.optimal { width: 8px; height: 8px; border-radius: 50%; background: var(--ok-strong); }
.legend-swatch.ceiling { height: 0; border-top: 2px dashed var(--bad-strong); }

svg.chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 260px;
  max-height: 340px;
  background: transparent;
  overflow: visible;
}

svg.chart .chart-pt {
  cursor: pointer;
}

svg.chart .chart-pt:focus {
  outline: none;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: #0f172a;
  color: #f8fafc;
  font-size: 12px;
  line-height: 1.45;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 120ms ease;
  z-index: 6;
}

.chart-tooltip.show {
  opacity: 1;
}

/* ---------- Settings Cards & Site Configuration ---------- */
.storage-notice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--tip-bg);
  border: 1px solid var(--tip-border);
  color: var(--tip);
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 14px;
}

.storage-notice .icon {
  margin-top: 2px;
}

.data-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.site-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}

.site-meta-row {
  display: grid;
  grid-template-columns: 1.3fr 0.8fr 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

.site-meta-row > div {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 0;
}

.site-meta-row button {
  min-height: 36px;
}

.plat-table-wrap {
  margin-top: 14px;
  max-width: 780px;
}

.plat-table {
  min-width: 560px;
}

.plat-table td {
  padding: 6px 8px;
}

.plat-table input,
.plat-table select {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
}

.plat-table input[type="number"] {
  min-width: 84px;
}

.plat-table select {
  min-width: 175px;
}

/* ---------- CSV Partial Import Preview Badges ---------- */
.imp-section {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.imp-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.imp-cols {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.imp-col {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.4;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.imp-col.matched {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary-hover);
}

.imp-col.preserved {
  background: var(--surface-subtle);
  border-color: var(--border);
  color: var(--text-muted);
}

.imp-col.cleared {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.imp-warn {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn);
  font-size: 12.5px;
  line-height: 1.55;
}

.imp-warn-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  margin-bottom: 4px;
}

.imp-warn ul {
  margin: 4px 0 0;
  padding-left: 18px;
}

.site-card-foot {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Glossary & 左 i / 右 i Concept Explainer ---------- */
.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  color: var(--primary);
  border: 0;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  box-shadow: none;
}

.link-btn:hover {
  background: var(--primary-soft);
  color: var(--primary-hover);
  text-decoration: underline;
}

.empty-glossary {
  margin: 18px auto 0;
  max-width: 560px;
  padding: 9px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
}

.lr-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.lr-grid.lr-compact {
  gap: 12px;
  margin-bottom: 12px;
}

.lr-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 15px 16px;
  box-shadow: var(--shadow-xs);
  min-width: 0;
}

.lr-grid.lr-compact .lr-card {
  background: var(--bg);
  padding: 12px 14px;
  box-shadow: none;
}

.lr-card.lr-left {
  border-top-color: var(--primary);
}

.lr-card.lr-right {
  border-top-color: #0d9488;
}

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

.lr-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}

.lr-badge.lr-left {
  background: var(--primary-soft);
  color: var(--primary-hover);
  border-color: var(--primary-border);
}

.lr-badge.lr-right {
  background: #f0fdfa;
  color: #0f766e;
  border-color: #99f6e4;
}

.lr-pos {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.lr-title {
  margin: 0 0 6px;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}

.lr-grid.lr-compact .lr-title {
  font-size: 13.5px;
}

.lr-desc {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.lr-grid.lr-compact .lr-desc {
  margin-bottom: 6px;
}

.lr-points {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.lr-points li {
  position: relative;
  padding-left: 14px;
}

.lr-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border-strong);
}

.lr-card.lr-left .lr-points li::before {
  background: var(--primary);
}

.lr-card.lr-right .lr-points li::before {
  background: #0d9488;
}

.lr-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.lr-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.lr-flow {
  margin-top: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card .lr-flow {
  background: var(--bg);
}

.lr-flow-steps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.lr-flow-node {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
}

.lr-flow-node.lr-right {
  background: #f0fdfa;
  color: #0f766e;
  border-color: #99f6e4;
}

.lr-flow-node.lr-left {
  background: var(--primary-soft);
  color: var(--primary-hover);
  border-color: var(--primary-border);
}

.lr-flow-arrow {
  display: inline-flex;
  align-items: center;
  color: var(--text-subtle);
}

.lr-flow-note {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.55;
}

.glossary-sec-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 14px 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.glossary-sec-title .icon {
  color: var(--primary);
}

.glossary-rules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.glossary-rule {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}

.glossary-rule-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.glossary-rule-title .icon {
  color: var(--primary);
}

.glossary-rule-desc {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.55;
}

/* ---------- Toast Notification ---------- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 10px);
  background: #0f172a;
  color: #f8fafc;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  max-width: min(560px, calc(100vw - 32px));
  text-align: center;
  transition: opacity 200ms ease, transform 200ms ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Noscript & Redirect Fallback Pages ---------- */
.noscript-banner {
  max-width: 640px;
  margin: 24px auto;
  padding: 16px 20px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-md);
  color: var(--warn);
}

.noscript-banner p {
  margin: 6px 0 0;
  font-size: 13.5px;
}

.redirect-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.redirect-shell {
  padding: 24px;
  width: 100%;
  max-width: 420px;
}

.redirect-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  text-align: center;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.redirect-card h1 {
  margin: 4px 0 0;
  font-size: 20px;
  color: var(--text);
}

.redirect-card p {
  margin: 0 0 8px;
}

/* ==========================================================================
   Responsive Breakpoints (1280px / 1024px / 768px / 390px)
   ========================================================================== */

@media (max-width: 1200px) {
  .kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .header-meta {
    display: none;
  }
}

@media (max-width: 1024px) {
  .header-inner {
    padding: 0 16px;
  }
  main,
  .app-main {
    padding: 16px 16px 32px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .site-meta-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  .grid2 {
    grid-template-columns: 1fr;
  }
  .brand .sub {
    display: none;
  }
}

@media (max-width: 768px) {
  .header-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "nav nav";
    align-items: center;
    gap: 10px 8px;
    padding: 10px 14px 12px;
    min-height: 0;
  }
  .brand {
    grid-area: brand;
  }
  .header-right {
    grid-area: actions;
  }
  .brand .sub {
    display: none;
  }
  nav,
  .nav-tabs {
    grid-area: nav;
    width: 100%;
    justify-content: flex-start;
  }
  nav button,
  .nav-tabs button {
    padding: 7px 12px;
    font-size: 13px;
  }
  .lr-grid {
    grid-template-columns: 1fr;
  }
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .kpis > .kpi:first-child {
    grid-column: span 2;
  }
  .kpi {
    padding: 11px 13px;
  }
  .kpi .v {
    font-size: 21px;
  }
  .kpi .v.kpi-multi {
    font-size: 14.5px;
    gap: 2px;
  }
  .toolbar-panel {
    padding: 10px 12px;
  }
  .toolbar .sp {
    display: none;
  }
  .toolbar-filters {
    width: 100%;
  }
  .search-wrap {
    width: 100%;
    min-width: 0;
    flex: 1 1 100%;
  }
  .toolbar .search-wrap input {
    width: 100%;
    min-width: 0;
  }
  .toolbar select {
    flex: 1 1 130px;
    min-width: 0;
  }
  .tblwrap {
    max-height: none;
  }
  .stat-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .modal {
    padding: 10px;
  }
  .modal-box {
    max-height: calc(100vh - 20px);
    border-radius: var(--radius-md);
  }
  .modal-head,
  .modal-body,
  .modal-foot {
    padding-left: 14px;
    padding-right: 14px;
  }
}

@media (max-width: 640px) {
  main,
  .app-main {
    padding: 12px 12px 28px;
  }
  .card {
    padding: 14px;
  }
  .row,
  .row3,
  .row4,
  .site-meta-row,
  .ana-stats,
  .glossary-rules {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .col-span-2 {
    grid-column: span 1;
  }
  .context-bar {
    padding: 10px 12px;
  }
  .context-bar select {
    width: 100%;
    min-width: 0;
  }
  .plat-table-wrap {
    max-width: 100%;
  }
}

@media (max-width: 520px) {
  .header-inner {
    padding: 10px 12px 10px;
  }
  .brand {
    gap: 8px;
  }
  .brand-logo {
    width: 26px;
    height: 26px;
  }
  header h1 {
    font-size: 16px;
  }
  .sop-badge {
    padding: 2px 6px;
    font-size: 10.5px;
  }
  .help-btn {
    padding: 5px 9px;
    font-size: 12px;
    gap: 4px;
  }
  nav,
  .nav-tabs {
    padding: 3px;
    gap: 2px;
  }
  nav button,
  .nav-tabs button {
    flex: 1 1 auto;
    min-width: 0;
    padding: 7px 5px;
    gap: 3px;
    font-size: 12px;
  }
  nav button .icon,
  .nav-tabs button .icon {
    width: 13px;
    height: 13px;
  }
}
