:root {
  --bg: #0b1220;
  --panel: #111a2b;
  --panel-2: #0f172a;
  --line: #243247;
  --text: #e5edf8;
  --muted: #8fa3be;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --success: #22c55e;
  --danger: #f87171;
  --warning: #fbbf24;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "PingFang SC", Arial, sans-serif;
  font-size: 13px;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.error { color: var(--danger); min-height: 1.2em; }

/* ---------- login ---------- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(14,165,233,.18), transparent 60%),
    radial-gradient(700px 420px at 100% 100%, rgba(34,197,94,.10), transparent 65%),
    var(--bg);
}
.login-lang {
  position: fixed; top: 18px; right: 18px; z-index: 5;
  padding: 6px 8px; color: var(--text); background: #0f172a;
  border: 1px solid var(--line); border-radius: 6px; font-size: 12px;
}
.login-card {
  width: min(520px, 100%);
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(17,26,43,.92);
  box-shadow: 0 24px 80px rgba(0,0,0,.45);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .3px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px var(--accent); }
.brand-ipb { color: var(--accent); font-weight: 800; letter-spacing: .5px; }
.eyebrow { margin: 22px 0 6px; font-size: 11px; letter-spacing: 2px; color: var(--accent); }
h1 { margin: 0 0 12px; font-size: 26px; line-height: 1.3; }
.login-card form { display: grid; gap: 9px; margin-top: 22px; }
.login-card label { color: var(--muted); font-size: 13px; }
.login-card input {
  width: 100%; padding: 12px 13px; margin-bottom: 6px;
  color: var(--text); background: #0a1322;
  border: 1px solid var(--line); border-radius: 9px;
}
.login-card input:focus { outline: 2px solid rgba(56,189,248,.28); border-color: var(--accent); }
.footnote { margin: 18px 0 0; color: #64748b; font-size: 12px; }

button.primary, button.success, button.ghost {
  border: 0; border-radius: 7px; padding: 8px 12px; color: #fff;
}
button.primary { background: var(--accent-2); }
button.primary:hover { background: #0284c7; }
button.success { background: #15803d; }
button.success:hover { background: var(--success); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .55; cursor: wait; }
button.ghost:disabled { opacity: .35; cursor: default; }

/* ---------- workspace ---------- */
.topbar {
  height: 52px; padding: 0 16px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line);
  background: #0a1322;
}
.version { font-size: 10px; color: #0b1220; background: var(--accent); padding: 2px 6px; border-radius: 4px; }
.topbar-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar-center { display: flex; justify-content: center; }
.topbar-center .success { padding: 7px 18px; font-size: 12px; }
.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.topbar-left .ghost { padding: 7px 10px; font-size: 12px; }
.invite-chip {
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; color: #bae6fd; background: rgba(56,189,248,.1);
  border: 1px solid rgba(56,189,248,.25); padding: 4px 8px; border-radius: 999px;
}
.workspace {
  display: grid; grid-template-columns: var(--side-width, 250px) minmax(0, 1fr);
  height: calc(100vh - 52px);
}
.workspace > * { min-height: 0; }
.settings-panel {
  overflow: hidden; display: flex; flex-direction: column;
  padding: 8px 9px 0;
  border-right: 1px solid var(--line); background: var(--panel);
}
.settings-scroll { flex: 1; min-height: 0; overflow: auto; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-heading h2 { margin: 0; font-size: 17px; }
.unit-select {
  padding: 3px 7px; color: var(--text); background: #0a1322;
  border: 1px solid var(--line); border-radius: 5px; font-size: 12px;
}
.lang-select {
  padding: 5px 6px; color: var(--text); background: #0a1322;
  border: 1px solid var(--line); border-radius: 5px; font-size: 12px;
}
.board-info { margin: 2px 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.file-info {
  flex: 0 0 auto; min-width: 0;
  margin: 10px 0 0; padding: 9px 0 4px;
  border-top: 2px solid #3b4d66;
}
.file-info-title { color: #7dd3fc; font-size: 10px; letter-spacing: .5px; }
.file-name {
  margin-top: 1px; color: var(--text); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-meta { margin-top: 1px; color: var(--muted); font-size: 11px; }
.settings-section { padding: 4px 0 5px; border-top: 1px solid var(--line); }
.settings-section h3 { margin: 0 0 4px; font-size: 13px; color: #bae6fd; font-weight: 600; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 6px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px 6px; }
.field-grid.three label { gap: 3px; }
.field-grid.compact { margin-top: 2px; }
.field-grid label {
  display: grid; grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center; gap: 3px; color: var(--muted); font-size: 12px;
  white-space: nowrap;
}
.field-grid label > :first-child, .field-grid label { min-width: 0; }
.field-grid label:not(:has(.unit)) { grid-template-columns: auto minmax(0, 1fr); }
.field-grid label input, .field-grid label select { grid-column: 3; }
.field-grid label:not(:has(.unit)) input,
.field-grid label:not(:has(.unit)) select { grid-column: 2; }
.field-grid label:has(.unit) { grid-template-columns: auto auto minmax(0, 1fr); }
.field-grid label .unit { grid-column: 2; font-size: 11px; color: #64748b; }
.field-grid label.wide { grid-column: 1 / -1; }
.field-grid label.wide input { max-width: 96px; }
.field-grid label input, .field-grid label select {
  width: 100%; min-width: 0; padding: 2px 4px;
  color: var(--text); background: #0a1322;
  border: 1px solid var(--line); border-radius: 4px; font-size: 13px;
}
.rail-row { display: flex; gap: 14px; margin-bottom: 5px; }
body.lang-en .rail-row { gap: 8px; }
.rail-row label, .check-line label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.check-line { margin: 4px 0; }
.inline-select { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin: 4px 0; }
.inline-select select { padding: 4px 6px; color: var(--text); background: #0a1322; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; }
.vcut-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 4px 0; }
.vcut-row label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.vcut-row select { max-width: 122px; padding: 3px 5px; color: var(--text); background: #0a1322; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; }
.assembly-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.assembly-summary {
  flex: 1; min-width: 0; color: var(--muted); font-size: 12px;
  line-height: 1.5; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.mini-btn {
  flex: 0 0 auto; padding: 3px 7px; color: #bae6fd; background: #0a1322;
  border: 1px solid var(--line); border-radius: 5px; font-size: 12px;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.subhead-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mini-link {
  padding: 1px 5px; color: #7dd3fc; background: transparent;
  border: 1px solid transparent; border-radius: 4px; font-size: 11px;
}
.mini-link:hover { border-color: var(--line); color: var(--accent); }
.settings-actions {
  position: static; display: flex; gap: 5px;
  margin: 6px -9px 0; padding: 7px 9px 8px;
  border-top: 1px solid var(--line); background: var(--panel);
}
.settings-actions button { flex: 1; padding: 7px 6px; font-size: 12px; }

/* ---------- preview ---------- */
.preview-panel { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: #0a1322; }
.preview-grid {
  display: grid;
  grid-template-columns: var(--pane-left, 1fr) 6px minmax(0, 1fr);
  min-height: 0; background: var(--line);
}
.preview-splitter {
  position: relative; z-index: 3; background: #0a1322; cursor: col-resize;
}
.preview-splitter::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 2px; width: 2px;
  background: var(--line);
}
.preview-splitter:hover::after, .preview-splitter.dragging::after { background: var(--accent); }
.preview-pane {
  display: grid; grid-template-rows: 36px minmax(0, 1fr);
  min-width: 0; min-height: 0; background: #0a1322;
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel);
  font-size: 13px;
}
.pane-tools { display: flex; align-items: center; gap: 8px; }
.pane-fit {
  padding: 2px 7px; color: #bae6fd; background: #0a1322;
  border: 1px solid var(--line); border-radius: 4px; font-size: 11px;
}
.pane-fit:hover { border-color: var(--accent); color: var(--accent); }
.preview-stage {
  position: relative; min-height: 0; overflow: hidden; cursor: grab;
  touch-action: none;
  background-image: radial-gradient(#17212c 1px, transparent 1px);
  background-size: 22px 22px;
}
.preview-stage.dragging { cursor: grabbing; }
.canvas-caption {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  padding: 7px 10px 6px; text-align: center; pointer-events: none;
  color: #e2e8f0; font-size: 12px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(transparent, rgba(10, 19, 34, .92) 55%);
}
.preview-stage img {
  position: absolute; top: 50%; left: 50%; z-index: 1;
  transform-origin: center center; max-width: none; max-height: none;
  user-select: none; -webkit-user-drag: none;
  background: #0f172a; border-radius: 4px;
}
.preview-stage img.detail-layer {
  z-index: 2; background: transparent; border-radius: 0; pointer-events: none;
}
.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  padding: 16px; text-align: center; color: var(--muted);
}
.empty-state p { margin: 0; line-height: 1.7; font-size: 12px; }
.empty-state code { color: #bae6fd; }
.diagnostics {
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 6px 12px 8px; max-height: 15vh; overflow: auto;
}
.diag-head { display: flex; justify-content: space-between; margin-bottom: 3px; }
.diagnostics.has-errors .diag-head strong { color: #ff5c5c; }
.diagnostics.has-warnings .diag-head strong { color: #fde68a; }
.diag-tools { display: flex; align-items: center; gap: 10px; }
.pour-toggle { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; }
.pour-toggle input { accent-color: var(--accent); }
.diag-body { white-space: pre-wrap; line-height: 1.5; font-size: 11px; }
.diag-body.has-errors {
  color: #ff5c5c; background: rgba(220, 38, 38, .16);
  border-left: 4px solid #ef4444; border-radius: 4px;
  padding: 6px 8px; font-weight: 600;
}
.diag-body.has-warnings {
  color: #fde68a; background: rgba(245, 158, 11, .09);
  border-left: 3px solid #f59e0b; border-radius: 4px;
  padding: 6px 8px;
}

/* ---------- assembly modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 18px;
  background: rgba(3, 8, 16, .72);
}
.modal-card {
  width: min(560px, 94vw); max-height: 90vh; overflow: auto;
  padding: 14px 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.modal-x {
  width: 26px; height: 26px; color: var(--muted); background: transparent;
  border: 0; border-radius: 5px; font-size: 18px; line-height: 1;
}
.modal-x:hover { color: var(--text); background: #0a1322; }
.slot-note { margin: 0 0 8px; color: #64748b; font-size: 11px; line-height: 1.5; }
.slot-matrix { display: grid; gap: 3px; }
.slot-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 76px 76px 36px;
  align-items: center; gap: 6px; padding: 4px 8px;
  color: var(--muted); background: #0a1322;
  border: 1px solid var(--line); border-radius: 5px; font-size: 12px;
}
.slot-row.slot-head { padding: 0 8px; border-color: transparent; background: transparent; color: #64748b; font-size: 11px; }
.slot-row.slot-head span:not(:first-child) { text-align: left; }
.slot-row > span:first-child { color: var(--text); }
.slot-row label { display: flex; align-items: center; gap: 5px; }
.slot-row input { accent-color: var(--accent); }
.slot-row.unavailable { opacity: .4; background: #080f1c; }
.slot-row.unavailable > span:first-child { color: var(--muted); }
.slot-row.unavailable label { cursor: not-allowed; }
.slot-badge { font-size: 10px; color: var(--warning); text-align: right; }
.swap-btn {
  width: 100%; margin-top: 8px; padding: 6px 8px;
  color: #bae6fd; background: transparent;
  border: 1px dashed var(--line); border-radius: 5px; font-size: 11px;
}
.swap-btn:hover { color: var(--accent); border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.modal-actions button { min-width: 76px; }

/* ---------- export progress modal ---------- */
.export-card { width: min(460px, 94vw); }
.progress-track {
  height: 8px; margin: 12px 0 7px;
  background: #0a1322; border: 1px solid var(--line); border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  width: 0; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #0ea5e9, #22c55e);
  transition: width .45s ease-out;
}
.progress-meta {
  display: flex; justify-content: space-between; gap: 10px;
  color: var(--muted); font-size: 12px;
}
.progress-meta #export-percent { font-variant-numeric: tabular-nums; color: var(--text); }
#export-stage { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-error {
  margin: 10px 0 0; padding: 8px 10px; border-radius: 6px;
  color: #fecaca; background: rgba(127, 29, 29, .35);
  border: 1px solid #7f1d1d; font-size: 12px; line-height: 1.6;
}
.export-card.done .progress-bar { background: linear-gradient(90deg, #16a34a, #22c55e); }
.export-card.failed .progress-bar { background: var(--danger, #f87171); }

/* ---------- feedback modal ---------- */
.feedback-card { width: min(560px, 94vw); }
.feedback-card .modal-head strong { font-size: 13px; line-height: 1.45; }
.feedback-text {
  width: 100%; margin-top: 8px; padding: 9px 10px; resize: vertical;
  min-height: 130px; color: var(--text); background: #0a1322;
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 12px; line-height: 1.6;
}
.feedback-text:focus { outline: none; border-color: var(--accent); }
.feedback-text::placeholder { color: #475569; }
.feedback-meta {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 6px; font-size: 11px;
}
#feedback-state { color: var(--accent); }
#feedback-state.error { color: var(--danger, #f87171); }
#feedback-submit[disabled] { opacity: .55; }

.toast {
  position: fixed; right: 18px; bottom: 18px; max-width: min(420px, 80vw);
  padding: 10px 13px; border-radius: 8px;
  color: #fff; background: #0f172a; border: 1px solid var(--line);
  box-shadow: 0 12px 34px rgba(0,0,0,.4); z-index: 40;
}
.nav-hint {
  position: fixed; z-index: 50; pointer-events: none;
  padding: 8px 12px; border-radius: 7px;
  color: #f8fafc; background: #0f172a; border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(0,0,0,.45);
  font-size: 12px; white-space: nowrap;
}
.toast.error { border-color: #7f1d1d; background: #450a0a; }
.toast.success { border-color: #14532d; background: #052e16; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 300px minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .settings-panel { display: block; overflow: visible; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .settings-scroll { overflow: visible; }
  .settings-actions { position: static; }
  .preview-grid { grid-template-columns: 1fr !important; grid-template-rows: minmax(300px, 1fr) minmax(300px, 1fr); }
  .preview-splitter { display: none; }
  .preview-panel { min-height: 78vh; }
  .topbar { display: flex; flex-wrap: wrap; padding: 8px 12px; height: auto; gap: 6px; }
  .topbar-center { order: 3; width: 100%; }
  .topbar-left { flex-wrap: wrap; }
  .invite-chip { display: none; }
}
