:root {
  --paper: #fbfaf6;
  --panel: #f5f1e8;
  --panel-strong: #ebe2d3;
  --ink: #20201d;
  --muted: #706a60;
  --line: #cfc3b2;
  --accent: #0f766e;
  --accent-2: #c47b2b;
  --danger: #b42318;
  --ok: #147a45;
  --code: #18211f;
  --shadow: 0 18px 50px rgba(38, 29, 18, 0.13);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(20, 122, 69, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(196, 123, 43, 0.07) 1px, transparent 1px),
    #eee7da;
  background-size: 28px 28px;
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  background: #fffaf0;
  color: var(--ink);
  min-height: 30px;
  padding: 5px 10px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(520px, 1fr) 360px;
  grid-template-rows: minmax(0, 1fr) 150px;
  height: 100vh;
  overflow: hidden;
}

.left-rail,
.right-rail,
.workspace,
.log-dock {
  min-width: 0;
  min-height: 0;
}

.left-rail {
  grid-row: 1 / 3;
  border-right: 1px solid var(--line);
  background: rgba(245, 241, 232, 0.96);
  display: grid;
  grid-template-rows: auto auto minmax(132px, 28vh) minmax(0, 1fr);
  overflow: hidden;
}

.right-rail {
  border-left: 1px solid var(--line);
  background: rgba(245, 241, 232, 0.98);
  display: grid;
  grid-template-rows: 45% 55%;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  background: rgba(255, 252, 246, 0.45);
  overflow: hidden;
}

.log-dock {
  grid-column: 2 / 4;
  border-top: 1px solid var(--line);
  background: #211f1a;
  color: #f8efe0;
  overflow: hidden;
}

.brand-strip,
.property-panel,
.code-panel,
.workspace-toolbar,
.log-dock {
  padding: 16px;
}

.queue-panel,
.field-panel {
  padding: 16px;
  min-height: 0;
}

.queue-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-top: 1px solid rgba(207, 195, 178, 0.65);
  border-bottom: 1px solid rgba(207, 195, 178, 0.65);
}

.field-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.brand-strip {
  display: grid;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.brand-actions {
  display: grid;
  justify-items: start;
  gap: 8px;
  flex: 0 0 auto;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-2);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: 23px;
  font-weight: 800;
}

h2 {
  font-size: 15px;
  font-weight: 800;
}

.status-pill {
  border: 1px solid rgba(15, 118, 110, 0.35);
  color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
  padding: 4px 8px;
  font-size: 12px;
}

.account-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 72px;
  max-width: 118px;
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
  background: #fffdf8;
}

.account-button span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a7a196;
  flex: 0 0 8px;
}

.account-dot.online {
  background: var(--ok);
}

.account-dot.error {
  background: var(--danger);
}

.upload-zone {
  position: relative;
  margin: 16px;
  padding: 18px;
  border: 1px dashed #9a876e;
  background: #fff9ed;
  min-height: 132px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 5px;
}

.upload-zone.dragging {
  border-color: var(--accent);
  background: #edf8f5;
}

.upload-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
}

.upload-zone span,
.queue-meta,
.field-group small,
.property-help,
.property-form small {
  color: var(--muted);
  font-size: 12px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.queue-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  align-content: start;
  padding-right: 2px;
}

.queue-item {
  border: 1px solid var(--line);
  background: #fffaf0;
  padding: 10px;
  cursor: pointer;
}

.queue-item.active {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

.queue-name {
  font-weight: 800;
  font-size: 13px;
  word-break: break-all;
}

.queue-meta {
  display: flex;
  justify-content: space-between;
  margin: 8px 0;
}

.progress-track {
  height: 5px;
  background: #eadfcc;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 180ms ease;
}

.field-groups {
  display: grid;
  gap: 12px;
  overflow: auto;
  align-content: start;
  padding-right: 2px;
}

.field-group {
  display: grid;
  gap: 7px;
}

.field-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.field-chip {
  border: 1px solid #d7cab8;
  background: #fffaf0;
  padding: 6px 7px;
  font-size: 12px;
  display: grid;
  gap: 2px;
  text-align: left;
  max-width: 100%;
  min-height: 54px;
}

.field-chip span {
  color: var(--ink);
  font-weight: 800;
}

.field-chip code {
  color: var(--accent);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  white-space: normal;
  word-break: break-all;
}

.field-chip small {
  color: var(--muted);
}

.field-search {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  padding: 8px 9px;
  margin-bottom: 10px;
  min-height: 34px;
}

.empty-field-result {
  color: var(--muted);
  font-size: 12px;
  border: 1px dashed var(--line);
  padding: 12px;
  background: #fffaf0;
}

.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.9);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.preview-stage {
  overflow: auto;
  padding: 28px;
  display: grid;
  place-items: start center;
}

.preview-scale-shell {
  position: relative;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 16px;
  color: var(--muted);
  width: 100%;
  height: 100%;
}

.skeleton-page {
  width: 240px;
  height: 330px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.75), transparent),
    linear-gradient(#ded3c1 20px, transparent 20px),
    linear-gradient(#ded3c1 10px, transparent 10px),
    #fffaf0;
  background-size: 120px 100%, 170px 58px, 205px 32px, 100% 100%;
  background-position: -120px 0, 36px 48px, 18px 112px, 0 0;
  background-repeat: no-repeat, repeat-y, repeat-y, no-repeat;
  border: 1px solid var(--line);
  animation: sweep 1.2s linear infinite;
}

@keyframes sweep {
  to {
    background-position: 240px 0, 36px 48px, 18px 112px, 0 0;
  }
}

.page-preview {
  width: 706px;
  height: 992px;
  min-height: 992px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
  transform-origin: top center;
}

.doc-preview {
  width: 706px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
  transform-origin: top center;
}

.page-node {
  position: relative;
}

.preview-node {
  outline: 1px solid transparent;
  outline-offset: -1px;
}

.preview-node:hover {
  outline-color: rgba(196, 123, 43, 0.55);
}

.preview-node.selected {
  outline: 2px solid var(--accent);
  background-color: rgba(15, 118, 110, 0.05);
}

.pm-header {
  padding: 0;
}

.pm-content {
  padding: 0;
}

.pm-container,
.pm-task-list,
.pm-task-item {
  display: flex;
}

.pm-table {
  border-collapse: collapse;
  table-layout: fixed;
}

.pm-cell {
  overflow: hidden;
}

.pm-static,
.pm-datetime,
.pm-signature {
  display: inline-flex;
  min-height: 18px;
  align-items: center;
}

.pm-datetime,
.pm-signature {
  border-bottom: 1px solid #000;
  min-width: 88px;
  padding: 0 4px;
}

.pm-signature {
  justify-content: center;
  color: #62584b;
}

.pm-paragraph,
.pm-heading {
  margin: 0;
  min-height: 1em;
  white-space: pre-wrap;
}

.pm-image-placeholder {
  position: absolute;
  height: 45px;
  color: #9b8a74;
  font-size: 12px;
}

.pm-labelblock {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
}

.pm-labelblock .pm-paragraph {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pm-label {
  flex: 0 0 auto;
}

.pm-check {
  width: 12px;
  height: 12px;
  border: 1px solid #111;
  margin-top: 2px;
  flex: 0 0 12px;
}

.property-panel,
.code-panel {
  overflow: auto;
  border-bottom: 1px solid var(--line);
}

.property-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.advanced-props {
  border: 1px solid rgba(207, 195, 178, 0.7);
  background: rgba(255, 252, 245, 0.72);
  padding: 10px;
}

.advanced-props summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--ink);
}

.advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.node-tools {
  border-top: 1px solid rgba(207, 195, 178, 0.75);
  margin-top: 14px;
  padding-top: 14px;
  display: grid;
  gap: 12px;
}

.node-tool-section {
  display: grid;
  gap: 8px;
}

.node-tool-title {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

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

.node-tool-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.node-tool-grid button {
  min-width: 0;
  padding: 6px 7px;
  text-align: left;
  background: #fffdf8;
}

.node-tool-grid button.danger {
  border-color: rgba(180, 35, 24, 0.45);
  color: var(--danger);
}

.node-tool-grid button span {
  display: block;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.node-tool-grid button code {
  color: var(--accent);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 10px;
  white-space: normal;
  word-break: break-all;
}

.property-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.prop-title {
  color: var(--ink);
  font-weight: 800;
}

.prop-title code {
  color: var(--accent);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  font-weight: 500;
}

.property-form label.wide {
  grid-column: 1 / -1;
}

.property-form .wide {
  grid-column: 1 / -1;
}

.property-form input,
.property-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  padding: 7px;
  min-height: 32px;
}

.property-form textarea {
  resize: vertical;
  min-height: 70px;
}

#codeEditor {
  width: 100%;
  height: calc(100% - 38px);
  min-height: 260px;
  border: 1px solid #3c4a44;
  background: var(--code);
  color: #edf8f1;
  padding: 12px;
  resize: none;
  line-height: 1.45;
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
}

.log-dock .panel-title {
  margin-bottom: 6px;
}

.log-dock button {
  background: #2b2923;
  color: #f8efe0;
  border-color: #6a5d4c;
}

.log-list {
  height: 92px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 4px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.log-row {
  display: grid;
  grid-template-columns: 72px 78px 1fr;
  gap: 10px;
}

.log-row .level {
  color: #f2be6b;
}

.log-row.error .level {
  color: #ff9b8f;
}

.log-row.ok .level {
  color: #8bd3a7;
}

.auth-modal[hidden] {
  display: none;
}

.confirm-modal[hidden] {
  display: none;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 32, 29, 0.46);
}

.auth-modal.locked .auth-backdrop {
  background: rgba(32, 32, 29, 0.62);
}

.auth-panel {
  position: relative;
  width: min(500px, 100%);
  max-height: min(680px, calc(100vh - 40px));
  overflow: auto;
  border: 1px solid #9e8e79;
  background: #fbfaf6;
  box-shadow: var(--shadow);
  padding: 16px;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 20px;
}

.confirm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 32, 29, 0.52);
}

.confirm-panel {
  position: relative;
  width: min(420px, 100%);
  border: 1px solid #9e8e79;
  background: #fbfaf6;
  box-shadow: var(--shadow);
  padding: 16px;
}

.confirm-message {
  margin: 14px 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.65;
}

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

.auth-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(207, 195, 178, 0.8);
}

.icon-button {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
}

.auth-notice {
  display: grid;
  gap: 4px;
  margin: 14px 0;
  border: 1px solid rgba(15, 118, 110, 0.24);
  background: rgba(15, 118, 110, 0.08);
  padding: 11px 12px;
}

.auth-notice strong {
  font-size: 13px;
}

.auth-notice span {
  color: var(--muted);
  font-size: 12px;
}

.auth-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.auth-form[hidden],
.account-panel[hidden] {
  display: none;
}

.auth-form span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.auth-form label {
  display: grid;
  gap: 5px;
}

.auth-mode-tabs,
.auth-email-field,
.auth-code-field,
.auth-actions {
  grid-column: 1 / -1;
}

.auth-mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: #fffaf0;
}

.auth-mode-tabs button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  min-height: 34px;
}

.auth-mode-tabs button:last-child {
  border-right: 0;
}

.auth-mode-tabs button.active {
  background: var(--accent);
  color: #fff;
}

.auth-form input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  padding: 8px;
  min-height: 34px;
}

.inline-input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
}

.inline-input-action button {
  min-width: 0;
}

.account-panel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.account-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(207, 195, 178, 0.82);
  background: #fffaf0;
  padding: 10px;
}

.account-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.account-card strong,
.account-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.profile-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.profile-list div {
  border: 1px solid rgba(207, 195, 178, 0.75);
  background: #fffdf8;
  padding: 8px;
  min-width: 0;
}

.profile-list dt {
  color: var(--muted);
  font-size: 12px;
}

.profile-list dd {
  margin: 3px 0 0;
  color: var(--ink);
  font-weight: 800;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.password-box {
  border: 1px solid rgba(207, 195, 178, 0.75);
  background: #fffdf8;
  padding: 10px;
}

.password-box summary {
  cursor: pointer;
  font-weight: 800;
}

.password-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.password-grid input,
.password-grid button {
  min-width: 0;
}

.password-grid input:first-child,
.password-grid button {
  grid-column: 1 / -1;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-actions.compact {
  margin-top: 4px;
}

.auth-actions button {
  min-width: 88px;
}

.auth-actions .primary {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--accent);
  color: #fff;
}

.auth-actions .primary:hover {
  border-color: var(--accent);
  color: #fff;
  filter: brightness(0.96);
}

.auth-actions button.danger {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.45);
}

.auth-message {
  margin-top: 14px;
  min-height: 38px;
  border: 1px solid rgba(207, 195, 178, 0.85);
  background: #fffaf0;
  color: var(--muted);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.45;
}

.auth-message.ok {
  border-color: rgba(20, 122, 69, 0.35);
  background: rgba(20, 122, 69, 0.08);
  color: var(--ok);
}

.auth-message.error {
  border-color: rgba(180, 35, 24, 0.35);
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 280px minmax(480px, 1fr);
    grid-template-rows: minmax(0, 1fr) 360px 140px;
  }

  .right-rail {
    grid-column: 1 / 3;
    grid-row: 2;
    grid-template-columns: 40% 60%;
    grid-template-rows: 1fr;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .log-dock {
    grid-column: 1 / 3;
    grid-row: 3;
  }
}

@media (max-width: 720px) {
  .auth-form,
  .auth-mode-tabs,
  .password-grid,
  .profile-list {
    grid-template-columns: 1fr;
  }
}
