/* THEME-EDITOR-1 - full-screen theme editor (#/themes/customize). Uses the admin's semantic tokens
   (tokens.css); flat surfaces, 1px borders, no gradients, no decorative motion. */
body.te-open { overflow: hidden; }
body.te-open #view-themes { padding: 0; }
.te { position: fixed; inset: 0; z-index: 150; display: flex; flex-direction: column; background: var(--color-bg); color: var(--color-text); font-size: 13px; line-height: 1.4; }
.te *, .te *::before, .te *::after { box-sizing: border-box; }
.te button, .te select, .te input, .te textarea { font: inherit; color: inherit; }
.te-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.te :focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* ---- toolbar ---- */
.te-bar { flex: none; height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--color-surface); border-bottom: 1px solid var(--color-border); }
.te-title { display: flex; align-items: center; gap: 8px; min-width: 0; margin-right: 4px; }
.te-title b { font-size: 14px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.te-live { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; background: var(--color-success-soft); color: var(--color-success-text); border: 1px solid var(--color-success-border); font-size: 11px; font-weight: 600; }
.te-live i { width: 6px; height: 6px; border-radius: 50%; background: var(--color-success); }
.te-ibtn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 0; border-radius: 3px; background: transparent; color: var(--color-text-secondary); cursor: pointer; text-decoration: none; flex: none; }
.te-ibtn:hover:not(:disabled) { background: var(--color-surface-muted); }
.te-ibtn:disabled { color: var(--color-text-placeholder); cursor: default; }
.te-ibtn.is-on { background: var(--color-primary-soft); color: var(--color-primary-hover); }
.te-ibtn.is-danger:hover:not(:disabled) { background: var(--color-danger-soft); color: var(--color-danger-text); }
.te-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; padding: 0 14px; border: 1px solid var(--color-border-strong); border-radius: 3px; background: var(--color-surface); color: var(--color-text); font-weight: 600; cursor: pointer; text-decoration: none; }
.te-btn:hover:not(:disabled) { background: var(--color-surface-muted); }
.te-btn.is-primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); }
.te-btn.is-primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.te-btn.is-danger { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.te-btn:disabled { opacity: .5; cursor: default; }
.te-sel select { height: 32px; padding: 0 28px 0 10px; border: 1px solid var(--color-border-strong); border-radius: 3px; background: var(--color-surface); max-width: 150px; }
.te-hist, .te-dev, .te-right { display: flex; align-items: center; gap: 2px; }
.te-dev { margin-left: auto; margin-right: auto; padding: 2px; background: var(--color-surface-muted); border-radius: 4px; }
.te-right { gap: 8px; }
.te-more { position: relative; }
.te-status { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text-muted); white-space: nowrap; }
.te-status.is-warn { background: var(--color-warning-soft); border-color: var(--color-warning-border); color: var(--color-warning-text); }
.te-status.is-bad { background: var(--color-danger-soft); border-color: var(--color-danger-border); color: var(--color-danger-text); }
.te-status.is-ok { color: var(--color-success-text); }
.te-menu { position: absolute; z-index: 20; right: 0; top: 36px; min-width: 190px; padding: 4px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 6px; box-shadow: 0 8px 24px rgba(15, 23, 42, .14); display: flex; flex-direction: column; }
.te-menu button, .te-menu a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 0; background: none; border-radius: 3px; text-align: left; cursor: pointer; color: var(--color-text); text-decoration: none; }
.te-menu button:hover:not(:disabled), .te-menu a:hover { background: var(--color-surface-muted); }
.te-menu button:disabled { color: var(--color-text-placeholder); cursor: default; }

/* ---- body ---- */
.te-body { flex: 1; min-height: 0; display: flex; }
.te-rail { width: 330px; flex: none; display: flex; flex-direction: column; background: var(--color-surface); border-right: 1px solid var(--color-border); min-height: 0; }
.te.rail-closed .te-rail { display: none; }
.te-tabs { display: flex; padding: 0 12px; border-bottom: 1px solid var(--color-border); gap: 16px; }
.te-tabs[hidden] { display: none; }
.te-tabs button { padding: 12px 0 10px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--color-text-muted); font-weight: 600; cursor: pointer; }
.te-tabs button.is-on { color: var(--color-text); border-bottom-color: var(--color-primary); }
.te-rail-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.te-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
.te-head { flex: none; display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 6px; border-bottom: 1px solid var(--color-border); }
.te-head b { flex: 1; min-width: 0; font-size: 14px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.te-head-actions { display: flex; gap: 0; }
.te-note { margin: 0 0 12px; color: var(--color-text-muted); font-size: 12.5px; }
.te-group { margin-bottom: 18px; }
.te-group h3 { margin: 0 0 6px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--color-text-muted); font-weight: 650; }
.te-list-ul, .te-blocks { list-style: none; margin: 0; padding: 0; }
.te-item { position: relative; border-radius: 4px; }
.te-item.is-drag { opacity: .45; }
.te-item.te-drop::before, .te-item.te-drop-end::after { content: ""; position: absolute; left: 0; right: 0; height: 2px; background: var(--color-primary); }
.te-item.te-drop::before { top: -1px; } .te-item.te-drop-end::after { bottom: -1px; }
.te-row { display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 2px 4px; border-radius: 4px; cursor: pointer; }
.te-row:hover { background: var(--color-surface-muted); }
.te-item.is-sel > .te-row, .te-block.is-sel > .te-row { background: var(--color-primary-soft); }
.te-item.is-hidden > .te-row .te-name { opacity: .55; }
.te-grip { width: 16px; color: var(--color-text-placeholder); cursor: grab; display: inline-flex; flex: none; }
.te-grip.is-off { cursor: default; visibility: hidden; }
.te-ico { display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; border-radius: 4px; background: var(--color-surface-muted); color: var(--color-text-secondary); flex: none; }
.te-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.te-name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.te-name em { font-style: normal; font-size: 11.5px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.te-blocks { margin: 0 0 4px 38px; border-left: 1px solid var(--color-border); }
.te-block .te-row { min-height: 30px; padding-left: 10px; }
.te-add { display: flex; align-items: center; gap: 6px; width: 100%; margin-top: 8px; padding: 8px 10px; border: 1px dashed var(--color-border-strong); border-radius: 4px; background: none; color: var(--color-primary-hover); font-weight: 600; cursor: pointer; }
.te-add:hover:not(:disabled) { background: var(--color-primary-soft); }
.te-add:disabled { color: var(--color-text-placeholder); cursor: default; }
.te-addblock { display: flex; flex-direction: column; gap: 0; }
.te-blocks-edit { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--color-border); }
.te-blocks-edit h4 { margin: 0 0 6px; font-size: 13px; }

/* ---- forms ---- */
.te-form { display: flex; flex-direction: column; gap: 14px; }
.te-field label, .te-label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 12.5px; }
.te-field input[type=text], .te-field textarea, .te-field select { width: 100%; padding: 7px 9px; border: 1px solid var(--color-border-strong); border-radius: 3px; background: var(--color-surface); }
.te-field textarea { resize: vertical; min-height: 84px; }
.te-help { margin: 4px 0 0; color: var(--color-text-muted); font-size: 12px; }
.te-warn { margin: 4px 0 0; color: var(--color-warning-text); font-size: 12px; }
.te-check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.te-check input { margin-top: 2px; }
.te-range { display: flex; align-items: center; gap: 10px; }
.te-range input { flex: 1; accent-color: var(--color-primary); }
.te-range output { min-width: 44px; text-align: right; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.te-color { display: flex; gap: 8px; align-items: center; }
.te-color input[type=color] { width: 36px; height: 32px; padding: 2px; border: 1px solid var(--color-border-strong); border-radius: 3px; background: var(--color-surface); cursor: pointer; }
.te-hex { width: 100%; max-width: 120px; padding: 7px 9px; border: 1px solid var(--color-border-strong); border-radius: 3px; font-family: var(--font-mono, monospace); }
.te-hex[aria-invalid=true] { border-color: var(--color-danger); }
.te-img { width: 100%; aspect-ratio: 16 / 9; border: 1px solid var(--color-border); border-radius: 4px; background: var(--color-surface-muted); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--color-text-placeholder); }
.te-img img { width: 100%; height: 100%; object-fit: cover; }
.te-img-actions { display: flex; gap: 8px; margin-top: 8px; }
.te-acc { border-bottom: 1px solid var(--color-border); padding: 4px 0 12px; margin-bottom: 8px; }
.te-acc summary { cursor: pointer; font-weight: 650; padding: 8px 0; list-style: none; display: flex; justify-content: space-between; }
.te-acc summary::after { content: "+"; color: var(--color-text-muted); }
.te-acc[open] summary::after { content: "-"; }
.te-acc summary::-webkit-details-marker { display: none; }

/* ---- stage ---- */
.te-stage { flex: 1; min-width: 0; position: relative; display: flex; justify-content: center; align-items: flex-start; padding: 12px; overflow: hidden; background: var(--color-surface-muted); }
.te-frame-host { position: relative; background: #fff; border: 1px solid var(--color-border); border-radius: 4px; overflow: hidden; flex: none; }
.te-frame-host.is-mobile { border-radius: 22px; border: 8px solid #111827; }
.te-frame-host iframe { display: block; border: 0; transform-origin: 0 0; background: #fff; }
.te-frame-load { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff; color: var(--color-text-muted); }
.te-fab { display: none; position: absolute; right: 16px; bottom: 16px; box-shadow: 0 4px 14px rgba(15, 23, 42, .25); }
.te.is-preview .te-rail, .te.is-preview .te-hist, .te.is-preview .te-status { display: none; }
.te.is-preview .te-stage { padding: 0; background: #fff; }

/* ---- modal ---- */
.te-modal { position: absolute; inset: 0; z-index: 30; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.te-modal-card { width: 460px; max-width: 100%; max-height: 90%; display: flex; flex-direction: column; background: var(--color-surface); border-radius: 8px; box-shadow: 0 24px 48px rgba(15, 23, 42, .3); }
.te-modal-card.is-wide { width: 560px; }
.te-modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 12px 8px 18px; font-size: 15px; }
.te-modal-body { padding: 4px 18px 14px; overflow-y: auto; }
.te-modal-body p { margin: 0 0 8px; }
.te-modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--color-border); }
.te-search { width: 100%; margin-bottom: 10px; padding: 8px 10px; border: 1px solid var(--color-border-strong); border-radius: 3px; }
.te-lib { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.te-lib-item { display: flex; gap: 10px; align-items: flex-start; width: 100%; padding: 8px; border: 0; border-radius: 4px; background: none; text-align: left; cursor: pointer; }
.te-lib-item:hover, .te-lib-item:focus-visible { background: var(--color-primary-soft); }
.te-lib-item b { display: block; font-weight: 600; } .te-lib-item em { font-style: normal; color: var(--color-text-muted); font-size: 12px; }
.te-list { margin: 0; padding-left: 18px; } .te-list li { margin-bottom: 4px; }
.te-vers { list-style: none; margin: 0 0 8px; padding: 0; }
.te-ver { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--color-border-soft); }
.te-ver em { display: block; font-style: normal; color: var(--color-text-muted); font-size: 12px; }
.te-pill { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--color-success-soft); color: var(--color-success-text); font-size: 11px; font-weight: 600; }

/* ---- loading / error ---- */
.te-loading, .te-fail { position: fixed; inset: 0; z-index: 150; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: var(--color-bg); color: var(--color-text-muted); text-align: center; padding: 24px; }
.te-fail h2 { margin: 0; color: var(--color-text); font-size: 18px; } .te-fail p { max-width: 460px; margin: 0; } .te-fail div { display: flex; gap: 8px; }
.te-spin { width: 18px; height: 18px; border: 2px solid var(--color-border-strong); border-top-color: var(--color-primary); border-radius: 50%; animation: te-spin .8s linear infinite; display: inline-block; }
@keyframes te-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .te-spin { animation-duration: 2.4s; } }

/* ---- narrow screens: rail becomes a bottom sheet ---- */
@media (max-width: 899px) {
  .te-bar { gap: 4px; padding: 0 6px; overflow-x: auto; }
  .te-title b, .te-live, .te-sel, .te-dev { display: none; }
  .te-status { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  .te-right { margin-left: auto; } .te-btn#tePreviewBtn { display: none; }
  .te-rail { position: absolute; left: 0; right: 0; bottom: 0; z-index: 10; width: auto; height: 62%; border-right: 0; border-top: 1px solid var(--color-border); box-shadow: 0 -8px 24px rgba(15, 23, 42, .18); }
  .te.rail-closed .te-fab { display: inline-flex; }
  .te-body { position: relative; }
  .te-modal-card, .te-modal-card.is-wide { width: 100%; }
}
