:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --line: #dfe4ea;
  --text: #1f2933;
  --muted: #6b7280;
  --blue: #1677ff;
  --blue-dark: #0f5dcc;
  --danger: #d93025;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button, input, textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

button.primary:hover:not(:disabled) {
  background: var(--blue-dark);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 18px;
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 10px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(460px, 1.25fr) minmax(420px, .95fr);
  gap: 1px;
  background: var(--line);
}

.info-pane, .pdf-pane, .right-pane {
  min-height: 0;
  background: var(--bg);
}

.info-pane {
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr);
  min-height: 0;
  overflow: auto;
}

.pdf-pane {
  min-height: 0;
  display: grid;
}

.input-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.source-tabs, .file-row {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.source-tabs label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

input[type="url"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
}

#paperPdf {
  display: none;
}

.file-row label {
  color: var(--muted);
  font-size: 13px;
}

.progress-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.progress-header span {
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-header strong {
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width .2s ease;
}

.progress-log {
  max-height: 84px;
  overflow: auto;
  display: grid;
  gap: 4px;
  padding-right: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.progress-log p {
  margin: 0;
  word-break: break-word;
}

.pdf-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #222831;
}

.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  color: #e5e7eb;
  background: #111827;
}

.pdf-toolbar button {
  padding: 6px 9px;
  background: #1f2937;
  color: #fff;
  border-color: #374151;
}

.shot-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.shot-tools[hidden] {
  display: none !important;
}

.shot-tools span {
  color: #fca5a5;
  font-size: 13px;
  white-space: nowrap;
}

.pdf-stage {
  position: relative;
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 16px;
}

#pdfCanvas {
  display: none;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
}

.empty-state {
  margin: auto;
  color: #cbd5e1;
  font-size: 14px;
}

.selection-box {
  position: absolute;
  display: none;
  border: 2px solid var(--danger);
  background: rgba(217, 48, 37, .12);
  pointer-events: none;
}

.meta-panel {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  overflow: auto;
}

.meta-panel div {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 10px;
  font-size: 13px;
}

.meta-panel span {
  color: var(--muted);
}

.meta-panel strong, .meta-panel a {
  color: var(--text);
  word-break: break-all;
}

.meta-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.right-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.wechat-preview {
  width: min(720px, calc(100% - 36px));
  margin: 18px auto 40px;
  padding: 24px 16px;
  min-height: calc(100% - 58px);
  overflow: auto;
  background: #fff;
  outline: none;
}

.image-placeholder {
  display: block;
  margin: 18px auto;
  padding: 18px 12px;
  max-width: 92%;
  border: 1px dashed var(--danger);
  color: var(--danger);
  text-align: center;
  font-size: 15px;
  line-height: 1.5;
  cursor: crosshair;
  background: #fff7f6;
}

@media (max-width: 1180px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .info-pane {
    min-height: 520px;
  }

  .pdf-pane {
    min-height: 760px;
  }

  .right-pane {
    min-height: 700px;
  }
}
