:root {
  --red: #cd052a;
  --red-dark: #a8041f;
  --red-soft: #fdecef;
  --navy: #003365;
  --bg: #f4f5f8;
  --panel: #ffffff;
  --line: #e6e8ee;
  --line-strong: #d3d7e0;
  --text: #1c2230;
  --muted: #6b7385;
  --ok: #0f9d58;
  --err: #d93025;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: rgba(255, 255, 255, .9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  background: var(--red); color: #fff; font-weight: 700; letter-spacing: .5px;
  box-shadow: 0 4px 12px rgba(205, 5, 42, .3);
}
.brand h1 { margin: 0; font-size: 17px; font-weight: 700; }
.brand p { margin: 0; font-size: 12.5px; color: var(--muted); }
.status {
  font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  background: #eef0f4; color: var(--muted);
}
.status.busy { background: #fff5d6; color: #8a6200; }
.status.ok { background: #e3f6ec; color: var(--ok); }
.status.err { background: #fde8e6; color: var(--err); }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(380px, 480px) 1fr; gap: 24px;
  padding: 24px 28px; max-width: 1600px; margin: 0 auto;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- form ---------- */
.form-panel { display: flex; flex-direction: column; align-self: start; }
.step { padding: 22px 24px; border-bottom: 1px solid var(--line); }
.step-head { display: flex; gap: 12px; margin-bottom: 16px; }
.num {
  flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--red-soft); color: var(--red); font-weight: 700; font-size: 13px;
}
.step-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.step-head p { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }

.lbl { display: block; font-size: 12.5px; font-weight: 600; margin: 14px 0 6px; }
.lbl:first-of-type { margin-top: 0; }
.muted { color: var(--muted); font-weight: 400; }

.input-wrap {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 12px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.input-wrap.narrow { max-width: 220px; }
.input-wrap:focus-within, .ta:focus, .editor:focus-within {
  border-color: var(--red); box-shadow: 0 0 0 3px rgba(205, 5, 42, .12);
}
.in-ico { color: var(--muted); flex: none; }
.input-wrap input { flex: 1; min-width: 0; border: 0; outline: 0; padding: 10px 0; font: inherit; color: inherit; background: none; }
.ta {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; padding: 10px 12px;
  font: inherit; color: inherit; resize: vertical; outline: 0; transition: border-color .15s, box-shadow .15s;
}
.counter { text-align: right; font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* segmented control */
.seg { display: inline-flex; padding: 3px; background: #eef0f4; border-radius: 9px; margin-bottom: 14px; }
.seg-btn {
  border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer;
  font: 500 13px Inter, sans-serif; color: var(--muted); transition: all .15s;
}
.seg-btn.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.seg.small { margin: 0; }
.seg.small .seg-btn { padding: 4px 10px; font-size: 12px; }

/* drop zone */
.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 26px 16px; border: 1.5px dashed var(--line-strong); border-radius: 10px;
  background: #fafbfc; cursor: pointer; text-align: center; transition: all .15s;
}
.drop:hover, .drop.over { border-color: var(--red); background: var(--red-soft); }
.drop.has-file { border-style: solid; border-color: var(--ok); background: #effaf4; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-ico { width: 26px; height: 26px; color: var(--red); margin-bottom: 4px; }
.drop.has-file .drop-ico { color: var(--ok); }
.drop-main { font-size: 13.5px; }
.drop-sub { font-size: 12px; color: var(--muted); }

/* editor */
.editor { border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.toolbar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: 6px; background: #fafbfc; border-bottom: 1px solid var(--line); }
.toolbar button {
  display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px;
  border: 0; background: none; border-radius: 6px; cursor: pointer; color: #3b4254; font-size: 14px;
}
.toolbar button svg { width: 16px; height: 16px; }
.toolbar button:hover { background: #eceef3; }
.toolbar .sep { width: 1px; height: 18px; background: var(--line-strong); margin: 0 4px; }
.toolbar .grow { flex: 1; }
.toolbar .src-toggle { font: 600 12px Consolas, monospace; padding: 0 10px; }
.toolbar .src-toggle.on { background: var(--navy); color: #fff; }
.rte, .rte-src { display: block; width: 100%; min-height: 170px; max-height: 360px; overflow: auto; padding: 12px 16px; }
.rte { outline: 0; }
.rte:empty::before { content: attr(data-placeholder); white-space: pre-wrap; color: #a1a7b5; }
.rte ul, .rte ol { margin: 0; padding-left: 20px; }
.rte li { margin-bottom: 8px; }
.rte p { margin: 0 0 2px; }
.rte a { color: #167cdb; }
.rte-src { border: 0; outline: 0; resize: vertical; font: 12.5px/1.6 Consolas, "Cascadia Code", monospace; background: #0f1623; color: #d6deeb; }

.hint { margin-top: 10px; font-size: 12.5px; }
.hint summary { cursor: pointer; color: var(--muted); font-weight: 500; }
.hint pre {
  margin: 8px 0 0; padding: 10px 12px; border-radius: 8px; overflow: auto;
  background: #f4f5f8; font: 12px/1.6 Consolas, monospace; color: #3b4254;
}

/* actions */
.actions {
  position: sticky; bottom: 0; display: flex; justify-content: space-between; gap: 12px;
  padding: 16px 24px; background: #fff; border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 8px; cursor: pointer;
  font: 600 13.5px Inter, sans-serif; border: 1px solid transparent; transition: all .15s;
}
.btn.sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 2px 8px rgba(205, 5, 42, .25); }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover:not(:disabled) { background: #f4f5f8; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
#submitBtn { flex: 1; }
.spinner { display: none; width: 14px; height: 14px; border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- preview ---------- */
.preview-panel { display: flex; flex-direction: column; position: sticky; top: 92px; height: calc(100vh - 116px); min-height: 520px; overflow: hidden; }
.pv-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.pv-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pv-title h2 { margin: 0; font-size: 15px; font-weight: 600; }
.pv-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 11.5px; font-weight: 500; padding: 3px 9px; border-radius: 999px; background: #eef0f4; color: #3b4254; }
.chip.main { background: var(--red-soft); color: var(--red); }

.pv-stage { flex: 1; display: flex; justify-content: center; overflow: hidden; background: repeating-linear-gradient(45deg, #f6f7f9 0 10px, #f1f2f5 10px 20px); }
#preview { width: 100%; height: 100%; border: 0; background: #fff; transition: width .25s ease; }
.pv-stage.mobile #preview { width: 390px; margin: 16px 0; height: calc(100% - 32px); border-radius: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .15); }

.empty { align-self: center; max-width: 320px; text-align: center; color: var(--muted); }
.empty svg { width: 48px; height: 48px; color: #c3c8d3; stroke-width: 1.4; }
.empty h3 { margin: 10px 0 4px; color: var(--text); font-size: 15px; }
.empty p { margin: 0; font-size: 13px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  padding: 10px 18px; border-radius: 8px; background: #1c2230; color: #fff; font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all .2s; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .preview-panel { position: static; height: 80vh; }
  .topbar { padding: 12px 16px; }
  .brand p { display: none; }
}
