/* ==========================================================================
   ITLA 光刻工序流程 · 可编辑版
   版式取自 flowdoc.py 生成的 A4 工序表：同一套尺寸、色值、留白与分隔线。
   ========================================================================== */

:root {
  /* 设计令牌（与 PDF 完全一致） */
  --ink: #1b1f23;
  --gray: #6b7178;
  --gold: #b3801f;
  --hair: #d8dcdf;
  --soft: #23282d;
  --empty: #a9aeb3;

  /* 工作台（屏幕专用，不进打印） */
  --desk: #e8eaec;
  --chrome: #ffffff;
  --chrome-line: #d8dcdf;
  --chrome-hi: #f5f6f7;

  --zoom: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--desk);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
               "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@page { size: A4 portrait; margin: 0; }

/* ============================ 顶栏 ============================ */

.chrome {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 56px;
  padding: 0 20px;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.brand .mark {
  width: 3px;
  height: 18px;
  background: var(--gold);
  flex: none;
  transform: translateY(3px);
}
.brand b {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
}
.brand span {
  font-size: 11.5px;
  color: var(--gray);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.spacer { flex: 1 1 auto; }

/* 签署人 */
.signer {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--chrome-line);
  border-radius: 6px;
  background: var(--chrome-hi);
}
.signer label {
  font-size: 11px;
  color: var(--gray);
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.signer input {
  width: 108px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  outline: none;
  padding: 0;
}
.signer input::placeholder { color: #b9bec3; }

/* 存储状态 */
.mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--gray);
  white-space: nowrap;
}
.mode .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  flex: none;
}
.mode[data-state="local"] .dot { background: var(--gold); }
.mode[data-state="remote"] .dot { background: #2f7d4f; }

/* 按钮 */
.btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--chrome-line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { background: var(--chrome-hi); border-color: #c4c9ce; }
.btn:active { background: #eceef0; }
.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn.primary:hover { background: #2c3136; border-color: #2c3136; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--chrome-hi); border-color: var(--chrome-line); }
.btn .badge {
  display: inline-block;
  min-width: 16px;
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--gold);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.zoom {
  display: flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--chrome-line);
  border-radius: 6px;
  overflow: hidden;
}
.zoom button {
  width: 28px;
  height: 30px;
  border: 0;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.zoom button:hover { background: var(--chrome-hi); }
.zoom .lvl {
  min-width: 42px;
  font-size: 11.5px;
  color: var(--gray);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ============================ 工作台 ============================ */

.desk {
  padding: 28px 16px 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}

.sheet {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  padding: 14mm 12mm 12mm;
  background: #fff;
  color: var(--ink);
  zoom: var(--zoom);
  box-shadow:
    0 1px 2px rgba(27, 31, 35, 0.10),
    0 12px 32px -8px rgba(27, 31, 35, 0.18);
  /* 保持表格文字与 PDF 一致 */
  font-variant-numeric: tabular-nums;
}

/* ---------------- 报头 ---------------- */

.eyebrow {
  font-size: 2.6mm;
  color: var(--gray);
  letter-spacing: 0.4mm;
}

h1 {
  font-size: 6.4mm;
  font-weight: 700;
  letter-spacing: -0.1mm;
  margin: 1.4mm 0 0;
  line-height: 1.2;
}

.mast {
  border-bottom: 0.8mm solid var(--ink);
  padding-bottom: 3mm;
}

.accent {
  height: 0.9mm;
  width: 22mm;
  background: var(--gold);
  margin-top: 2.6mm;
}

/* ---------------- 类别行 ---------------- */

.section {
  display: flex;
  align-items: baseline;
  gap: 4mm;
  margin: 7mm 0 3mm;
}
.section .right {
  margin-left: auto;
  font-size: 2.6mm;
  color: var(--gray);
}

/* ---------------- 表格 ---------------- */

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

thead th {
  font-size: 2.7mm;
  font-weight: 700;
  text-align: left;
  padding: 2.4mm 1.6mm 2.4mm 0;
  border-bottom: 0.5mm solid var(--ink);
}

thead th.gap,
tbody td.gap { padding-left: 2.6mm; }

tbody td {
  font-size: 2.65mm;
  line-height: 1.5;
  vertical-align: top;
  padding: 3.1mm 1.6mm 3.2mm 0;
  border-bottom: 0.2mm solid var(--hair);
}

tbody tr:last-child td { border-bottom: 0.5mm solid var(--ink); }

td.plate { font-weight: 600; }
td.coat,
td.expdev { color: var(--soft); white-space: pre-line; }
td.remark .k { color: var(--gray); margin-right: 0.6mm; }
td.empty { color: var(--empty); }

/* ---------------- 页脚 ---------------- */

.foot {
  position: absolute;
  left: 12mm;
  right: 12mm;
  bottom: 9mm;
  border-top: 0.2mm solid var(--hair);
  padding-top: 2mm;
  display: flex;
  justify-content: space-between;
  font-size: 2.3mm;
  color: var(--gray);
}
.foot .pg { color: var(--ink); font-weight: 600; }

/* ==================== 可编辑单元（仅屏幕） ==================== */

.cell {
  position: relative;
  cursor: text;
  border-radius: 2px;
  transition: background 110ms ease, box-shadow 110ms ease;
}

.cell .val {
  display: block;
  min-height: 1lh;
  border-radius: 2px;
}

.cell:hover,
.cell:focus-visible {
  background: #fffcf3;
  box-shadow: inset 0 0 0 0.3mm rgba(179, 128, 31, 0.5);
  outline: none;
}

.cell:hover .val { color: var(--ink); }

/* 编辑态 */
.cell.editing {
  background: #fffdf6;
  box-shadow: inset 0 0 0 0.45mm var(--gold);
}
.cell textarea {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-variant-numeric: tabular-nums;
}
.cell textarea::placeholder { color: #c2c7cb; }

/* 单元格角标：最近一次改动 */
.cell[data-changed="1"]::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-top: 1.4mm solid rgba(179, 128, 31, 0.85);
  border-left: 1.4mm solid transparent;
}

/* ==================== 变更记录抽屉 ==================== */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 60;
  width: 480px;
  max-width: 100vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-left: 1px solid var(--chrome-line);
  box-shadow: -18px 0 48px -16px rgba(27, 31, 35, 0.28);
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
  font-variant-numeric: tabular-nums;
}
.drawer.open { transform: translateX(0); }

.drawer header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  height: 56px;
  border-bottom: 1px solid var(--chrome-line);
  flex: none;
}
.drawer header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.1px;
}
.drawer header .x {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 17px;
  line-height: 1;
  color: var(--gray);
  cursor: pointer;
}
.drawer header .x:hover { background: var(--chrome-hi); color: var(--ink); }

.drawer .body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 14px 18px 28px;
}

/* 记录列表 */
.rec {
  position: relative;
  padding: 0 0 18px 26px;
  border-left: 1px solid var(--hair);
  margin-left: 6px;
}
.rec:last-child { border-left-color: transparent; padding-bottom: 4px; }
.rec::before {
  content: "";
  position: absolute;
  left: -3.5px;
  top: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--gold);
}
.rec.bad::before { border-color: #b3453a; }

.rec .top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.rec .seq {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10.5px;
  color: var(--gold);
  font-weight: 700;
}
.rec .who {
  font-size: 12.5px;
  font-weight: 600;
}
.rec .when {
  margin-left: auto;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10.5px;
  color: var(--gray);
  white-space: nowrap;
}

.rec .where {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--gray);
}
.rec .where .pill {
  display: inline-block;
  padding: 0 5px;
  border-radius: 3px;
  background: var(--chrome-hi);
  border: 1px solid var(--hair);
  color: var(--soft);
  font-size: 10.5px;
}

.rec .diff {
  margin-top: 7px;
  font-size: 12px;
  line-height: 1.5;
  border-radius: 6px;
  background: #fafbfb;
  border: 1px solid #edeff0;
  overflow: hidden;
}
.rec .diff .line {
  display: flex;
  gap: 8px;
  padding: 5px 9px;
  white-space: pre-wrap;
  word-break: break-word;
}
.rec .diff .line + .line { border-top: 1px solid #f1f3f4; }
.rec .diff .sign {
  flex: none;
  width: 10px;
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 700;
}
.rec .diff .from { color: #8a2f22; background: #fdf6f5; }
.rec .diff .to { color: #1f5c37; background: #f5faf6; }
.rec .diff .none { color: var(--empty); font-style: italic; }

/* 校验结果：只给一句结论 */
.rec .check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  font-size: 11.5px;
  color: #2f7d4f;
}
.rec .check::before {
  content: "✓";
  font-weight: 700;
}
.rec .check.bad { color: #b3453a; }
.rec .check.bad::before { content: "!"; }

.empty-state {
  padding: 34px 8px;
  text-align: center;
  color: var(--gray);
  font-size: 12.5px;
  line-height: 1.7;
}
.empty-state .big {
  font-size: 26px;
  color: #d4d8db;
  display: block;
  margin-bottom: 10px;
}

/* ==================== 轻提示 ==================== */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 80;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.4;
  box-shadow: 0 10px 28px -10px rgba(27, 31, 35, 0.6);
  animation: toast-in 180ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.toast .tick {
  color: var(--gold);
  font-weight: 700;
}
.toast.out { opacity: 0; transform: translateY(6px); transition: 200ms ease; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== 打印 ==================== */

@media print {
  body { background: #fff; }
  .chrome, .drawer, .modal, .toasts, .desk-hint { display: none !important; }
  .desk { padding: 0; gap: 0; }
  .sheet {
    zoom: 1;
    height: 297mm;
    min-height: 0;
    box-shadow: none;
    page-break-after: always;
    break-after: page;
  }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
  .cell { background: transparent !important; box-shadow: none !important; }
  .cell[data-changed="1"]::after { display: none; }
  .cell textarea { display: none; }
}

/* ==================== 响应式 ==================== */

@media (max-width: 900px) {
  .brand span, .mode { display: none; }
  .chrome { gap: 10px; padding: 0 12px; }
  .drawer { width: 100%; }
}
