/* ============================================================
   Kanvas — shared tokens and components
   ============================================================ */
:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-2: #eceff0;
  --hover: #e8edeb;
  --line: #e0e4e5;
  --line-strong: #b8c2c3;
  --text: #24282c;
  --muted: #697477;
  --accent: #087f70;
  --accent-2: #71dfbe;
  --accent-weak: #e1f4ed;
  --accent-ink: #086e60;
  --accent-hover: #066759;
  --danger: #c9344e;
  --ok: #267448;
  --gradient: linear-gradient(110deg, #087f70, #087f70);
  --ink: #202729;
  --ink-text: #f2f6f5;
  --display-font: "Space Grotesk", "Inter", -apple-system, sans-serif;
  --shadow: 0 2px 5px rgba(22, 39, 74, .05);
  --shadow-lg: 0 16px 48px rgba(17, 27, 46, .16), 0 2px 8px rgba(17, 27, 46, .05);
  --radius: 10px;
  --radius-lg: 16px;
  --canvas-bg: #e9eded;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121719; --panel: #1b2326; --panel-2: #161e21; --hover: #293539;
    --line: #344145; --line-strong: #52656a; --text: #eef4f2; --muted: #a7b9b7;
    --accent-weak: #1a3b34; --accent-ink: #80e0c5; --accent-hover: #066759;
    --danger: #ff8da3; --ok: #80d5ac;
    --shadow: 0 2px 5px rgba(0, 0, 0, .15);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .4);
    --canvas-bg: #131a1c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121719; --panel: #1b2326; --panel-2: #161e21; --hover: #293539;
  --line: #344145; --line-strong: #52656a; --text: #eef4f2; --muted: #a7b9b7;
  --accent-weak: #1a3b34; --accent-ink: #80e0c5; --accent-hover: #066759;
  --danger: #ff8da3; --ok: #80d5ac;
  --shadow: 0 2px 5px rgba(0, 0, 0, .15); --shadow-lg: 0 16px 48px rgba(0, 0, 0, .4);
  --canvas-bg: #131a1c; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.icon { flex: none; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Buttons ---------- */
a.btn { text-decoration: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--text);
  font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--hover); }
.btn:focus-visible, .icon-btn:focus-visible, .input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); background: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius);
  border: 0; background: transparent; color: inherit; cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.active, .btn.active { background: var(--accent-weak); color: var(--accent-ink); }
.icon-btn:disabled { opacity: .4; cursor: default; background: transparent; }

/* ---------- Inputs ---------- */
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--panel); outline: none;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field > span { font-size: 13px; font-weight: 600; }
.search-input { position: relative; display: flex; align-items: center; }
.search-input .icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search-input .input { padding-left: 40px; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 20px; border-radius: 99px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000; background: rgba(14, 19, 24, .45);
  display: grid; place-items: center; padding: 16px; animation: fade .12s ease-out;
}
.modal {
  background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  max-height: calc(100vh - 32px); display: flex; flex-direction: column; animation: pop .14s ease-out;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 10px 20px; overflow: auto; }
.modal-body p { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.modal-error { color: var(--danger); margin: 0 20px; font-size: 13px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }

/* ---------- Popover & menu ---------- */
.popover {
  position: fixed; z-index: 900; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 8px; animation: pop .1s ease-out;
  max-height: calc(100vh - 16px); max-width: calc(100vw - 16px); overflow: auto;
}
.popover > * { max-width: 100%; }
.menu { display: grid; min-width: 220px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none;
  border-radius: 6px; cursor: pointer; text-align: left; width: 100%;
}
.menu-item:hover:not(:disabled) { background: var(--hover); }
a.menu-item { color: inherit; text-decoration: none; }
.menu-item:disabled { opacity: .45; cursor: default; }
.menu-item.danger { color: var(--danger); }
.menu-item kbd { margin-left: auto; font: 12px/1 inherit; color: var(--muted); }
.menu-label { flex: 1; }
.menu-gap { width: 18px; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }

/* ---------- Toast ---------- */
.toast-host { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1100; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 14px; background: #1f2329; color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: auto; max-width: min(560px, calc(100vw - 32px));
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--danger); }
.toast-action { background: none; border: 0; color: #71dfbe; font-weight: 700; cursor: pointer; padding: 0; }

/* ---------- Brand mark ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--display-font); font-weight: 700; font-size: 25px; letter-spacing: -.055em; text-decoration: none; color: inherit; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent-2) url('/favicon.svg') center / cover no-repeat; display: inline-block; flex: none; font-size: 0; }
.studio-eyebrow { font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.avatar {
  width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; border: 0; cursor: pointer; flex: none;
}

/* ---------- Rendered pages (shared by editor, viewer, previews) ---------- */
.page-render { position: relative; overflow: hidden; }
.page-bg { position: absolute; inset: 0; }
.page-bg .el { pointer-events: none; }
.el { position: absolute; transform-origin: center center; }
.el-content { width: 100%; height: 100%; position: relative; }
.el-content > svg { display: block; overflow: visible; }
.el-image { overflow: hidden; }
.el-image img { position: absolute; max-width: none; user-select: none; -webkit-user-drag: none; }
.el-border { position: absolute; inset: 0; pointer-events: none; }
.el-curve-inner, .el-curve-inner svg { display: block; overflow: visible; }
.el-frame-empty { background: repeating-linear-gradient(45deg, #dfe2e6 0 10px, #e9ebee 10px 20px); }
.el-text-inner { outline: none; min-height: 1em; }
.el-shape-text { position: absolute; display: flex; flex-direction: column; justify-content: center; }
.el-shape-text .el-text-inner { width: 100%; }
.page-scaled { position: relative; overflow: hidden; flex: none; }
.page-scaled .page-render { position: absolute; left: 0; top: 0; }

/* ---------- Color swatches ---------- */
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 2px var(--panel);
}
.swatch.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.swatch-none { background: linear-gradient(135deg, #fff 45%, #e53935 45% 55%, #fff 55%) !important; }
.swatch-add { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); position: relative; }

/* ---------- Chips ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-strong); background: var(--panel); border-radius: 99px; padding: 6px 14px; cursor: pointer; font-weight: 500; }
.chip:hover { background: var(--hover); }
.chip.active { background: var(--text); color: var(--panel); border-color: var(--text); }

.empty-state { display: grid; place-items: center; gap: 10px; text-align: center; color: var(--muted); padding: 48px 16px; }
.empty-state .icon { width: 44px; height: 44px; color: var(--line-strong); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Template cards reserve their layout before visible previews are loaded. */
.template-preview-status { display: grid; place-items: center; width: 100%; height: 100%; padding: 12px; color: var(--muted); font-size: 12px; }
.template-batch-footer { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 20px 0; flex-wrap: wrap; }
.template-page-controls { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }
.tpl-preview, .l-tpl-prev, .template-hero-preview { contain: layout paint; }
