:root {
  --bg: #f4f4f8; --bg-card: #ffffff; --bg-input: #f0f0f5; --bg-hover: #e8e8f0;
  --border: #d8d8e0; --border-focus: #6366f1;
  --text: #1a1a2e; --text-dim: #6b6b80; --text-bright: #000;
  --accent: #6366f1; --accent-hover: #818cf8;
  --green: #16a34a; --green-hover: #15803d;
  --red: #dc2626; --red-hover: #b91c1c;
  --yellow: #ca8a04; --blue: #0ea5e9;
  --camping: #182c38;
  --radius: 8px; --radius-sm: 5px;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --preview-bg: #e4e4ec;
}
[data-theme="dark"] {
  --bg: #0f0f14; --bg-card: #1a1a24; --bg-input: #12121a; --bg-hover: #22222e;
  --border: #2a2a3a; --border-focus: #6366f1;
  --text: #e4e4ef; --text-dim: #8888a0; --text-bright: #fff;
  --accent: #6366f1; --accent-hover: #818cf8;
  --green: #22c55e; --green-hover: #16a34a;
  --red: #ef4444; --red-hover: #dc2626;
  --yellow: #FCC917; --blue: #2ABDFB;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --preview-bg: #1e1e26;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* ── Top Bar ── */
#topbar {
  height: 52px; background: var(--bg-card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 12px; flex-shrink: 0; z-index: 50;
}
#topbar .logo { font-weight: 700; font-size: 14px; color: var(--accent); letter-spacing: -0.3px; white-space: nowrap; }
#topbar .sep { width: 1px; height: 24px; background: var(--border); }
.back-link {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; min-width: 30px; flex-shrink: 0;
  border-radius: var(--radius-sm); color: var(--text-dim); transition: all 0.15s;
  text-decoration: none;
}
.back-link:hover { background: var(--bg-hover); color: var(--text); }
.back-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.tb-btn {
  display: flex; align-items: center; gap: 6px; padding: 6px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: transparent; color: var(--text); font-size: 12px;
  font-weight: 500; cursor: pointer; transition: all 0.15s; white-space: nowrap; font-family: inherit;
}
.tb-btn:hover { background: var(--bg-hover); border-color: var(--text-dim); }
.tb-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tb-btn.primary:hover { background: var(--accent-hover); }
.tb-btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.tb-btn.success:hover { background: var(--green-hover); }
.tb-btn svg { width: 14px; height: 14px; }
#topbar .spacer { flex: 1; }
#status { font-size: 11px; color: var(--text-dim); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main Layout ── */
#main { display: flex; flex: 1; overflow: hidden; }

/* ── Panel lateral ── */
#panel {
  width: 300px; min-width: 300px; background: var(--bg-card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; transition: width 0.2s;
}
#panel.collapsed { width: 0; min-width: 0; overflow: hidden; }
.panel-header {
  padding: 14px 16px 10px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-dim); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-scroll { flex: 1; overflow-y: auto; padding: 0; }
.panel-scroll::-webkit-scrollbar { width: 4px; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Header image section */
.header-section {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.header-section label { font-size: 11px; color: var(--text-dim); font-weight: 500; display: block; margin-bottom: 6px; }
.header-thumb {
  width: 100%; height: 60px; object-fit: cover; border-radius: var(--radius-sm);
  border: 1px solid var(--border); cursor: pointer; display: block; margin-bottom: 8px;
}
.header-thumb:hover { border-color: var(--accent); }
.input-row { display: flex; gap: 6px; }
.input-row input { flex: 1; }

/* Section items in panel */
.section-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  cursor: pointer; transition: background 0.1s; border-bottom: 1px solid var(--border);
}
.section-item:hover { background: var(--bg-hover); }
.section-num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent);
  color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
.section-info { flex: 1; min-width: 0; }
.section-info .name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-info .meta { font-size: 10px; color: var(--text-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-del {
  width: 24px; height: 24px; border: none; border-radius: 4px; background: transparent;
  color: var(--text-dim); cursor: pointer; font-size: 16px; display: flex; align-items: center;
  justify-content: center; opacity: 0; transition: opacity 0.15s;
}
.section-item:hover .section-del { opacity: 1; }
.section-del:hover { color: var(--red); background: var(--bg); }

/* ── Preview Area ── */
#preview-area {
  flex: 1; background: var(--preview-bg); overflow-y: auto; display: flex; justify-content: center;
  padding: 24px 20px 60px;
}
#preview-area::-webkit-scrollbar { width: 6px; }
#preview-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#newsletter-frame {
  background: #fff; width: 760px; flex-shrink: 0; border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; align-self: flex-start;
}
#newsletter-frame iframe { width: 100%; border: none; display: block; min-height: 400px; }

/* ── Inputs globales ── */
input[type="text"], input[type="url"], input[type="email"], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-input); color: var(--text); font-size: 12px; font-family: inherit;
  transition: border-color 0.15s; resize: vertical;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text-dim); }

/* ── Modal ── */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-bg.hidden { display: none; }
.modal-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  width: 540px; max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-box::-webkit-scrollbar { width: 4px; }
.modal-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.modal-head {
  padding: 18px 24px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { font-size: 15px; font-weight: 600; }
.modal-head button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 20px; line-height: 1; }
.modal-head button:hover { color: var(--text); }
.modal-body { padding: 18px 24px; }
.modal-foot {
  padding: 14px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; font-weight: 500; color: var(--text-dim); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
.fetch-row { display: flex; gap: 6px; }
.fetch-row input { flex: 1; }

.img-preview {
  max-width: 100%; max-height: 160px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); margin-top: 6px; display: block;
}
.img-info {
  display: block; font-size: 10px; color: var(--text-dim); margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.modal-btn {
  padding: 8px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.modal-btn.cancel { background: transparent; color: var(--text-dim); }
.modal-btn.cancel:hover { background: var(--bg-hover); color: var(--text); }
.modal-btn.save { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-btn.save:hover { background: var(--accent-hover); }
.modal-btn.delete { background: transparent; border-color: var(--red); color: var(--red); }
.modal-btn.delete:hover { background: var(--red); color: #fff; }

/* Spinner */
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin 0.5s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border); padding: 10px 20px;
  border-radius: var(--radius); font-size: 12px; z-index: 300; box-shadow: var(--shadow);
  transition: opacity 0.3s, transform 0.3s; pointer-events: none;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); }

/* Draft items */
.draft-item {
  display: flex; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s;
}
.draft-item:hover { background: var(--bg-hover); }
.draft-current { border-left: 3px solid var(--accent); }
.draft-info { flex: 1; min-width: 0; }
.draft-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.draft-meta { font-size: 10px; color: var(--text-dim); margin-top: 3px; }
.draft-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.draft-item:hover .draft-actions { opacity: 1; }
.draft-action-btn {
  width: 26px; height: 26px; border: none; border-radius: 4px; background: transparent;
  color: var(--text-dim); cursor: pointer; font-size: 14px; display: flex; align-items: center;
  justify-content: center; transition: all 0.1s;
}
.draft-action-btn:hover { background: var(--bg); color: var(--text); }
.draft-action-btn.del:hover { color: var(--red); }
