/* Forma 0.7 — стилі інтерфейсу.
   Теми задаються змінними на :root[data-theme]. Анімації вимикаються при prefers-reduced-motion. */

:root, :root[data-theme="dark"] {
  --bg: #0d0d10;
  --panel: #16161a;
  --panel-2: #1e1e23;
  --panel-3: #26262d;
  --panel-4: #303038;
  --border: #26262d;
  --border-strong: #383841;
  --text: #ececf1;
  --muted: #a3a3af;
  --faint: #8e8e9a;
  --accent: #8b6cff;
  --accent-btn: #6d4dff;   /* фон кнопок з білим текстом: контраст ≥ 4.5:1 */
  --accent-hi: #a891ff;
  --accent-soft: rgba(139, 108, 255, .16);
  --accent-ring: rgba(139, 108, 255, .45);
  --danger: #ff5c6c;
  --success: #3ddc97;
  --warn: #ffb547;
  --canvas: #1c1c21;
  --guide: #ff4d8d;
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .35);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, .45);
  --menu-bg: rgba(30, 30, 36, .94);
  --tok-tag: #ff7ab6; --tok-attr: #ffc070; --tok-str: #8fe3a7; --tok-com: #6b6b78; --tok-key: #b49bff; --tok-num: #7cc7ff; --tok-fn: #6fe0e0;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eeeef2;
  --panel: #ffffff;
  --panel-2: #f3f3f6;
  --panel-3: #ebebf0;
  --panel-4: #e1e1e8;
  --border: #e6e6ec;
  --border-strong: #d3d3dc;
  --text: #1a1a21;
  --muted: #55555f;
  --faint: #66666f;
  --accent: #6e4dff;
  --accent-btn: #6340f0;
  --success: #0b7d4d;
  --accent-hi: #5a37f5;
  --accent-soft: rgba(110, 77, 255, .12);
  --accent-ring: rgba(110, 77, 255, .35);
  --canvas: #e8e8ed;
  --shadow-lg: 0 24px 64px rgba(20, 20, 40, .18), 0 2px 8px rgba(20, 20, 40, .08);
  --shadow-md: 0 10px 30px rgba(20, 20, 40, .14);
  --menu-bg: rgba(255, 255, 255, .96);
  --tok-tag: #d6246e; --tok-attr: #b26b00; --tok-str: #12804a; --tok-com: #9a9aa6; --tok-key: #6a3df0; --tok-num: #0b6bb8; --tok-fn: #0a7f86;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 12px/1.4 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, textarea { user-select: text; }
[hidden] { display: none !important; }
.ic { display: block; flex: none; }
.ic-wrap { display: inline-flex; }
::selection { background: var(--accent-ring); }
.theme-anim, .theme-anim * { transition: background-color .3s, border-color .3s, color .3s !important; }

/* скролбари */
* { scrollbar-width: thin; scrollbar-color: var(--panel-4) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-4); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--faint); }

/* ---------- каркас ---------- */
.app {
  --left-w: 260px; --right-w: 288px;
  display: grid;
  grid-template-rows: 44px 40px minmax(0, 1fr) 26px;
  height: 100vh;
  opacity: 0;
  transition: opacity .35s ease;
}
body.ready .app { opacity: 1; }
.main {
  display: grid;
  grid-template-columns: 48px var(--left-w) minmax(0, 1fr) var(--right-w);
  min-height: 0;
  transition: grid-template-columns .32s cubic-bezier(.2, .8, .2, 1);
}
.app.resizing .main { transition: none; }
.app.resizing, .app.resizing * { cursor: col-resize !important; }
.app.focus-mode .main { grid-template-columns: 48px 0 minmax(0, 1fr) 0; }
.app.focus-mode .panel { opacity: 0; pointer-events: none; }

/* ---------- верхня панель ---------- */
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px 0 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 5;
}
.brand { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; cursor: pointer; transition: transform .2s, background .2s; }
.brand:hover { background: var(--panel-3); transform: rotate(-6deg); }
.menubar { display: flex; gap: 1px; }
.menu-btn {
  height: 28px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-weight: 500; transition: background .15s, color .15s;
}
.menu-btn:hover, .menu-btn.open { background: var(--panel-3); color: var(--text); }
.doc-title {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
}
.doc-title input {
  width: 260px; height: 28px; text-align: center; border: 1px solid transparent; border-radius: 7px;
  background: transparent; font-weight: 600; font-size: 13px; outline: none; transition: background .15s, border-color .15s;
  text-overflow: ellipsis;
}
.doc-title input:hover { background: var(--panel-2); }
.doc-title input:focus { background: var(--panel-2); border-color: var(--accent); }
.save-state { display: inline-flex; align-items: center; gap: 6px; color: var(--faint); font-size: 11px; white-space: nowrap; position: absolute; left: 100%; margin-left: 4px; }
.save-state i { width: 6px; height: 6px; border-radius: 50%; background: var(--success); transition: background .2s, box-shadow .2s; }
.save-state[data-state="saving"] i { background: var(--warn); animation: pulse 1s infinite; }
.save-state[data-state="error"] i { background: var(--danger); }
.save-state[data-state="error"] { color: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.divider { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex: none; }

/* ---------- кнопки ---------- */
.icon-btn {
  width: 30px; height: 30px; display: inline-grid; place-items: center; flex: none;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  transition: background .15s, color .15s, transform .12s;
}
.icon-btn:hover:not(:disabled) { background: var(--panel-3); color: var(--text); }
.icon-btn:active:not(:disabled) { transform: scale(.92); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.sm { width: 26px; height: 26px; border-radius: 7px; }
.icon-btn.xs { width: 22px; height: 22px; border-radius: 6px; }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.btn {
  height: 30px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel-2); font-weight: 500;
  transition: background .15s, border-color .15s, transform .12s, box-shadow .2s; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel-3); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.sm { height: 26px; padding: 0 9px; font-size: 11.5px; border-radius: 7px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--panel-3); color: var(--text); }
.btn.primary { background: var(--accent-btn); border-color: var(--accent-btn); color: #fff; box-shadow: 0 4px 14px -4px var(--accent-ring); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hi); border-color: var(--accent-hi); box-shadow: 0 6px 20px -4px var(--accent-ring); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; box-shadow: none; }
.btn.grow, .grow { flex: 1; min-width: 0; }

/* ---------- панель параметрів ---------- */
.optionsbar {
  display: flex; align-items: center; gap: 14px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--border); overflow: hidden; white-space: nowrap;
  animation: obIn .25s ease;
}
.ob-tool { display: inline-flex; align-items: center; gap: 7px; color: var(--text); }
.ob-tool b { font-weight: 600; }
.ob-sep { width: 1px; height: 18px; background: var(--border); }
.ob-field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); animation: fadeSlide .25s ease both; }
.ob-field output { min-width: 42px; color: var(--text); font-variant-numeric: tabular-nums; }
.ob-field em { font-style: normal; }
.ob-num { width: 56px; height: 24px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--panel-2); padding: 0 6px; outline: none; }
.ob-num:focus { border-color: var(--accent); }
.ob-range { width: 110px; accent-color: var(--accent); }
.ob-swatch { position: relative; width: 22px; height: 22px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15), 0 0 0 1px var(--border-strong); overflow: hidden; }
.ob-swatch input, .swatch input, .cf-swatch input { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); opacity: 0; cursor: pointer; }
.ob-toggle { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border: 1px solid var(--border); background: transparent; border-radius: 7px; color: var(--muted); transition: color .15s, background .15s, border-color .15s; animation: fadeSlide .25s ease both; }
.ob-toggle:hover { color: var(--text); background: var(--panel-3); }
.ob-toggle.on { color: var(--accent-hi); border-color: var(--accent-ring); background: var(--accent-soft); }
.ob-spacer { flex: 1; }
.ob-hint { color: var(--faint); overflow: hidden; text-overflow: ellipsis; animation: fadeSlide .3s ease both; }
@keyframes obIn { from { opacity: .6; } }
@keyframes fadeSlide { from { opacity: 0; transform: translateY(-3px); } }

/* ---------- панель інструментів ---------- */
.toolrail {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0;
  background: var(--panel); border-right: 1px solid var(--border); z-index: 2;
}
.tool {
  position: relative; z-index: 1; width: 36px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: 9px; background: transparent; color: var(--muted); transition: color .15s, background .15s, transform .12s;
}
.tool:hover { color: var(--text); background: var(--panel-3); }
.tool:active { transform: scale(.9); }
.tool.active { color: #fff; background: transparent; }
.tool-ink {
  position: absolute; left: 6px; top: 0; width: 36px; height: 36px; border-radius: 9px;
  background: var(--accent); box-shadow: 0 6px 16px -6px var(--accent-ring);
  transition: transform .28s cubic-bezier(.3, 1.4, .5, 1), opacity .2s; pointer-events: none;
}
.rail-sep { width: 22px; height: 1px; background: var(--border); margin: 5px 0; }
.rail-spacer { flex: 1; }
.swatches { position: relative; width: 36px; height: 40px; margin-bottom: 4px; }
.swatch { position: absolute; width: 22px; height: 22px; border-radius: 6px; overflow: hidden; box-shadow: 0 0 0 1.5px var(--panel), 0 0 0 2.5px var(--border-strong); cursor: pointer; transition: transform .15s; }
.swatch:hover { transform: scale(1.08); }
.swatch.fg { left: 2px; top: 2px; z-index: 1; }
.swatch.bg { right: 2px; bottom: 2px; }
.swatch-swap { position: absolute; right: 0; top: 0; width: 13px; height: 13px; padding: 0; border: 0; background: none; color: var(--muted); display: grid; place-items: center; }
.swatch-swap:hover { color: var(--text); }

/* ---------- бічні панелі ---------- */
.panel {
  position: relative; min-width: 0; display: flex; flex-direction: column;
  background: var(--panel); overflow: hidden; transition: opacity .25s;
}
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }
.resizer { position: absolute; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 3; }
.panel-left .resizer { right: -3px; }
.panel-right .resizer { left: -3px; }
.resizer::after { content: ""; position: absolute; inset: 0 2px; background: var(--accent); opacity: 0; transition: opacity .15s; }
.resizer:hover::after, .app.resizing .resizer::after { opacity: .6; }
.panel-tabs { position: relative; display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--border); flex: none; }
.ptab { height: 30px; padding: 0 10px; border: 0; background: transparent; color: var(--muted); font-weight: 600; border-radius: 7px 7px 0 0; transition: color .15s; }
.ptab:hover, .ptab.active { color: var(--text); }
.ptab-ink { position: absolute; bottom: -1px; left: 0; height: 2px; border-radius: 2px; background: var(--accent); transition: transform .3s cubic-bezier(.2, .8, .2, 1), width .3s cubic-bezier(.2, .8, .2, 1); }
.ltab-body { display: flex; flex-direction: column; min-height: 0; flex: 1; animation: tabIn .25s ease; }
@keyframes tabIn { from { opacity: 0; transform: translateX(-4px); } }

.section-head { display: flex; align-items: center; justify-content: space-between; height: 34px; padding: 0 8px 0 12px; flex: none; }
.section-toggle, .section-label { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.section-toggle:hover { color: var(--text); }
.chev { width: 14px; height: 14px; display: inline-block; position: relative; transition: transform .2s; }
.chev::before { content: ""; position: absolute; left: 4px; top: 3px; width: 5px; height: 5px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); }
.collapsed > .section-head .chev, .ins-section.collapsed .chev { transform: rotate(-90deg); }
.muted-count { color: var(--faint); font-size: 11px; }

.pages { border-bottom: 1px solid var(--border); flex: none; }
.pages-list { padding: 0 6px 8px; display: grid; grid-template-rows: 1fr; transition: grid-template-rows .25s, padding .25s; max-height: 160px; overflow: auto; }
.pages.collapsed .pages-list { display: none; }
.page-row { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 8px; border-radius: 7px; cursor: pointer; color: var(--muted); transition: background .12s, color .12s; }
.page-row:hover { background: var(--panel-3); color: var(--text); }
.page-row.active { color: var(--text); font-weight: 600; }
.pg-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-check { color: var(--accent); }
.inline-input { flex: 1; min-width: 0; height: 22px; border: 1px solid var(--accent); border-radius: 5px; background: var(--panel-2); padding: 0 6px; outline: none; }

.layers { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.layers-list { position: relative; flex: 1; overflow: auto; padding: 0 6px 24px; }
.layer-row {
  --depth: 0;
  display: flex; align-items: center; gap: 6px; height: 30px;
  padding: 0 6px 0 calc(4px + var(--depth) * 14px); border-radius: 7px; cursor: default;
  color: var(--text); transition: background .1s;
  position: absolute; left: 0; right: 0;
}
.layers-spacer { position: relative; }
.layer-row:hover, .layer-row.hover { background: var(--panel-3); }
.layer-row.in-selected { background: color-mix(in srgb, var(--accent) 7%, transparent); border-radius: 0; }
.layer-row.selected { background: var(--accent-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent); }
.layer-row.selected .lr-icon { color: var(--accent); }
.layer-row.is-hidden .lr-name, .layer-row.is-hidden .lr-icon { opacity: .4; }
.layer-row.drop-into { box-shadow: inset 0 0 0 2px var(--accent); }
.lr-toggle { width: 14px; height: 14px; display: grid; place-items: center; color: var(--faint); transition: transform .2s; flex: none; }
.lr-toggle.open { transform: rotate(90deg); }
.lr-toggle:not(.empty):hover { color: var(--text); }
.lr-icon { color: var(--muted); flex: none; display: grid; place-items: center; }
.lr-icon.t-frame { color: var(--text); }
.lr-icon.t-image { color: #5ec3ff; }
.lr-icon.t-text { color: var(--muted); }
.lr-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row[data-id] .lr-name { font-weight: 450; }
.lr-actions { display: flex; gap: 1px; opacity: 0; transition: opacity .12s; }
.layer-row:hover .lr-actions { opacity: 1; }
.lr-btn { width: 22px; height: 22px; display: grid; place-items: center; border: 0; border-radius: 5px; background: transparent; color: var(--muted); }
.lr-btn:hover { background: var(--panel-4); color: var(--text); }
.lr-btn.on { opacity: 1; color: var(--text); }
.layer-row:not(:hover) .lr-actions:has(.lr-btn.on) { opacity: 1; }
.layer-row:not(:hover) .lr-btn:not(.on) { visibility: hidden; }
.layers-list.dragging .layer-row { cursor: grabbing; }
.drop-line { position: absolute; right: 8px; height: 2px; background: var(--accent); border-radius: 2px; pointer-events: none; transition: top .08s, left .08s; }
.drop-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--accent); background: var(--panel); box-sizing: border-box; }
.layers-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 40px 20px; color: var(--muted); animation: fadeSlide .4s ease; }
.layers-empty b { color: var(--text); }
.le-ic { color: var(--faint); margin-bottom: 4px; }

/* ---------- ресурси ---------- */
#assetsBody { overflow: auto; padding: 10px 10px 30px; }
#assetsBody > * { flex: none; }
.asset-search { width: 100%; height: 30px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel-2); padding: 0 10px; outline: none; margin-bottom: 4px; }
.asset-search:focus { border-color: var(--accent); }
.asset-sec h4 { margin: 14px 2px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.asset-tile { display: flex; flex-direction: column; gap: 6px; padding: 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); text-align: left; transition: transform .18s cubic-bezier(.3, 1.4, .5, 1), border-color .15s, box-shadow .2s; animation: fadeSlide .3s ease both; }
.asset-tile:hover { transform: translateY(-2px); border-color: var(--accent-ring); box-shadow: var(--shadow-md); }
.asset-tile:active { transform: scale(.97); }
.at-thumb { height: 64px; display: grid; place-items: center; border-radius: 7px; background: repeating-conic-gradient(var(--panel-3) 0 25%, transparent 0 50%) 0 0 / 12px 12px; overflow: hidden; }
.at-thumb img { max-width: 100%; max-height: 100%; }
.at-label { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-empty { grid-column: 1 / -1; color: var(--faint); padding: 10px 4px; line-height: 1.5; }

/* ---------- полотно ---------- */
.stage { position: relative; overflow: hidden; background: var(--canvas); outline: none; touch-action: none; }
.stage canvas { position: absolute; inset: 0; display: block; }
.overlay-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.overlay-layer > * { pointer-events: auto; }
.text-editor {
  position: absolute; margin: 0; padding: 0; border: 0; outline: none; resize: none; overflow: hidden;
  background: transparent; caret-color: var(--accent); word-break: break-word; overflow-wrap: break-word;
}
.text-editor::selection { background: rgba(139, 108, 255, .35); }
.zoom-pill {
  position: absolute; right: 14px; bottom: 14px; display: flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--menu-bg); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
}
.zp-label { min-width: 52px; height: 26px; border: 0; background: none; border-radius: 7px; font-weight: 600; font-variant-numeric: tabular-nums; }
.zp-label:hover { background: var(--panel-3); }
.zp-sep { width: 1px; height: 16px; background: var(--border); margin: 0 2px; }
.drop-hint {
  position: absolute; inset: 12px; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 16px;
  background: var(--accent-soft); color: var(--text); font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, inset .2s;
}
.stage.drop-hover .drop-hint { opacity: 1; inset: 18px; }

/* ---------- рядок стану ---------- */
.statusbar { display: flex; align-items: center; gap: 16px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--border); color: var(--faint); font-size: 11px; white-space: nowrap; overflow: hidden; }
.st-item { font-variant-numeric: tabular-nums; }
#stCursor { min-width: 120px; }
#stSelection { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.st-spacer { flex: 1; }
.st-version { color: var(--accent); font-weight: 600; }

/* ---------- інспектор ---------- */
.inspector { flex: 1; overflow: auto; overflow-x: hidden; }
.ins-content { padding-bottom: 30px; }
.ins-content.enter > * { animation: fadeSlide .22s ease both; }
.ins-content.enter > *:nth-child(2) { animation-delay: .02s; }
.ins-content.enter > *:nth-child(3) { animation-delay: .04s; }
.ins-content.enter > *:nth-child(4) { animation-delay: .06s; }
.ins-content.enter > *:nth-child(5) { animation-delay: .08s; }
.ins-content.enter > *:nth-child(n+6) { animation-delay: .1s; }
.ins-header { display: flex; align-items: center; gap: 10px; padding: 12px 12px 10px; }
.ins-type { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; background: var(--accent-soft); color: var(--accent); flex: none; }
.ins-header-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ins-name { width: 100%; height: 24px; margin-left: -5px; padding: 0 5px; border: 1px solid transparent; border-radius: 6px; background: transparent; font-weight: 600; font-size: 13px; outline: none; text-overflow: ellipsis; }
.ins-name:hover:not(:disabled) { border-color: var(--border-strong); }
.ins-name:focus { border-color: var(--accent); background: var(--panel-2); }
.ins-name:disabled { color: var(--text); }
.ins-type-label { color: var(--faint); font-size: 11px; }
.ins-badge { display: inline-flex; gap: 4px; align-items: center; font-size: 10.5px; color: var(--warn); background: rgba(255, 181, 71, .12); padding: 3px 7px; border-radius: 20px; }
.align-bar { display: flex; align-items: center; gap: 1px; padding: 0 8px 8px; border-bottom: 1px solid var(--border); }
.ab-sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; }
.ins-section { border-bottom: 1px solid var(--border); }
.ins-head { display: flex; align-items: center; justify-content: space-between; height: 38px; padding: 0 8px 0 10px; }
.ins-title { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; font-weight: 600; color: var(--text); }
.ins-title .chev { color: var(--faint); }
.ins-head-actions { display: flex; align-items: center; gap: 4px; }
.ins-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .26s cubic-bezier(.2, .8, .2, 1); }
.ins-section.collapsed .ins-body { grid-template-rows: 0fr; }
.ins-inner { overflow: hidden; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.ins-section.collapsed .ins-inner { padding-bottom: 0; }
.ins-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ins-row > * { min-width: 0; }
.ins-row > .nf, .ins-row > .cf { flex: 1; }
.ins-cap { color: var(--muted); font-size: 11px; flex: 1; }
.ins-empty-hint { color: var(--faint); font-size: 11px; }
.nf {
  position: relative; display: flex; align-items: center; height: 28px; min-width: 0;
  border: 1px solid transparent; border-radius: 7px; background: var(--panel-2); transition: border-color .15s, background .15s;
}
.nf:hover { border-color: var(--border-strong); }
.nf:focus-within { border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 3px var(--accent-soft); }
.nf.disabled { opacity: .45; }
.nf-label { flex: none; min-width: 26px; height: 100%; display: grid; place-items: center; color: var(--faint); font-size: 11px; cursor: ew-resize; border-radius: 7px 0 0 7px; transition: color .15s; }
.nf-label:hover { color: var(--accent); }
.nf.disabled .nf-label { cursor: default; }
.nf-input { flex: 1; min-width: 0; width: 100%; height: 100%; padding: 0 6px 0 0; border: 0; background: transparent; outline: none; font-variant-numeric: tabular-nums; }
.nf-input::placeholder { color: var(--faint); }
.nf-suffix { color: var(--faint); padding-right: 7px; font-size: 11px; }
body.scrubbing, body.scrubbing * { cursor: ew-resize !important; }
.cf { display: flex; align-items: center; gap: 6px; height: 28px; min-width: 0; }
.cf .nf { width: 64px; flex: none; }
.cf-swatch {
  --c: #fff; position: relative; width: 28px; height: 28px; flex: none; border-radius: 7px; overflow: hidden;
  background: linear-gradient(var(--c), var(--c)), repeating-conic-gradient(#999 0 25%, #fff 0 50%) 0 0 / 8px 8px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2), 0 0 0 1px var(--border-strong); transition: transform .15s;
}
.cf-swatch:hover { transform: scale(1.06); }
.cf-swatch.mixed { background: conic-gradient(#ff5c6c, #ffc542, #3ddc97, #5ec3ff, #8b6cff, #ff5c6c); }
.cf-hex { flex: 1; min-width: 0; height: 28px; border: 1px solid transparent; border-radius: 7px; background: var(--panel-2); padding: 0 8px; outline: none; font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 11.5px; text-transform: uppercase; }
.cf-hex:hover { border-color: var(--border-strong); }
.cf-hex:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sf { height: 28px; min-width: 0; border: 1px solid transparent; border-radius: 7px; background: var(--panel-2); padding: 0 6px; outline: none; cursor: pointer; }
.sf:hover { border-color: var(--border-strong); }
.sf:focus { border-color: var(--accent); }
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 8px; background: var(--panel-2); flex: 1; }
.seg-btn { flex: 1; height: 24px; min-width: 28px; display: grid; place-items: center; padding: 0 6px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 11.5px; font-weight: 500; transition: background .15s, color .15s, box-shadow .15s; white-space: nowrap; }
.seg-btn:hover:not(:disabled) { color: var(--text); }
.seg-btn.active { background: var(--panel-4); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.seg-btn:disabled { opacity: .35; cursor: default; }
.ins-textarea { width: 100%; resize: vertical; min-height: 56px; border: 1px solid transparent; border-radius: 7px; background: var(--panel-2); padding: 7px 8px; outline: none; line-height: 1.45; }
.ins-textarea:focus { border-color: var(--accent); }
.grad-preview { height: 10px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; position: relative; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui { width: 28px; height: 16px; border-radius: 10px; background: var(--panel-4); position: relative; transition: background .2s; flex: none; }
.switch-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .22s cubic-bezier(.3, 1.4, .5, 1); }
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(12px); }
.switch input:indeterminate + .switch-ui { background: color-mix(in srgb, var(--accent) 50%, var(--panel-4)); }
.switch input:focus-visible + .switch-ui { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch-label { color: var(--text); }
.tips-card { margin: 14px 12px; padding: 12px; border-radius: 12px; background: linear-gradient(135deg, var(--accent-soft), transparent); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); }
.tc-head { display: flex; align-items: center; gap: 6px; color: var(--accent); margin-bottom: 4px; }
.tips-card p { margin: 0; color: var(--muted); line-height: 1.55; }

/* експорт */
.exp-block { padding: 10px 12px 0; display: flex; flex-direction: column; gap: 6px; }
.exp-block > .btn { margin-top: 4px; flex: none; height: 34px; }
.exp-preview { margin: 14px 12px 0; height: 170px; display: grid; place-items: center; border-radius: 10px; background: repeating-conic-gradient(var(--panel-3) 0 25%, var(--panel-2) 0 50%) 0 0 / 14px 14px; overflow: hidden; }
.exp-preview canvas { box-shadow: var(--shadow-md); animation: popIn .3s cubic-bezier(.3, 1.4, .5, 1); }
.exp-info { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 6px; }
.exp-note { margin: 10px 12px; color: var(--faint); font-size: 11px; line-height: 1.5; }
.exp-modal { margin: -6px -12px -10px; }
.muted { color: var(--faint); }
@keyframes popIn { from { opacity: 0; transform: scale(.94); } }

/* ---------- меню ---------- */
.menu {
  position: fixed; z-index: 1000; min-width: 220px; max-width: 320px; padding: 5px;
  background: var(--menu-bg); border: 1px solid var(--border-strong); border-radius: 11px; box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px) saturate(1.4);
  opacity: 0; transform: scale(.97) translateY(-4px); transform-origin: top left;
  transition: opacity .14s ease, transform .16s cubic-bezier(.2, .9, .3, 1.2);
}
.menu.open, .menu.sub { opacity: 1; transform: none; }
.menu.sub { animation: menuIn .14s ease; }
.menu-item.sub-open { background: var(--panel-3); color: var(--text); }
.menu.closing { opacity: 0; transform: scale(.98); transition-duration: .12s; }
@keyframes menuIn { from { opacity: 0; transform: translateX(-4px); } }
.menu-item {
  width: 100%; height: 28px; display: flex; align-items: center; gap: 8px; padding: 0 8px; border: 0; border-radius: 7px;
  background: transparent; text-align: left; color: var(--text); transition: background .08s;
}
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--accent-btn); color: #fff; outline: none; }
.menu-item:hover:not(:disabled) .mi-key, .menu-item:hover:not(:disabled) .mi-icon { color: rgba(255, 255, 255, .85); }
.menu-item:disabled { opacity: .38; cursor: default; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.mi-icon { width: 16px; display: grid; place-items: center; color: var(--muted); flex: none; }
.mi-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mi-key, .mi-sub { color: var(--faint); font-size: 11px; white-space: nowrap; }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--border); }
.menu-header { padding: 6px 8px 2px; color: var(--faint); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- підказки ---------- */
.tooltip {
  position: fixed; z-index: 2000; display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 7px;
  background: #0a0a0d; color: #f2f2f5; font-size: 11.5px; box-shadow: var(--shadow-md); pointer-events: none;
  opacity: 0; transform: translateY(2px); transition: opacity .12s, transform .12s; white-space: nowrap;
}
:root[data-theme="light"] .tooltip { background: #1b1b22; }
.tooltip[data-side="right"] { transform: translateX(-2px); }
.tooltip.show { opacity: 1; transform: none; }
.tooltip kbd, kbd {
  font: 500 10.5px "JetBrains Mono", ui-monospace, monospace; padding: 1px 5px; border-radius: 4px;
  background: rgba(255, 255, 255, .12); color: inherit; opacity: .85; white-space: nowrap;
}
:root[data-theme="light"] .modal kbd, :root[data-theme="light"] .palette kbd { background: var(--panel-3); }

/* ---------- модальні вікна ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1500; display: grid; place-items: center; padding: 20px;
  background: rgba(5, 5, 10, .5); backdrop-filter: blur(1.5px); opacity: 0; transition: opacity .2s ease;
}
.modal-backdrop.open { opacity: 1; }
.modal-backdrop.closing { opacity: 0; }
.modal {
  max-width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: var(--shadow-lg);
  transform: scale(.96) translateY(8px); transition: transform .26s cubic-bezier(.2, .9, .3, 1.15);
}
.modal-backdrop.open .modal { transform: none; }
.modal-backdrop.closing .modal { transform: scale(.97); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px 18px; }
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-body { padding: 8px 18px 14px; overflow: auto; }
.modal-text { margin: 0; color: var(--muted); line-height: 1.55; font-size: 12.5px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px 16px; }
.field-col { display: flex; flex-direction: column; gap: 6px; }
.field-cap { color: var(--muted); }
.input { height: 34px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel-2); padding: 0 10px; outline: none; font-size: 13px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.palette-modal .modal-head { display: none; }
.palette-modal .modal-body { padding: 0; }
.palette-search { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); color: var(--muted); }
.palette-input { flex: 1; height: 50px; border: 0; background: transparent; outline: none; font-size: 15px; }
.palette-list { max-height: 380px; overflow: auto; padding: 6px; }
.palette-item { width: 100%; display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; }
.palette-item.active { background: var(--accent-soft); }
.palette-item.active .pi-icon { color: var(--accent); }
.palette-item.disabled { opacity: .4; }
.pi-icon { width: 18px; color: var(--muted); display: grid; place-items: center; }
.pi-label { flex: 1; }
.pi-group { color: var(--faint); font-size: 11px; }
.palette-empty { padding: 30px; text-align: center; color: var(--faint); }
.shortcuts { columns: 3 220px; column-gap: 28px; }
.sc-group { break-inside: avoid; margin-bottom: 18px; }
.sc-group h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.sc-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; color: var(--muted); border-bottom: 1px dashed var(--border); }
.sc-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.about { text-align: center; }
.about-logo { display: grid; place-items: center; margin: 4px 0 10px; animation: popIn .5s cubic-bezier(.3, 1.4, .5, 1); }
.about h3 { margin: 0 0 6px; font-size: 18px; }
.about p { color: var(--muted); line-height: 1.55; }
.about-list { text-align: left; color: var(--muted); line-height: 1.6; padding-left: 18px; }

/* ---------- сповіщення ---------- */
.toasts { position: fixed; left: 50%; bottom: 42px; transform: translateX(-50%); z-index: 2500; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 12px; padding: 9px 14px; border-radius: 10px; pointer-events: auto;
  background: #101014; color: #f2f2f5; border: 1px solid #2c2c34; box-shadow: var(--shadow-lg); font-size: 12.5px; max-width: 560px;
  opacity: 0; transform: translateY(10px) scale(.97); transition: opacity .22s ease, transform .3s cubic-bezier(.2, .9, .3, 1.2);
}
.toast.show { opacity: 1; transform: none; }
.toast.hide { opacity: 0; transform: translateY(4px) scale(.98); }
.toast.error { border-color: rgba(255, 92, 108, .5); }
.toast.error::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); flex: none; }
.toast-action { border: 0; background: none; color: var(--accent-hi); font-weight: 600; padding: 0; }

/* ---------- Code Studio ---------- */
.code-studio {
  position: fixed; inset: 0; z-index: 900; display: grid; grid-template-rows: 48px minmax(0, 1fr) 30px;
  background: var(--bg); opacity: 0; transform: translateY(14px); transition: opacity .25s ease, transform .3s cubic-bezier(.2, .8, .2, 1);
}
.code-studio.open { opacity: 1; transform: none; }
.cs-head { display: flex; align-items: center; gap: 14px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--border); }
.cs-title { display: flex; align-items: center; gap: 8px; color: var(--accent); white-space: nowrap; }
.cs-title b { color: var(--text); }
.cs-title span { color: var(--faint); }
.cs-tabs { display: flex; gap: 2px; padding: 3px; background: var(--panel-2); border-radius: 9px; }
.cs-tab { height: 26px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 600; font-size: 11.5px; letter-spacing: .04em; transition: all .15s; }
.cs-tab:hover { color: var(--text); }
.cs-tab.active { background: var(--panel-4); color: var(--text); }
.cs-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.switch.sm .switch-label { color: var(--muted); }
.cs-body { display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.cs-editor { display: flex; min-height: 0; background: var(--panel); border-right: 1px solid var(--border); }
.cs-gutter { margin: 0; padding: 14px 10px 14px 14px; color: var(--faint); text-align: right; overflow: hidden; user-select: none; border-right: 1px solid var(--border); min-width: 44px; }
.cs-code { position: relative; flex: 1; min-width: 0; }
.cs-gutter, .cs-highlight, .cs-input { font: 13px/1.6 "JetBrains Mono", ui-monospace, Consolas, monospace; tab-size: 2; }
.cs-highlight, .cs-input { position: absolute; inset: 0; margin: 0; padding: 14px 16px; white-space: pre; overflow: auto; }
.cs-highlight { pointer-events: none; color: var(--text); }
.cs-input { border: 0; outline: none; resize: none; background: transparent; color: transparent; caret-color: var(--accent); }
.cs-input::selection { background: var(--accent-ring); color: transparent; }
.tok-tag { color: var(--tok-tag); } .tok-attr { color: var(--tok-attr); } .tok-str { color: var(--tok-str); }
.tok-com { color: var(--tok-com); font-style: italic; } .tok-key { color: var(--tok-key); } .tok-num { color: var(--tok-num); } .tok-fn { color: var(--tok-fn); }
.cs-preview-wrap { display: flex; flex-direction: column; min-height: 0; padding: 14px; background: var(--canvas); }
.cs-preview-bar { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; background: var(--panel); border: 1px solid var(--border); border-bottom: 0; border-radius: 10px 10px 0 0; color: var(--muted); }
.cs-preview-bar b { margin-left: 8px; color: var(--text); font-weight: 600; }
.cs-preview-bar em { margin-left: auto; font-style: normal; color: var(--faint); font-size: 11px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.r { background: #ff5f57; } .dot.y { background: #febc2e; } .dot.g { background: #28c840; }
.cs-preview { flex: 1; width: 100%; border: 1px solid var(--border); border-radius: 0 0 10px 10px; background: #fff; box-shadow: var(--shadow-md); }
.cs-foot { display: flex; align-items: center; padding: 0 14px; color: var(--faint); font-size: 11px; background: var(--panel); border-top: 1px solid var(--border); }

/* ---------- адаптивність ---------- */
@media (max-width: 1100px) {
  .ob-hint { display: none; }
  .doc-title input { width: 180px; }
  .save-state span { display: none; }
}
@media (max-width: 860px) {
  .main { grid-template-columns: 48px 0 minmax(0, 1fr) var(--right-w); }
  .panel-left { opacity: 0; pointer-events: none; }
  .menubar .menu-btn:nth-child(n+3) { display: none; }
  .btn.ghost span { display: none; }
  .cs-body { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}
@media (max-width: 640px) {
  .main { grid-template-columns: 44px 0 minmax(0, 1fr) 0; }
  .panel-right { opacity: 0; pointer-events: none; }
  .doc-title { position: static; transform: none; }
  .doc-title input { width: 120px; }
  .top-actions .btn span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

.top-avatar { margin-left: 6px; padding: 0; border: 0; background: none; border-radius: 50%; display: grid; transition: transform .15s; }
.top-avatar:hover { transform: scale(1.08); }
.top-avatar .avatar { box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--border-strong); }

/* ---------- 0.13: бета-режим ---------- */
.beta-fab { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: none; align-items: center; gap: 8px; padding: 10px 16px; border: 0; border-radius: 999px; background: linear-gradient(135deg, #8b6cff, #ff6fb5); color: #fff; font: 600 13px/1 Inter, system-ui, sans-serif; box-shadow: 0 8px 24px rgba(139, 108, 255, .35); cursor: pointer; }
.beta-fab:hover { filter: brightness(1.08); }
.beta-fab:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
html[data-view="hub"] .beta-fab { display: inline-flex; }
.beta-fb { gap: 6px; }
.beta-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 12px; }
.beta-list li { display: grid; grid-template-columns: 18px 1fr; gap: 10px; align-items: start; font-size: 13px; line-height: 1.45; }
.beta-list li svg { margin-top: 2px; color: var(--accent, #8b6cff); }
.sup-send { display: grid; gap: 14px; }
.sup-send-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.sup-send-btns .btn { display: inline-flex; align-items: center; gap: 6px; }
.sup-send .sup-preview { max-height: 200px; overflow: auto; white-space: pre-wrap; }
