:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #1c2333;
  --muted: #6b7385;
  --border: #e1e5ee;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --green: #15803d;
  --green-bg: #dcfce7;
  --red: #c62828;
  --red-bg: #fde2e2;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --blue: #1d4ed8;
  --blue-bg: #dbeafe;
  --gray-bg: #eef0f4;
  --input: #ffffff;
  --code: #f7f8fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 8px rgba(16, 24, 40, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131a; --panel: #171c25; --text: #e5e9f0; --muted: #96a0b3; --border: #2a3140;
    --primary: #3b82f6; --primary-d: #2563eb; --green: #4ade80; --green-bg: #12301f; --red: #f87171; --red-bg: #3a1717;
    --amber: #fbbf24; --amber-bg: #3a2c0c; --blue: #93c5fd; --blue-bg: #172a4a; --gray-bg: #232a36; --input: #10141b; --code: #10141b;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f131a; --panel: #171c25; --text: #e5e9f0; --muted: #96a0b3; --border: #2a3140;
  --primary: #3b82f6; --primary-d: #2563eb; --green: #4ade80; --green-bg: #12301f; --red: #f87171; --red-bg: #3a1717;
  --amber: #fbbf24; --amber-bg: #3a2c0c; --blue: #93c5fd; --blue-bg: #172a4a; --gray-bg: #232a36; --input: #10141b; --code: #10141b;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
.hidden { display: none !important; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 12px; }
a { color: var(--primary); }
code { background: var(--code); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 12px; }

/* ---------- topbar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand.big { font-size: 22px; margin-bottom: 4px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.tabs a:hover { background: var(--gray-bg); color: var(--text); }
.tabs a.active { background: var(--blue-bg); color: var(--blue); }
main { max-width: 1400px; margin: 0 auto; padding: 20px; }

/* ---------- layout */
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.row-between h3 { margin: 0; }
.grow { flex: 1; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-2.tight { grid-template-columns: 1fr 1fr; gap: 0 12px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.mt { margin-top: 10px; }
.mt-lg { margin-top: 22px; }
.m0 { margin: 0 !important; }
.center { text-align: center; }
.small { font-size: 12.5px; }
.muted { color: var(--muted); }
.err { color: var(--red); }
.green-t { color: var(--green); }
.red-t { color: var(--red); }
.amber-t { color: var(--amber); }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.hint ul { margin: 6px 0; padding-left: 18px; }
details summary { cursor: pointer; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

/* ---------- forms */
label { display: block; font-weight: 500; font-size: 13px; margin: 10px 0 4px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 6px 0; cursor: pointer; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--input); color: var(--text); font: inherit; }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--primary); flex: none; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
textarea { resize: vertical; }
.w-auto { width: auto; }
.title-input { font-size: 17px; font-weight: 600; border-color: transparent; background: transparent; width: auto; min-width: 240px; }
.title-input:hover { border-color: var(--border); }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--gray-bg); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-d); }
.btn.success { background: #16a34a; border-color: #16a34a; color: #fff; }
.btn.success:hover:not(:disabled) { background: #15803d; }
.btn.warn { background: #f59e0b; border-color: #f59e0b; color: #1c1300; }
.btn.warn:hover:not(:disabled) { background: #d97706; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger-ghost { color: var(--red); }
.btn.danger-ghost:hover:not(:disabled) { background: var(--red-bg); }
.file-btn { cursor: pointer; }
.link { display: inline; color: var(--primary); text-decoration: underline; margin: 0; font-weight: 600; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: var(--muted); font-size: 14px; }
.icon-btn:hover { background: var(--gray-bg); color: var(--text); }

/* ---------- badges */
.badge, .pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--gray-bg); color: var(--muted); white-space: nowrap; }
.badge.green, .pill.green { background: var(--green-bg); color: var(--green); }
.badge.red, .pill.red { background: var(--red-bg); color: var(--red); }
.badge.amber, .pill.amber { background: var(--amber-bg); color: var(--amber); }
.badge.blue, .pill.blue { background: var(--blue-bg); color: var(--blue); }
.import-summary { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ---------- tables */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.tbl th { background: var(--gray-bg); font-size: 12px; font-weight: 600; color: var(--muted); position: sticky; top: 0; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--gray-bg) 50%, transparent); }
.w-cb { width: 32px; }
.w-act { width: 76px; }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 10px; min-height: 8px; }
.preview { max-height: 340px; }

/* ---------- campaigns */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card { display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.card:hover { border-color: var(--primary); }
.card .row-between { margin: 0; }
.progress { height: 8px; background: var(--gray-bg); border-radius: 99px; overflow: hidden; margin: 8px 0 6px; }
.progress.sm { height: 5px; margin: 4px 0; }
.progress > div { height: 100%; background: linear-gradient(90deg, #22c55e, #16a34a); width: 0; transition: width .4s; }
.control { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.progress-wrap { flex: 1; min-width: 280px; }
.control-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.stats { display: flex; gap: 26px; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats span { font-size: 12px; color: var(--muted); }
.stats b { font-size: 22px; line-height: 1.2; }
.checklist { max-height: 150px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; }

/* ---------- editor */
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; padding: 6px; border: 1px solid var(--border); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--gray-bg); margin-top: 6px; }
.editor-toolbar button { border: 0; background: transparent; color: var(--text); padding: 5px 8px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; min-width: 30px; }
.editor-toolbar button:hover:not(:disabled), .editor-toolbar button.active { background: var(--panel); }
.editor-toolbar button:disabled { opacity: .35; }
.editor-toolbar select { width: auto; padding: 4px 6px; font-size: 13px; }
.editor-toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.color-btn { position: relative; margin: 0; padding: 4px 8px; font-weight: 700; color: #d93025; cursor: pointer; border-radius: 6px; }
.color-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.editor { min-height: 360px; max-height: 70vh; overflow: auto; border: 1px solid var(--border); border-radius: 0 0 8px 8px; padding: 14px 16px; background: #fff; color: #222; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 1.6; }
.editor:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); }
.editor img { max-width: 100%; height: auto; }
.editor table { border-collapse: collapse; }
.editor td, .editor th { border: 1px solid #ccc; padding: 4px 8px; }
.editor.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; white-space: pre-wrap; background: var(--code); color: var(--text); }

/* ---------- lists */
.lists-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.list-nav { list-style: none; margin: 0; padding: 0; }
.list-nav a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.list-nav a:hover { background: var(--gray-bg); }
.list-nav a.active { background: var(--blue-bg); color: var(--blue); font-weight: 600; }
.drop { border: 2px dashed var(--border); border-radius: 12px; padding: 28px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.drop.over { border-color: var(--primary); background: var(--blue-bg); }

/* ---------- log, dialog, toast */
.log { background: var(--code); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 12px; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 10px 0 0; }
.log.ok { border-color: var(--green); }
.log.bad { border-color: var(--red); }
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.dlg.wide { width: min(1000px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(15, 20, 30, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); margin: 0; }
.dlg-head h3 { margin: 0; }
.dlg-head .x { border: 0; background: transparent; font-size: 18px; cursor: pointer; color: var(--muted); }
.dlg-body { padding: 16px 18px; max-height: calc(100vh - 200px); overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); }
.dlg-foot.inner { padding: 14px 0 0; border: 0; }
#previewFrame { width: 100%; height: 65vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; margin-top: 8px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1c2333; color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: #b91c1c; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); text-align: center; }
.login-card p { margin: 0 0 6px; }

/* ---------- responsive */
@media (max-width: 960px) {
  .grid-2, .lists-layout { grid-template-columns: minmax(0, 1fr); }
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar .brand { display: none; }
  main { padding: 16px; }
}
@media (max-width: 560px) {
  .grid-2.tight { grid-template-columns: 1fr; }
  .stats { gap: 16px; }
  .stats b { font-size: 18px; }
  .title-input { min-width: 0; width: 100%; }
  .ellipsis { max-width: 160px; }
}
