:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --text: #1f2328;
  --muted: #687076;
  --border: #d8dee4;
  --border-strong: #b9c1c9;
  --teal: #21335b;
  --teal-soft: #e9edf5;
  --shipment: #0f766e;
  --accent: #ef5d31;
  --accent-soft: #fff0ea;
  --green: #177245;
  --green-soft: #e9f6ef;
  --amber: #ef5d31;
  --amber-soft: #fff0ea;
  --red: #b42318;
  --red-soft: #fde8e5;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --purple: #7c3aed;
  --purple-soft: #f0e9ff;
  --shadow: 0 18px 60px rgba(31, 35, 40, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    Arial,
    sans-serif;
  letter-spacing: 0;
}

.is-hidden {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.login-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(120deg, rgba(33, 51, 91, 0.96), rgba(18, 28, 50, 0.92)),
    #21335b;
}

.login-brand-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 840px;
  padding: 72px 72px 72px clamp(104px, 7vw, 132px);
  color: #ffffff;
}

.login-hero-image {
  position: relative;
  z-index: 2;
  width: clamp(430px, 50vw, 720px);
  max-height: 56vh;
  object-fit: contain;
  object-position: center bottom;
  margin: 0 0 26px -12px;
  filter: drop-shadow(0 28px 46px rgba(0, 0, 0, 0.26));
  animation: mascot-breathe 6.2s ease-in-out infinite;
}

.login-brand-panel h1 {
  position: relative;
  z-index: 2;
  max-width: 640px;
  font-size: 42px;
  line-height: 1.16;
}

.login-brand-panel p {
  position: relative;
  z-index: 2;
  max-width: 560px;
  margin-top: 18px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 16px;
  line-height: 1.8;
}

.login-card {
  align-self: center;
  position: relative;
  z-index: 3;
  display: grid;
  gap: 18px;
  width: min(100% - 48px, 390px);
  margin-right: 48px;
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

@keyframes mascot-breathe {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }

  50% {
    transform: translate3d(-10px, -8px, 0) scale(1.018);
  }
}

.login-card h2 {
  font-size: 24px;
}

.login-card p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

.login-submit {
  width: 100%;
  justify-content: center;
}

.login-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 16px;
  background: #ffffff;
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 26px;
}

.brand-logo {
  width: 46px;
  height: 46px;
  object-fit: contain;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid var(--border);
}

.brand-name {
  font-size: 17px;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--teal-soft);
  color: var(--teal);
  border-color: #b9e6dd;
  font-weight: 700;
}

.nav-symbol {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 16px;
  line-height: 1;
}

.main-area {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 84px;
  padding: 18px 28px;
  background: rgba(245, 246, 248, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
}

#pageSubtitle {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions,
.toolbar,
.row-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.db-status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.db-status[data-tone="ok"] {
  background: var(--green-soft);
  border-color: #b9e2cb;
  color: var(--green);
}

.db-status[data-tone="pending"] {
  background: var(--blue-soft);
  border-color: #bfd0ff;
  color: var(--blue);
}

.db-status[data-tone="warn"] {
  background: var(--amber-soft);
  border-color: #f4d392;
  color: var(--amber);
}

.account-badge {
  display: grid;
  gap: 2px;
  min-height: 38px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  font-size: 12px;
}

.account-badge strong {
  font-size: 13px;
}

.account-badge span {
  color: var(--muted);
}

.role-panel {
  display: flex;
  align-items: center;
  gap: 10px;
}

.segmented {
  display: inline-flex;
  min-height: 38px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #ffffff;
}

.segment-button {
  min-height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment-button.is-active {
  background: var(--teal);
  color: #ffffff;
}

#factoryScopeSelect,
#accountSelect {
  height: 38px;
  min-width: 180px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

.content {
  padding: 22px 28px 34px;
}

.view-stack {
  display: grid;
  gap: 18px;
}

.section-spacer {
  margin-top: 18px;
}

.compact-heading {
  margin: 0 0 10px;
  color: var(--teal);
  font-size: 1rem;
}

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

.metric-card {
  min-height: 108px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.metric-card.is-clickable {
  cursor: pointer;
}

.metric-card.is-clickable:hover {
  border-color: var(--teal);
  box-shadow: 0 10px 30px rgba(15, 118, 110, 0.1);
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  margin-top: 12px;
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
}

.metric-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.factory-update-notice {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid #f1b65f;
  border-radius: 8px;
  background: linear-gradient(135deg, #fff7e8 0%, #ffffff 72%);
  box-shadow: 0 12px 28px rgba(161, 92, 7, 0.1);
}

.factory-update-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.factory-update-head h2 {
  margin-top: 4px;
  color: #6f3d00;
  font-size: 20px;
}

.factory-update-head p {
  margin-top: 6px;
  color: #8a5a17;
  font-size: 13px;
}

.factory-update-head strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  min-height: 46px;
  border-radius: 8px;
  background: #b45309;
  color: #ffffff;
  font-size: 22px;
}

.notice-kicker {
  color: #b45309;
  font-size: 12px;
  font-weight: 900;
}

.factory-update-list {
  display: grid;
  gap: 8px;
}

.factory-update-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(180, 83, 9, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.factory-update-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 28px;
  border-radius: 6px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.factory-update-tag.order {
  background: #b45309;
}

.factory-update-tag.sample {
  background: #0f766e;
}

.factory-update-body {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.factory-update-body strong,
.factory-update-body span,
.factory-update-body p,
.factory-update-body small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.factory-update-body strong {
  color: var(--text);
  font-size: 14px;
}

.factory-update-body span,
.factory-update-body p,
.factory-update-body small {
  color: var(--muted);
  font-size: 12px;
}

.notice-dismiss-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(180, 83, 9, 0.24);
  border-radius: 6px;
  background: #ffffff;
  color: #9a3412;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.notice-dismiss-button:hover {
  background: #fff1e6;
  border-color: #d97706;
}

.surface {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.surface-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 56px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.surface-head h2 {
  font-size: 17px;
}

.surface-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  background: var(--panel-soft);
  color: #4f5962;
  font-size: 12px;
  font-weight: 800;
}

th.table-group {
  text-align: center;
  color: var(--text);
  border-right: 1px solid var(--border);
}

th.table-group.procurement {
  background: #eef6ff;
}

td {
  font-size: 14px;
}

tbody tr:hover {
  background: #fbfcfd;
}

tr.is-clickable {
  cursor: pointer;
}

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

.muted {
  color: var(--muted);
}

.number {
  font-variant-numeric: tabular-nums;
}

.status-badge,
.risk-badge,
.state-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-badge.done {
  background: var(--green-soft);
  color: var(--green);
}

.status-badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-badge.danger,
.risk-badge.danger {
  background: var(--red-soft);
  color: var(--red);
}

.risk-badge {
  margin-right: 6px;
  background: var(--amber-soft);
  color: var(--amber);
}

.risk-badge.info {
  background: var(--purple-soft);
  color: var(--purple);
}

.state-pill {
  background: var(--panel-soft);
  color: var(--muted);
}

.state-pill.ok {
  background: var(--green-soft);
  color: var(--green);
}

.state-pill.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.state-pill.info {
  background: var(--purple-soft);
  color: var(--purple);
}

.state-pill.danger {
  background: var(--red-soft);
  color: var(--red);
}

.record-type-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.progress {
  display: grid;
  gap: 6px;
  width: 150px;
}

.progress-track {
  overflow: hidden;
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: #e3e8ee;
}

.progress-fill {
  width: var(--value);
  height: 100%;
  border-radius: 999px;
  background: var(--teal);
}

.progress-fill.secondary {
  background: var(--shipment);
}

.progress-fill.inspection {
  background: var(--accent);
}

.progress-label {
  color: var(--muted);
  font-size: 12px;
}

.progress-label.strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.quantity-progress {
  min-width: 230px;
  display: grid;
  gap: 10px;
}

.quantity-progress .progress {
  width: 100%;
}

.finished-progress {
  display: grid;
  gap: 10px;
  min-width: 300px;
  max-width: 420px;
}

.finished-progress .progress {
  width: 100%;
}

.finished-order-list {
  display: grid;
  min-width: 190px;
  gap: 8px;
}

.finished-order-item {
  display: grid;
  gap: 6px;
  align-items: start;
}

.finished-order-actions,
.finished-order-actions .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.finished-order-actions .success-button,
.finished-order-actions .ghost-button {
  min-height: 30px;
  padding: 0 10px;
}

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

.progress-percent {
  min-width: 42px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.bar-list {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-row.is-clickable {
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.bar-row.is-clickable:hover {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ecf0;
}

.bar-fill {
  width: var(--value);
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--accent));
}

.toolbar {
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.toolbar label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar select,
.toolbar input {
  width: 180px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

.search-input {
  width: 240px;
}

.link-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--teal);
  font-weight: 800;
  text-align: left;
}

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

.primary-button,
.secondary-button,
.ghost-button,
.success-button,
.icon-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover {
  background: #0b625b;
}

.success-button {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

.success-button:hover {
  background: #0f5f38;
}

.secondary-button,
.ghost-button {
  padding: 0 12px;
  background: #ffffff;
  color: var(--text);
  border-color: var(--border-strong);
}

.secondary-button:hover,
.ghost-button:hover {
  background: var(--panel-soft);
}

.ghost-button {
  min-height: 32px;
  font-size: 13px;
}

.danger-button {
  color: #b42318;
  border-color: #f2b8b5;
}

.danger-button:hover {
  background: #fff1f0;
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 0;
}

.batch-record-panel {
  display: grid;
  gap: 12px;
}

.order-board-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.factory-update-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.factory-update-head h3 {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 20px;
}

.order-board-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.order-board-card {
  display: grid;
  gap: 6px;
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.order-board-card span {
  color: var(--muted);
  font-size: 12px;
}

.order-board-card strong {
  color: var(--text);
  font-size: 15px;
}

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

.factory-progress-grid .progress {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.factory-line-list {
  display: grid;
  gap: 8px;
}

.factory-line-item {
  display: grid;
  align-items: center;
  gap: 12px;
  grid-template-columns: 1fr auto auto;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.factory-line-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.order-edit-section {
  display: grid;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.order-edit-section summary {
  cursor: pointer;
  color: var(--teal);
  font-weight: 800;
}

.order-edit-section[open] summary {
  margin-bottom: 12px;
}

.order-materials-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.order-materials-card .section-heading h3 {
  margin: 0;
  color: var(--teal);
  font-size: 17px;
}

.order-materials-card .section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.attachment-readonly-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.order-confirm-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid #b9e6dd;
  border-radius: 8px;
  background: #f0fdfa;
}

.order-confirm-panel strong,
.order-confirm-panel span {
  display: block;
}

.order-confirm-panel strong {
  color: var(--teal);
  font-size: 15px;
}

.order-confirm-panel span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.batch-record-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.batch-record-group summary {
  cursor: pointer;
  font-weight: 700;
}

.batch-record-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.batch-record-item {
  display: grid;
  align-items: center;
  gap: 10px;
  grid-template-columns: 1fr auto auto auto;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  padding: 0;
  background: #ffffff;
  color: var(--text);
  border-color: var(--border-strong);
  font-size: 20px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--panel-soft);
}

.button-symbol {
  font-size: 18px;
  line-height: 1;
}

.empty-state {
  padding: 34px 16px;
  color: var(--muted);
  text-align: center;
}

.modal {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.detail-modal {
  width: min(1080px, calc(100vw - 28px));
}

.detail-content {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.detail-title {
  display: grid;
  gap: 7px;
}

.detail-title h2 {
  font-size: 21px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.detail-stat {
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.detail-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-stat strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.detail-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.detail-section h3 {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
  font-size: 15px;
}

.model-stack {
  display: grid;
  gap: 4px;
}

.batch-line {
  color: var(--muted);
  font-size: 12px;
}

.product-cell {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 260px;
}

.product-thumb {
  width: 58px;
  height: 44px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-soft);
}

.product-params {
  max-width: 360px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  white-space: normal;
}

.product-link-list {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
}

.product-link-list a {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #c9e0f8;
  border-radius: 6px;
  background: #eef6ff;
  color: #17416f;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.product-link-list a:hover {
  background: #dcecff;
}

.scenario-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
}

.product-card-scenarios .scenario-tag-list {
  padding: 0;
}

.scenario-tag-list span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid #b7e4d7;
  border-radius: 999px;
  background: #e9fbf5;
  color: #0f766e;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
}

.matched-sku-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 150px;
  max-width: 260px;
}

.matched-sku-list span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef6ff;
  color: #17416f;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  border: 1px solid #c9e0f8;
}

.bom-tree {
  display: grid;
  gap: 14px;
  padding: 14px 16px 16px;
}

.bom-product-node {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.bom-product-node.is-collapsed {
  border-color: #cfd8e3;
}

.bom-product-node.is-collapsed .bom-branch-list {
  display: none;
}

.bom-product-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.bom-product-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.bom-toggle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 104px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid #173b70;
  border-radius: 6px;
  background: #173b70;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.bom-toggle-button:hover {
  background: #0f2d58;
  border-color: #0f2d58;
}

.bom-toggle-button strong {
  font-size: 12px;
}

.bom-branch-list {
  display: grid;
  gap: 0;
}

.bom-component-node {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  min-height: 86px;
}

.bom-branch-line {
  position: relative;
  border-right: 2px solid #dbe4ef;
}

.bom-branch-line::after {
  content: "";
  position: absolute;
  top: 42px;
  right: -2px;
  width: 24px;
  border-top: 2px solid #dbe4ef;
}

.bom-component-body {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(260px, 0.9fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px 12px 20px;
  border-bottom: 1px solid var(--border);
}

.bom-component-node:last-child .bom-component-body {
  border-bottom: 0;
}

.bom-component-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.bom-component-quantity {
  min-width: 126px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.bom-component-quantity strong,
.bom-component-quantity span {
  display: block;
}

.bom-component-quantity span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.bom-component-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.history-list {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(160px, 1.2fr) minmax(160px, 1fr) minmax(120px, 0.8fr);
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  font-size: 13px;
}

.history-item strong {
  display: block;
}

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

.product-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.product-card-image {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.product-card-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.attachment-list {
  display: grid;
  gap: 10px;
}

.attachment-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
}

.attachment-thumb {
  width: 52px;
  height: 42px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}

.attachment-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 42px;
  border-radius: 6px;
  background: #ffffff;
  color: var(--teal);
  border: 1px solid var(--border);
  font-weight: 800;
}

.attachment-name {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-meta {
  color: var(--muted);
  font-size: 12px;
}

.attachment-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.attachment-preview {
  display: grid;
  gap: 14px;
  width: min(980px, calc(100vw - 48px));
  padding: 18px;
}

.attachment-preview .modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.attachment-preview-body {
  display: grid;
  place-items: center;
  min-height: 420px;
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.attachment-preview-image {
  max-width: 100%;
  max-height: 68vh;
  object-fit: contain;
}

.attachment-preview-frame {
  width: 100%;
  height: 68vh;
  border: 0;
}

.modal::backdrop {
  background: rgba(31, 35, 40, 0.38);
}

.modal-form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

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

.modal-head h2 {
  font-size: 20px;
}

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

.form-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
}

.form-section-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
}

.bom-form-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.bom-form-section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.bom-form-summary {
  display: grid;
  gap: 8px;
}

.bom-product-summary-card {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(180px, 0.8fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.bom-product-summary-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state.compact {
  padding: 12px;
  min-height: auto;
  text-align: left;
}

.procurement-section {
  background: #f8fbff;
}

.procurement-row-list {
  display: grid;
  gap: 10px;
}

.procurement-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.modal-form label {
  display: grid;
  gap: 6px;
  color: #4f5962;
  font-size: 13px;
  font-weight: 700;
}

.modal-form label.required-field .field-label::after {
  content: "*";
  color: #d92d20;
  font-size: 16px;
  line-height: 1;
  margin-left: 4px;
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

.modal-form input[readonly] {
  background: var(--panel-soft);
  color: var(--muted);
}

.permission-field {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
}

.permission-field legend {
  margin-bottom: 8px;
  color: #4f5962;
  font-size: 13px;
  font-weight: 800;
}

.permission-check-list {
  display: grid;
  gap: 14px;
}

.permission-group {
  display: grid;
  gap: 8px;
}

.permission-group-title {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

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

.modal-form .permission-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.modal-form .permission-check input {
  width: 16px;
  min-height: 16px;
  height: 16px;
  flex: 0 0 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--teal);
}

.modal-form .permission-check:has(input:checked) {
  border-color: #6fb3ad;
  background: var(--teal-soft);
}

.password-mask-button {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #e5e7eb;
  color: #64748b;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0;
  cursor: pointer;
}

.password-mask-button:hover {
  background: #d8dde6;
}

.modal-form textarea {
  resize: vertical;
}

.modal-actions {
  justify-content: flex-end;
  padding-top: 4px;
}

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

.factory-card {
  display: grid;
  gap: 13px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.factory-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.factory-name {
  font-size: 17px;
  font-weight: 800;
}

.factory-meta {
  color: var(--muted);
  font-size: 13px;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mini-stat {
  min-height: 62px;
  padding: 10px;
  border-radius: 7px;
  background: var(--panel-soft);
}

.mini-stat strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.mini-stat span {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1180px) {
  .login-brand-panel {
    padding-left: clamp(78px, 8vw, 98px);
  }

  .login-hero-image {
    width: min(92%, 540px);
    margin-left: -10px;
  }

  .metric-grid,
  .factory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .order-board-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-grid {
    grid-template-columns: 1fr;
  }

  .bom-component-body {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 780px) {
  .login-screen {
    grid-template-columns: 1fr;
  }

  .login-brand-panel {
    padding: 34px 24px 12px;
  }

  .login-brand-panel h1 {
    font-size: 30px;
  }

  .login-hero-image {
    width: min(112%, 500px);
    max-height: 38vh;
    margin: 0 0 16px -20px;
  }

  .login-card {
    align-self: start;
    width: calc(100% - 32px);
    margin: 16px;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .role-panel {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .account-badge,
  .db-status,
  #factoryScopeSelect {
    width: 100%;
  }

  .content {
    padding: 16px;
  }

  .metric-grid,
  .factory-grid,
  .product-grid,
  .order-board-grid,
  .factory-progress-grid,
  .factory-line-item,
  .form-grid,
  .detail-grid,
  .history-item {
    grid-template-columns: 1fr;
  }

  .permission-group-grid {
    grid-template-columns: 1fr;
  }

  .factory-update-head,
  .factory-update-item {
    grid-template-columns: 1fr;
  }

  .factory-update-head {
    flex-direction: column;
  }

  .factory-update-item {
    align-items: stretch;
  }

  .bom-product-head,
  .bom-component-main {
    align-items: flex-start;
    flex-direction: column;
  }

  .bom-component-node {
    grid-template-columns: 22px minmax(0, 1fr);
  }

  .bom-component-body {
    padding-left: 14px;
  }

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

  .toolbar select,
  .toolbar input,
  .search-input {
    width: min(100%, 260px);
  }

  h1 {
    font-size: 23px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .login-hero-image {
    animation: none;
  }
}
