/* Moret admin: "Edit in Place" */
:root {
  --bg: #111113; --panel: #18181c; --canvas: #0c0c0e; --line: #2c2c32; --text: #efefec; --muted: #a09fa4;
  --field: #111113; --accent: #eb6165; --accent-ink: #111113; --ok: #5fc48a; --warn: #f0b44c; --danger: #ff7a7d;
  --sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif; --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eeeeec; --panel: #ffffff; --canvas: #e3e3df; --line: #dcdcd7; --text: #141416; --muted: #5c5c62; --field: #f7f7f5; --danger: #c8383c; --ok: #1f8a4c; --warn: #9a6400;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #eeeeec; --panel: #ffffff; --canvas: #e3e3df; --line: #dcdcd7; --text: #141416; --muted: #5c5c62; --field: #f7f7f5; --danger: #c8383c; --ok: #1f8a4c; --warn: #9a6400;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono-label { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.logo-light { display: none; }
:root[data-theme="light"] .logo-light { display: inline; } :root[data-theme="light"] .logo-dark { display: none; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .logo-light { display: inline; } :root:not([data-theme="dark"]) .logo-dark { display: none; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-weight: 500; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.06); }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.icon-btn { width: 36px; padding: 0; }

/* Sign-in */
body.login { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.login-card img { height: 26px; width: auto; align-self: flex-start; }
.login-card h1 { margin: 8px 0 0; font-size: 24px; }
.login-card p { margin: 0; color: var(--muted); }
.login-card .btn { min-height: 46px; }
.login-error { color: var(--danger) !important; }
.login-card .dev { font-size: 13px; color: var(--muted); text-align: center; }

/* Shell */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { flex: 0 0 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .left, .topbar .right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .logo { height: 20px; width: auto; }
.topbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }
.topbar select { min-height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); padding: 0 10px; max-width: 200px; }
.seg { display: flex; padding: 3px; border-radius: 9px; background: var(--bg); }
.seg button { border: 0; background: transparent; color: var(--muted); min-height: 30px; padding: 0 12px; border-radius: 7px; cursor: pointer; font-weight: 500; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--text); }
.save-state { font-size: 12px; color: var(--muted); min-width: 70px; text-align: right; }
.save-state.err { color: var(--danger); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent-ink); color: var(--accent); font-size: 12px; font-weight: 600; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 12px 32px rgba(0,0,0,.25); display: flex; flex-direction: column; }
.menu button, .menu a { all: unset; cursor: pointer; padding: 8px 10px; border-radius: 6px; }
.menu button:hover, .menu a:hover, .menu button:focus-visible, .menu a:focus-visible { background: var(--bg); }
.menu .who { padding: 8px 10px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

.workspace { flex: 1; display: flex; min-height: 0; }
.tree { flex: 0 0 236px; overflow: auto; padding: 14px 10px 24px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 18px; }
.tree .group { display: flex; flex-direction: column; gap: 2px; }
.tree .group > .mono-label { padding: 0 8px 6px; display: flex; justify-content: space-between; align-items: center; }
.tree-item { all: unset; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; color: var(--muted); min-height: 20px; }
.tree-item:hover { color: var(--text); }
.tree-item[aria-current="true"] { background: var(--bg); color: var(--text); font-weight: 500; }
.tree-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); flex: none; }
.tree-item .off { font-size: 11px; color: var(--muted); }
.tree-add { all: unset; cursor: pointer; margin-top: 6px; padding: 7px 8px; border-radius: 6px; border: 1px dashed var(--line); color: var(--muted); text-align: center; }
.tree-add:hover { color: var(--text); border-color: var(--muted); }
.add-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 6px; }
.add-menu button { all: unset; cursor: pointer; padding: 6px 8px; border-radius: 6px; background: var(--bg); font-size: 12.5px; }
.add-menu button:hover { outline: 1px solid var(--muted); }

.stage { flex: 1 1 auto; min-width: 0; background: var(--canvas); display: flex; flex-direction: column; }
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 16px; font-size: 12px; color: var(--muted); }
.stage-bar a { color: var(--muted); }
.frame-wrap { flex: 1; min-height: 0; padding: 0 16px 16px; display: flex; justify-content: center; }
.frame-wrap iframe { width: 100%; height: 100%; border: 0; border-radius: 10px; background: #08080a; transition: width .25s; }
.frame-wrap.phone iframe { width: 390px; max-width: 100%; }

.inspector { flex: 0 0 380px; overflow: auto; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.insp-head { position: sticky; top: 0; z-index: 2; background: var(--panel); padding: 16px 16px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.insp-head h2 { margin: 0; font-size: 18px; line-height: 1.25; }
.insp-head .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.insp-head .tools { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs { display: flex; gap: 18px; }
.tabs button { all: unset; cursor: pointer; padding: 8px 0 10px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs button[aria-selected="true"] { color: var(--text); border-color: var(--accent); }
.insp-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.insp-empty { padding: 32px 20px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.insp-empty strong { color: var(--text); font-size: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .lbl { font-weight: 500; font-size: 13px; }
.field .help { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--danger); }
.field .ok { font-size: 12px; color: var(--ok); }
.inp, .field input[type=text], .field input[type=number], .field input[type=url], .field select, .field textarea { width: 100%; min-height: 38px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--field); }
.field textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; font-weight: 500; font-size: 13px; }
.toggle input { appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; cursor: pointer; flex: none; margin: 0; transition: background .2s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(16px); }
.chipset { display: flex; flex-wrap: wrap; gap: 6px; }
.chipset label { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.chipset label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.chipset input { accent-color: var(--accent); margin: 0; }

.img-field { display: flex; gap: 10px; align-items: center; }
.thumb { width: 72px; height: 54px; border-radius: 6px; background: var(--bg) center / cover no-repeat; border: 1px solid var(--line); flex: none; }
.img-field .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.img-grid .cell { position: relative; aspect-ratio: 4 / 3; border-radius: 6px; background: var(--bg) center / cover no-repeat; border: 1px solid var(--line); }
.img-grid .cell .x { position: absolute; top: 3px; right: 3px; display: none; gap: 2px; }
.img-grid .cell:hover .x, .img-grid .cell:focus-within .x { display: flex; }
.img-grid .cell .x button { width: 22px; height: 22px; padding: 0; border-radius: 5px; border: 0; background: rgba(0,0,0,.7); color: #fff; cursor: pointer; font-size: 12px; }
.img-grid .add { all: unset; cursor: pointer; aspect-ratio: 4 / 3; border-radius: 6px; border: 1px dashed var(--line); display: grid; place-items: center; color: var(--muted); font-size: 20px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.list-item > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-weight: 500; }
.list-item > summary::-webkit-details-marker { display: none; }
.list-item > summary .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item > summary .mini { display: flex; gap: 2px; }
.list-item > summary .mini button { width: 26px; height: 26px; padding: 0; border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--muted); }
.list-item > summary .mini button:hover { background: var(--panel); color: var(--text); }
.list-item .inner { padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 12px; }
.list-item .field input, .list-item .field textarea, .list-item .field select { background: var(--panel); }

.code-note { font-size: 12.5px; color: var(--muted); padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
.code { width: 100%; min-height: 220px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--field); font: 12.5px/1.6 var(--mono); tab-size: 2; white-space: pre; overflow: auto; resize: vertical; }
.yt-preview { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); }
.yt-preview img { width: 96px; border-radius: 6px; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Modal */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 16px; }
.modal { width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; }
.modal.small { width: min(440px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 17px; }
.modal .body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.lib button { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); }
.lib button .im { aspect-ratio: 4 / 3; border-radius: 8px; background: var(--bg) center / cover no-repeat; border: 2px solid transparent; }
.lib button:hover .im, .lib button:focus-visible .im { border-color: var(--accent); }
.lib button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop { border: 1px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); color: var(--text); }
.changes { margin: 0; padding-left: 18px; color: var(--muted); }
.rev { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rev small { color: var(--muted); display: block; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 1180px) { .tree { flex-basis: 200px; } .inspector { flex-basis: 340px; } }
@media (max-width: 980px) {
  .workspace { flex-direction: column; overflow: auto; }
  .tree { flex: none; border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; max-height: 40vh; }
  .tree .group { flex: 1 1 200px; }
  .stage { flex: none; height: 70vh; }
  .inspector { flex: none; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .topbar .hide-sm { display: none; }
}
