:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e2e5ea;
  --line-2: #cfd4dc;
  --text: #1d2330;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-2: #0d9488;
  --accent-soft: #ccfbf1;
  --danger: #b91c1c;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .08);
  --topbar: 52px;
  --formatbar: 44px;
  --status: 30px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 13px/1.4 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  height: var(--topbar);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); margin-right: 6px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #14b8a6);
  color: #fff; font-weight: 700; font-size: 17px;
  display: grid; place-items: center;
}
.brand-name { font-size: 15px; white-space: nowrap; }
.brand-name b { color: var(--accent); }
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.tb-spacer { flex: 1; }
.tb-btn, .tb-icon, .zoom-val {
  border: 0; background: transparent; border-radius: 6px;
  height: 34px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px;
}
.tb-icon { width: 34px; padding: 0; justify-content: center; }
.tb-btn:hover, .tb-icon:hover, .zoom-val:hover { background: var(--panel-2); }
.tb-icon:disabled { opacity: .35; cursor: default; background: none; }
.zoom-val { min-width: 58px; justify-content: center; font-variant-numeric: tabular-nums; padding: 0 6px; }
.doc-title {
  border: 1px solid transparent; background: transparent; border-radius: 6px;
  padding: 6px 8px; font-weight: 600; min-width: 120px; width: 240px; max-width: 30vw;
}
.doc-title:hover { border-color: var(--line); }
.doc-title:focus { outline: none; border-color: var(--accent); background: #fff; }
.btn-primary, .btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 8px; font-weight: 600; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
.btn-primary:hover { background: #115e59; }
.btn { background: #fff; border: 1px solid var(--line-2); }
.btn:hover { background: var(--panel-2); }

/* ---------- format bar ---------- */
.formatbar {
  height: var(--formatbar); flex: none;
  background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 4px; padding: 0 12px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.formatbar::-webkit-scrollbar { display: none; }
.formatbar.disabled > *:not(.fb-hint) { opacity: .4; pointer-events: none; }
.formatbar:not(.disabled) .fb-hint { display: none; }
.fb-hint { color: var(--muted); margin-left: 8px; white-space: nowrap; }
.fb-font { width: 170px; height: 30px; border: 1px solid var(--line-2); border-radius: 6px; padding: 0 6px; background: #fff; }
.fb-size { position: relative; display: flex; }
.fb-size input { width: 52px; height: 30px; border: 1px solid var(--line-2); border-radius: 6px 0 0 6px; padding: 0 6px; }
.fb-size select { width: 22px; height: 30px; border: 1px solid var(--line-2); border-left: 0; border-radius: 0 6px 6px 0; background: #fff; color: transparent; padding: 0; }
.fb-size select option { color: var(--text); }
.fb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; flex: none; }
.fb-btn {
  width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent;
  display: inline-grid; place-items: center; flex: none;
}
.fb-btn svg { width: 16px; height: 16px; }
.fb-btn.fb-small svg { width: 12px; height: 12px; }
.fb-btn:hover { background: var(--panel-2); }
.fb-btn.on { background: var(--accent-soft); color: var(--accent); }
.fb-color {
  position: relative; width: 34px; height: 30px; border-radius: 6px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.fb-color:hover { background: var(--panel-2); }
.fb-color svg { width: 15px; height: 15px; }
.fb-color-a { font-weight: 700; font-size: 14px; line-height: 1; }
.fb-swatch { width: 18px; height: 4px; border-radius: 2px; margin-top: 2px; background: #000; border: 1px solid rgba(0,0,0,.1); }
.fb-color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.fb-num { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; margin-right: 6px; white-space: nowrap; }
.fb-num select, .fb-num input { height: 28px; border: 1px solid var(--line-2); border-radius: 6px; background: #fff; color: var(--text); }
.fb-num input { width: 58px; padding: 0 6px; }

/* ---------- workspace ---------- */
.workspace { flex: 1; display: flex; min-height: 0; position: relative; }
.rail {
  width: 64px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 2px;
}
.rail-btn {
  width: 56px; padding: 7px 0 5px; border: 0; background: transparent; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; color: #4b5563;
}
.rail-btn svg { width: 20px; height: 20px; }
.rail-btn:hover { background: var(--panel-2); color: var(--text); }
.rail-btn.active { background: var(--accent-soft); color: var(--accent); }
.rail-spacer { flex: 1; }
.rail-panel { display: none; }
.shape-pop {
  position: absolute; left: 66px; top: 260px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  display: flex; gap: 2px; padding: 6px;
}
.shape-pop button { width: 38px; height: 38px; border: 0; background: transparent; border-radius: 8px; display: grid; place-items: center; }
.shape-pop button:hover { background: var(--panel-2); }

.leftpanel {
  width: 212px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.lp-section { padding: 12px; border-bottom: 1px solid var(--line); }
.lp-section h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.lp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.lp-head h3 { margin: 0; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.quick {
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
  min-height: 44px; padding: 6px; display: flex; align-items: center; justify-content: center; gap: 6px;
  cursor: grab; user-select: none; text-align: center; color: #374151; font-size: 11.5px;
}
.quick:hover { border-color: var(--accent); background: #fff; color: var(--accent); }
.quick:active { cursor: grabbing; }
.quick svg { width: 16px; height: 16px; }
.quick[data-add="heading"], .quick[data-add="subheading"], .quick[data-add="body"] { grid-column: span 2; justify-content: flex-start; padding-left: 10px; }
.q-h { font-size: 18px; font-weight: 700; color: var(--text); }
.q-s { font-size: 14px; font-weight: 600; color: var(--text); }
.q-b { font-size: 12px; color: var(--muted); }
.drop-card {
  display: flex; align-items: center; gap: 10px; padding: 10px; cursor: pointer;
  border: 1.5px dashed var(--line-2); border-radius: 10px; background: var(--panel-2); color: var(--accent);
}
.drop-card:hover { border-color: var(--accent); background: #f0fdfa; }
.drop-card svg { width: 20px; height: 20px; }
.drop-card b { display: block; color: var(--text); font-size: 12px; }
.drop-card span { display: block; color: var(--muted); font-size: 11px; line-height: 1.3; }
.fname { display: flex; align-items: center; border: 1px solid var(--line-2); border-radius: 6px; background: #fff; }
.fname:focus-within { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.fname input { flex: 1; min-width: 0; height: 34px; border: 0 !important; outline: none !important; padding: 0 8px; font-size: 14px; color: var(--text); background: transparent; }
.fname span { padding: 0 10px 0 2px; color: var(--muted); font-size: 14px; }
.lp-pages { flex: 1; min-height: 0; display: flex; flex-direction: column; border-bottom: 0; }
.page-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px 12px; }
.page-item { display: flex; gap: 6px; align-items: flex-start; }
.page-num { width: 16px; text-align: right; color: var(--muted); font-size: 11px; padding-top: 4px; flex: none; }
.page-thumb {
  flex: 1; border: 2px solid transparent; border-radius: 6px; padding: 2px; cursor: pointer; position: relative; background: transparent;
}
.page-thumb img { display: block; width: 100%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); border-radius: 2px; }
.page-item.active .page-thumb { border-color: var(--accent); }
.page-tools { position: absolute; right: 4px; top: 4px; display: none; gap: 2px; }
.page-item:hover .page-tools { display: flex; }
.page-tools button { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; padding: 0; }
.page-tools button:hover { color: var(--accent); border-color: var(--accent); }
.page-tools button.danger:hover { color: var(--danger); border-color: var(--danger); }
.page-tools svg { width: 13px; height: 13px; }
.mini-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 8px; font-size: 12px;
  border: 1px solid var(--line-2); border-radius: 6px; background: #fff;
}
.mini-btn svg { width: 13px; height: 13px; }
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- stage ---------- */
.stage { flex: 1; min-width: 0; position: relative; overflow: auto; background: var(--bg); }
.stage-inner { min-width: 100%; min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 40px; width: max-content; }
.page-wrap { box-shadow: 0 2px 6px rgba(0,0,0,.12), 0 12px 32px rgba(0,0,0,.10); background: #fff; flex: none; }
.drop-hint {
  position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 14px;
  background: rgba(15,118,110,.06); pointer-events: none; display: none; align-items: flex-start; justify-content: center;
}
.drop-hint div { margin-top: 16px; background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 99px; font-weight: 600; }
.stage.dragging .drop-hint { display: flex; }

/* ---------- properties ---------- */
.props {
  width: 272px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto;
}
.p-section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.p-section h3 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.p-title { font-size: 14px; font-weight: 600; margin: 0 0 2px; }
.p-sub { color: var(--muted); font-size: 12px; margin: 0; }
.props { overflow-x: hidden; }
.p-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.field input, .field select { min-width: 0; }
.p-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.p-grid .field { margin-bottom: 0; }
.field input[type=number], .field input[type=text], .field select {
  height: 32px; border: 1px solid var(--line-2); border-radius: 6px; padding: 0 8px; background: #fff; color: var(--text); width: 100%;
}
.field input:focus, .field select:focus, .fb-size input:focus, .fb-font:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.unit-input { position: relative; }
.unit-input input { padding-right: 30px !important; }
.unit-input span { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 11px; pointer-events: none; }
.color-field { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.color-field label { flex: 1; font-size: 12px; color: var(--muted); }
.swatch-btn {
  width: 34px; height: 28px; border-radius: 6px; border: 1px solid var(--line-2); position: relative; overflow: hidden; flex: none;
  background-image: linear-gradient(45deg,#ddd 25%,transparent 25%),linear-gradient(-45deg,#ddd 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#ddd 75%),linear-gradient(-45deg,transparent 75%,#ddd 75%);
  background-size: 8px 8px; background-position: 0 0,0 4px,4px -4px,-4px 0;
}
.swatch-btn i { position: absolute; inset: 0; }
.swatch-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.none-btn { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line-2); background: #fff; font-size: 12px; }
.none-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.range-field { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.range-field span:first-child { width: 64px; flex: none; }
.range-field input[type=range] { flex: 1; accent-color: var(--accent); }
.range-field output { width: 40px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.icon-row { display: flex; gap: 4px; flex-wrap: wrap; }
.icon-btn {
  height: 32px; min-width: 32px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line-2); background: #fff;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.icon-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn.wide { flex: 1; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 6px; height: 28px; font-size: 12px; font-weight: 500; color: var(--muted); }
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg-lg button { height: 36px; font-size: 14px; font-weight: 600; }
.tips { margin: 0; padding-left: 16px; color: var(--muted); font-size: 12px; }
.tips li { margin-bottom: 4px; }
kbd { font: 11px ui-monospace, Consolas, monospace; background: var(--panel-2); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--text); }
.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-bottom: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- status ---------- */
.statusbar {
  height: var(--status); flex: none; background: var(--panel); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--muted); font-size: 12px;
  white-space: nowrap; overflow: hidden;
}
#status, #pageInfo { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sb-spacer { flex: 1; }
.sb-toggle { display: inline-flex; align-items: center; gap: 4px; height: 22px; border-radius: 5px; border: 1px solid transparent; background: transparent; padding: 0 8px; color: var(--muted); font-size: 12px; }
.sb-toggle svg { width: 13px; height: 13px; }
.sb-toggle[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; box-shadow: 0 24px 64px rgba(0,0,0,.25); padding: 24px; width: 420px; max-width: 100%; position: relative; max-height: calc(100vh - 32px); overflow: auto; }
.modal-card h2 { margin: 0 0 16px; font-size: 18px; }
.modal-x { position: absolute; right: 12px; top: 12px; width: 32px; height: 32px; border: 0; background: transparent; border-radius: 8px; display: grid; place-items: center; }
.modal-x:hover { background: var(--panel-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.welcome-card { width: 860px; padding: 0; overflow: hidden; }
.welcome-grid { display: grid; grid-template-columns: 1fr 1.25fr; }
.welcome-open {
  background: linear-gradient(160deg, #f0fdfa, #e6f4f1); padding: 36px 28px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--line);
  border: 2px dashed transparent; transition: border-color .15s;
}
.welcome-open.over { border-color: var(--accent); }
.wo-icon { width: 64px; height: 64px; border-radius: 16px; background: #fff; display: grid; place-items: center; color: var(--accent); box-shadow: var(--shadow); margin-bottom: 14px; }
.wo-icon svg { width: 30px; height: 30px; }
.welcome-open h2 { margin: 0 0 6px; }
.welcome-open p { margin: 6px 0 14px; }
.welcome-open .small { margin-top: 18px; max-width: 280px; }
.welcome-new { padding: 28px; }
.welcome-new h4 { margin: 4px 0 10px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tpl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tpl { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); padding: 10px 8px 8px; cursor: pointer; text-align: center; font-size: 12px; font-weight: 500; }
.tpl:hover { border-color: var(--accent); color: var(--accent); background: #fff; }
.tpl-prev { height: 78px; display: grid; place-items: center; margin-bottom: 6px; }
.tpl-prev div { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); position: relative; overflow: hidden; }

/* ---------- busy / toast ---------- */
.busy { position: fixed; inset: 0; background: rgba(255,255,255,.6); z-index: 200; display: grid; place-items: center; }
.busy-card { background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 18px 24px; display: flex; align-items: center; gap: 12px; font-weight: 500; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 300;
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: min(560px, calc(100vw - 32px));
}
.toast.warn { background: #92400e; }

/* ---------- smaller screens ---------- */
@media (max-width: 1180px) {
  .tb-btn span { display: none; }
  .doc-title { width: 160px; }
}
@media (max-width: 980px) {
  .rail-panel { display: flex; }
  .leftpanel, .props {
    position: absolute; top: 0; bottom: 0; z-index: 20; box-shadow: var(--shadow); display: none;
  }
  .leftpanel { left: 64px; }
  .props { right: 0; }
  .workspace.show-pages .leftpanel { display: flex; }
  .workspace.show-props .props { display: block; }
  .brand-name { display: none; }
  .btn-primary span { display: none; }
  .welcome-grid { grid-template-columns: 1fr; }
  .welcome-open { border-right: 0; border-bottom: 1px solid var(--line); padding: 24px 16px; }
}
@media (max-width: 600px) {
  .topbar { padding: 0 8px; gap: 4px; }
  .doc-title, .tb-sep { display: none; }
  .zoom .tb-icon { display: none; }
  .rail { width: 52px; }
  .rail-btn { width: 46px; font-size: 9.5px; }
  .leftpanel { left: 52px; }
  .stage-inner { padding: 16px; }
  #status { display: none; }
  .sb-toggle svg { display: none; }
  .tpl-grid { grid-template-columns: repeat(2, 1fr); }
  .welcome-new { padding: 16px; }
}
