:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --text: #1d1b19;
  --muted: #6b6560;
  --line: #e4e0db;
  --accent: #c27c1a;
  --accent-soft: #fbf1e2;
  --danger: #c0392b;
  --ok: #2e7d4f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151312;
    --surface: #1f1c1a;
    --text: #f1ece6;
    --muted: #a39b93;
    --line: #34302c;
    --accent: #e8a33d;
    --accent-soft: #3a2b16;
    --danger: #ef6b5b;
    --ok: #5cc28a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; min-height: 100vh; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.side { width: 270px; flex: none; background: var(--surface); border-right: 1px solid var(--line); padding: 18px; display: flex; flex-direction: column; gap: 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.new-event { display: flex; gap: 6px; }
.new-event input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.new-event button, .btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn.primary, .new-event button { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:focus-visible, .new-event button:focus-visible, nav a:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: block; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: var(--text); }
nav a small { display: block; color: var(--muted); font-size: 12px; }
nav a.on { background: var(--accent-soft); }

main { flex: 1; min-width: 0; padding: 24px 32px 80px; }
.empty-main { max-width: 520px; margin: 12vh auto; text-align: center; color: var(--muted); }
.empty-main h1 { color: var(--text); }

.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.head h1 { margin: 0; font-size: 26px; }
.head .links { display: flex; gap: 8px; flex-wrap: wrap; }
.head .links a { text-decoration: none; }
.status { color: var(--muted); font-size: 13px; min-height: 20px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: 16px 0 24px; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

.section { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; margin-bottom: 18px; max-width: 980px; }
.section h2 { margin: 0 0 4px; font-size: 18px; }
.section > p.help { margin: 0 0 14px; color: var(--muted); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 20px; }
.f { display: flex; flex-direction: column; gap: 5px; }
.f.wide { grid-column: 1 / -1; }
.f > span { font-weight: 600; font-size: 14px; }
.f small { color: var(--muted); font-size: 12.5px; }
.f input[type=text], .f input[type=number], .f input[type=password], .f select, .f textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.f textarea { min-height: 80px; resize: vertical; }
.f input:focus, .f select:focus, .f textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.f input[type=color] { width: 56px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.f input[type=range] { accent-color: var(--accent); }
.f.check { flex-direction: row; align-items: center; gap: 10px; }
.f.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.f.check > span { font-weight: 500; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.checks label { display: flex; align-items: center; gap: 6px; }

.file { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file .thumb { width: 56px; height: 56px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; background: repeating-conic-gradient(#ccc 0 25%, #fff 0 50%) 0 0 / 12px 12px; }
.file .name { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; max-width: 220px; white-space: nowrap; }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; background: var(--bg); }
.list-item .f > span { font-size: 12.5px; }

.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.tpl { border: 2px solid var(--line); border-radius: 12px; padding: 8px; background: var(--bg); cursor: pointer; text-align: left; }
.tpl.on { border-color: var(--accent); }
.tpl canvas { width: 100%; display: block; border-radius: 6px; background: #fff; }
.tpl b { display: block; font-size: 12.5px; margin-top: 6px; line-height: 1.3; }
.tpl-editor { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; margin-top: 18px; }
.tpl-editor canvas { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; position: sticky; top: 20px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.gallery img, .gallery video { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: #000; }
.gallery figcaption { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; font-size: 12px; color: var(--muted); gap: 6px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: var(--accent-soft); }
.badge.sent { background: color-mix(in srgb, var(--ok) 20%, transparent); }
.badge.failed, .badge.not_configured { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.qr-inline { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.qr-inline svg { width: 140px; height: 140px; background: #fff; border-radius: 10px; }
code { background: var(--bg); padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); font-size: 13px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 860px) {
  body { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding: 16px; }
  .tpl-editor { grid-template-columns: 1fr; }
  .tpl-editor canvas { position: static; max-width: 320px; }
}

/* ---------- outputs & visual editor ---------- */
.outputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.out-card { display: flex; gap: 12px; border: 2px solid var(--line); border-radius: 12px; padding: 12px; background: var(--bg); }
.out-card.on { border-color: var(--accent); }
.out-card.off { opacity: .6; }
.out-thumb { width: 84px; flex: none; display: flex; align-items: flex-start; justify-content: center; font-size: 40px; }
.out-thumb canvas { width: 100%; border-radius: 6px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.out-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.out-top { display: flex; gap: 14px; flex-wrap: wrap; }
.out-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.adder { display: flex; gap: 8px; margin-top: 14px; }
.adder select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
details.more { margin-top: 16px; }
details.more summary { cursor: pointer; font-weight: 600; margin-bottom: 12px; }

.ve { position: relative; width: 100%; user-select: none; }
.ve canvas { width: 100%; display: block; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.tpl-editor .ve canvas { position: static; max-width: none; }
.ve-layer { position: absolute; inset: 0; }
.ve-box { position: absolute; border: 2px dashed rgba(194,124,26,.9); cursor: move; touch-action: none; border-radius: 4px; }
.ve-box:hover, .ve-box.sel { background: rgba(194,124,26,.12); border-style: solid; }
.ve-box.text { border-color: rgba(37,99,235,.9); }
.ve-box.text:hover, .ve-box.text.sel { background: rgba(37,99,235,.12); }
.ve-box span { position: absolute; top: 4px; left: 4px; font-size: 11px; font-weight: 700; background: rgba(194,124,26,.95); color: #fff; padding: 1px 6px; border-radius: 4px; }
.ve-handle { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 50%; background: #c27c1a; border: 2px solid #fff; cursor: nwse-resize; touch-action: none; }

/* ---------- bulk download ---------- */
.dl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 4px 0 14px; }
.dl-bar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.gallery figure { position: relative; }
.gallery figure.picked { outline: 3px solid var(--accent); }
.fig-pick { position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; accent-color: var(--accent); z-index: 1; cursor: pointer; }

/* ---------- segmented choice ---------- */
.seg { display: inline-flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); margin: 6px 0 14px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Drive checklist ---------- */
.checklist { list-style: none; padding: 12px 14px; margin: 0 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); display: grid; gap: 8px; }
.checklist li.todo { color: var(--text); font-weight: 600; }
.checklist li.ok { color: var(--muted); }
.ve-box.image { border-color: rgba(147, 51, 234, .9); }
.ve-box.image:hover, .ve-box.image.sel { background: rgba(147, 51, 234, .12); }
.ve-box.image span { background: rgba(147, 51, 234, .95); }
.save-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.save-note { color: var(--muted); font-size: 13px; }
