:root {
  --bg: #f6f7f9;
  --chrome: #1e2430;
  --chrome-2: #262d3b;
  --chrome-border: #343d4e;
  --text-on-chrome: #e8ebf0;
  --muted-on-chrome: #9aa4b5;
  --accent: #3b82f6;
  --panel: #ffffff;
  --panel-border: #e2e6ec;
  --ink: #2a3140;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- Toolbar ---------- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 12px;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-border);
  user-select: none;
}

.brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-on-chrome);
  margin-right: 6px;
  letter-spacing: 0.2px;
}
.brand span { color: var(--accent); font-weight: 600; }

.tb-group {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--chrome-2);
  border: 1px solid var(--chrome-border);
  border-radius: 8px;
  padding: 2px;
}

.tb-spacer { flex: 1; }

#toolbar button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-on-chrome);
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  min-width: 32px;
}
#toolbar button:hover { background: rgba(255, 255, 255, 0.09); }
#toolbar button:active { background: rgba(255, 255, 255, 0.16); }
#toolbar button:disabled { opacity: 0.35; cursor: default; background: transparent; }
.zoom-label { min-width: 52px; font-variant-numeric: tabular-nums; }

#doc-select {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-on-chrome);
  font: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 6px;
  max-width: 170px;
  text-overflow: ellipsis;
  cursor: pointer;
  outline: none;
}
#doc-select:hover { background: rgba(255, 255, 255, 0.09); }
#doc-select option { color: #2a3140; background: #fff; }

#mode-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 10px;
  margin-left: 4px;
  white-space: nowrap;
}
#mode-chip.design { background: #1d4ed8; color: #dbeafe; }
#mode-chip.order { background: #15803d; color: #dcfce7; }
#mode-chip.editing { background: #b45309; color: #ffedd5; }
#mode-chip.closed { background: #475569; color: #e2e8f0; }

/* ---------- Layout ---------- */
#workspace {
  display: flex;
  height: calc(100% - 48px);
}

/* ---------- Palette ---------- */
#palette {
  width: 156px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  padding: 12px 10px;
  overflow-y: auto;
  user-select: none;
}

.palette-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #8b93a5;
  margin-bottom: 10px;
}

.palette-item {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 6px 4px;
  margin-bottom: 8px;
  cursor: grab;
  text-align: center;
  background: #fff;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.palette-item:hover {
  border-color: var(--accent);
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.25);
}
.palette-item svg { width: 100%; height: 40px; display: block; }
.palette-item span { font-size: 11.5px; color: #5a6275; }
.pv { fill: #eef2f8; stroke: #5b6470; stroke-width: 1.5; }

.palette-hint {
  font-size: 11.5px;
  line-height: 1.45;
  color: #98a0b0;
  margin-top: 14px;
}

/* ---------- Canvas ---------- */
#canvas-wrap { position: relative; flex: 1; min-width: 0; }

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  touch-action: none;
  display: block;
}

#stats-bar {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: #3c4354;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 5px 16px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
#stats-bar[hidden] { display: none; }
.stat-status { display: inline-flex; align-items: center; gap: 4px; }
.stat-status i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.stat-link { color: #b45309; cursor: pointer; font-weight: 600; }
.stat-link:hover { text-decoration: underline; }
.stat-late { color: #dc2626; font-weight: 600; }
.stat-drift { color: #b45309; font-weight: 600; }
.stat-seq { color: #dc2626; font-weight: 600; cursor: pointer; }
.stat-seq:hover { text-decoration: underline; }

#doc-dates {
  margin-top: 14px;
  padding: 10px 12px;
  background: #f6f8fb;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.9;
  color: #3c4354;
}
#doc-dates:empty { display: none; }
.late-text { color: #dc2626; font-weight: 600; }

#hint-bar {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  font-size: 11.5px;
  color: #8b93a5;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 4px 14px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- SVG content ---------- */
.node { cursor: grab; }
.node.dragging { cursor: grabbing; }
.node .shape { transition: filter 0.1s; }
.node:hover .shape { filter: brightness(0.97); }
.node.selected .shape {
  stroke: var(--accent) !important;
  stroke-width: 2.5;
}
.node text {
  pointer-events: none;
  user-select: none;
}

.port {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 1.5;
  cursor: crosshair;
  opacity: 0;
  transition: opacity 0.12s;
}
.node:hover .port, .node.selected .port { opacity: 1; }
.port:hover { fill: var(--accent); }

.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  cursor: pointer;
}
.edge-line {
  fill: none;
  stroke: #5b6470;
  stroke-width: 1.8;
  pointer-events: none;
}
.edge.selected .edge-line { stroke: var(--accent); stroke-width: 2.4; }
.edge-label {
  font-size: 12px;
  fill: #3c4354;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4;
  stroke-linejoin: round;
  pointer-events: none;
  user-select: none;
}

.status-dot { pointer-events: none; }

.log-entry {
  font-size: 11px;
  color: #8b93a5;
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}

.resize-handle { cursor: nwse-resize; }

.lane-body { pointer-events: none; }
.lane-header { cursor: grab; }
.lane-title { pointer-events: none; user-select: none; }
.lane.selected .lane-body, .lane.selected .lane-header {
  stroke: var(--accent);
  stroke-width: 1.5;
}

.edge-end {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 2;
  cursor: crosshair;
}
.edge-end:hover { fill: var(--accent); }

.temp-edge {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-dasharray: 6 4;
  pointer-events: none;
}
.drop-target .shape {
  stroke: var(--accent) !important;
  stroke-width: 2.5;
}

/* ---------- Properties panel ---------- */
#panel-resizer {
  flex: none;
  width: 5px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.12s;
}
#panel-resizer:hover, #panel-resizer.dragging { background: var(--accent); }

/* The panel is the work surface in production mode.
   Width is user-adjustable via the drag handle; this is only the default. */
#props {
  width: 360px;
  flex: none;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---- sticky head: identity, standing, next action ---- */
#panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  padding: 12px 14px 10px;
}
#panel-head[hidden] { display: none; }

#panel-sub {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: #8b93a5;
}
#panel-title {
  font-size: 16px;
  font-weight: 650;
  color: var(--ink);
  line-height: 1.3;
  margin-top: 3px;
  word-break: break-word;
}

/* lifecycle stepper: 未开始 → 进行中 → 已完成; blocked interrupts the middle */
#status-stepper {
  display: flex;
  gap: 4px;
  margin-top: 10px;
}
#status-stepper[hidden] { display: none; }
.step {
  flex: 1;
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 4px;
  border-radius: 6px;
  background: #f8fafc;
  color: #b6bfcc;
  white-space: nowrap;
}
.step.past        { background: #eef2f6; color: #64748b; }
.step.cur-todo    { background: #f1f5f9; color: #475569; box-shadow: inset 0 0 0 1.5px #94a3b8; }
.step.cur-doing   { background: #dbeafe; color: #1d4ed8; box-shadow: inset 0 0 0 1.5px #60a5fa; }
.step.cur-done    { background: #dcfce7; color: #15803d; box-shadow: inset 0 0 0 1.5px #4ade80; }
.step.cur-blocked { background: #fee2e2; color: #b91c1c; box-shadow: inset 0 0 0 1.5px #f87171; }

#status-line {
  font-size: 12px;
  color: #64748b;
  margin-top: 6px;
  min-height: 0;
}
#status-line.warn { color: #dc2626; font-weight: 600; }
#status-line:empty { display: none; }

/* actions styled by intent: forward move filled, exceptions outlined */
#status-btns {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
#status-btns:empty { display: none; }
.act {
  flex: 1;
  padding: 9px 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.1s, background 0.1s;
}
.act:hover { filter: brightness(0.95); }
.act.filled-blue   { background: #3b82f6; color: #fff; }
.act.filled-green  { background: #22c55e; color: #fff; }
.act.outline-red   { background: #fff; color: #dc2626; border-color: #fecaca; }
.act.outline-red:hover { background: #fef2f2; filter: none; }
.act.outline-green { background: #fff; color: #15803d; border-color: #bbf7d0; }
.act.outline-green:hover { background: #f0fdf4; filter: none; }
.act.outline-gray  { background: #fff; color: #64748b; border-color: #e2e6ec; }
.act.outline-gray:hover { background: #f2f5f9; filter: none; }

/* ---- body sections ---- */
#panel-body { padding: 12px 14px 16px; }

.sec {
  border-top: 1px solid var(--panel-border);
  padding: 12px 0 4px;
}
.sec:first-child { border-top: none; padding-top: 2px; }
.sec[hidden] { display: none; }

.sec-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: #8b93a5;
  margin-bottom: 8px;
}
details.sec > summary.sec-head {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
details.sec > summary.sec-head::-webkit-details-marker { display: none; }
details.sec > summary.sec-head::before {
  content: "▸";
  font-size: 9px;
  transition: transform 0.12s;
}
details.sec[open] > summary.sec-head::before { transform: rotate(90deg); }

.sec.alert {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 12px;
}
.sec.alert .sec-head { color: #b91c1c; }

.fld-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: #5a6275;
  margin: 9px 0 4px;
}
.note-line {
  font-size: 12px;
  margin-top: 8px;
  padding: 6px 9px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #475569;
}
.note-line.warn { background: #fef2f2; color: #b91c1c; font-weight: 600; }
.note-line.good { background: #f0fdf4; color: #15803d; }

#props textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
  resize: vertical;
  outline: none;
}
#props textarea:focus { border-color: var(--accent); }

#props input, #props select {
  width: 100%;
  background: #fff;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
}
#props input:focus, #props select:focus { border-color: var(--accent); }
#props input:disabled, #props select:disabled, #props textarea:disabled {
  background: #f1f5f9;
  color: #64748b;
  border-color: transparent;
  cursor: default;
  opacity: 1;
}

#shape-type-btns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.shape-btn {
  padding: 4px 2px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #fff;
  cursor: pointer;
}
.shape-btn svg { width: 100%; height: 20px; display: block; }
.shape-btn:hover { background: #f2f5f9; }
.shape-btn.active {
  border-color: var(--accent);
  background: #eff6ff;
}

#edge-style-btns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.seg-btn {
  font: inherit;
  font-size: 11.5px;
  padding: 5px 4px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #fff;
  cursor: pointer;
  color: #3c4354;
  white-space: nowrap;
}
.seg-btn:hover { background: #f2f5f9; }
.seg-btn.active {
  border-color: var(--accent);
  background: #eff6ff;
  font-weight: 600;
}

#swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
}
.swatch.active { outline: 2px solid var(--accent); outline-offset: 1px; }

.props-btn {
  width: 100%;
  margin-top: 14px;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #fff;
  cursor: pointer;
}
.props-btn:hover { background: #f2f5f9; }
.props-btn.danger { color: #d43c3c; border-color: #ecc8c8; }
.props-btn.danger:hover { background: #fdf1f1; }
.props-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.props-btn.primary:hover { background: #2f6fe0; }

#order-source {
  font-size: 11.5px;
  color: #8b93a5;
  margin-top: 8px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 44px;
  transform: translateX(-50%);
  z-index: 80;
  background: #1e2430;
  color: #e8ebf0;
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  white-space: nowrap;
}
#toast[hidden] { display: none; }

/* ---------- Dialogs ---------- */
#prod-dialog, #block-dialog {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 18px 20px;
  width: 300px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}
#prod-dialog::backdrop, #block-dialog::backdrop, #edit-dialog::backdrop { background: rgba(15, 20, 30, 0.35); }
/* the reason dialog carries prose, so it gets room to write in */
#edit-dialog {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 18px 20px;
  width: 420px;
}
#edit-dialog textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 10px;
  resize: vertical;
  min-height: 84px;
  outline: none;
}
#edit-dialog textarea:focus { border-color: var(--accent); }

#prod-dialog input, #block-dialog input, #block-dialog select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
}
#prod-dialog input:focus, #block-dialog input:focus, #block-dialog select:focus { border-color: var(--accent); }
.dlg-title { font-size: 15px; font-weight: 650; color: var(--ink); }
.dlg-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.dlg-actions .props-btn { margin-top: 0; }

#sched-note:empty { display: none; }
#sec-order-log { margin-top: 14px; }
#sec-order-log[hidden] { display: none; }

/* ---------- Schedule: plan vs actual ---------- */
#sched-gantt { margin: 2px 0 10px; }
#sched-gantt:empty { display: none; }
#sched-gantt svg { display: block; }

#sched-grid {
  display: grid;
  grid-template-columns: 32px 1fr 1fr 62px;
  gap: 5px 6px;
  align-items: center;
}
.sg-h {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #8b93a5;
}
.sg-l {
  font-size: 11px;
  font-weight: 600;
  color: #5a6275;
}
.sg-v {
  font-size: 12px;
  color: #2a3140;
  font-variant-numeric: tabular-nums;
}
.sg-v input {
  width: 100%;
  padding: 4px 5px;
  font-size: 12px;
}
.warn-text { color: #dc2626; font-weight: 600; }

/* ---------- Inline label editor ---------- */
#inline-editor {
  position: fixed;
  z-index: 50;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  background: #fff;
  font-family: inherit;
  text-align: center;
  resize: none;
  overflow: hidden;
  outline: none;
  padding: 2px 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

/* ---------- Palette drag ghost ---------- */
#drag-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  opacity: 0.75;
  width: 110px;
}
#drag-ghost svg { width: 100%; display: block; }

/* ---------- Sign-in gate ---------- */
#login-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--chrome);
  display: flex;
  align-items: center;
  justify-content: center;
}
#login-gate[hidden] { display: none; }

#login-card {
  width: 340px;
  background: var(--panel);
  border-radius: 14px;
  padding: 26px 28px 24px;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.35);
}
.login-brand { font-size: 19px; font-weight: 700; color: var(--ink); }
.login-brand span { color: var(--accent); }
.login-sub { font-size: 12.5px; color: #8b93a5; margin: 4px 0 14px; }
#login-card input {
  width: 100%;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 10px;
  outline: none;
}
#login-card input:focus { border-color: var(--accent); }
#login-error { font-size: 12px; color: #dc2626; margin-top: 10px; min-height: 0; }
#login-error:empty { display: none; }
#login-btn { margin-top: 16px; }

/* ---------- Cloud status in the toolbar ---------- */
#cloud-group[hidden] { display: none; }
#save-state {
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 10px;
  white-space: nowrap;
  color: var(--muted-on-chrome);
}
#save-state:empty { display: none; }
#save-state.saving { color: #cbd5e1; }
#save-state.saved  { color: #86efac; }
#save-state.failed { background: #b91c1c; color: #fee2e2; font-weight: 600; }
#btn-account { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
