:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #dde3ea;
  --text: #17202a;
  --muted: #647487;
  --teal: #0f9f8f;
  --amber: #d88910;
  --rose: #d94d57;
  --blue: #3366cc;
  --shadow: 0 14px 32px rgba(21, 31, 45, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  padding: 22px 16px;
  background: #16202b;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
}

.brand-mark {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: #aebdcc;
  font-size: 12px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #c7d1dc;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: #223041;
  color: #fff;
  border-color: #2d4055;
}

.nav-item svg,
.icon-btn svg,
.text-btn svg,
.primary-btn svg,
.secondary-btn svg,
.empty-state svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.content-area {
  position: relative;
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 18px;
}

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

.topbar-actions,
.section-head {
  justify-content: space-between;
}

.compact-head {
  margin: 0;
}

.icon-btn,
.text-btn,
.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.icon-btn {
  width: 38px;
  padding: 0;
}

.text-btn,
.primary-btn,
.secondary-btn {
  padding: 0 14px;
}

.primary-btn {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.secondary-btn:hover,
.text-btn:hover,
.icon-btn:hover {
  background: var(--panel-soft);
}

.login-panel {
  display: grid;
  min-height: calc(100vh - 112px);
  place-items: center;
}

.login-box {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

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

label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 159, 143, 0.14);
}

.form-message {
  min-height: 20px;
  margin-top: 10px;
  color: var(--rose);
  font-size: 13px;
}

.workspace {
  display: block;
}

.hidden {
  display: none !important;
}

.view-stack {
  display: none;
}

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

.quick-entry-panel {
  padding: 18px;
  overflow: auto;
}

.quick-entry-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.quick-entry-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.quick-entry-form-grid {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(260px, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.quick-entry-form-grid label {
  margin: 0;
}

.quick-entry-matrix-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quick-entry-matrix {
  min-width: 720px;
}

.quick-entry-matrix th:first-child,
.quick-entry-matrix td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 150px;
  background: var(--panel);
}

.quick-entry-matrix th:first-child {
  z-index: 2;
  background: var(--panel-soft);
}

.quick-entry-matrix input {
  min-width: 82px;
  min-height: 34px;
  padding: 4px 8px;
  text-align: center;
}

.quick-entry-matrix input.invalid {
  border-color: var(--rose);
  background: #fff5f6;
}

.quick-entry-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.quick-entry-preview {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.quick-entry-preview .section-head {
  padding: 0;
}

.quick-entry-error {
  padding: 10px 12px;
  border-left: 4px solid var(--rose);
  border-radius: 8px;
  background: #fff1f3;
  color: #9d2936;
  font-size: 13px;
}

.quick-entry-preview-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  font-size: 13px;
}

.quick-entry-preview-row small {
  color: var(--muted);
}

.quick-entry-order-picker select {
  min-width: min(440px, 70vw);
}

.quick-entry-history .panel-head {
  padding: 14px 16px 0;
}

.risk-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #ffe0a9;
  border-radius: 8px;
  background: #fff7e8;
  color: #9b6500;
  font-size: 12px;
  font-weight: 700;
}

.risk-badge svg {
  width: 16px;
  height: 16px;
}

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

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 18px;
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card strong {
  font-size: 30px;
}

.accent-teal {
  border-left-color: var(--teal);
}

.accent-amber {
  border-left-color: var(--amber);
}

.accent-rose {
  border-left-color: var(--rose);
}

.accent-blue {
  border-left-color: var(--blue);
}

.table-wrap,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

.wrap-cell {
  max-width: 360px;
  white-space: normal;
  word-break: break-word;
}

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

tbody tr {
  transition: background 0.16s ease;
}

tbody tr:hover {
  background: #f6fbfb;
}

tbody tr.selected {
  background: #eef8f7;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 8px;
  background: #eef2f6;
  color: #425163;
  font-size: 12px;
  font-weight: 700;
}

.status-ACTIVE {
  background: #e5f7f4;
  color: #087d71;
}

.status-DRAFT {
  background: #eef2f6;
  color: #4d5c6e;
}

.status-PAUSED,
.status-WARNING {
  background: #fff5df;
  color: #9b6500;
}

.status-OVERDUE {
  background: #ffecef;
  color: #b73543;
}

.status-CLOSED,
.status-COMPLETED {
  background: #edf3ff;
  color: #2458b8;
}

.status-CANCELLED,
.status-ARCHIVED {
  background: #ffecef;
  color: #b73543;
}

.toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-row input,
.filter-row select {
  width: auto;
  min-width: 150px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.segmented button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: #16202b;
  color: #fff;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.detail-panel {
  min-height: 360px;
  padding: 18px;
}

.empty-state {
  display: grid;
  gap: 8px;
  min-height: 300px;
  place-items: center;
  align-content: center;
  color: var(--muted);
}

.detail-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.detail-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.detail-item small,
.process-row small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

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

.process-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(14, 22, 31, 0.48);
  z-index: 20;
}

.modal {
  width: min(720px, 100%);
  padding: 20px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.wide-modal {
  width: min(920px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

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

.modal-actions {
  justify-content: flex-end;
}

.modal-actions.spread {
  justify-content: space-between;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-actions button:disabled,
.modal-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.process-editor-head,
.process-editor-row {
  display: grid;
  grid-template-columns: 34px minmax(160px, 1.6fr) repeat(3, minmax(96px, 1fr)) 72px 38px;
  gap: 8px;
  align-items: center;
}

.process-editor-head {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.process-editor {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.process-editor-row {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.process-editor-row.dragging {
  opacity: 0.48;
  box-shadow: 0 10px 28px rgba(16, 24, 40, 0.14);
}

.drag-handle {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-handle svg {
  width: 16px;
  height: 16px;
}

.is-dragging-process,
.is-dragging-process * {
  cursor: grabbing !important;
  user-select: none;
}

.process-editor-row label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0;
}

.process-editor-row input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

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

.workpiece-barcode {
  color: var(--muted);
  font-size: 12px;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.mini-btn:hover {
  background: var(--panel-soft);
}

.mini-btn.danger {
  border-color: #ffd2d7;
  color: #b73543;
}

.checkbox-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow: auto;
  margin: 10px 0 16px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.checkbox-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  min-height: 54px;
  margin: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.checkbox-item input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
  padding: 0;
}

.checkbox-item small,
.salary-preview small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.salary-preview {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.salary-preview-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.salary-total {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  background: #e5f7f4;
  color: #087d71;
  font-weight: 700;
}

.progress-track {
  position: relative;
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef4;
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.report-summary {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

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

.report-row span:first-child {
  color: var(--muted);
  font-size: 12px;
}

.select-cell input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #16202b;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  z-index: 30;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .brand span:last-child,
  .nav-item span {
    display: none;
  }

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

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

  .content-area {
    padding: 18px;
  }

  .toolbar {
    align-items: flex-start;
  }

  .filter-row {
    flex: 1 1 100%;
  }
}

@media (max-width: 760px) {
  body {
    padding-bottom: calc(74px + env(safe-area-inset-bottom));
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    display: block;
    height: calc(66px + env(safe-area-inset-bottom));
    overflow: hidden;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(21, 31, 45, 0.14);
  }

  .brand {
    display: none;
  }

  .nav-list {
    display: grid;
    grid-auto-columns: 52px;
    grid-auto-flow: column;
    grid-template-columns: none;
    gap: 4px;
    height: 54px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    width: 52px;
    min-height: 52px;
    justify-content: center;
    padding: 0;
  }

  .nav-item span {
    display: none;
  }

  .content-area {
    min-height: 100dvh;
    padding: 14px 14px calc(88px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .text-btn {
    width: 38px;
    padding: 0;
  }

  .topbar-actions .text-btn span {
    display: none;
  }

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

  .metric-card {
    min-height: 96px;
    padding: 14px;
  }

  .metric-card strong {
    font-size: 26px;
  }

  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .section-head,
  .compact-head,
  .detail-title,
  .quick-entry-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .toolbar > .primary-btn,
  .toolbar > .secondary-btn {
    width: 100%;
  }

  .segmented {
    max-width: 100%;
    overflow-x: auto;
  }

  .segmented button {
    flex: none;
  }

  .process-editor-head {
    display: none;
  }

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

  .filter-row,
  .filter-row input,
  .filter-row select {
    width: 100%;
  }

  .checkbox-list {
    grid-template-columns: 1fr;
  }

  .quick-entry-form-grid {
    grid-template-columns: 1fr;
  }

  .quick-entry-actions {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .quick-entry-actions button {
    flex: 1 1 140px;
  }

  .quick-entry-panel,
  .detail-panel {
    padding: 14px;
  }

  .quick-entry-matrix th,
  .quick-entry-matrix td {
    padding: 10px;
  }

  .quick-entry-matrix th:first-child,
  .quick-entry-matrix td:first-child {
    min-width: 128px;
  }

  .quick-entry-order-picker select {
    min-width: 0;
  }

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

  .table-wrap table {
    min-width: 640px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 10px;
  }

  .modal {
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
    padding: 16px;
  }

  .modal-actions {
    flex-wrap: wrap;
  }

  .modal-actions:not(.spread) button {
    flex: 1 1 120px;
  }

  .toast {
    right: 14px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    left: 14px;
    max-width: none;
  }
}

@media (max-width: 390px) {
  .content-area {
    padding-inline: 12px;
  }

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

  .quick-entry-preview-row {
    grid-template-columns: 1fr;
  }

  .risk-badge {
    width: 100%;
    justify-content: center;
  }
}
