/* ==========================================================================
   ATL Theme Customizer — Preview Page Styles
   ========================================================================== */

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --ts-primary: #1E40AF;
    --ts-primary-hover: #1E3A8A;
    --ts-accent: #059669;
    --ts-bg: #F1F5F9;
    --ts-sidebar-bg: #FFFFFF;
    --ts-sidebar-width: 360px;
    --ts-header-height: 56px;
    --ts-border: #E2E8F0;
    --ts-text: #1E293B;
    --ts-text-muted: #64748B;
    --ts-radius: 8px;
    --ts-radius-lg: 12px;
    --ts-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --ts-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --ts-transition: 0.2s ease;
}

.ts-body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--ts-text);
    background: var(--ts-bg);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* ==========================================================================
   Header
   ========================================================================== */

.ts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--ts-header-height);
    padding: 0 20px;
    background: #FFFFFF;
    border-bottom: 1px solid var(--ts-border);
    z-index: 100;
    position: relative;
}

/* Page preview selector — centered in the top bar between brand and actions */
.ts-header__page {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 7px;
    max-width: 38%;
    padding: 6px 12px;
    background: #F5F7FA;
    border: 1px solid var(--ts-border);
    border-radius: 999px;
    transition: box-shadow .22s cubic-bezier(.4,0,.2,1), border-color .22s cubic-bezier(.4,0,.2,1), background .22s cubic-bezier(.4,0,.2,1);
}
.ts-header__page:hover,
.ts-header__page:focus-within {
    border-color: var(--ts-primary);
    box-shadow: 0 3px 12px rgba(30, 64, 175, 0.14);
    background: #FFFFFF;
}
.ts-header__page-icon { color: #64748B; flex-shrink: 0; }
.ts-header__page-select {
    border: 0;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    color: var(--ts-primary);
    cursor: pointer;
    padding: 0 20px 0 0;
    max-width: 100%;
    text-overflow: ellipsis;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right center;
    background-size: 12px;
}
.ts-header__page-select:focus { outline: none; }

.ts-header__page-select option { color: #1e293b; font-weight: 500; }
/* Below 901px the page selector is MOVED into the sidebar by
   relocatePageSelector() in preview.js rather than hidden. Hiding it outright
   meant phone and tablet users could only ever preview a template's homepage —
   42% of the catalogue has inner pages worth seeing. The class below is applied
   once it has been relocated, so it lays out as a full-width sidebar field. */
.ts-header__page.ts-header__page--in-sidebar {
    /* the header version is absolutely centred and capped at 38% — neither makes
       sense once it is a field in the sidebar */
    position: static;
    transform: none;
    left: auto;
    top: auto;
    max-width: none;
    width: 100%;
    margin: 0 0 14px;
    padding: 9px 14px;
    border-radius: 10px;
    box-sizing: border-box;
}
.ts-header__page.ts-header__page--in-sidebar .ts-header__page-select {
    /* the container is display:flex, so width:100% does not stretch a child that
       sizes to its content — it rendered 100px wide, too narrow to read a page
       name. flex:1 makes it claim the remaining space. */
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    color: var(--ts-text, #1e293b);
}

/* Quick Palettes CTA — pulled above the accordion, always visible */
.ts-palettes-cta {
    font-size: 12px;
    line-height: 1.45;
    color: #64748B;
    margin: 2px 0 8px;
}

.ts-header__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--ts-primary);
}

.ts-header__icon {
    flex-shrink: 0;
}

.ts-header__actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;          /* the buttons are the point; shrink the title instead */
}

/* At 320px the header wanted 424px: brand 177 + actions 247. The actions are the
   function (Reset / Purchase this Site) so they hold their size; the brand gives
   way. min-width:0 must sit on the BRAND — it is the flex item — since a flex item
   will not shrink below its content width without it. */
.ts-header__brand {
    min-width: 0;
    flex: 1 1 auto;
}

.ts-header__title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.ts-layout {
    display: grid;
    grid-template-columns: var(--ts-sidebar-width) 1fr;
    height: calc(100vh - var(--ts-header-height));
    position: relative;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.ts-sidebar {
    background: var(--ts-sidebar-bg);
    border-right: 1px solid var(--ts-border);
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    scrollbar-width: thin;
    scrollbar-color: #CBD5E1 transparent;
}

.ts-sidebar::-webkit-scrollbar {
    width: 6px;
}

.ts-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.ts-sidebar::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

.ts-sidebar__inner {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ==========================================================================
   Sections
   ========================================================================== */

.ts-section {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--ts-border);
}

.ts-section:last-child {
    border-bottom: none;
}

.ts-section__title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ts-text-muted);
    margin-bottom: 12px;
    padding-top: 12px;
}

/* ==========================================================================
   Template Cards
   ========================================================================== */

.ts-templates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    min-width: 0; /* allow children to shrink */
}

.ts-template-card {
    cursor: pointer;
    position: relative;
    min-width: 0; /* prevent long labels from pushing the grid wider than the sidebar */
    max-width: 100%;
    overflow: hidden;
}

.ts-template-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.ts-template-card__preview {
    position: relative;
    height: 48px;
    border-radius: var(--ts-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    transition: box-shadow var(--ts-transition), transform var(--ts-transition);
    border: 2px solid transparent;
    overflow: hidden;
}

/* Theme thumbnail overlays the color block */
.ts-template-card__thumb {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    display: block;
}
.ts-template-card__preview:has(.ts-template-card__thumb) {
    height: 96px;
}

/* -------- Accordions (Custom Colors / Quick Palettes) -------- */
.ts-accordion__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    text-align: left;
}
.ts-accordion__header .ts-section__title {
    margin: 0;
}
.ts-accordion__chevron {
    flex: 0 0 auto;
    transition: transform 0.28s ease;
    color: var(--ts-color-muted, #888);
}
.ts-accordion:not(.ts-accordion--open) .ts-accordion__chevron {
    transform: rotate(-90deg);
}
/* Animated collapse: grid-rows 1fr↔0fr smoothly animates auto-height content */
.ts-accordion__body {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.28s ease;
}
.ts-accordion:not(.ts-accordion--open) .ts-accordion__body {
    grid-template-rows: 0fr;
}
.ts-accordion__inner {
    overflow: hidden;
    min-height: 0;
    padding-top: 12px;
    transition: padding-top 0.28s ease;
}
/* Collapse the inner's own padding in sync with the row so nothing peeks at the top. */
.ts-accordion:not(.ts-accordion--open) .ts-accordion__inner {
    padding-top: 0;
}
.ts-accordion__hint {
    margin: 0 0 12px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--ts-color-muted, #888);
}
@media (prefers-reduced-motion: reduce) {
    .ts-accordion__body,
    .ts-accordion__inner,
    .ts-accordion__chevron { transition: none; }
}

/* -------- Guided steps (OS-quality accordion wizard) -------- */
.ts-step--hidden { display: none; }

/* Whole-step fold: locked/future steps collapse to nothing; unlocking folds them open. */
.ts-step {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.46s cubic-bezier(0.4, 0, 0.2, 1);
}
.ts-step--locked { grid-template-rows: 0fr; }
.ts-step__wrap {
    overflow: hidden;
    min-height: 0;
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--ts-border, #e5e7eb);
    transition: padding-bottom 0.46s cubic-bezier(0.4, 0, 0.2, 1), margin-bottom 0.46s cubic-bezier(0.4, 0, 0.2, 1);
}
.ts-step:last-of-type .ts-step__wrap { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
/* Locked/future steps: collapse the wrap's own bottom spacing in sync with the fold so nothing peeks. */
.ts-step--locked > .ts-step__wrap {
    padding-bottom: 0;
    margin-bottom: 0;
    border-bottom-color: transparent;
}

/* Header row — visible whenever the step is reachable (active or done). */
.ts-step__title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0 16px;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--ts-text, #1f2937);
    transition: color 0.32s ease, opacity 0.35s ease;
}
.ts-step--active > .ts-step__wrap > .ts-step__title {
    transform-origin: left center;
    animation: ts-step-title-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes ts-step-title-in {
    from { transform: scale(1.42); opacity: 0; }
    55%  { opacity: 1; }
    to   { transform: scale(1); opacity: 1; }
}
.ts-step__num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--ts-primary, #1e40af);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    transition: background 0.32s ease;
}
/* Completed step: greyed but visible; its header re-opens it. */
.ts-step--done > .ts-step__wrap > .ts-step__title { color: #94a3b8; cursor: pointer; }
.ts-step--done > .ts-step__wrap > .ts-step__title:hover { color: var(--ts-primary, #1e40af); }
.ts-step--done .ts-step__num { background: #cbd5e1; }
.ts-step--done > .ts-step__wrap > .ts-step__title:hover .ts-step__num { background: var(--ts-primary, #1e40af); }

/* Collapsible body — folds away when the step is done. */
.ts-step__body {
    display: grid;
    grid-template-rows: 1fr;
    opacity: 1;
    transition: grid-template-rows 0.42s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}
.ts-step__body-inner { overflow: hidden; min-height: 0; }
.ts-step--done .ts-step__body { grid-template-rows: 0fr; opacity: 0; }

/* "Change Selection" — springs into the header when a step is completed. */
.ts-step__change {
    margin-left: auto;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-3px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease 0.08s, transform 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) 0.08s;
}
.ts-step--done .ts-step__change { opacity: 1; transform: none; pointer-events: auto; }

/* Suppress transitions during first-paint state setup (avoids initial fold flash). */
.ts-steps--priming .ts-step,
.ts-steps--priming .ts-step__body,
.ts-steps--priming .ts-step__title,
.ts-steps--priming .ts-step__change { transition: none !important; animation: none !important; }

.ts-substep__title { margin-top: 4px; }
.ts-step__nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--ts-border, #e5e7eb);
}
.ts-step__nav .ts-step__next { margin-left: 0; }

/* Green background-save indicator, left of the Continue button.
   Sequence: slide+fade in → round arrow spins → check slams in → holds → fade+slide out. No display swaps. */
.ts-step__saving {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-left: auto;
    font-size: 0.78rem;
    font-weight: 600;
    color: #16A34A;
    white-space: nowrap;
    opacity: 0;
    transform: translateX(10px);
    pointer-events: none;
    transition: opacity 0.42s cubic-bezier(0.16, 1, 0.3, 1), transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: opacity, transform;
}
.ts-step__saving.is-saving,
.ts-step__saving.is-saved { opacity: 1; transform: none; }
/* Exit: even dissolve (easeInOutSine, not the front-loaded expo) so the visible fade is spread evenly,
   never a quick-drop-then-ghost. is-saved is kept during hide so the check stays put while it fades. */
.ts-step__saving.is-hiding {
    opacity: 0;
    transform: translateX(10px);
    transition: opacity 0.5s cubic-bezier(0.37, 0, 0.63, 1), transform 0.5s cubic-bezier(0.37, 0, 0.63, 1);
}

/* Icon slot — arrow and check overlaid so one crossfades into the other (no display swap). */
.ts-step__saving-icon {
    position: relative;
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
}
.ts-step__saving-arrow,
.ts-step__saving-check {
    position: absolute;
    inset: 0;
    width: 15px;
    height: 15px;
    color: #16A34A;
    transform-origin: 50% 50%;
}
/* Round arrow: OPACITY owns its fade; the spin animation OWNS transform → clean, uninterrupted rotation. */
.ts-step__saving-arrow {
    opacity: 0;
    transition: opacity 0.3s ease;
}
.ts-step__saving.is-saving .ts-step__saving-arrow {
    opacity: 1;
    animation: ts-spin 0.72s linear infinite;
}
.ts-step__saving.is-saved .ts-step__saving-arrow { opacity: 0; } /* crossfades out as the check slams in */

/* Check: hidden while saving; slams in with an overshoot + settle on completion. */
.ts-step__saving-check {
    opacity: 0;
    transform: scale(0.2);
}
.ts-step__saving.is-saved .ts-step__saving-check {
    animation: ts-check-slam 0.52s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes ts-check-slam {
    0%   { opacity: 0; transform: scale(2.2); }
    30%  { opacity: 1; }
    55%  { transform: scale(0.80); }
    75%  { transform: scale(1.08); }
    100% { opacity: 1; transform: scale(1); }
}
.ts-step__saving-label { transition: opacity 0.22s ease; }

@media (prefers-reduced-motion: reduce) {
    .ts-step__saving { transition: opacity 0.2s ease; transform: none; }
    .ts-step__saving.is-hiding { transform: none; }
    .ts-step__saving.is-saving .ts-step__saving-arrow { animation-duration: 1.6s; }
    .ts-step__saving.is-saved .ts-step__saving-check { animation: none; opacity: 1; transform: none; }
}

/* Outline button (Change Selection + morph target) — .ts-btn.ts-btn--outline beats .ts-btn{border:none} */
.ts-btn.ts-btn--outline {
    background: transparent;
    color: var(--ts-primary, #1e40af);
    border: 1.5px solid var(--ts-primary, #1e40af);
}
.ts-btn.ts-btn--outline:hover { background: rgba(30, 64, 175, 0.08); }

@media (prefers-reduced-motion: reduce) {
    .ts-step, .ts-step__wrap, .ts-step__body, .ts-step__title, .ts-step__num, .ts-step__change { transition: none; animation: none; }
}

.ts-template-card--active .ts-template-card__preview,
.ts-template-card input:checked ~ .ts-template-card__preview {
    border-color: var(--ts-primary);
    box-shadow: 0 0 0 2px rgba(30, 64, 175, 0.2);
}

.ts-template-card:hover .ts-template-card__preview {
    transform: translateY(-1px);
    box-shadow: var(--ts-shadow);
}

/* Hide the in-preview label — redundant now that the card name shows below */
.ts-template-card__label {
    display: none;
}

.ts-template-card__name {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--ts-text);
    text-align: center;
    margin-top: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    line-height: 1.3;
}

/* "More Templates" card */

.ts-template-card--more {
    cursor: pointer;
}

.ts-template-card__preview--more {
    border: 2px dashed var(--ts-border);
    background: transparent !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ts-text-muted);
    transition: border-color var(--ts-transition), color var(--ts-transition), background var(--ts-transition);
}

.ts-template-card--more:hover .ts-template-card__preview--more {
    border-color: var(--ts-primary);
    color: var(--ts-primary);
    background: #F0F4FF !important;
}

/* ==========================================================================
   Palette Group Tabs
   ========================================================================== */

.ts-palette-group-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 10px;
}

.ts-palette-group-tab {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--ts-border);
    border-radius: 14px;
    background: #FFFFFF;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.75rem;
    color: var(--ts-text-muted);
    transition: all var(--ts-transition);
    white-space: nowrap;
}

.ts-palette-group-tab:hover {
    border-color: var(--ts-primary);
    color: var(--ts-primary);
    background: #F0F4FF;
}

.ts-palette-group-tab--active {
    border-color: var(--ts-primary);
    background: var(--ts-primary);
    color: #FFFFFF;
    font-weight: 500;
}

.ts-palette-group-tab--active:hover {
    background: var(--ts-primary-hover);
    color: #FFFFFF;
}

/* Gradient swatch variant for the Gradient palette group */
.ts-preset-swatch--gradient {
    width: 34px;
    height: 14px;
    border-radius: 7px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

/* Receiver-not-responding warning banner */
.ts-receiver-warning {
    position: absolute;
    top: 20px;
    right: 20px;
    max-width: 380px;
    background: #FEF3C7;
    border: 1px solid #F59E0B;
    border-radius: 8px;
    padding: 14px 18px;
    font-size: 0.85rem;
    color: #78350F;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
    display: none;
}
.ts-receiver-warning strong { display:block; margin-bottom: 6px; font-size: 0.9rem; }
.ts-receiver-warning p { margin: 6px 0; }
.ts-receiver-warning ul { margin: 6px 0 10px 18px; }
.ts-receiver-warning li { margin: 2px 0; }
.ts-receiver-warning code { font-size: 0.78rem; background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 3px; }

/* ==========================================================================
   Preset Palettes
   ========================================================================== */

.ts-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ts-preset-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--ts-border);
    border-radius: 20px;
    background: #FFFFFF;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    color: var(--ts-text);
    transition: all var(--ts-transition);
    white-space: nowrap;
}

.ts-preset-btn:hover {
    border-color: var(--ts-primary);
    background: #F0F4FF;
}

.ts-preset-btn--active {
    border-color: var(--ts-primary);
    background: #EFF6FF;
    font-weight: 500;
}

.ts-preset-swatch {
    display: flex;
    gap: 2px;
}

.ts-preset-swatch__dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   Color Pickers
   ========================================================================== */

.ts-colors {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ts-color-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ts-color-row__label {
    flex: 1;
    font-size: 0.8rem;
    color: var(--ts-text);
    font-weight: 500;
}

.ts-color-row__picker {
    width: 32px;
    height: 32px;
    border: 2px solid var(--ts-border);
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    background: none;
}

.ts-color-row__picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.ts-color-row__picker::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.ts-color-row__picker::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

.ts-color-row__hex {
    width: 80px;
    font-size: 0.75rem;
    padding: 6px 8px;
    border: 1px solid var(--ts-border);
    border-radius: var(--ts-radius);
    font-family: 'SF Mono', 'Fira Code', monospace;
    text-transform: uppercase;
    color: var(--ts-text);
    background: #F8FAFC;
}

.ts-color-row__hex:focus {
    outline: none;
    border-color: var(--ts-primary);
    box-shadow: 0 0 0 2px rgba(30, 64, 175, 0.15);
}

/* ==========================================================================
   Form Fields
   ========================================================================== */

.ts-field {
    margin-bottom: 12px;
}

.ts-field:last-child {
    margin-bottom: 0;
}

.ts-field__label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--ts-text);
    margin-bottom: 4px;
}

.ts-field__select,
.ts-field__input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--ts-border);
    border-radius: var(--ts-radius);
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--ts-text);
    background: #FFFFFF;
    transition: border-color var(--ts-transition), box-shadow var(--ts-transition);
    -webkit-appearance: none;
    appearance: none;
}

.ts-field__select {
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

.ts-field__select:focus,
.ts-field__input:focus {
    outline: none;
    border-color: var(--ts-primary);
    box-shadow: 0 0 0 2px rgba(30, 64, 175, 0.15);
}

/* ==========================================================================
   Logo Upload
   ========================================================================== */

.ts-logo-upload__area {
    border: 2px dashed var(--ts-border);
    border-radius: var(--ts-radius-lg);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--ts-transition);
    background: #FAFBFC;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ts-logo-upload__area:hover,
.ts-logo-upload__area--dragover {
    border-color: var(--ts-primary);
    background: #F0F4FF;
}

.ts-logo-upload__icon {
    color: var(--ts-text-muted);
    margin-bottom: 8px;
}

.ts-logo-upload__text {
    font-size: 0.8rem;
    color: var(--ts-text-muted);
    line-height: 1.4;
}

.ts-logo-upload__text small {
    font-size: 0.7rem;
    opacity: 0.7;
}

.ts-logo-upload__preview {
    max-width: 200px;
    max-height: 80px;
    object-fit: contain;
    border-radius: 4px;
}

.ts-logo-upload--has-logo .ts-logo-upload__icon,
.ts-logo-upload--has-logo .ts-logo-upload__text {
    display: none;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.ts-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--ts-radius);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--ts-transition);
    white-space: nowrap;
}

.ts-btn--primary {
    background: var(--ts-primary);
    color: #FFFFFF;
}

.ts-btn--primary:hover {
    background: var(--ts-primary-hover);
}

.ts-btn--ghost {
    background: transparent;
    color: var(--ts-text-muted);
    border: 1px solid var(--ts-border);
}

.ts-btn--ghost:hover {
    background: #F1F5F9;
    color: var(--ts-text);
}

.ts-btn--small {
    padding: 4px 10px;
    font-size: 0.75rem;
}

.ts-btn--full {
    width: 100%;
    justify-content: center;
    padding: 12px 20px;
    font-size: 0.95rem;
}

.ts-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==========================================================================
   Preview Frame
   ========================================================================== */

.ts-main {
    position: relative;
    overflow: hidden;
}

.ts-preview-container {
    width: 100%;
    height: 100%;
    position: relative;
    background: #E2E8F0;
}

.ts-preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #FFFFFF;
    display: block;
}

.ts-preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--ts-bg);
    z-index: 10;
    gap: 16px;
    transition: opacity 0.3s ease;
}

.ts-preview-loading.ts-hidden {
    opacity: 0;
    pointer-events: none;
}

.ts-preview-loading p {
    color: var(--ts-text-muted);
    font-size: 0.9rem;
}

.ts-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--ts-border);
    border-top-color: var(--ts-primary);
    border-radius: 50%;
    animation: ts-spin 0.8s linear infinite;
}

@keyframes ts-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ==========================================================================
   Sidebar Toggle (Mobile)
   ========================================================================== */

.ts-sidebar-toggle {
    display: none;
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 200;
    width: 32px;
    height: 48px;
    border: none;
    border-radius: 0 8px 8px 0;
    background: var(--ts-primary);
    color: #FFFFFF;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: var(--ts-shadow);
    transition: left var(--ts-transition);
}

.ts-sidebar-toggle svg {
    transition: transform var(--ts-transition);
}

.ts-sidebar-toggle--open svg {
    transform: rotate(180deg);
}

/* ==========================================================================
   Modal
   ========================================================================== */

.ts-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.ts-modal {
    background: #FFFFFF;
    border-radius: var(--ts-radius-lg);
    padding: 32px;
    max-width: 480px;
    width: 100%;
    position: relative;
    box-shadow: var(--ts-shadow-lg);
    animation: ts-modal-in 0.2s ease;
}

@keyframes ts-modal-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ts-modal__close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    color: var(--ts-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background var(--ts-transition);
}

.ts-modal__close:hover {
    background: #F1F5F9;
}

.ts-modal__title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.ts-modal__desc {
    font-size: 0.9rem;
    color: var(--ts-text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

/* Wide Modal (Gallery) — near-window so themes can be compared side by side */

.ts-modal--wide {
    max-width: none;
    width: 94vw;
    height: 90vh;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 26px 30px 20px;
}
.ts-modal--wide .ts-modal__desc { margin-bottom: 16px; }

/* ==========================================================================
   Gallery Grid
   ========================================================================== */

.ts-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    max-height: none;
    flex: 1 1 auto;
    align-content: start;
    overflow-y: auto;
    padding: 4px;
    margin-bottom: 16px;
    scrollbar-width: thin;
    scrollbar-color: #CBD5E1 transparent;
}
@media (max-width: 900px) {
    .ts-gallery { grid-template-columns: 1fr; }
}

.ts-gallery::-webkit-scrollbar {
    width: 6px;
}

.ts-gallery::-webkit-scrollbar-track {
    background: transparent;
}

.ts-gallery::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

.ts-gallery-card {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: var(--ts-radius-lg);
    padding: 12px;
    transition: all var(--ts-transition);
    background: #FAFBFC;
}

.ts-gallery-card:hover {
    border-color: var(--ts-primary);
    box-shadow: var(--ts-shadow);
    background: #F0F4FF;
}

.ts-gallery-card--active {
    border-color: var(--ts-primary);
    background: #EFF6FF;
}

/* Carousel viewport — large preview so layouts are actually comparable */
.ts-gallery-card__preview {
    height: 300px;
    border-radius: var(--ts-radius);
    margin-bottom: 10px;
    position: relative;
    overflow: hidden;
    background: #E9EDF3;
}

.ts-carousel__track {
    display: flex;
    height: 100%;
    transition: transform 0.52s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}
.ts-carousel__slide {
    flex: 0 0 100%;
    height: 100%;
    background-size: cover;
    background-position: center top;
    background-repeat: no-repeat;
}

/* Slide arrows — fade/spring in on hover */
.ts-carousel__nav {
    position: absolute;
    top: 50%;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    color: #1E293B;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    opacity: 0;
    transform: translateY(-50%) scale(0.9);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    transition: opacity 0.24s ease, transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;
}
.ts-carousel__nav--prev { left: 8px; }
.ts-carousel__nav--next { right: 8px; }
.ts-gallery-card:hover .ts-carousel__nav,
.ts-gallery-card:focus-within .ts-carousel__nav { opacity: 1; transform: translateY(-50%) scale(1); }
.ts-carousel__nav:hover { background: #FFFFFF; transform: translateY(-50%) scale(1.14); }

/* Dots */
.ts-carousel__dots {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 5px;
    z-index: 2;
}
.ts-carousel__dot {
    width: 6px;
    height: 6px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.55);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: background 0.25s ease, width 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-radius 0.3s ease;
}
.ts-carousel__dot--active { background: #FFFFFF; width: 16px; border-radius: 3px; }

/* Page label (which demo page this slide shows) */
.ts-carousel__pagelabel {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    font-size: 0.62rem;
    font-weight: 600;
    color: #FFFFFF;
    background: rgba(0, 0, 0, 0.55);
    padding: 3px 8px;
    border-radius: 4px;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

@media (prefers-reduced-motion: reduce) {
    .ts-carousel__track, .ts-carousel__nav, .ts-carousel__dot, .ts-gallery-card { transition: none; }
}

.ts-gallery-card__label {
    font-size: 0.65rem;
    font-weight: 600;
    color: #FFFFFF;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 8px;
    border-radius: 4px;
}

.ts-gallery-card__badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7rem;
    font-weight: 600;
    color: #FFFFFF;
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 12px;
    border-radius: 12px;
    white-space: nowrap;
}

.ts-gallery-card__name {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ts-text);
}

.ts-gallery-card__desc {
    display: block;
    font-size: 0.7rem;
    color: var(--ts-text-muted);
    margin-top: 2px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Coming Soon cards */

.ts-gallery-card--soon {
    cursor: default;
    opacity: 0.6;
}

.ts-gallery-card--soon:hover {
    border-color: transparent;
    box-shadow: none;
    background: #FAFBFC;
}

/* Gallery CTA */

.ts-gallery__cta {
    text-align: center;
    padding-top: 4px;
}

/* ==========================================================================
   Form
   ========================================================================== */

.ts-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ts-form__error {
    padding: 10px 14px;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: var(--ts-radius);
    color: #DC2626;
    font-size: 0.85rem;
}

.ts-form__success {
    padding: 16px;
    background: #F0FDF4;
    border: 1px solid #BBF7D0;
    border-radius: var(--ts-radius);
    color: #16A34A;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ts-form__success svg {
    flex-shrink: 0;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1024px) {
    :root {
        --ts-sidebar-width: 300px;
    }
}

@media (max-width: 768px) {
    .ts-layout {
        grid-template-columns: 1fr;
    }

    .ts-sidebar {
        position: fixed;
        top: var(--ts-header-height);
        left: 0;
        width: 320px;
        height: calc(100vh - var(--ts-header-height));
        z-index: 150;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: var(--ts-shadow-lg);
    }

    .ts-sidebar--open {
        transform: translateX(0);
    }

    .ts-sidebar-toggle {
        display: flex;
    }

    .ts-sidebar-toggle--open {
        left: 320px;
    }

    .ts-header__actions {
        gap: 6px;
    }

    .ts-btn span.ts-btn__text-desktop {
        display: none;
    }

    .ts-modal {
        padding: 24px;
    }
}

@media (max-width: 600px) {
    .ts-modal--wide {
        max-width: 100%;
        margin: 10px;
    }

    .ts-gallery {
        grid-template-columns: 1fr;
        /* was 40vh — shorter than one card, so the modal showed a sliver of grid
           above a screenful of empty white. */
        max-height: 70vh;
    }
}

@media (max-width: 480px) {
    .ts-header {
        padding: 0 12px;
    }

    .ts-header__title {
        font-size: 0.95rem;
    }

    /* Below 480px even an ellipsised title cannot buy back enough room, so drop the
       wordmark and keep the icon. The two action buttons total 247px; on a 320px
       screen that leaves nothing for text nobody needs in order to use the tool. */
    .ts-header__title {
        display: none;
    }

    .ts-sidebar {
        width: 100%;
    }

    .ts-sidebar-toggle--open {
        left: calc(100% - 32px);
    }

    .ts-templates {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   Version Count Badge (on lead type cards)
   ========================================================================== */

.ts-template-card__version-count {
    display: block;
    font-size: 0.65rem;
    color: var(--ts-text-muted);
    text-align: center;
    margin-top: 2px;
}

/* Lead Type Cards — cursor pointer */

.ts-lead-type-card {
    cursor: pointer;
    position: relative;
}

.ts-lead-type-card .ts-template-card__preview {
    transition: box-shadow var(--ts-transition), transform var(--ts-transition);
    border: 2px solid transparent;
}

.ts-lead-type-card[data-active="true"] .ts-template-card__preview {
    border-color: var(--ts-primary);
    box-shadow: 0 0 0 2px rgba(30, 64, 175, 0.2);
}

.ts-lead-type-card:hover .ts-template-card__preview {
    transform: translateY(-2px);
    box-shadow: var(--ts-shadow-lg);
}

/* ==========================================================================
   Version Selector Modal
   ========================================================================== */

.ts-modal--versions {
    max-width: 860px;
}

.ts-version-grid {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding: 4px 0 12px;
    scrollbar-width: thin;
    scrollbar-color: #CBD5E1 transparent;
}

.ts-version-grid::-webkit-scrollbar {
    height: 6px;
}

.ts-version-grid::-webkit-scrollbar-track {
    background: transparent;
}

.ts-version-grid::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

.ts-version-card {
    flex: 0 0 260px;
    border: 2px solid var(--ts-border);
    border-radius: var(--ts-radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--ts-transition);
    background: #FFFFFF;
}

.ts-version-card:hover {
    border-color: var(--ts-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    transform: translateY(-4px);
}

.ts-version-card--active {
    border-color: var(--ts-primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.ts-version-card__thumb {
    position: relative;
    height: 160px;
    overflow: hidden;
    background: #E2E8F0;
}

.ts-version-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    display: block;
}

.ts-version-card__badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--ts-primary);
    color: #FFFFFF;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 12px;
    letter-spacing: 0.03em;
}

.ts-version-card__info {
    padding: 14px 16px 16px;
}

.ts-version-card__label {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ts-text);
    margin-bottom: 4px;
}

.ts-version-card__desc {
    font-size: 0.8rem;
    color: var(--ts-text-muted);
    line-height: 1.4;
    margin: 0 0 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ts-version-card__select {
    width: 100%;
    justify-content: center;
}

/* ==========================================================================
   Version Modal — Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .ts-modal--versions {
        max-width: 100%;
        margin: 10px;
    }

    .ts-version-grid {
        flex-direction: column;
        overflow-x: visible;
    }

    .ts-version-card {
        flex: 0 0 auto;
        width: 100%;
    }

    .ts-version-card__thumb {
        height: 140px;
    }
}

@media (max-width: 600px) {
    .ts-version-card__thumb {
        height: 120px;
    }
}

/* ── Lead Type × Industry Voice ───────────────────────────────────────────────
   Two context selectors side by side above the template gallery. They stack on
   narrow screens, where side-by-side selects leave neither wide enough to read a
   label like "REALTOR / Real Estate Agent (11)". */
.ts-facets {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.ts-facets .ts-field {
    flex: 1 1 200px;
    min-width: 0;
}

@media (max-width: 600px) {
    .ts-facets .ts-field {
        flex: 1 1 100%;
    }
}

/* The fallback-ladder notice. Deliberately visible rather than subtle: it is the
   difference between "closest available" and quietly showing someone a site
   written in the wrong professional voice. */
.ts-facet-note {
    margin: 10px 0 0;
    padding: 8px 12px;
    border-left: 3px solid var(--ts-accent, #E87722);
    background: rgba(232, 119, 34, 0.07);
    border-radius: 0 var(--ts-radius) var(--ts-radius) 0;
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--ts-text);
}

.ts-facet-note[hidden] {
    display: none;
}
