:root {
  --bg: #f5f7f8;
  --panel: #fff;
  --ink: #172026;
  --muted: #667580;
  --line: #dfe5e8;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --danger: #b42318;
  --ok-bg: #e8f5ef;
  --warn-bg: #fff4df;
  --shadow: 0 16px 40px rgba(21, 35, 43, 0.08);
  --scroll-table-max-height: 732px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell { width: min(1560px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 40px; }
.login-view { display: grid; min-height: 100vh; place-items: center; }
.login-card {
  display: grid; width: min(420px, 100%); gap: 18px; padding: 30px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 4px; color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: 0; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1, h2 { margin-bottom: 0; letter-spacing: 0; }
h1 { font-size: clamp(24px, 4vw, 38px); line-height: 1.15; }
h2 { font-size: 18px; }
.topbar-actions, .row-actions, .toolbar, .panel-heading, .section-heading, .section-actions {
  display: flex; align-items: center; gap: 10px;
}
.topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
.panel-heading, .section-heading { justify-content: space-between; padding: 18px; border-bottom: 1px solid var(--line); }
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; }

.primary-button, .ghost-button, .small-button {
  min-height: 40px; border: 1px solid transparent; border-radius: 8px; font-weight: 700;
}
.primary-button { padding: 0 18px; color: #fff; background: var(--primary); }
.primary-button:hover { background: var(--primary-dark); }
.ghost-button, .small-button { color: var(--ink); background: #fff; border-color: var(--line); }
.ghost-button { padding: 0 14px; }
.small-button { min-height: 32px; padding: 0 10px; font-size: 13px; }
.small-button.danger { color: var(--danger); }
.full-width { width: 100%; }
.user-pill {
  min-height: 36px; padding: 8px 12px; color: var(--primary-dark); background: #e6f4f1;
  border: 1px solid #c7e6df; border-radius: 999px; font-size: 13px; font-weight: 800;
}
.module-switch {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px;
}
.module-card {
  display: grid; gap: 8px; min-height: 108px; padding: 20px; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); text-align: left;
}
.module-card strong { font-size: 22px; line-height: 1.2; }
.module-card span { color: var(--muted); font-size: 13px; line-height: 1.5; }
.module-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13), var(--shadow); }
.module-actions { display: flex; justify-content: flex-end; gap: 10px; margin-bottom: 12px; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { min-height: 96px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.metric span { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.metric strong { display: block; margin-top: 10px; font-size: 28px; line-height: 1; }

.workspace { display: grid; grid-template-columns: 390px minmax(0, 1fr); gap: 16px; align-items: start; }
.list-panel, .detail-panel, .users-panel, .database-panel, .inventory-panel, .sales-order-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden;
}
.list-panel { position: sticky; top: 16px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.toolbar { padding: 16px; border-bottom: 1px solid var(--line); }
.toolbar.compact { align-items: end; flex-direction: column; }
.search-box { width: 100%; }
.record-list { overflow: auto; padding: 8px; }
.record-card {
  width: 100%; padding: 12px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px;
  background: #fbfcfc; text-align: left;
}
.record-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }
.record-card strong { display: block; font-size: 15px; margin-bottom: 4px; }
.record-card span { display: block; color: var(--muted); font-size: 12px; line-height: 1.55; }

form { margin: 0; }
fieldset { margin: 0; padding: 18px; border: 0; }
.production-plan-form fieldset { min-width: 0; }
fieldset[disabled] { opacity: 0.58; }
legend { width: 100%; padding: 12px 0 10px; color: var(--primary-dark); font-size: 16px; font-weight: 900; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%; color: var(--ink); background: #fbfcfc; border: 1px solid var(--line); border-radius: 8px; outline: none;
}
input, select { height: 42px; padding: 0 12px; }
textarea { min-height: 88px; resize: vertical; padding: 11px 12px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13); }
.form-grid { display: grid; gap: 12px; margin-bottom: 14px; }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.tabs { display: flex; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-weight: 800; white-space: nowrap; }
.tab.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.data-table-wrap, .table-wrap { overflow: auto; }
.production-plan-form .data-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}
.data-table, table { width: 100%; border-collapse: collapse; }
.data-table { min-width: 780px; margin-bottom: 14px; }
.data-table th, .data-table td, th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th, th { color: #39464f; background: #eef3f4; font-size: 12px; font-weight: 900; white-space: nowrap; }
.data-table input { min-width: 110px; }
.sequence-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.upload-box { padding: 14px; background: #f7faf9; border: 1px solid var(--line); border-radius: 8px; }
.file-list { display: grid; gap: 8px; margin-top: 10px; }
.file-item, .service-card {
  padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.file-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.file-item a { color: var(--primary-dark); font-weight: 800; text-decoration: none; }
.service-list { display: grid; gap: 12px; }
.service-card-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.save-button { margin: 0 18px 18px; width: calc(100% - 36px); }
.empty-state { display: none; padding: 38px 20px; color: var(--muted); text-align: center; }
.empty-state.visible { display: block; }
.users-panel, .database-panel, .inventory-panel, .sales-order-panel { margin-top: 16px; }
.sales-order-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 560px; }
.sales-menu {
  display: grid; align-content: start; gap: 8px; padding: 16px; background: #f8fbfb; border-right: 1px solid var(--line);
}
.sales-menu-item {
  min-height: 42px; padding: 0 12px; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 8px; font-weight: 800; text-align: left;
}
.sales-menu-item.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.sales-menu-item:disabled { cursor: not-allowed; opacity: 0.58; }
.sales-content { min-width: 0; }
.sales-board { display: none; }
.sales-board.active { display: block; }
.production-plan-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(460px, 0.85fr); gap: 16px; padding: 18px; }
.production-plan-form, .production-plan-list {
  min-width: 0; background: #fbfcfc; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.production-items-table { min-width: 980px; }
.production-items-table input { min-width: 96px; }
.production-items-table [data-plan-field="deliveryDate"] { min-width: 150px; }
.production-plan-table-wrap table { min-width: 760px; }
.production-schedule-shell {
  margin: 18px; background: #fbfcfc; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.production-schedule-table-wrap table { min-width: 1040px; }
.compact-status-select { width: 112px; height: 34px; padding: 0 9px; border-radius: 8px; font-weight: 800; }
.technical-params-shell { padding: 18px; }
.technical-params-shell > div {
  background: #fbfcfc; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.order-context-bar {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: #fff; border-bottom: 1px solid var(--line);
}
.order-context-bar label { width: min(520px, 100%); }
.technical-params-form { background: #fbfcfc; }
.technical-params-table-wrap table { min-width: 960px; }
.template-param-groups { display: grid; gap: 14px; }
.template-param-group {
  padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.template-param-group h3 { margin: 0 0 12px; font-size: 15px; }
.technical-major-group { border-color: #b7d8d2; background: #f7fbfa; }
.technical-major-group > h3 {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-bottom: 10px; border-bottom: 1px solid #cfe4e0; color: var(--primary-dark); font-size: 17px;
}
.technical-major-group.completed { border-color: #92cfad; background: #f2faf5; }
.template-group-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.template-param-subgroup {
  margin-top: 12px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.template-param-subgroup.disabled { opacity: 0.62; background: #f3f6f6; }
.technical-major-group.completed .template-param-subgroup { background: #f8fcf9; }
.template-param-subgroup h4 { margin: 0 0 10px; font-size: 14px; }
.template-enable-line { display: flex; grid-template-columns: none; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.template-enable-line input { width: 18px; height: 18px; }
.template-param-group input:disabled { color: #4d5a61; background: #eef4f1; }
.template-param-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.process-sheets-shell { padding: 18px; }
.process-sheets-shell > .section-heading, .process-sheets-layout {
  background: #fbfcfc; border: 1px solid var(--line);
}
.process-sheets-shell > .section-heading { border-radius: 8px 8px 0 0; }
.process-sheets-layout {
  display: grid; grid-template-columns: 240px minmax(0, 1fr); border-top: 0; border-radius: 0 0 8px 8px; overflow: hidden;
}
.process-sheet-list-wrap { background: #fbfcfc; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; }
.process-sheet-list-wrap table { min-width: 980px; }
.process-template-menu {
  display: grid; align-content: start; gap: 8px; padding: 12px; background: #fff; border-right: 1px solid var(--line);
}
.process-template-item {
  min-height: 38px; padding: 0 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  text-align: left; font-weight: 800;
}
.process-template-item.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.process-template-item.muted-template { color: var(--muted); background: #f6f8f8; }
.compact-select {
  display: flex; grid-template-columns: none; align-items: center; gap: 8px; color: var(--muted); font-size: 13px;
}
.compact-select select { width: 172px; height: 38px; }
.process-sheet-preview { min-width: 0; overflow: auto; padding: 16px; background: #e9eef0; }
.process-print-page {
  width: var(--template-width); height: var(--template-height); background: #fff;
}
.process-print-all-pages { display: none; }
.excel-template {
  width: auto; table-layout: fixed; border-collapse: collapse; background: #fff; box-shadow: 0 10px 24px rgba(21, 35, 43, 0.12);
}
.excel-template .excel-cell {
  min-width: 36px; padding: 1px 4px; border: 1px solid #202020; color: #111; white-space: pre-wrap; line-height: 1.08;
  overflow: hidden;
}
.excel-param-input {
  display: block; width: 100%; min-width: 46px; height: 16px; min-height: 0; margin: 0; padding: 0 2px;
  border: 0; border-radius: 0; appearance: none; color: inherit; background: transparent;
  box-shadow: none; font-size: inherit; line-height: 16px;
}
.excel-param-label { display: inline; white-space: pre-wrap; }
.inline-param-input {
  display: inline-block; width: 82px; min-width: 42px; max-width: calc(100% - 20px); vertical-align: baseline;
}
.compact-inline-param-input {
  height: 16px; padding: 0 2px; line-height: 16px;
}
.excel-param-input:focus { outline: 1px solid var(--primary); outline-offset: -1px; background: #fff; }
.excel-template .excel-auto { padding: 3px 5px; background: #ffc000 !important; line-height: 1.18; }
.excel-template .excel-param { background: #d9d9d9 !important; }
.form-footer-actions { display: flex; gap: 10px; padding: 0 18px 18px; }
.database-table-wrap table { min-width: 980px; }
.inventory-layout { display: grid; grid-template-columns: 390px minmax(0, 1fr); gap: 16px; padding: 18px; }
.inventory-tabs { display: flex; gap: 8px; padding: 14px 18px 0; overflow-x: auto; }
.inventory-board { display: none; }
.inventory-board.active { display: block; }
.inventory-form, .inventory-list-panel {
  min-width: 0; padding: 16px; background: #fbfcfc; border: 1px solid var(--line); border-radius: 8px;
}
.inventory-form.readonly { opacity: 0.72; }
.inventory-list-panel { padding: 0; overflow: hidden; }
.inventory-list-panel .toolbar { background: #fff; }
.inventory-table-wrap table { min-width: 1040px; }
.inventory-table-wrap th,
.inventory-table-wrap td {
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.25;
  vertical-align: middle;
}
.inventory-table-wrap .small-button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}
.inventory-table-wrap .row-actions { gap: 6px; }
.technical-params-table-wrap,
.production-schedule-table-wrap,
.inventory-table-wrap {
  max-height: var(--scroll-table-max-height);
  overflow: auto;
}
.technical-params-table-wrap thead th,
.production-schedule-table-wrap thead th,
.inventory-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}
.muted-cell { color: var(--muted); text-align: center; }
.user-form { display: grid; grid-template-columns: 1fr 1fr 1fr 1.4fr 2.2fr auto auto auto; gap: 12px; align-items: center; padding: 18px; }
.permission-checks { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.checkbox-line { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.checkbox-line input { width: 18px; height: 18px; }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.enabled { color: #0f5132; background: var(--ok-bg); }
.badge.disabled { color: #8a4b00; background: var(--warn-bg); }
.badge.warning { color: #8a4b00; background: var(--warn-bg); border: 1px solid #ffd89a; }
.spec-change-badge { margin-left: 8px; vertical-align: middle; }
.spec-change-notice {
  margin: 12px 18px 0; padding: 10px 12px; color: #8a4b00; background: var(--warn-bg);
  border: 1px solid #ffd89a; border-radius: 8px; font-size: 13px; font-weight: 800;
}
.hint { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 10; max-width: min(420px, calc(100% - 40px));
  padding: 12px 14px; color: #fff; background: #172026; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px;
}

@media (max-width: 1180px) {
  .workspace, .inventory-layout, .production-plan-layout, .process-sheets-layout { grid-template-columns: 1fr; }
  .list-panel { position: static; max-height: none; }
  .form-grid.four, .form-grid.three, .form-grid.two, .user-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .process-template-menu { border-right: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .app-shell { width: min(100% - 20px, 1480px); padding-top: 18px; }
  .topbar, .panel-heading, .section-heading { align-items: stretch; flex-direction: column; }
  .module-switch, .metrics-grid, .form-grid.four, .form-grid.three, .form-grid.two, .sequence-grid, .user-form, .sales-order-layout, .template-param-grid { grid-template-columns: 1fr; }
  .sales-menu { border-right: 0; border-bottom: 1px solid var(--line); }
  .module-actions { justify-content: stretch; flex-direction: column; }
}

@media print {
  html, body { width: 100%; height: 100%; margin: 0; padding: 0; overflow: visible; background: #fff; }
  body.process-printing:not(.process-printing-all) { overflow: hidden; }
  body.process-printing .topbar,
  body.process-printing .module-switch,
  body.process-printing .sales-menu,
  body.process-printing .process-template-menu,
  body.process-printing .section-heading,
  body.process-printing .order-context-bar,
  body.process-printing .toast,
  body.process-printing #technicalParamsListView,
  body.process-printing #technicalParamsDetailView,
  body.process-printing .archive-module,
  body.process-printing .inventory-panel,
  body.process-printing .users-panel,
  body.process-printing .sales-board:not(.active) {
    display: none !important;
  }
  body.process-printing .app-shell,
  body.process-printing .sales-order-panel,
  body.process-printing .sales-order-layout,
  body.process-printing .sales-content,
  body.process-printing .sales-board.active,
  body.process-printing .technical-params-shell,
  body.process-printing .process-sheets-shell,
  body.process-printing #processSheetsDetailView,
  body.process-printing .process-sheets-layout,
  body.process-printing .process-sheet-preview {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    overflow: visible !important;
  }
  body.process-printing .process-sheet-preview {
    position: fixed;
    inset: 0;
    display: flex !important;
    align-items: center;
    justify-content: center;
    overflow: hidden !important;
  }
  body.process-printing .process-print-page {
    width: var(--print-width);
    height: var(--print-height);
    margin: 0 auto;
    overflow: hidden;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  body.process-printing .excel-template {
    box-shadow: none;
    transform: none;
    transform-origin: top left;
    zoom: var(--print-scale);
    page-break-inside: avoid;
    break-inside: avoid;
  }
  body.process-printing .excel-param-input {
    height: 14px;
    line-height: 14px;
  }
  body.process-printing-all .app-shell,
  body.process-printing-all .process-sheet-preview {
    display: none !important;
  }
  body.process-printing-all .process-print-all-pages {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }
  body.process-printing-all .process-print-all-page {
    display: flex !important;
    align-items: center;
    justify-content: center;
    page: process-portrait;
    width: 100%;
    height: 281mm;
    min-height: 0;
    box-sizing: border-box;
    overflow: hidden;
    page-break-after: always;
    break-after: page;
  }
  body.process-printing-all .process-print-all-page.landscape {
    page: process-landscape;
    height: 194mm;
  }
  body.process-printing-all .process-print-all-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }
}
