:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --line: #dfe4ea;
  --text: #1f2937;
  --brand: #3772ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #e8f0ff, #f8fafc 52%);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.top-bar h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-btn {
  border: 1px solid #b8c5d8;
  background: #fff;
  color: #334155;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.2;
}

.mini-btn {
  padding: 8px 10px;
  font-size: 14px;
  width: 100%;
}

.save-btn {
  border: none;
  padding: 8px 14px;
  font-size: 15px;
  color: #fff;
  border-radius: 8px;
  background: linear-gradient(90deg, #cf7cff, #3f8efc);
}

.save-status {
  font-size: 13px;
  color: #64748b;
  min-width: 96px;
}

.save-status[data-tone="dirty"] { color: #c2410c; }
.save-status[data-tone="saved"] { color: #15803d; }

.ghost-btn:disabled,
.save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 12px;
  padding: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

.editor h2,
.preview h2 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 600;
}

.editor label {
  display: block;
  margin-bottom: 10px;
}

input, select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid #cfd6df;
  border-radius: 6px;
  font-size: 14px;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin: 0;
  padding: 0;
  border: 0;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  align-items: center;
}

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

.toggle-ui {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
}

.toggle-ui input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.2s ease;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.24);
  transition: transform 0.2s ease;
}

.toggle-ui input:checked + .toggle-slider {
  background: #2563eb;
}

.toggle-ui input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

.layout-picker {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 10px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 10px;
}

.group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.group h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.toggle-group {
  padding-bottom: 4px;
}

.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}

.toggle-group .switch-toggle {
  margin-bottom: 0;
  padding: 4px 2px;
}

.history-panel {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.history-panel h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.history-panel ul {
  margin: 0;
  padding-left: 18px;
  max-height: 150px;
  overflow: auto;
}

.history-panel li {
  font-size: 12px;
  margin-bottom: 6px;
  line-height: 1.4;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.history-restore-btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}

.report-title {
  text-align: center;
  font-size: var(--report-title-size, 42px);
  color: var(--report-line-color, #374151);
  margin: 8px 0 18px;
  font-family: var(--report-title-font, 'STSong', 'Songti SC', 'Noto Serif SC', serif);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.header-block {
  position: relative;
  padding: 6px 0 0;
}

.profile {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: transparent;
  border-radius: 0;
  padding: 8px 2px 10px;
  align-items: center;
}

.strong { font-size: var(--report-profile-strong-size, 26px); margin: 0; }
.profile p { margin: 2px 0; font-size: var(--report-profile-size, 22px); }

hr {
  border: 0;
  border-top: calc(var(--report-line-width, 4px) + 2px) double var(--report-line-color, #555);
  margin: 16px 0;
}

.status-line { display: flex; align-items: center; gap: 10px; font-size: 32px; }
.status-line { font-size: var(--report-table-size, 18px); }
.status-tag { padding: 3px 10px; border-radius: 8px; font-size: 16px; }
.status-tag.danger { color: #c53030; background: #ffe3e3; }
.status-tag.warning { color: #b45309; background: #ffedd5; }
.status-tag.primary { color: #1d4ed8; background: #dbeafe; }
.status-tag.success { color: #15803d; background: #dcfce7; }

.grid-table {
  width: 100%;
  margin: 10px 0 12px;
  border-collapse: collapse;
  table-layout: fixed;
}
.grid-table td {
  border: 1px solid #cfd4dc;
  width: 33.333%;
  min-width: 0;
  height: 52px;
  font-size: var(--report-table-size, 18px);
  padding: 5px 8px;
  vertical-align: top;
  cursor: text;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}

.grid-table td:focus {
  outline: 2px solid #60a5fa;
  outline-offset: -2px;
}

.preview.card {
  --theme-profile-bg: #f4f6f8;
  --report-line-color: #d8344b;
  --report-line-width: 4px;
  --report-double-line-width: 8px;
  padding: var(--report-padding, 16px);
  max-width: 1080px;
  margin: 0 auto;
  font-family: 'STSong', 'Songti SC', 'Noto Serif SC', serif;
  color: #1f2937;
  position: relative;
}

.logo-box {
  position: relative;
  width: min(360px, 90%);
  min-height: 88px;
  border: 2px dashed #1e88e5;
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: visible;
  cursor: pointer;
  background: #f7fbff;
}

.logo-placeholder {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1e88e5;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}

.logo-image {
  width: 100%;
  height: 88px;
  object-fit: contain;
  background: #fff;
}

.logo-remove-btn {
  position: absolute;
  right: -14px;
  top: -14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 0;
  background: #374151;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.body-text {
  font-size: var(--report-body-size, 24px);
  line-height: var(--report-line-height, 1.5);
  letter-spacing: 0.02em;
}

.editable:focus {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
  border-radius: 4px;
}

.columns {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.columns.layout-single { grid-template-columns: 1fr; }
.columns.layout-double { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.columns.layout-triple { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.columns.layout-quad { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.columns.layout-pin-double { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.columns.layout-pin-triple { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.columns.layout-pin-double > .image-frame:first-child,
.columns.layout-pin-triple > .image-frame:first-child {
  grid-column: 1 / -1;
  max-width: 62%;
  justify-self: center;
}

.image-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f7f7f7;
}

.image-frame.drop-target {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

.placeholder-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #888b90;
  cursor: pointer;
}

.placeholder-frame .plus {
  font-size: 24px;
  line-height: 1;
}

.placeholder-frame .text {
  font-size: 16px;
  line-height: 1.1;
}

.draggable-image {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  z-index: 1;
}

.draggable-image.dragging {
  cursor: grabbing;
}

.image-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  border: 0;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1.6;
  color: #fff;
  background: rgba(15, 23, 42, 0.65);
  cursor: pointer;
}

.preview.card.template-classic-green {
  --theme-profile-bg: #f4f6f8;
}

.preview.card.template-classic-green .report-title {
  letter-spacing: 0.12em;
}

.preview.card.template-daily-red {
  --theme-profile-bg: #faf5f5;
}

.preview.card.template-daily-red .header-block {
  padding-top: 10px;
}

.preview.card.template-daily-red .report-title {
  letter-spacing: 0.18em;
  margin-top: 28px;
  margin-bottom: 24px;
}

.preview.card.template-daily-red .profile {
  background: transparent;
  border-radius: 0;
  padding: 8px 0 10px;
}

.preview.card.template-daily-red hr {
  border-top-style: solid;
  border-top-width: var(--report-line-width, 4px);
  border-top-color: var(--report-line-color, #d8344b);
}

.preview.card.template-frame-red {
  --theme-profile-bg: #fff7f8;
  border: 0;
}

.preview.card.template-frame-red .profile {
  border: 0;
  border-top: var(--report-double-line-width, 8px) double var(--report-line-color, #d8344b);
  border-radius: 0;
  background: transparent;
  padding: 18px 26px 14px;
  grid-template-columns: 1fr 1fr;
  align-items: end;
}

.preview.card.template-frame-red .header-block {
  border: var(--report-line-width, 4px) solid var(--report-line-color, #d8344b);
  border-radius: 0;
  padding: 0;
  margin: 2px 0 16px;
  background: #fff;
}

.preview.card.template-frame-red .header-block::before,
.preview.card.template-frame-red .header-block::after {
  content: '';
  position: absolute;
  top: calc(-1 * var(--report-line-width, 4px));
  width: 34px;
  height: 30px;
  background: #fff;
  z-index: 3;
}

.preview.card.template-frame-red .header-block::before {
  left: calc(-1 * var(--report-line-width, 4px));
  border-right: var(--report-line-width, 4px) solid var(--report-line-color, #d8344b);
  border-bottom: var(--report-line-width, 4px) solid var(--report-line-color, #d8344b);
  border-bottom-right-radius: 28px;
}

.preview.card.template-frame-red .header-block::after {
  right: calc(-1 * var(--report-line-width, 4px));
  border-left: var(--report-line-width, 4px) solid var(--report-line-color, #d8344b);
  border-bottom: var(--report-line-width, 4px) solid var(--report-line-color, #d8344b);
  border-bottom-left-radius: 28px;
}

.preview.card.template-frame-red .header-block .report-title {
  position: relative;
  z-index: 2;
}

.preview.card.template-frame-red .report-title {
  margin: 34px 0 34px;
  letter-spacing: 0.26em;
  font-weight: 700;
}

.preview.card.template-frame-red #previewPhone,
.preview.card.template-frame-red #previewTitle {
  display: none;
}

.preview.card.template-frame-red #previewName,
.preview.card.template-frame-red #previewDate {
  font-size: clamp(22px, 2.6vw, 34px);
  line-height: 1.2;
  margin: 0;
  color: #4b5563;
}

.preview.card.template-frame-red #previewName::before {
  content: '汇报人:';
  margin-right: 8px;
}

.preview.card.template-frame-red #previewDate::before {
  content: '日期:';
  margin-right: 8px;
}

.preview.card.template-frame-red .profile > div:last-child #previewDate {
  text-align: right;
}

.preview.card.template-frame-red hr {
  border-top-style: solid;
  border-top-width: var(--report-line-width, 4px);
  border-top-color: var(--report-line-color, #d8344b);
}

.columns.gallery-grid .image-frame {
  border-radius: 6px;
  box-shadow: none;
  border-color: #d7dce3;
}

.columns.gallery-rounded .image-frame {
  border-radius: 18px;
  background: #f8fafc;
  border-color: #d7dce3;
}

.columns.gallery-card .image-frame {
  border-radius: 12px;
  border-color: #d7dce3;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.1);
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .report-title { font-size: 36px; }
  .profile p, .body-text, .status-line { font-size: 22px; }
  .strong { font-size: 18px; }
  .row { grid-template-columns: 1fr 1fr; }
  .toggle-grid { grid-template-columns: 1fr; }
  .placeholder-frame .plus { font-size: 26px; }
  .placeholder-frame .text { font-size: 18px; }
  .logo-box { width: 100%; }
  .logo-placeholder { font-size: 16px; }
  .preview.card.template-frame-red .header-block {
    margin-bottom: 12px;
  }
  .preview.card.template-frame-red .header-block::before,
  .preview.card.template-frame-red .header-block::after {
    width: 24px;
    height: 20px;
  }
  .preview.card.template-frame-red .report-title {
    margin: 20px 0 20px;
    letter-spacing: 0.14em;
  }
  .preview.card.template-frame-red .profile {
    padding: 12px 12px 10px;
  }
}

.debug-panel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 9999;
  min-width: 240px;
  max-width: 360px;
  border: 1px solid #cbd5e1;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  border-radius: 8px;
  padding: 8px 10px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
}

.floating-toolbar {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 1200;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  margin: 0;
  border: 1px solid #d5deea;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 251, 255, 0.94));
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
  backdrop-filter: blur(6px);
}

.floating-toolbar::before {
  content: '正文工具';
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #334155;
  background: #eef4ff;
  border: 1px solid #d9e6ff;
}

.floating-toolbar button {
  border: 1px solid #d4dbe7;
  background: #fff;
  color: #334155;
  border-radius: 9px;
  min-width: 34px;
  height: 32px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.floating-toolbar button:hover {
  border-color: #9fb6da;
  background: #f8fbff;
  color: #1e40af;
}

.floating-toolbar button:active {
  transform: translateY(1px);
}

.floating-toolbar .tool-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #475569;
  border: 1px solid #dde5f0;
  border-radius: 10px;
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.7);
}

.floating-toolbar .tool-item > span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.floating-toolbar input,
.floating-toolbar select {
  margin: 0;
  padding: 2px 6px;
  width: auto;
  height: 28px;
  font-size: 12px;
  border: 1px solid #d5deea;
  border-radius: 8px;
  background: #fff;
  color: #334155;
}

.floating-toolbar #toolbarFontSize {
  width: 74px;
}

.floating-toolbar #toolbarColor {
  width: 32px;
  height: 28px;
  padding: 1px;
  border-radius: 8px;
}

@media (max-width: 1080px) {
  .floating-toolbar {
    right: 10px;
    left: 10px;
    bottom: 10px;
    justify-content: center;
  }
}

.floating-toolbar[hidden] {
  display: none !important;
}

.preview.card.exporting .image-frame.placeholder-frame {
  display: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 9998;
  max-width: min(85vw, 480px);
  padding: 10px 14px;
  border-radius: 10px;
  color: #fff;
  background: rgba(15, 23, 42, 0.9);
  font-size: 14px;
  box-shadow: 0 8px 26px rgba(15, 23, 42, 0.28);
}
