/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * Copyright © 2026 Marcel Rymenhout and IniqDash contributors */
/* ==========================================================================
   Theme Studio (components/editor/themestudio.js): the gallery, the preview bar and the three-pane editor.
   The editor's own chrome keeps the editor's look; only the preview / thumbnails are drawn with the theme being shown.
   ========================================================================== */

/* ---- gallery */
.ed-dlg--tgal { width: min(1180px, calc(100vw - 24px)); }
.tsg { display: flex; flex-direction: column; gap: 12px; }
.tsg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tsg-applied { margin: 0; font: 600 13.5px var(--font); color: var(--text-primary); }
.tsg-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tsg-msg:empty { display: none; }
.tsg-h { margin: 6px 0 0; font: 700 12px var(--font); letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.tsg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin: 0; padding: 0; list-style: none; }
.tsg-empty { grid-column: 1 / -1; }
.tsg-card { display: flex; flex-direction: column; gap: 9px; min-width: 0; padding: 10px; border-radius: 14px; background: var(--surface-secondary); box-shadow: inset 0 0 0 1px var(--border-primary); }
.tsg-card.is-applied { box-shadow: inset 0 0 0 2px var(--accent); }
.tsg-card__meta { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tsg-card__name b { font: 700 14px var(--font); color: var(--text-primary); }
.tsg-card__name input { width: 100%; box-sizing: border-box; }
.tsg-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tsg-tag { padding: 2px 7px; border-radius: 999px; font: 600 11px var(--font); color: var(--text-secondary); background: var(--surface-tertiary); }
.tsg-tag--dark { color: #e8e8ee; background: #2b2c33; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); }
.tsg-tag--light { color: #1d1d22; background: #f2f2f4; }
.tsg-tag--on { color: var(--accent-on); background: var(--accent); }
.tsg-pal { display: flex; border-radius: 7px; overflow: hidden; box-shadow: 0 0 0 1px var(--border-primary); }
.tsg-pal i { flex: 1; height: 14px; }
.tsg-card__btns { display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; }
.tsg-ovr h4 { margin: 8px 0 2px; font: 700 13px var(--font); }
.tsg-ovr ul { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.tsg-ovr li { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }

/* ---- thumbnail: a small dashboard drawn WITH the theme (its tokens on .tsg-th) */
.tsg-th { position: relative; display: flex; height: 132px; border-radius: 10px; overflow: hidden; background: var(--page-bg); box-shadow: 0 0 0 1px rgba(255, 255, 255, .08); font-family: var(--font); }
:where(.tsg-th i) { display: block; }
.tsg-th__nav { flex: none; width: 26px; display: flex; flex-direction: column; align-items: center; gap: 7px; padding-top: 10px; background: var(--nav-bg); }
.tsg-th__nav i { width: 12px; height: 12px; border-radius: 4px; background: var(--nav-inactive, var(--text-secondary)); opacity: .45; }
.tsg-th__nav i.is-on { opacity: 1; background: var(--nav-indicator, var(--accent)); }
.tsg-th__canvas { position: relative; flex: 1; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: min-content; gap: 6px; padding: 8px; background-color: var(--page-bg); }
.tsg-th__title { grid-column: 1 / -1; width: 38%; height: 7px; border-radius: 3px; background: var(--text-heading, var(--text-primary)); }
.tsg-th__card { display: flex !important; flex-direction: column; gap: 5px; min-height: 40px; padding: 7px; box-sizing: border-box; border-radius: calc(var(--radius-device) * .55); background: var(--device-surface); box-shadow: var(--device-shadow); }
.tsg-th__card--wide { grid-column: 1 / -1; min-height: 28px; flex-direction: row !important; align-items: center; justify-content: space-between; }
.tsg-th__l1 { width: 62%; height: 5px; border-radius: 3px; background: var(--text-primary); }
.tsg-th__l2 { width: 40%; height: 4px; border-radius: 3px; background: var(--text-secondary); }
.tsg-th__btn { width: 28px; height: 11px; border-radius: 6px; background: var(--accent); }
.tsg-th__track { height: 5px; border-radius: 3px; background: var(--slider-track, rgba(255, 255, 255, .14)); }
.tsg-th__track i { width: 60%; height: 100%; border-radius: 3px; background: var(--slider-fill, var(--accent)); }
.tsg-th__dots { display: flex !important; gap: 4px; }
.tsg-th__dots i { width: 8px; height: 8px; border-radius: 50%; }
.tsg-th__dots .is-ok { background: var(--success); } .tsg-th__dots .is-warn { background: var(--warning); } .tsg-th__dots .is-bad { background: var(--danger); }

/* ---- preview bar (a theme shown on the dashboard, not applied) */
.tsg-pbar { position: fixed; z-index: 2147483000; top: 12px; left: 50%; transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  max-width: calc(100vw - 24px); box-sizing: border-box; padding: 10px 12px 10px 16px; border-radius: 14px; font: 13px var(--font); color: #f1f1f3; background: #1b1c20;
  box-shadow: 0 0 0 1px rgba(110, 168, 255, .55), 0 18px 40px -12px rgba(0, 0, 0, .7); }
.tsg-pbar__t { flex: 1 1 220px; }

/* ---- the editor: properties · live preview · selected element */
.ed-dlg--tstudio { width: min(1560px, calc(100vw - 16px)); max-height: calc(100vh - 16px); }
.ed-dlg--tstudio .ecfg-body { padding-bottom: 0; }
.tst-titles { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tst-titles h3 { margin: 0; }
.tst-state-chip { padding: 3px 9px; border-radius: 999px; font: 700 11.5px var(--font); color: #0f2a17; background: #7fd99a; }
.tst-state-chip[data-dirty="true"] { color: #2a1a03; background: #ffc061; }
.tst-applied { font-size: 12px; color: var(--text-muted); }
.tst { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr) minmax(220px, 270px); gap: 14px; height: min(78vh, 860px); min-height: 0; }
.tst > * { min-height: 0; overflow: auto; }
.tst-props { padding-right: 4px; }
.tst-name { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.tst-props .ef-field.is-flash { animation: tst-flash 1.2s ease; }
@media (prefers-reduced-motion: reduce) { .tst-props .ef-field.is-flash { animation: none; box-shadow: 0 0 0 2px #6ea8ff; } }
@keyframes tst-flash { 0%, 60% { box-shadow: 0 0 0 2px #6ea8ff; border-radius: 8px; } 100% { box-shadow: none; } }
.tst-centre { display: flex; flex-direction: column; gap: 8px; }
.tst-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tst-sizes { display: inline-flex; gap: 4px; }
.tst-pvwrap { flex: 1; min-height: 0; overflow: auto; padding: 8px; border-radius: 14px; background: repeating-conic-gradient(#202126 0 25%, #1a1b1f 0 50%) 0 0 / 18px 18px; }
.tst-contrast[data-warn="true"] { color: var(--warning); }
.tst-info { display: flex; flex-direction: column; gap: 14px; padding: 12px; border-radius: 14px; background: var(--surface-secondary); box-shadow: inset 0 0 0 1px var(--border-primary); }
.tst-info h4 { margin: 0 0 4px; font: 700 11.5px var(--font); letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.tst-info__name { margin: 0 0 4px; font: 700 15px var(--font); color: var(--text-primary); }
.tst-info__count { margin: 6px 0 0; font-size: 12.5px; color: #9cc3ff; }
.tst-info__list { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.tst-info__row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 0; border-radius: 8px; font: 500 12.5px var(--font); text-align: left; color: var(--text-primary); background: var(--surface-tertiary); cursor: pointer; }
.tst-info__row:hover { background: var(--surface-interactive); }
.tst-info__row small { margin-left: auto; color: var(--text-muted); }
.tst-info__sw { flex: none; width: 16px; height: 16px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.tst-info__sw--look { background: linear-gradient(135deg, #888 50%, #444 50%); }

/* the live preview: real components, drawn with the theme (its tokens / look on .tst-pv) */
.tst-pv { position: relative; margin: 0 auto; width: 100%; max-width: 1100px; color: var(--text-primary); font-family: var(--font); }
.tst-pv[data-size="tablet"] { max-width: 720px; }
.tst-pv[data-size="mobile"] { max-width: 380px; }
.tst-pv * { cursor: default; }
.tst-pv.is-probing, .tst-pv.is-probing * { transition: none !important; animation: none !important; }
.tst-shell { display: flex; gap: 12px; padding: 10px; border-radius: 22px; background: var(--page-bg); }
.tst-pv .mnav { flex: none; align-self: flex-start; }
.tst-pv .mnav__list { flex-direction: column; }
.tst-pv[data-size="mobile"] .tst-shell { flex-direction: column-reverse; }
.tst-pv[data-size="mobile"] .mnav { align-self: stretch; }
.tst-pv[data-size="mobile"] .mnav__list { flex-direction: row; justify-content: space-around; }
.tst-canvas { position: relative; flex: 1; min-width: 0; padding: 16px; border-radius: 20px; background: var(--page-bg); box-shadow: 0 0 0 1px var(--border-subtle); }
.tst-head { margin: 2px 2px 14px; }
.tst-head .ed-dash-title { margin: 0; font-size: 20px; font-weight: 600; }
.tst-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--text-secondary); }
.tst-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 150px; gap: 12px; }
.tst-pv[data-size="tablet"] .tst-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tst-pv[data-size="mobile"] .tst-grid { grid-template-columns: minmax(0, 1fr); }
.tst-tile { position: relative; display: flex; min-width: 0; }
.tst-tile > * { flex: 1 1 auto; min-width: 0; }
.tst-tile--tall { grid-row: span 2; }
.tst-tile--panel { grid-column: span 2; }
.tst-tile--wide { grid-column: 1 / -1; height: auto; }
.tst-pv[data-size="mobile"] .tst-tile--panel { grid-column: auto; }
.tst-panel__txt { margin: 0; font-size: 13px; color: var(--text-secondary); }
.tst-states { display: flex; flex-wrap: wrap; align-content: center; gap: 8px; padding: 12px; border-radius: var(--radius-device); background: var(--device-surface); box-shadow: var(--device-shadow); }
.tst-state { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font: 600 12px var(--font); color: var(--tst-c); background: color-mix(in srgb, var(--tst-c) 14%, transparent); }
.tst-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--tst-c); }
.tst-controls { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding: 12px; box-sizing: border-box; border-radius: var(--radius-device); background: var(--device-surface); box-shadow: var(--device-shadow); }
.tst-controls__row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tst-controls__slider { position: relative; height: 22px; display: flex; align-items: center; }
.tst-controls__slider > input { flex: 1; }
.tst-pbtn, .tst-sbtn { padding: 6px 14px; border-radius: var(--radius-md); font: 700 12.5px var(--font); }
.tst-pbtn { color: var(--accent-on); background: var(--accent); box-shadow: var(--theme-glow, 0 0 0 transparent); }
.tst-sbtn { color: var(--button-fg, var(--text-primary)); background: var(--button-bg, var(--surface-tertiary)); box-shadow: inset 0 0 0 1px var(--border-primary); }
.tst-miss { display: grid; place-items: center; color: var(--text-muted); }
.tst-hl { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.tst-hl i { position: absolute; box-sizing: border-box; border-radius: 6px; }
.tst-hl .is-hit { outline: 2px dashed #6ea8ff; outline-offset: 1px; background: rgba(110, 168, 255, .1); }
.tst-hl .is-sel { outline: 2px solid #b49cff; outline-offset: 3px; }

@media (max-width: 1180px) {
  .tst { grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); height: auto; }
  .tst > * { max-height: 72vh; }
  .tst-info { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .tst { grid-template-columns: minmax(0, 1fr); }
  .tst > * { max-height: none; }
}
