@import "./design-tokens.css";

/* PSI Dashboard 視覺系統：維持 Glassmorphism + Soft Neon 風格與高密度資料表格可讀性。 */
:root {
  color-scheme: light;
  /* 正式背景與前景 token 分離，避免 Apple 前景調整誤改頁面背景。 */
  --bg: var(--color-page-background-base, #eef5f7);
  --glass: var(--color-foreground-surface-data, rgba(226, 234, 229, 0.8));
  --glass-hover: var(--color-foreground-surface-data-hover, rgba(234, 240, 236, 0.9));
  --glass-strong: var(--color-foreground-surface-strong, #e8eeeb);
  --control-surface: var(--color-foreground-surface-control, rgba(228, 237, 239, 0.84));
  --accent-warm: var(--color-foreground-accent-warm, #b8844a);
  --glass-border: var(--color-foreground-border, rgba(255, 255, 255, 0.58));
  --ink: var(--color-foreground-text-primary, #172a2e);
  --muted: var(--color-foreground-text-muted, #566966);
  --line: var(--color-foreground-line, rgba(37, 72, 78, 0.18));
  --line-strong: var(--color-foreground-line-strong, rgba(62, 116, 124, 0.56));
  --brand: var(--color-foreground-brand, #3e747c);
  --brand-strong: var(--color-foreground-brand-strong, #25484e);
  --brand-soft: var(--color-foreground-brand-soft, rgba(62, 116, 124, 0.16));
  --brand-rgb: 62, 116, 124;
  --brand-deep-rgb: 37, 72, 78;
  --neon-pink: var(--color-brand-pink, #ec4899);
  --neon-cyan: var(--color-brand-cyan, #06b6d4);
  --red: var(--color-state-danger, #ef4444);
  --amber: var(--color-state-warning, #f59e0b);
  --emerald: var(--color-state-success, #10b981);
  --shadow-glass: 0 10px 30px -10px var(--color-foreground-shadow, rgba(37, 72, 78, 0.17));
  --shadow-lift: 0 24px 56px -28px var(--color-foreground-shadow-strong, rgba(37, 72, 78, 0.3));
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --page-max: 1720px;
  --page-gutter: var(--space-page-gutter, clamp(16px, 2.5vw, 40px));
  --motion-fast: 160ms;
  --motion-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

* {
  box-sizing: border-box;
}

/* 瀏覽器內建的 [hidden] { display: none } 屬於 user-agent origin，任何作者樣式
   （例如 .icon-button 的 display: inline-flex）都會贏過它，導致同時帶 class 與
   hidden 屬性的元素其實藏不起來。這裡用作者 origin + !important 把 hidden 的
   語意搶回來，讓 el.hidden = true 在全站一律有效。
   注意：本專案沒有使用 hidden="until-found"（該值需要 display 可被覆寫才能
   由瀏覽器的頁內搜尋展開），若日後要用，需改成 [hidden]:not([hidden="until-found"])。 */
[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 1px 1px, var(--color-page-background-grid-dot, rgba(80, 153, 175, 0.18)) 1px, transparent 0) 0 0 / 24px 24px,
    linear-gradient(135deg, var(--color-page-background-gradient-start, #eef5f7) 0%, var(--color-page-background-gradient-mid, #fffce6) 34%, var(--color-page-background-gradient-green, #e9f7d4) 68%, var(--color-page-background-gradient-end, #b9d6df) 100%);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: transparent;
  color: var(--ink);
  font-family: var(--typography-family-sans, Inter, "Noto Sans TC", "Segoe UI", system-ui, -apple-system, sans-serif);
  font-optical-sizing: auto;
  font-weight: 500;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

#app {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  padding-bottom: 34px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 2000;
  padding: 10px 14px;
  border: 2px solid var(--color-state-focus-ring, var(--brand));
  border-radius: var(--radius-sm);
  background: var(--glass-strong);
  color: var(--brand-strong);
  font-weight: 800;
  text-decoration: none;
  transform: translateY(calc(-100% - 20px));
  transition: transform var(--motion-fast) var(--motion-ease-out);
}

.skip-link:focus-visible {
  outline: 3px solid rgba(var(--brand-rgb), 0.22);
  outline-offset: 2px;
  transform: translateY(0);
}

.background-layer {
  position: fixed;
  inset: 0;
  z-index: -20;
  overflow: hidden;
  pointer-events: none;
}

.background-layer::after {
  position: absolute;
  inset: 0;
  content: "";
  background:
    radial-gradient(circle at 1px 1px, var(--color-page-background-grid-dot-overlay, rgba(80, 153, 175, 0.14)) 1px, transparent 0) 0 0 / 24px 24px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.2));
}

.glow {
  position: absolute;
  width: 560px;
  height: 560px;
  border-radius: 999px;
  filter: blur(124px);
  opacity: 0.38;
}

.glow-one {
  top: -180px;
  left: -150px;
  background: var(--color-page-background-glow-one, rgba(80, 153, 175, 0.32));
}

.glow-two {
  top: 16%;
  right: -230px;
  background: var(--color-page-background-glow-two, rgba(253, 238, 104, 0.22));
}

.glow-three {
  right: 20%;
  bottom: -250px;
  background: var(--color-page-background-glow-three, rgba(158, 255, 102, 0.2));
}

.glow-four {
  bottom: 16%;
  left: 16%;
  background: var(--color-page-background-glow-four, rgba(82, 122, 95, 0.18));
}

.glass-panel,
.glass-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  box-shadow: var(--shadow-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.glass-card {
  border-radius: var(--radius-lg);
}

.icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.icon svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(calc(100% - (var(--page-gutter) * 2)), var(--page-max));
  min-height: 78px;
  margin: 16px auto 0;
  padding: 14px 20px;
  overflow: visible;
  border: 0;
  border-bottom: 1px solid var(--color-border-subtle);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  display: inline-flex;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid rgba(var(--brand-rgb), 0.28);
  border-radius: var(--radius-md);
  background: rgba(var(--brand-rgb), 0.11);
  color: var(--brand-strong);
  box-shadow: 0 12px 28px -18px rgba(var(--brand-deep-rgb), 0.42);
  font-size: 13px;
  font-weight: 900;
}

.brand-copy {
  min-width: 0;
}

.brand h1 {
  margin: 2px 0 3px;
  font-size: 24px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p {
  max-width: 520px;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0;
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.source-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.filter-chips {
  display: flex;
  min-width: 0;
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
}

.release-health-notice {
  position: relative;
  z-index: 2;
  display: flex;
  width: min(calc(100% - (var(--page-gutter) * 2)), var(--page-max));
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 auto 12px;
  padding: 10px 14px;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: var(--color-surface-glass-strong);
  color: var(--color-text-secondary);
  box-shadow: var(--shadow-glass);
}

.release-health-notice strong {
  color: var(--color-text-primary);
  white-space: nowrap;
}

.release-health-notice.is-warning {
  border-color: var(--color-risk-warning);
}

.release-health-notice.is-critical {
  border-color: var(--color-risk-critical);
}

.release-health-notice.is-info {
  border-color: var(--color-risk-info);
}

.release-health-notice details {
  flex-basis: 100%;
  color: var(--color-text-secondary);
}

.release-health-notice details summary {
  cursor: pointer;
  color: var(--color-text-primary);
}

.psi2-conflict-badge {
  display: block;
  margin-top: 3px;
  color: var(--color-risk-warning);
  font-size: 0.72rem;
  line-height: 1.25;
}

.meta-chip,
.filter-chip,
.mod-badge,
.action-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid rgba(var(--brand-rgb), 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.meta-chip,
.filter-chip {
  padding: 5px 10px;
}

.filter-chip {
  gap: 4px;
  padding-right: 6px;
}

.filter-chip-clear {
  display: inline-flex;
  flex: 0 0 16px;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: transform var(--motion-fast) var(--motion-ease-out), opacity var(--motion-fast) var(--motion-ease-out);
}

.filter-chip-clear:hover {
  background: rgba(var(--brand-rgb), 0.12);
}

.filter-chip-clear:active {
  transform: scale(0.97);
}

.filter-chip-clear:focus-visible {
  outline: 2px solid var(--color-state-focus-ring, var(--brand));
  outline-offset: 1px;
}

.app-header .source-meta {
  gap: 0;
}

.app-header .brand-mark,
.app-header .meta-chip {
  box-shadow: none;
}

.app-header .brand-mark {
  background: transparent;
}

.app-header .meta-chip {
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-secondary);
}

.app-header .meta-chip + .meta-chip::before {
  margin: 0 8px;
  color: var(--muted);
  content: "\00b7";
}

.meta-chip.is-cyan {
  border-color: rgba(6, 182, 212, 0.22);
  background: rgba(6, 182, 212, 0.09);
  color: #0e7490;
}

.meta-chip.is-modified,
.mod-badge {
  border-color: rgba(var(--brand-rgb), 0.3);
  background: var(--brand-soft);
  color: var(--brand-strong);
  box-shadow: 0 8px 22px -16px rgba(var(--brand-deep-rgb), 0.48);
}

.mod-badge {
  min-height: 22px;
  padding: 2px 7px;
  font-size: 11px;
}

.mod-badge.inline {
  min-height: 18px;
  padding: 1px 6px;
  font-size: 10px;
}

.mod-badge.muted,
.muted-chip {
  border-color: rgba(148, 163, 184, 0.18);
  background: rgba(255, 255, 255, 0.38);
  color: var(--muted);
  box-shadow: none;
}

.save-status {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-status.is-saving {
  border-color: rgba(6, 182, 212, 0.24);
  background: rgba(6, 182, 212, 0.1);
  color: #0e7490;
}

.save-status.is-success {
  border-color: rgba(16, 185, 129, 0.24);
  background: rgba(16, 185, 129, 0.11);
  color: #047857;
}

.save-status.is-error {
  border-color: rgba(239, 68, 68, 0.26);
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

.save-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 1400;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--glass-strong);
  box-shadow: var(--shadow-lift);
  color: var(--ink);
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 16px) scale(0.97);
  transition:
    transform var(--motion-fast) var(--motion-ease-out),
    opacity var(--motion-fast) var(--motion-ease-out);
}

.save-toast.is-open {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.save-toast.is-success {
  border-color: rgba(16, 185, 129, 0.26);
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}

.save-toast.is-error {
  border-color: rgba(239, 68, 68, 0.26);
  background: rgba(239, 68, 68, 0.12);
  color: #b91c1c;
}

.form-field.is-shaking,
.add-row-form .custom-select.is-shaking,
.add-row-form .control-input.is-shaking {
  animation: fieldShake 280ms linear;
}

@keyframes fieldShake {
  0% { transform: translateX(0); }
  28.57% { transform: translateX(6px); }
  57.14% { transform: translateX(-6px); }
  78.57% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

.action-badge {
  min-height: 28px;
  padding: 4px 10px;
  border-color: rgba(148, 163, 184, 0.22);
  background: rgba(255, 255, 255, 0.5);
  color: #475569;
  justify-content: center;
}

.action-badge.is-pull-in {
  border-color: var(--color-action-pull-in-border, rgba(236, 72, 153, 0.22));
  background: var(--color-action-pull-in-background, rgba(236, 72, 153, 0.1));
  color: var(--color-action-pull-in-text, #be185d);
}

.action-badge.is-push-out {
  border-color: var(--color-action-push-out-border, rgba(245, 158, 11, 0.24));
  background: var(--color-action-push-out-background, rgba(245, 158, 11, 0.12));
  color: var(--color-action-push-out-text, #b45309);
}

.action-badge.is-borrow {
  border-color: var(--color-action-borrow-border, rgba(6, 182, 212, 0.26));
  background: var(--color-action-borrow-background, rgba(6, 182, 212, 0.11));
  color: var(--color-action-borrow-text, #0e7490);
}

.action-badge.is-po {
  border-color: var(--color-action-purchase-border, rgba(16, 185, 129, 0.24));
  background: var(--color-action-purchase-background, rgba(16, 185, 129, 0.11));
  color: var(--color-action-purchase-text, #047857);
}

.action-badge.is-no-limit {
  border-color: var(--color-action-no-limit-border, rgba(100, 116, 139, 0.22));
  background: var(--color-action-no-limit-background, rgba(100, 116, 139, 0.1));
  color: var(--color-action-no-limit-text, #475569);
}

.action-badge.is-done {
  border-color: var(--color-action-done-border, rgba(100, 116, 139, 0.22));
  background: var(--color-action-done-background, rgba(100, 116, 139, 0.1));
  color: var(--color-action-done-text, #475569);
}

.data-status-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.data-status-legend-key,
.data-status-legend-marks {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
}

.data-status-legend-key {
  gap: 10px;
}

.data-status-legend-marks {
  gap: 16px;
}

.data-status-legend-source {
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.data-status-legend-split {
  width: 1px;
  height: 22px;
  flex: 0 0 auto;
  background: var(--color-foreground-line, rgba(37, 72, 78, 0.18));
}

.data-status-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.customer-status-ring {
  display: inline-flex;
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: transparent;
  color: var(--color-risk-neutral, #94a3b8);
}

.customer-status-ring.is-status-confirmed {
  color: var(--color-state-success, #16a34a);
  background: currentColor;
  box-shadow: inset 0 0 0 2px var(--color-surface, #fff);
}
.customer-status-ring.is-status-partial {
  color: var(--color-risk-info, #06b6d4);
  border-style: dotted;
}
.customer-status-ring.is-status-pending {
  color: var(--color-risk-warning, #f59e0b);
  border-style: dashed;
}
.customer-status-ring.is-status-error {
  color: var(--color-risk-critical, #ef4444);
  border-style: dotted;
  background: currentColor;
  box-shadow: inset 0 0 0 3px var(--color-surface, #fff);
}
.customer-status-ring.is-status-conflict {
  color: var(--color-risk-critical, #ef4444);
  border: 3px double currentColor;
}
.customer-status-ring.is-status-unavailable {
  color: var(--color-risk-neutral, #94a3b8);
  border-style: dashed;
}
.customer-status-ring.is-status-integrity {
  color: var(--color-risk-critical, #ef4444);
  background: currentColor;
}
.customer-status-ring.is-status-neutral { color: var(--color-risk-neutral, #94a3b8); }

.actual-customer-value {
  display: flex !important;
  width: 100% !important;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
}

.actual-customer-value > .customer-status-ring,
.actual-customer-value > .source-hang-marks {
  margin-left: auto;
}

.source-hang-marks {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  flex: 0 0 auto;
}

.source-hang-slot {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.source-hang-slot-label {
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  color: var(--muted);
}

.source-hang-mark {
  display: inline-flex;
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  box-sizing: border-box;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: transparent;
}

.source-hang-mark.is-hang-hung {
  color: var(--color-state-success, #16a34a);
  background: currentColor;
  box-shadow: inset 0 0 0 2px var(--color-surface, #fff);
}

.source-hang-mark.is-hang-absent {
  color: var(--color-risk-neutral, #64748b);
  background: transparent;
}

.source-hang-mark.is-hang-unassigned {
  color: var(--color-risk-warning, #f59e0b);
  border-style: dashed;
}

.source-hang-mark.is-hang-stuck {
  color: var(--color-risk-critical, #ef4444);
  border-radius: 1px;
  background: currentColor;
}

.actual-customer-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.same-demand-tag {
  display: inline-flex;
  flex: 0 0 auto;
  min-height: 18px;
  align-items: center;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.action-badge-stack {
  display: inline-flex;
  align-items: center;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.action-badge-quantity {
  color: var(--color-text-muted, var(--muted));
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.action-badge-quantity.is-pull-in {
  color: var(--color-action-pull-in-text, #be185d);
}

.action-badge-quantity.is-push-out {
  color: var(--color-action-push-out-text, #b45309);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  width: min(calc(100% - (var(--page-gutter) * 2)), var(--page-max));
  margin: 0 auto;
  padding: 22px 24px 0;
}


.panel-heading,
.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 已套用 chip 與清除篩選靠左，圖例靠右同一列。 */
.table-heading-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 16px;
  min-width: 0;
}

.table-heading-meta .table-filter-toolbar {
  flex: 0 1 auto;
  min-width: 0;
}

.table-heading-meta .data-status-legend {
  flex: 0 0 auto;
  margin-left: auto;
}

.table-filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.filter-clear-button {
  height: 28px;
  min-height: 28px;
  padding: 0 10px;
  line-height: 1;
}

.filter-clear-button .icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.filter-clear-button span:not(.icon) {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.page-tabs-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  border-bottom: 1px solid var(--color-border-subtle);
}

.page-tabs {
  position: relative;
  display: inline-flex;
  flex: 0 1 auto;
  width: fit-content;
  min-width: 0;
  min-height: 54px;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  padding: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

.page-tabs,
.fcst-status-strip {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.page-tab {
  position: relative;
  z-index: 1;
  display: inline-flex;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  padding: 0 16px;
  text-decoration: none;
  touch-action: manipulation;
  white-space: nowrap;
  transition: transform var(--motion-fast) var(--motion-ease-out);
}

.page-tab:active {
  transform: scale(0.97);
}

.page-tab:focus-visible {
  border-color: rgba(var(--brand-rgb), 0.52);
  color: var(--brand-strong);
  outline: 3px solid var(--color-state-focus-ring, var(--brand));
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(var(--brand-rgb), 0.16);
}

.page-tab.is-active {
  background: transparent;
  box-shadow: none;
  color: var(--brand-strong);
}

.page-tab-indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 0;
  width: 0;
  height: 3px;
  border-radius: 999px;
  background: var(--brand-strong);
  opacity: 0.72;
  pointer-events: none;
  transform: translateX(0);
  transition:
    transform var(--motion-fast) var(--motion-ease-out),
    width var(--motion-fast) var(--motion-ease-out);
}

.page-tab-upload {
  color: var(--color-state-success, var(--emerald));
}

.fcst-status-strip {
  display: flex;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  align-items: center;
  align-content: center;
  flex: 1 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  margin-left: auto;
  padding: 0 8px 0 16px;
}

.fcst-status-strip.is-loading,
.fcst-status-strip.is-error {
  flex: 0 1 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.fcst-status-strip.is-error {
  color: var(--red);
}

.fcst-status-chip {
  position: relative;
  display: inline-flex;
  min-height: 24px;
  max-width: none;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  padding: 0;
  white-space: nowrap;
}

.fcst-status-chip::before {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  box-sizing: border-box;
  border-radius: 999px;
  content: "";
}

.fcst-status-chip.is-current-month {
  background: transparent;
  color: var(--color-text-primary);
}

.fcst-status-chip.is-current-month::before {
  background: var(--color-state-success);
}

.fcst-status-chip.is-not-current-month {
  background: transparent;
  color: var(--color-text-secondary);
}

.fcst-status-chip.is-not-current-month::before {
  background: var(--color-risk-warning);
  box-shadow: 0 0 0 1.5px var(--bg, #eef5f7), 0 0 0 3px var(--color-risk-warning);
}

.fcst-status-chip.is-not-uploaded {
  background: transparent;
  color: var(--color-text-muted);
}

.fcst-status-chip.is-not-uploaded::before {
  border: 2px solid var(--color-risk-neutral, #64748b);
  background: transparent;
}

.fcst-status-chip-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: 2;
  max-width: 240px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  background: var(--glass-strong);
  color: var(--ink);
  box-shadow: var(--shadow-glass);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.45;
  white-space: pre-line;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0) scale(0.98);
  transform-origin: 50% 100%;
  transition:
    opacity var(--motion-fast) var(--motion-ease-out),
    transform var(--motion-fast) var(--motion-ease-out);
}

.fcst-status-chip:hover .fcst-status-chip-tooltip,
.fcst-status-chip:focus-visible .fcst-status-chip-tooltip {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
  transition-delay: 80ms;
}

.data-relations-card {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.data-relations-heading {
  align-items: flex-start;
  margin-bottom: 0;
}

.data-relations-heading h2 {
  margin: 0;
}

.data-relations-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.data-relations-mode-switch {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.data-relations-intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.42);
  padding: 14px;
}

.data-relations-intro .eyebrow {
  margin: 0 0 5px;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.data-relations-intro strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

.data-relations-direction {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.45;
}

.data-relations-legend {
  display: flex;
  flex: 0 1 auto;
  width: max-content;
  max-width: min(760px, 60vw);
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  margin-right: 0;
  overflow: visible;
}

.data-relations-legend-item {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 8px 10px;
  white-space: nowrap;
}

.data-relations-legend-item i {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--legend-color, var(--muted));
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), 0.08);
}

.data-relations-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: 16px;
  min-height: 560px;
}

.data-relations-canvas-wrap {
  position: relative;
  min-height: 560px;
  overflow: hidden;
  border: 1px solid rgba(var(--brand-rgb), 0.18);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 20% 20%, rgba(var(--brand-rgb), 0.07), transparent 32%),
    radial-gradient(circle at 84% 80%, rgba(6, 182, 212, 0.12), transparent 32%),
    rgba(255, 255, 255, 0.46);
}

.data-relations-canvas-wrap::before {
  position: absolute;
  inset: 0;
  content: "";
  background: radial-gradient(circle at 1px 1px, rgba(var(--brand-rgb), 0.1) 1px, transparent 0) 0 0 / 22px 22px;
  pointer-events: none;
}

.data-relations-canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.data-relations-canvas:active {
  cursor: grabbing;
}

.data-relations-detail {
  min-height: 560px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.58);
  padding: 18px;
}

.data-relations-detail-kicker {
  margin: 0 0 8px;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.data-relations-detail h3 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  line-height: 1.12;
}

.data-relations-detail p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
}

.data-relations-relation-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.data-relations-relation-list li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 2px 8px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.5);
  padding: 9px;
}

.data-relations-relation-list span {
  grid-row: span 2;
  color: var(--brand-strong);
  font-weight: 900;
}

.data-relations-relation-list strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.data-relations-relation-list small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.formula-card {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.formula-visual-page {
  gap: 18px;
}

.formula-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.formula-heading h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.15;
}

.formula-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.formula-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.formula-item {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.38);
}

.formula-item h3 {
  margin: 0 0 8px;
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
}

.formula-item ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 17px;
}

.formula-item li {
  color: var(--color-text-secondary, var(--ink));
  font-size: 12px;
  font-weight: 650;
  line-height: 1.45;
}

.formula-flow-card-heading,
.formula-full-details summary {
  display: flex;
  align-items: center;
  gap: 12px;
}

.formula-flow-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0;
}

.formula-chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.formula-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 6px 10px;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
  border-radius: var(--radius-pill, 999px);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.15;
  white-space: normal;
}

.formula-core-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.formula-flow-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.52);
  outline: none;
}

.formula-flow-card:hover {
  border-color: var(--color-border-strong, rgba(80, 153, 175, 0.56));
  background: var(--glass-hover);
}

.formula-flow-steps {
  display: grid;
  gap: 10px;
}

.formula-flow-step {
  display: grid;
  gap: 6px;
}

.formula-flow-step-main code {
  display: block;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(16, 31, 35, 0.06);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.5;
  white-space: normal;
  word-break: break-word;
}

.formula-step-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.formula-step-label-impact {
  font-weight: var(--typography-weight-strong, 800);
}

.formula-step-impact-text {
  font-weight: var(--typography-weight-strong, 800);
}

.formula-flow-step p,
.formula-flow-step strong {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.formula-full-details {
  padding: 14px;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.5);
}

.formula-full-details summary {
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  list-style: none;
}

.formula-full-details summary::-webkit-details-marker {
  display: none;
}

.formula-decision-section {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.5);
}

.formula-decision-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.formula-decision-heading h3,
.formula-decision-heading p,
.formula-decision-detail h3,
.formula-decision-detail h4,
.formula-decision-detail p {
  margin: 0;
}

.formula-decision-heading h3 {
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
}

.formula-decision-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.45;
}

.formula-decision-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
  gap: 16px;
  align-items: start;
}

.formula-tree-pane {
  min-width: 0;
  overflow-x: auto;
  padding: 2px;
}

.formula-tree-root {
  position: relative;
  display: flex;
  justify-content: center;
  padding-bottom: 22px;
}

.formula-tree-root::after {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 1px;
  height: 18px;
  background: var(--color-foreground-line-strong, rgba(47, 79, 86, 0.28));
  content: "";
}

.formula-tree-columns {
  display: grid;
  min-width: 780px;
  grid-template-columns: repeat(3, minmax(240px, 1fr));
  gap: 12px;
  align-items: start;
}

.formula-tree-branch {
  position: relative;
  min-width: 0;
  padding: 14px 10px 0;
  border-top: 1px solid var(--color-foreground-line-strong, rgba(47, 79, 86, 0.28));
}

.formula-tree-branch::before {
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: 12px;
  background: var(--color-foreground-line-strong, rgba(47, 79, 86, 0.28));
  content: "";
}

.formula-tree-path,
.formula-tree-children {
  margin: 0;
  padding: 0;
  list-style: none;
}

.formula-tree-path {
  margin-top: 10px;
}

.formula-tree-item {
  min-width: 0;
}

.formula-tree-children {
  display: grid;
  gap: 8px;
  margin: 8px 0 0 14px;
  padding-left: 12px;
  border-left: 1px solid var(--color-foreground-line, rgba(47, 79, 86, 0.18));
}

.formula-tree-edge {
  position: relative;
  display: grid;
  min-width: 0;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
}

.formula-tree-edge::before {
  position: absolute;
  top: 13px;
  left: -12px;
  width: 12px;
  height: 1px;
  background: var(--color-foreground-line, rgba(47, 79, 86, 0.18));
  content: "";
}

.formula-tree-answer {
  display: inline-flex;
  width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.14));
  border-radius: 50%;
  background: var(--color-foreground-surface-control, rgba(255, 255, 255, 0.78));
  color: var(--color-text-secondary, var(--muted));
  font-size: 11px;
  font-weight: 800;
}

.formula-tree-node {
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  gap: 3px;
  align-content: center;
  padding: 9px 10px;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.14));
  border-radius: var(--radius-sm);
  background: var(--color-foreground-surface-control, rgba(255, 255, 255, 0.78));
  color: var(--ink);
  text-align: left;
  box-shadow: none;
  cursor: pointer;
}

.formula-tree-node:hover {
  border-color: var(--color-border-strong, rgba(80, 153, 175, 0.56));
  background: var(--color-foreground-surface-data-hover, rgba(255, 255, 255, 0.92));
}

.formula-tree-node:focus-visible,
.formula-tree-node.is-selected {
  border-color: var(--color-state-focus-ring, var(--brand));
  outline: 2px solid color-mix(in srgb, var(--color-state-focus-ring, var(--brand)) 28%, transparent);
  outline-offset: 2px;
}

.formula-tree-node strong {
  color: inherit;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.formula-tree-node small {
  color: inherit;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.35;
  opacity: 0.76;
}

.formula-tree-node.is-root {
  width: min(100%, 320px);
  min-height: 52px;
  border-color: var(--color-brand-base, var(--brand));
  background: var(--brand-soft);
  color: var(--brand-strong);
  text-align: center;
}

.formula-tree-node.is-scenario {
  position: relative;
  min-height: 58px;
  background: var(--color-foreground-surface-strong, rgba(238, 246, 242, 0.88));
  text-align: center;
}

.formula-tree-node.is-action-pull-in {
  border-color: var(--color-action-pull-in-border);
  background: var(--color-action-pull-in-background);
  color: var(--color-action-pull-in-text);
}

.formula-tree-node.is-action-borrow {
  border-color: var(--color-action-borrow-border);
  background: var(--color-action-borrow-background);
  color: var(--color-action-borrow-text);
}

.formula-tree-node.is-action-push-out {
  border-color: var(--color-action-push-out-border);
  background: var(--color-action-push-out-background);
  color: var(--color-action-push-out-text);
}

.formula-tree-node.is-action-purchase {
  border-color: var(--color-action-purchase-border);
  background: var(--color-action-purchase-background);
  color: var(--color-action-purchase-text);
}

.formula-tree-node.is-terminal {
  border-color: var(--color-action-done-border);
  background: var(--color-action-done-background);
  color: var(--color-action-done-text);
}

.formula-decision-detail {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.14));
  border-radius: var(--radius-md);
  background: var(--color-foreground-surface-data, rgba(255, 255, 255, 0.82));
}

.formula-decision-detail h3 {
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
}

.formula-decision-detail-section {
  display: grid;
  gap: 4px;
}

.formula-decision-detail-section h4 {
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
}

.formula-decision-detail-section p,
.formula-decision-detail-section code {
  color: var(--color-text-secondary, var(--ink));
  font-family: "Noto Sans TC", var(--typography-family-sans);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.5;
}

.formula-decision-detail-section code {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(16, 31, 35, 0.06);
  white-space: normal;
}

.formula-card.formula-visual-page :not(h2, h3, h4, summary) {
  font-family: "Noto Sans TC", var(--typography-family-sans);
}

.formula-visual-page .formula-heading p,
.formula-visual-page .formula-chip,
.formula-visual-page .formula-item li,
.formula-visual-page .formula-flow-step-main code,
.formula-visual-page .formula-step-label,
.formula-visual-page .formula-flow-step p,
.formula-visual-page .formula-flow-step strong {
  font-size: 12px;
  font-weight: 650;
}

.formula-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.search-shell,
.select-shell {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
}

.search-shell .icon {
  position: absolute;
  left: 13px;
  z-index: 1;
  color: var(--brand);
}

.control-input,
.edit-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-weight: 600;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.control-input {
  padding: 0 14px 0 42px;
}

.control-input:focus,
.edit-input:focus {
  border-color: rgba(var(--brand-rgb), 0.58);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), 0.14);
}

.custom-select {
  position: relative;
  width: 100%;
  min-width: 0;
}

.custom-select-trigger {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 11px 0 13px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.66));
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), 0 8px 24px -24px rgba(var(--brand-deep-rgb), 0.42);
  transition: transform var(--motion-fast) var(--motion-ease-out), border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease, background var(--motion-fast) ease;
}

.custom-select-trigger:active {
  transform: scale(0.98);
}

.custom-select-trigger:focus-visible,
.custom-select.is-open .custom-select-trigger {
  border-color: rgba(var(--brand-rgb), 0.62);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), 0.14), 0 18px 34px -28px rgba(var(--brand-deep-rgb), 0.5);
}

.custom-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-value.is-placeholder {
  color: var(--muted);
}

.custom-select-trigger > .icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--brand);
  transition: transform var(--motion-fast) var(--motion-ease-out);
}

.custom-select.is-open .custom-select-trigger > .icon {
  transform: rotate(180deg);
}

.custom-select-panel {
  position: fixed;
  z-index: 1000;
  display: grid;
  gap: 8px;
  max-height: min(390px, calc(100vh - 24px));
  padding: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: var(--radius-md);
  background: rgba(250, 252, 253, 0.86);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.96), 0 30px 76px -28px rgba(15, 23, 42, 0.42), 0 0 0 1px rgba(var(--brand-rgb), 0.1);
  backdrop-filter: blur(28px) saturate(175%);
  -webkit-backdrop-filter: blur(28px) saturate(175%);
  transform-origin: var(--dropdown-origin-x, 50%) var(--dropdown-origin-y, top);
  transform: scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition:
    transform var(--motion-fast) var(--motion-ease-out),
    opacity var(--motion-fast) var(--motion-ease-out);
  will-change: transform, opacity;
}

.custom-select-panel.is-open {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

.custom-select-panel.is-closing {
  transform: scale(0.99);
  opacity: 0;
  pointer-events: none;
}

.custom-select-search-shell {
  position: relative;
  display: flex;
  align-items: center;
}

.custom-select-search-shell .icon {
  position: absolute;
  left: 11px;
  z-index: 1;
  width: 16px;
  height: 16px;
  color: var(--brand);
  pointer-events: none;
}

.custom-select-search {
  width: 100%;
  min-height: 38px;
  padding: 0 11px 0 35px;
  border: 1px solid rgba(var(--brand-rgb), 0.2);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  font-weight: 650;
  outline: none;
}

.custom-select-search:focus {
  border-color: rgba(var(--brand-rgb), 0.56);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.12);
}

.custom-select-options {
  display: grid;
  gap: 3px;
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--brand-rgb), 0.32) transparent;
}

.custom-select-option {
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px 7px 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary, var(--ink));
  font-weight: 650;
  text-align: left;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.custom-select-option:hover,
.custom-select-option.is-highlighted {
  border-color: rgba(var(--brand-rgb), 0.12);
  background: rgba(var(--brand-rgb), 0.09);
  color: var(--brand-strong);
}

.custom-select-option.is-selected {
  border-color: rgba(var(--brand-rgb), 0.2);
  background: linear-gradient(135deg, rgba(var(--brand-rgb), 0.16), rgba(255, 255, 255, 0.44));
  color: var(--brand-strong);
}

.custom-select-option-copy {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 1px;
}

.custom-select-option-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-filter-panel .custom-select-option {
  justify-content: flex-start;
  font-size: var(--typography-table-body-size, 13px);
  font-weight: var(--typography-table-body-weight, 600);
  line-height: var(--typography-table-body-line-height, 1.35);
  text-align: left;
}

.header-filter-panel .custom-select-option-label {
  flex: 1 1 auto;
  text-align: left;
}

.custom-select-option-hint {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-muted, var(--muted));
  font-size: var(--typography-form-label-size, 12px);
  font-weight: var(--typography-form-label-weight, 800);
  line-height: var(--typography-form-label-line-height, 1.2);
}

.custom-select-option .icon,
.custom-select-option-spacer {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
}

.custom-select-option .icon {
  color: var(--brand);
}

.custom-select-empty {
  padding: 18px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid rgba(var(--brand-rgb), 0.2);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.56));
  color: var(--brand-strong);
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 12px 30px -26px rgba(16, 37, 42, 0.5);
  white-space: nowrap;
  transition: transform var(--motion-fast) var(--motion-ease-out), border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease, background var(--motion-fast) ease;
}

.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled),
.danger-button:active:not(:disabled) {
  transform: translateY(0) scale(0.97);
}

.primary-button:focus-visible,
.secondary-button:focus-visible,
.danger-button:focus-visible {
  outline: 3px solid var(--color-state-focus-ring, var(--brand));
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(var(--brand-rgb), 0.16);
}

.primary-button {
  border-color: rgba(var(--brand-rgb), 0.36);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(var(--brand-rgb), 0.12));
  color: var(--brand-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.96), 0 12px 28px -22px rgba(var(--brand-deep-rgb), 0.44);
}

.danger-button {
  border-color: rgba(239, 68, 68, 0.22);
  color: var(--red);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.period-zone {
  grid-column: span 8;
  display: grid;
  gap: 16px;
  padding: 18px;
}

.panel-icon {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(var(--brand-rgb), 0.16), rgba(255, 255, 255, 0.48));
  color: var(--brand-strong);
  box-shadow: 0 16px 34px -24px rgba(var(--brand-deep-rgb), 0.44);
}

.brand-mark .icon,
.brand-mark svg,
.panel-icon .icon,
.panel-icon svg {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.brand-mark svg,
.panel-icon svg {
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.panel-icon-formula {
  background: linear-gradient(135deg, var(--color-action-push-out-background), var(--brand-soft));
  color: var(--color-action-push-out-text, var(--amber));
}

.panel-icon-network {
  background: linear-gradient(135deg, var(--color-action-borrow-background), var(--brand-soft));
  color: var(--color-action-borrow-text, var(--brand-strong));
}

.panel-icon-table {
  background: linear-gradient(135deg, var(--brand-soft), rgba(80, 153, 175, 0.1));
  color: var(--brand-strong);
}

.panel-heading h2,
.section-heading h2 {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0;
}

.part-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
}

.part-title strong {
  min-width: 0;
  color: var(--ink);
  font-size: 25px;
  font-weight: 900;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.modified-dot {
  display: inline-flex;
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.4);
}

.modified-dot.show {
  background: var(--brand);
  box-shadow: 0 0 0 5px rgba(var(--brand-rgb), 0.14), 0 0 20px rgba(var(--brand-rgb), 0.42);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.detail-card {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid rgba(255, 255, 255, 0.44);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.44);
}

.detail-card-order {
  grid-row: span 2;
  align-content: center;
}

.detail-grid dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 0;
  color: #334155;
  overflow-wrap: anywhere;
}

.edit-summary {
  display: grid;
  gap: 8px;
  padding: 15px;
  border: 1px solid rgba(var(--brand-rgb), 0.16);
  border-radius: var(--radius-md);
  background: rgba(var(--brand-rgb), 0.06);
}

.edit-summary span {
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
}

.edit-summary strong {
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
}

.edit-summary small,
.period-edit small {
  color: var(--muted);
  font-size: 11px;
}

.selected-row-detail {
  position: sticky;
  left: 0;
  z-index: 32;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
  background: var(--color-foreground-surface-control);
}

.selected-row-reason {
  flex: 1 1 12rem;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--color-text-secondary, var(--ink));
  font-size: var(--typography-table-body-size, 13px);
  font-weight: var(--typography-table-body-weight, 600);
  line-height: var(--typography-table-body-line-height, 1.35);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-row-detail .row-delete-button {
  margin-left: auto;
}

.manual-delete-confirm {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

.manual-delete-confirm .form-field {
  flex: 1 1 12rem;
  min-width: 0;
}

.manual-delete-confirm .control-input {
  padding-left: 14px;
}

.manual-delete-confirm [role="alert"] {
  flex: 1 1 100%;
  max-width: none;
}

.ratio-summary-card {
  width: 100%;
  min-height: 0;
}

.ratio-summary-card strong {
  font-size: 20px;
}

.ratio-summary-card.is-pull-in {
  border-color: rgba(236, 72, 153, 0.28);
  background: rgba(236, 72, 153, 0.1);
}

.ratio-summary-card.is-pull-in span,
.ratio-summary-card.is-pull-in small {
  color: #be185d;
}

.ratio-summary-card.is-po {
  border-color: rgba(16, 185, 129, 0.28);
  background: rgba(16, 185, 129, 0.1);
}

.ratio-summary-card.is-po span,
.ratio-summary-card.is-po small {
  color: #047857;
}

.ratio-summary-card.is-stop {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
}

.ratio-summary-card.is-stop span,
.ratio-summary-card.is-stop small {
  color: #b91c1c;
}

.ratio-summary-card.is-neutral {
  border-color: rgba(148, 163, 184, 0.26);
  background: rgba(148, 163, 184, 0.1);
}

.ratio-summary-card.is-neutral span,
.ratio-summary-card.is-neutral small {
  color: #475569;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.period-heading {
  justify-content: space-between;
}

.period-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.period-card {
  min-width: 0;
  padding: 0;
  color: var(--neon-cyan);
}

.period-card.current-period {
  color: var(--brand);
  box-shadow: 0 18px 40px -28px rgba(var(--brand-deep-rgb), 0.42), var(--shadow-glass);
}

.period-card.dirty-card {
  border-color: rgba(var(--brand-rgb), 0.32);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), 0.1), var(--shadow-glass);
}

.period-card.risk-card {
  border-color: rgba(239, 68, 68, 0.22);
}

.period-card.risk-card.current-period {
  animation: pulseGlow 2s ease-in-out infinite alternate;
}

.period-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.period-head span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.period-head strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.risk-dot,
.safe-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.risk-dot {
  background: var(--red);
  box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.12), 0 0 20px rgba(239, 68, 68, 0.55);
}

.safe-dot {
  background: var(--emerald);
  box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.12);
}

.period-body {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.period-edit,
.period-stat {
  display: grid;
  gap: 5px;
}

.period-edit span,
.period-stat span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.period-stat strong {
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
  line-height: 1.1;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.input-wrap {
  position: relative;
}

.edit-input {
  min-height: 42px;
  padding: 0 55px 0 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.edit-input.dirty {
  border-color: rgba(var(--brand-rgb), 0.55);
  background: rgba(var(--brand-rgb), 0.1);
  color: var(--brand-strong);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), 0.13);
}

.p-edit-header,
.p-edit-cell {
  width: 108px;
  min-width: 108px;
  max-width: 108px;
}

.p-edit-header {
  text-align: center !important;
}

.p-edit-cell {
  background: rgba(255, 255, 255, 0.2);
}

.table-edit {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.table-edit .input-wrap {
  display: grid;
  width: 100%;
  justify-items: end;
  gap: 2px;
}

.table-edit-input {
  width: 100%;
  min-height: var(--space-table-edit-pill-height, 30px);
  padding: 0 9px;
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.table-edit-input.dirty {
  padding-right: 9px;
}

.original-value-hint {
  justify-self: end;
  margin-right: 2px;
  color: var(--color-state-edited, var(--brand));
  font-size: 10px;
  font-weight: 900;
  line-height: 1.05;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.table-edit .original-value-hint {
  font-size: 10px;
}

.table-edit small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.table-readonly-plain {
  position: relative;
  display: block;
  width: 100%;
  margin-left: auto;
  padding: 0;
}

.table-readonly-plain-value {
  width: 100%;
  display: block;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink);
}

.action-edit-header,
.action-edit-cell {
  width: 126px;
  min-width: 126px;
  max-width: 126px;
}

.table-action-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.dashboard-table .col-salesOwner {
  width: 132px;
  min-width: 132px;
  max-width: 132px;
  white-space: normal;
}

.sales-owner-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  line-height: 1.15;
}

.sales-owner-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sales-owner-id {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.05;
}

.dashboard-table .col-orderCustomer {
  width: var(--order-customer-width, 96px);
  min-width: var(--order-customer-width, 96px);
  max-width: var(--order-customer-width, 96px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.dashboard-table .col-shipCustomer {
  width: 100px;
  min-width: 100px;
  max-width: 100px;
}

.dashboard-table .col-productLine {
  width: 70px;
  min-width: 70px;
  max-width: 70px;
  text-align: center;
}

.dashboard-table .col-purchasePrice {
  width: 72px;
  min-width: 72px;
  max-width: 72px;
}

.dashboard-table .col-isRatioLimit {
  width: 104px;
  min-width: 104px;
  max-width: 104px;
}

.dashboard-table .col-rolling,
.dashboard-table .col-inventory {
  width: 108px;
  min-width: 108px;
  max-width: 108px;
}

.reset-header,
.reset-cell {
  width: 92px;
  min-width: 92px;
  text-align: center !important;
}

.row-reset-button {
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid rgba(var(--brand-rgb), 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 800;
}

.row-reset-button .icon {
  width: 14px;
  height: 14px;
}

.row-delete-button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 11px;
}

.table-heading-actions {
  --table-action-height: 44px;
  --table-action-radius: 16px;
  --table-action-width: 120px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.table-heading-actions > .primary-button,
.table-heading-actions > .secondary-button,
.table-heading-actions > .danger-button,
.table-heading-actions .export-menu-trigger {
  width: var(--table-action-width);
  min-width: var(--table-action-width);
  height: var(--table-action-height);
  min-height: var(--table-action-height);
  padding: 0 12px;
  border-radius: var(--table-action-radius);
  font-size: var(--typography-table-body-size, 13px);
}

.export-menu {
  display: inline-flex;
  width: var(--table-action-width);
}

.export-menu-trigger {
  width: 100%;
}

.export-menu-trigger .icon:last-child {
  width: 14px;
  height: 14px;
}

.export-menu.is-open .export-menu-trigger .icon:last-child {
  transform: rotate(180deg);
}

.export-menu-panel .custom-select-option {
  min-height: 34px;
}

.table-reset-all {
  width: 152px;
  min-width: 152px;
  min-height: 32px;
  overflow: hidden;
  padding: 0 12px;
  justify-content: center;
}

.table-reset-all span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.add-row-form {
  position: sticky;
  left: 0;
  display: grid;
  gap: 16px;
  width: auto;
  max-width: 100%;
  min-width: 0;
  margin: 12px 12px 16px;
  padding: 16px 18px 18px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-foreground-surface-control);
  box-shadow: var(--shadow-lift);
  backdrop-filter: blur(18px);
}

.add-row-form .eyebrow {
  color: var(--color-foreground-accent-warm);
}

.add-row-title,
.add-row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.add-row-title h3 {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
}

.add-row-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
}

.form-field {
  display: grid;
  gap: 6px;
}

.form-field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.add-row-form .form-field-reason {
  grid-column: 1 / -1;
}

.add-row-form .form-field-reason .control-input {
  padding-left: 14px;
  font-size: var(--typography-table-body-size, 13px);
  font-weight: var(--typography-table-body-weight, 600);
  line-height: var(--typography-table-body-line-height, 1.35);
}

.add-row-matrix-wrap {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
}

.add-row-matrix {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.add-row-matrix th,
.add-row-matrix td {
  padding: 6px;
  vertical-align: middle;
  border: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
}

.add-row-matrix-corner,
.add-row-matrix-metric {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 7.5rem;
  background: var(--color-foreground-surface-control);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
}

.add-row-matrix-month {
  min-width: 6.5rem;
  background: var(--color-surface-glass-strong);
  color: var(--color-brand-strong);
  border-bottom: 2px solid var(--color-brand-base);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.add-row-matrix-month .add-row-matrix-period-name,
.add-row-matrix-month .add-row-matrix-period-label {
  display: block;
}

.add-row-matrix th.add-row-matrix-month.month-offset-0 {
  background: var(--color-brand-strong);
  color: var(--color-text-inverse, #fff);
}

.add-row-matrix-current-col {
  background: var(--color-brand-soft);
}

.add-row-matrix-empty {
  display: block;
  color: var(--muted);
  text-align: center;
}

.add-row-matrix-only-current {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.add-row-matrix .control-input {
  min-width: 5.5rem;
  padding: 0 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.negative-value {
  color: var(--red) !important;
}

.table-wrap {
  --table-toolbar-offset: 112px;
  --table-horizontal-scrollbar-height: 18px;
  position: relative;
  overflow: auto;
  max-height: 1420px;
  min-height: 1360px;
  border-color: var(--color-border-default, var(--line));
  background: var(--color-surface-table-frozen, #fffce6);
  box-shadow: 0 10px 30px -24px var(--color-foreground-shadow, rgba(37, 72, 78, 0.17));
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.table-horizontal-scrollbar {
  position: sticky;
  top: calc(var(--table-toolbar-offset, 76px) + var(--table-header-height, 90px));
  left: 0;
  z-index: 33;
  width: 100%;
  height: var(--table-horizontal-scrollbar-height);
  margin-bottom: calc(-1 * var(--table-horizontal-scrollbar-height));
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
  border-bottom: 1px solid var(--color-border-subtle, rgba(32, 61, 70, 0.12));
  background: var(--glass-strong);
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--brand-rgb), 0.55) rgba(255, 255, 255, 0.42);
}

.table-horizontal-scrollbar::-webkit-scrollbar {
  height: 14px;
}

.table-horizontal-scrollbar::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.42);
  border-radius: var(--radius-pill, 999px);
}

.table-horizontal-scrollbar::-webkit-scrollbar-thumb {
  background: rgba(64, 122, 140, 0.55);
  border-radius: var(--radius-pill, 999px);
}

.table-horizontal-scrollbar-inner {
  height: 1px;
}

.table-wrap > .table-sticky-head {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 34;
  background: var(--color-foreground-surface-strong, #e8eeeb);
}

.table-wrap > .table-sticky-head > .section-heading {
  position: relative;
  top: auto;
  left: auto;
  z-index: auto;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 6px;
  padding: 10px 18px;
  background: var(--color-foreground-surface-strong, #e8eeeb);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.table-wrap > .table-sticky-head .selected-row-detail {
  position: relative;
  left: auto;
  z-index: auto;
}

.section-heading {
  position: sticky;
  left: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(242, 247, 249, 0.58));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.94), 0 14px 34px -34px rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(22px) saturate(155%);
  -webkit-backdrop-filter: blur(22px) saturate(155%);
}

.section-heading-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.section-heading-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.dashboard-table {
  width: max-content;
  min-width: 100%;
  --frozen-product-line-width: 70px;
  --frozen-part-no-width: 160px;
  --frozen-actual-ship-customer-width: 180px;
  --frozen-order-customer-width: var(--order-customer-width, 96px);
  --frozen-purchase-price-width: 72px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

.dashboard-table .frozen-column {
  position: sticky;
  z-index: 5;
  background: var(--color-surface-table-frozen, #fffce6);
}

.dashboard-table .frozen-product-line {
  left: 0;
  width: var(--frozen-product-line-width);
  min-width: var(--frozen-product-line-width);
  max-width: var(--frozen-product-line-width);
}

.dashboard-table .frozen-part-no {
  left: var(--frozen-product-line-width);
  width: var(--frozen-part-no-width);
  min-width: var(--frozen-part-no-width);
  max-width: var(--frozen-part-no-width);
}

.dashboard-table .frozen-actual-ship-customer {
  left: calc(var(--frozen-product-line-width) + var(--frozen-part-no-width));
  width: var(--frozen-actual-ship-customer-width);
  min-width: var(--frozen-actual-ship-customer-width);
  max-width: var(--frozen-actual-ship-customer-width);
  white-space: nowrap;
  overflow: hidden;
}

.dashboard-table .frozen-order-customer {
  left: calc(var(--frozen-product-line-width) + var(--frozen-part-no-width) + var(--frozen-actual-ship-customer-width));
  width: var(--frozen-order-customer-width);
  min-width: var(--frozen-order-customer-width);
  max-width: var(--frozen-order-customer-width);
}

.dashboard-table .frozen-purchase-price {
  left: calc(var(--frozen-product-line-width) + var(--frozen-part-no-width) + var(--frozen-actual-ship-customer-width) + var(--frozen-order-customer-width));
  width: var(--frozen-purchase-price-width);
  min-width: var(--frozen-purchase-price-width);
  max-width: var(--frozen-purchase-price-width);
  box-shadow: 3px 0 0 var(--color-border-subtle, rgba(32, 61, 70, 0.18));
}

.dashboard-table .frozen-actual-ship-customer > span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-table .frozen-actual-ship-customer .actual-customer-value {
  background: transparent;
}

.dashboard-table th,
.dashboard-table td {
  padding: var(--space-table-cell-y, 5px) var(--space-table-cell-x, 10px);
  border-right: 1px solid rgba(148, 163, 184, 0.15);
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  vertical-align: middle;
}

.dashboard-table th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface-table-header, #3b7080);
  color: var(--color-text-inverse, #fff);
  font-weight: 900;
  text-align: center;
  white-space: normal;
  backdrop-filter: none;
}

/* 凍結表頭必須高於一般 base-header（z-index:12）與月份副標（11），避免向左捲動時被蓋住。 */
.dashboard-table thead .frozen-column,
.dashboard-table .month-group-row th.frozen-column,
.dashboard-table .month-group-row .base-header.frozen-column {
  z-index: 16;
  background: var(--color-surface-table-header, #3b7080);
}

.dashboard-table .month-group-row th {
  top: var(--table-toolbar-offset, 76px);
  height: 38px;
  padding-top: 9px;
  padding-bottom: 8px;
  border-bottom: 0;
  background: var(--color-surface-table-header, #3b7080);
  color: var(--color-text-inverse, #fff);
  font-size: 12px;
  letter-spacing: 0;
}

/* 月份深淺條紋：偶數月（當月、+2、+4）深褐，奇數月淺褐。
   上排月份帶與該月副標列同色；前 8 欄基礎欄維持 table-header。 */
.dashboard-table .month-group-header.month-offset-0,
.dashboard-table .month-group-header.month-offset-2,
.dashboard-table .month-group-header.month-offset-4,
.dashboard-table .month-subheader-row th.month-offset-0,
.dashboard-table .month-subheader-row th.month-offset-2,
.dashboard-table .month-subheader-row th.month-offset-4 {
  background: var(--color-surface-table-header-month-dark, #232001);
}
.dashboard-table .month-group-header.month-offset-1,
.dashboard-table .month-group-header.month-offset-3,
.dashboard-table .month-group-header.month-offset-5,
.dashboard-table .month-subheader-row th.month-offset-1,
.dashboard-table .month-subheader-row th.month-offset-3,
.dashboard-table .month-subheader-row th.month-offset-5 {
  background: var(--color-surface-table-header-month-light, #645b02);
}

.dashboard-table .month-subheader-row th {
  top: calc(var(--table-toolbar-offset, 76px) + 38px);
  z-index: 11;
  height: 52px;
  min-height: 52px;
  padding-top: 6px;
  padding-bottom: 6px;
  background: var(--color-surface-table-header, #3b7080);
  color: var(--color-text-inverse, #fff);
  font-size: 11px;
}

.dashboard-table .table-horizontal-scrollbar-spacer th {
  position: static;
  height: var(--table-horizontal-scrollbar-height);
  padding: 0;
  border: 0;
  background: var(--glass-strong);
}

.dashboard-table th.is-resizable-column {
  position: sticky;
  overflow: visible;
  padding-right: 12px;
}

.dashboard-table th.is-resizable-column .sort-header-button {
  padding-right: 6px;
}

.dashboard-table .column-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  width: 10px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
}

.dashboard-table .column-resize-handle::after {
  content: "";
  position: absolute;
  top: 20%;
  bottom: 20%;
  left: 4px;
  width: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
  opacity: 0.55;
  transition: opacity 120ms ease, background-color 120ms ease;
}

.dashboard-table .column-resize-handle:hover::after,
.dashboard-table .column-resize-handle:focus-visible::after,
body.is-column-resizing .dashboard-table .column-resize-handle::after {
  opacity: 1;
  background: rgba(255, 255, 255, 0.88);
}

.dashboard-table .column-resize-handle:focus-visible {
  outline: 2px solid var(--color-state-focus-ring, var(--brand));
  outline-offset: -2px;
}

body.is-column-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}

body.is-column-resizing .sort-header-button {
  pointer-events: none;
}

.sort-header-button {
  display: inline-flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  line-height: 1.15;
  white-space: normal;
}

.sort-header-button:focus-visible {
  outline: 2px solid rgba(var(--brand-rgb), 0.58);
  outline-offset: 3px;
  border-radius: 10px;
}

.sort-header-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: visible;
  text-align: center;
  white-space: normal;
  overflow-wrap: break-word;
}

.sort-indicator {
  display: inline-flex;
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  align-items: center;
  justify-content: center;
  color: var(--color-text-inverse, #fff);
  opacity: 0.66;
}

.sort-indicator.is-active {
  color: var(--color-text-inverse, #fff);
  opacity: 1;
}

.sort-indicator .icon {
  width: 13px;
  height: 13px;
}

.dashboard-table .month-group-row .base-header {
  z-index: 12;
  color: var(--color-text-inverse, #fff);
  background: var(--color-surface-table-header, #3b7080);
  vertical-align: middle;
}

.dashboard-table .month-group-row .base-header.frozen-column {
  z-index: 16;
}

/* 表頭篩選鈕：緊湊尺寸塞進既有 38／52 表頭高度；下拉面板仍掛 body fixed。 */
.dashboard-table th.has-header-filter {
  vertical-align: middle;
}

.dashboard-table th.has-header-filter:not(.is-resizable-column) {
  padding-right: 6px;
  padding-left: 6px;
}

.header-filter-row {
  display: flex;
  min-width: 0;
  gap: 4px;
  margin-top: 5px;
}

.month-subheader-row .header-filter-row {
  margin-top: 3px;
}

.header-filter-row .custom-select {
  width: auto;
  min-width: 0;
  flex: 1 1 auto;
}

.header-filter .custom-select-trigger {
  min-height: 22px;
  gap: 2px;
  padding: 1px 4px;
  border-color: rgba(255, 255, 255, 0.36);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--color-text-inverse, #fff);
  font-size: 11px;
  font-weight: 700;
  box-shadow: none;
}

.header-filter .custom-select-value.is-placeholder {
  color: rgba(255, 255, 255, 0.8);
}

.header-filter .custom-select-trigger > .icon {
  width: 10px;
  height: 10px;
  color: rgba(255, 255, 255, 0.85);
}

.header-filter .custom-select-trigger:focus-visible,
.header-filter.is-open .custom-select-trigger,
.header-filter.has-value .custom-select-trigger {
  border-color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.94);
  color: var(--brand-strong);
}

.header-filter .custom-select-trigger:focus-visible > .icon,
.header-filter.is-open .custom-select-trigger > .icon,
.header-filter.has-value .custom-select-trigger > .icon {
  color: var(--brand-strong);
}

.dashboard-table .month-group-header,
.dashboard-table .month-start-cell {
  border-left: 2px solid rgba(var(--brand-rgb), 0.28);
}

.dashboard-table .month-group-header,
.dashboard-table .month-end-cell {
  border-right: 2px solid rgba(var(--brand-rgb), 0.28);
}

.dashboard-table td {
  color: var(--color-text-secondary, var(--ink));
  white-space: nowrap;
}

.dashboard-table tbody tr {
  cursor: pointer;
}

.dashboard-table tbody tr:not(.virtual-spacer-row) {
  height: var(--space-compact-row-height, 46px);
}

.dashboard-table .virtual-spacer-row {
  cursor: default;
}

.dashboard-table .virtual-spacer-row td {
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
}

.dashboard-table tbody tr:hover td {
  background: var(--color-surface-table-row-hover, rgba(255, 255, 255, 0.5));
}

.dashboard-table tbody tr.selected-row td {
  background: rgba(var(--brand-rgb), 0.1);
}

.dashboard-table tbody tr.selected-row.dirty-row td {
  background: rgba(255, 159, 10, 0.12);
}

.dashboard-table tbody tr:hover td.frozen-column {
  background: var(--color-surface-table-frozen-hover, #f4fbe9);
}

.dashboard-table tbody tr.selected-row td.frozen-column {
  background: var(--color-surface-table-frozen-selected, #dcebef);
}

.dashboard-table tbody tr.selected-row.dirty-row td.frozen-column {
  background: var(--color-surface-table-frozen-edited, #dfffcc);
}

.dashboard-table tbody tr.dirty-row td:first-child {
  box-shadow: inset 4px 0 0 var(--color-state-edited, var(--brand));
}

.dashboard-table tbody tr.is-save-error td {
  outline: 2px solid var(--color-risk-critical, var(--red));
  outline-offset: -2px;
}

.numeric-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.action-cell {
  text-align: center;
}

.product-line-cell {
  text-align: center;
}

.product-line-value {
  display: inline-flex;
  min-width: 44px;
  justify-content: center;
  padding: 4px 9px;
  border: 1px solid rgba(var(--brand-rgb), 0.18);
  border-radius: 999px;
  background: rgba(var(--brand-rgb), 0.08);
  color: var(--brand-strong);
  font-weight: 800;
}

.product-line-value[data-line="CM"] {
  border-color: rgba(99, 102, 241, 0.3);
  background: rgba(99, 102, 241, 0.12);
  color: #4f46e5;
}

.product-line-value[data-line="CN"] {
  border-color: rgba(6, 182, 212, 0.32);
  background: rgba(6, 182, 212, 0.12);
  color: #0e7490;
}

.product-line-value[data-line="MM"] {
  border-color: rgba(16, 185, 129, 0.32);
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
}

.product-line-value[data-line="PC"] {
  border-color: rgba(245, 158, 11, 0.34);
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
}

.product-line-value[data-line="SI"] {
  border-color: rgba(236, 72, 153, 0.32);
  background: rgba(236, 72, 153, 0.12);
  color: #be185d;
}

.product-line-value[data-line="Raymx"] {
  border-color: rgba(36, 123, 160, 0.45);
  background: rgba(36, 123, 160, 0.14);
  color: var(--color-text-primary);
}

.product-line-value.is-unknown {
  border-color: rgba(148, 163, 184, 0.22);
  background: rgba(148, 163, 184, 0.1);
  color: var(--muted);
}

.part-cell {
  min-width: 180px;
}

.part-cell-content {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  vertical-align: middle;
  white-space: nowrap;
}

.part-number-value {
  min-width: 0;
  white-space: nowrap;
}

.customer-match-warning-badge {
  display: inline-flex;
  min-height: 20px;
  align-items: center;
  padding: 3px 7px;
  border: 1px solid var(--color-state-warning, var(--amber));
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--color-state-warning, var(--amber)) 12%, transparent);
  color: var(--color-text-primary, var(--ink));
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.overridden-cell {
  background: rgba(var(--brand-rgb), 0.1) !important;
  color: var(--brand-strong);
  font-weight: 900;
}

.overridden-cell small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.empty-cell {
  padding: 24px !important;
  color: var(--muted);
  text-align: center;
}

.loading-state {
  width: min(720px, calc(100vw - 32px));
  margin: clamp(32px, 10vh, 96px) auto 0;
  padding: clamp(22px, 4vw, 32px);
  text-align: left;
}

.loading-icon {
  display: inline-flex;
  width: 52px;
  height: 52px;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--brand-strong);
  box-shadow: var(--shadow-glass);
}

.loading-copy h1 {
  margin: 4px 0 8px;
  font-size: clamp(24px, 3vw, 34px);
}

.loading-copy p:not(.eyebrow) {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.loading-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 800;
}

.loading-summary {
  min-width: 0;
}

.loading-progress-hint {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-align: right;
}

.loading-step-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 18px 0 0;
  padding: 0;
  border-bottom: 1px solid var(--line);
  list-style: none;
}

.loading-step-list li {
  --loading-state-color: var(--color-state-neutral);
  min-height: 46px;
  padding: 10px 12px;
  border: 0;
  border-top: 1px solid var(--line);
  border-inline-start: 4px solid var(--loading-state-color);
  background: color-mix(in srgb, var(--loading-state-color) 4%, transparent);
  color: var(--color-text-primary);
  font-size: 12px;
  font-weight: 750;
}

.loading-step-list li.is-loading {
  --loading-state-color: var(--color-state-selected);
}

.loading-step-list li.is-complete {
  --loading-state-color: var(--color-state-success);
}

.loading-step-list li.is-warning {
  --loading-state-color: var(--color-state-warning);
}

.loading-step-list li.is-error {
  --loading-state-color: var(--color-state-danger);
}

.loading-step-copy {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  align-items: baseline;
}

.loading-step-label {
  color: var(--color-text-primary);
  font-weight: 800;
}

.loading-step-status,
.loading-step-detail {
  color: var(--loading-state-color);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.45;
}

.loading-step-detail {
  grid-column: 1 / -1;
  overflow-wrap: anywhere;
  color: var(--color-state-danger);
}

.loading-retry-button {
  margin-top: 14px;
}

.error-state,
.empty-state {
  margin: 24px;
  padding: 24px;
}

@keyframes pulseGlow {
  from {
    transform: scale(0.995);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.08), var(--shadow-glass);
  }

  to {
    transform: scale(1.005);
    box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.16), 0 16px 42px -26px rgba(239, 68, 68, 0.55);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }

  .glow,
  .period-card.risk-card.current-period {
    animation: none !important;
    opacity: 1;
    transform: none;
  }

  .custom-select-panel,
  .save-toast,
  .page-tab-indicator,
  .fcst-status-chip-tooltip {
    transition: none !important;
  }

  .fcst-status-chip-tooltip {
    transform: translate(-50%, 0);
  }

  .fcst-status-chip:hover .fcst-status-chip-tooltip,
  .fcst-status-chip:focus-visible .fcst-status-chip-tooltip {
    transition-delay: 0s;
    transform: translate(-50%, 0);
  }

  .form-field.is-shaking,
  .add-row-form .custom-select.is-shaking,
  .add-row-form .control-input.is-shaking {
    animation: none !important;
    transform: none !important;
  }

  .filter-chip-clear {
    transition: none !important;
    transform: none !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .page-tabs,
  .fcst-status-strip,
  .section-heading,
  .custom-select-panel {
    background: #fffceb;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .page-tabs,
  .fcst-status-strip,
  .section-heading,
  .custom-select-panel,
  .custom-select-trigger,
  .primary-button,
  .secondary-button,
  .danger-button {
    border-color: currentColor;
  }
}

@media (hover: hover) and (pointer: fine) {
  .page-tab:hover {
    border-color: rgba(var(--brand-rgb), 0.42);
    color: var(--brand-strong);
  }

  .custom-select-trigger:hover {
    border-color: rgba(var(--brand-rgb), 0.42);
    background: rgba(255, 255, 255, 0.86);
  }

  /* 表頭底色深，hover 提亮時文字要跟著轉深色才讀得到。 */
  .header-filter .custom-select-trigger:hover {
    border-color: rgba(255, 255, 255, 0.92);
    color: var(--brand-strong);
  }

  .header-filter .custom-select-trigger:hover > .icon {
    color: var(--brand-strong);
  }

  .primary-button:hover:not(:disabled),
  .secondary-button:hover:not(:disabled),
  .danger-button:hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: rgba(var(--brand-rgb), 0.4);
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 14px 32px -22px rgba(var(--brand-deep-rgb), 0.38);
  }
}

@media (min-width: 1081px) {
  #main-content .table-filter-toolbar .filter-clear-button {
    height: 28px;
    min-height: 28px;
  }

  #main-content > .page-tabs-row .page-tab,
  #main-content > .page-tabs-row .fcst-status-strip {
    padding-bottom: 21px;
  }

  #main-content .table-wrap > .table-sticky-head > .section-heading {
    justify-content: center;
  }

  #main-content .table-heading-meta {
    min-height: 29px;
  }

  #main-content .dashboard-table .month-subheader-row th {
    padding-top: 5px;
    padding-bottom: 5px;
  }
}

@media (max-width: 1320px) {
  .app-header {
    margin-right: auto;
    margin-left: auto;
  }
}

@media (max-width: 1080px) {
  .formula-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .formula-core-grid,
  .formula-detail-grid {
    grid-template-columns: 1fr;
  }

  .formula-decision-layout {
    grid-template-columns: 1fr;
  }

  .formula-decision-detail {
    position: static;
  }

  .add-row-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .period-zone {
    grid-column: auto;
  }

  .data-relations-layout {
    grid-template-columns: 1fr;
  }

  .data-relations-detail {
    min-height: auto;
  }
}

@media (max-width: 780px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .source-meta {
    justify-content: flex-start;
  }

  .workspace {
    padding: 16px 14px 0;
  }

  .formula-grid,
  .formula-core-grid,
  .formula-detail-grid,
  .period-grid {
    grid-template-columns: 1fr;
  }

  .formula-tree-columns {
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .formula-tree-root {
    padding-bottom: 14px;
  }

  .formula-tree-root::after {
    height: 10px;
  }

  .formula-tree-branch {
    padding-top: 12px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .data-relations-heading,
  .data-relations-intro {
    flex-direction: column;
  }
  .data-relations-guide {
  display: flex;
  align-items: center;
  gap: 24px;
  width: 100%;
}

.data-relations-note {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}
  
  .data-relations-mode-switch,
  .data-relations-legend {
    justify-content: flex-start;
    width: 100%;
  }

  .add-row-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .detail-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-header {
    width: calc(100% - 20px);
    margin: 10px auto 0;
    padding: 13px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand p {
    white-space: normal;
  }

  .page-tabs,
  .fcst-status-strip {
    width: 100%;
  }

  .page-tab {
    flex: 0 0 auto;
    padding: 0 10px;
  }

  .fcst-status-chip {
    max-width: none;
  }

  .data-relations-card {
    padding: 16px;
  }

  .data-relations-canvas-wrap,
  .data-relations-detail {
    min-height: 420px;
  }

  .period-zone {
    padding: 16px;
    border-radius: var(--radius-md);
  }

  .part-title strong {
    font-size: 22px;
  }

  .table-wrap {
    --table-toolbar-offset: 150px;
    max-height: 1420px;
    min-height: 1360px;
  }

  .add-row-grid {
    grid-template-columns: 1fr;
  }
}
