:root {
  --bg: #f4f3f0;
  --panel: #ffffff;
  --sunk: #ecebe7;
  --line: #e2e0db;
  --line-strong: #cfccc5;
  --fg: #1c1b19;
  --muted: #6d6a63;
  --faint: #9a968d;
  --accent: #ff5a1f;
  --accent-fg: #ffffff;
  --accent-soft: #fff0e9;
  --ink: #1c1b19;
  --ink-fg: #ffffff;
  --ok: #1f8a4c;
  --ok-soft: #e6f4ec;
  --warn: #a35a00;
  --warn-soft: #fdf1df;
  --bad: #c62f22;
  --bad-soft: #fbe9e7;
  --r: 10px;
  --r-sm: 7px;
  --shadow: 0 1px 2px rgba(28, 27, 25, .06), 0 8px 24px -12px rgba(28, 27, 25, .18);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514; --panel: #1f1e1c; --sunk: #2a2926; --line: #33312d; --line-strong: #46433d;
    --fg: #f1efe9; --muted: #a9a59b; --faint: #7d796f; --accent-soft: #3a2116;
    --ink: #f1efe9; --ink-fg: #161514; --ok-soft: #173023; --warn-soft: #34260f; --bad-soft: #3a1915;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161514; --panel: #1f1e1c; --sunk: #2a2926; --line: #33312d; --line-strong: #46433d;
  --fg: #f1efe9; --muted: #a9a59b; --faint: #7d796f; --accent-soft: #3a2116;
  --ink: #f1efe9; --ink-fg: #161514; --ok-soft: #173023; --warn-soft: #34260f; --bad-soft: #3a1915;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: inherit; }

/* ---------- buttons & fields ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 13px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s; }
.btn:hover { border-color: var(--faint); }
.btn:focus-visible, .field:focus-visible, .seg button:focus-visible, .item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { box-shadow: 0 4px 14px -6px var(--accent); }
.btn.ink { background: var(--ink); border-color: var(--ink); color: var(--ink-fg); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--sunk); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn.icon { width: 34px; padding: 0; }
.btn .badge { background: rgba(255,255,255,.25); border-radius: 99px; padding: 1px 7px; font-size: 11.5px; }
.btn:not(.primary) .badge { background: var(--accent); color: #fff; }

.field { width: 100%; height: 36px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--panel); }
textarea.field { height: auto; min-height: 70px; padding: 8px 10px; resize: vertical; }
select.field { padding-right: 6px; }
.label { display: grid; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.label > span { display: flex; justify-content: space-between; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--bad); font-size: 13px; min-height: 1em; margin: 0; }
.mono { font-family: var(--mono); font-size: 12px; }

.seg { display: inline-flex; background: var(--sunk); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; height: 28px; padding: 0 10px; border-radius: 5px; cursor: pointer; font-weight: 600; font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* ---------- login ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.auth h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.auth p { margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--ink); display: grid; place-items: center; flex: none; }
.logo svg { width: 18px; height: 18px; }

/* ---------- app shell ---------- */
.shell { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.topbar .sep { width: 1px; height: 24px; background: var(--line); flex: none; }
.status { font-size: 12.5px; color: var(--muted); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.status.dirty::before { background: var(--accent); }
.status.saving::before { background: var(--faint); }

.switcher { position: relative; }
.switcher > button { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 4px 8px 4px 4px; border-radius: var(--r-sm); cursor: pointer; max-width: 260px; }
.switcher > button:hover { background: var(--sunk); }
.switcher .pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher .chev { color: var(--muted); flex: none; }
.menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 50; min-width: 260px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 6px; display: grid; gap: 1px; }
.menu.right { left: auto; right: 0; }
.menu button { text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.menu button:hover { background: var(--sunk); }
.menu button[aria-current="true"] { font-weight: 700; }
.menu button[aria-current="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }
.menu .head { padding: 6px 10px 4px; font-size: 11.5px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }

.workspace { display: grid; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); min-height: 0; }
.stage { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--sunk); }
.stagebar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg); flex-wrap: wrap; }
.stagebar select { max-width: 320px; }
.framewrap { flex: 1; min-height: 0; display: flex; justify-content: center; padding: 12px; overflow: auto; }
.framewrap iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; box-shadow: var(--shadow); transition: width .2s; }
.framewrap.tablet iframe { width: 820px; flex: none; }
.framewrap.mobile iframe { width: 390px; flex: none; }
.hint { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--ink); color: var(--ink-fg); border-radius: 99px; padding: 7px 14px; font-size: 12.5px; font-weight: 600; pointer-events: none; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; padding: 24px; display: grid; gap: 12px; justify-items: center; }

/* ---------- side panel ---------- */
.panel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel .tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); }
.panel .tabs button { border: 0; background: transparent; padding: 8px 10px 10px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.panel .tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.pbody { flex: 1; overflow-y: auto; padding: 14px; display: grid; gap: 14px; align-content: start; }
.section { display: grid; gap: 10px; }
.section > h3 { margin: 0; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: grid; gap: 10px; background: var(--panel); }

.items { display: grid; gap: 4px; }
.item { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center; text-align: left; border: 1px solid transparent; background: transparent; border-radius: var(--r-sm); padding: 6px 8px; cursor: pointer; }
.item:hover { background: var(--sunk); }
.item.on { border-color: var(--accent); background: var(--accent-soft); }
.item .ico { width: 34px; height: 34px; border-radius: 6px; background: var(--sunk); display: grid; place-items: center; font: 700 11px var(--font); color: var(--muted); overflow: hidden; }
.item .ico img { width: 100%; height: 100%; object-fit: cover; }
.item .txt { min-width: 0; }
.item .txt b { display: block; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.item .txt span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.dirty .txt b::after { content: " • " attr(data-dirty); color: var(--accent); text-transform: none; letter-spacing: 0; }

.ed-head { display: flex; align-items: center; gap: 8px; }
.ed-head .kind { font-weight: 700; font-size: 15px; }
.ed-head .tag { font: 600 11px var(--mono); background: var(--sunk); color: var(--muted); padding: 2px 6px; border-radius: 5px; }
.toolbar { display: flex; gap: 2px; flex-wrap: wrap; border: 1px solid var(--line-strong); border-bottom: 0; border-radius: var(--r-sm) var(--r-sm) 0 0; padding: 4px; background: var(--bg); }
.toolbar button { border: 0; background: transparent; width: 30px; height: 28px; border-radius: 5px; cursor: pointer; font-weight: 700; }
.toolbar button:hover { background: var(--sunk); }
.rte { min-height: 90px; max-height: 340px; overflow-y: auto; border: 1px solid var(--line-strong); border-radius: 0 0 var(--r-sm) var(--r-sm); padding: 10px 12px; background: var(--panel); outline: none; line-height: 1.55; overflow-wrap: anywhere; }
.rte:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rte img { max-width: 100%; height: auto; }
.rte a { color: var(--accent); }

.stylegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.colorfield { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 3px; height: 36px; background: var(--panel); }
.colorfield input[type="color"] { width: 28px; height: 28px; border: 0; padding: 0; background: none; cursor: pointer; flex: none; }
.colorfield input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.colorfield input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(0,0,0,.15); border-radius: 5px; }
.colorfield input[type="text"] { border: 0; width: 100%; min-width: 0; background: transparent; font: 12px var(--mono); outline: none; }
.sizefield { display: flex; align-items: center; border: 1px solid var(--line-strong); border-radius: var(--r-sm); height: 36px; background: var(--panel); overflow: hidden; }
.sizefield input { border: 0; width: 100%; min-width: 0; text-align: center; background: transparent; outline: none; }
.sizefield button { border: 0; background: var(--bg); width: 32px; height: 100%; cursor: pointer; font-weight: 700; flex: none; }
.sizefield button:hover { background: var(--sunk); }
.imgprev { border-radius: var(--r-sm); background: var(--sunk) repeating-conic-gradient(var(--line) 0 25%, transparent 0 50%) 0 0 / 16px 16px; display: grid; place-items: center; min-height: 120px; max-height: 240px; overflow: hidden; }
.imgprev img { max-width: 100%; max-height: 240px; display: block; }
.imgprev.drop { position: relative; cursor: pointer; border: 2px dashed transparent; }
.imgprev.drop:hover, .imgprev.drop.over { border-color: var(--accent); }
.drop-hint { position: absolute; inset: auto 8px 8px 8px; display: flex; align-items: center; justify-content: center; gap: 6px; background: rgba(28,27,25,.78); color: #fff; font-size: 12px; font-weight: 600; padding: 6px 8px; border-radius: 6px; opacity: 0; transition: opacity .12s; pointer-events: none; }
.imgprev.drop:hover .drop-hint, .imgprev.drop.over .drop-hint { opacity: 1; }
.media { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.media-item { display: grid; gap: 4px; text-align: left; border: 1px solid var(--line); border-radius: var(--r); padding: 6px; background: var(--panel); cursor: pointer; min-width: 0; }
.media-item:hover { border-color: var(--accent); }
.media-thumb { aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; display: grid; place-items: center; background: var(--sunk) repeating-conic-gradient(var(--line) 0 25%, transparent 0 50%) 0 0 / 12px 12px; }
.media-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.media-name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.swatches { display: grid; gap: 6px; }
.swatch { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; padding: 6px; border-radius: var(--r-sm); border: 1px solid var(--line); }
.swatch label { width: 40px; height: 32px; border-radius: 6px; border: 1px solid rgba(0,0,0,.12); position: relative; cursor: pointer; overflow: hidden; }
.swatch label input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--sunk); color: var(--muted); }
.chip.new { background: var(--ok-soft); color: var(--ok); }
.chip.modified { background: var(--warn-soft); color: var(--warn); }
.chip.admin { background: var(--accent-soft); color: var(--accent); }

/* ---------- modal ---------- */
.scrim { position: fixed; inset: 0; background: rgba(20, 19, 17, .45); z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal { width: min(640px, 100%); max-height: calc(100vh - 32px); background: var(--panel); border-radius: 14px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.5); display: flex; flex-direction: column; overflow: hidden; }
.modal.wide { width: min(880px, 100%); }
.modal header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 17px; flex: 1; }
.modal .mbody { padding: 18px; overflow-y: auto; display: grid; gap: 14px; align-content: start; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 700; }
.table tr:last-child td { border-bottom: 0; }
.list { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; max-height: 320px; overflow-y: auto; }
.list button, .list div.li { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: var(--panel); padding: 9px 12px; cursor: pointer; }
.list div.li { cursor: default; }
.list > :last-child { border-bottom: 0; }
.list button:hover { background: var(--sunk); }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; font-family: var(--mono); font-size: 12.5px; }
.crumbs button { border: 0; background: transparent; padding: 3px 5px; border-radius: 4px; cursor: pointer; }
.crumbs button:hover { background: var(--sunk); }
.progress { height: 8px; border-radius: 99px; background: var(--sunk); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.note { border-radius: var(--r-sm); padding: 10px 12px; font-size: 13px; }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.qr { background: #fff; padding: 8px; border-radius: 8px; width: 160px; height: 160px; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--ink-fg); padding: 10px 18px; border-radius: 99px; z-index: 100; font-weight: 600; font-size: 13.5px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); color: #fff; }
.toast { display: flex; align-items: center; gap: 12px; }
.toast-act { border: 0; background: rgba(255,255,255,.18); color: inherit; font: inherit; font-weight: 700; padding: 4px 10px; border-radius: 99px; cursor: pointer; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { display: grid; justify-items: center; gap: 8px; padding: 18px 8px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--panel); cursor: pointer; font-weight: 600; color: var(--fg); }
.tile:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.only-wide { }
@media (max-width: 1100px) {
  .only-wide { display: none !important; }
}
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; }
  .grid2, .stylegrid { grid-template-columns: 1fr; }
  .shell { height: auto; min-height: 100%; }
}
