/* ─────────────────────────────────────────────────────────────────
   styler.css — Theme Editor Panel
   Scoped under .styler-* to avoid collisions with the host page.
   Relies on CMS tokens (--cms-*) for its own chrome where possible.
───────────────────────────────────────────────────────────────── */

/* ── Floating trigger ─────────────────────────────────────────── */

.styler-trigger {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--main-color, #2c4135);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.22), 0 1px 4px rgba(0, 0, 0, 0.12);
    z-index: 9000;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.2s ease,
        background 0.2s ease;
    outline: none;
}

.styler-trigger:hover {
    transform: scale(1.12) rotate(28deg);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

.styler-trigger:focus-visible {
    box-shadow: 0 0 0 3px var(--main-color, #2c4135), 0 0 0 5px rgba(255, 255, 255, 0.8);
}

/* ── Backdrop overlay ─────────────────────────────────────────── */

.styler-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 9001;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.styler-overlay.open {
    opacity: 1;
    pointer-events: all;
}

/* ── Main panel ───────────────────────────────────────────────── */

.styler-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    height: 100dvh;
    z-index: 9002;
    display: flex;
    flex-direction: column;
    background: var(--cms-surface-1, #f0efeb);
    box-shadow: -6px 0 40px rgba(0, 0, 0, 0.14);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    /* Reset host-page styles that might leak in */
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    color: #1a1a1a;
    line-height: 1.5;
}

.styler-panel.open {
    transform: translateX(0);
}

/* ── Panel header ─────────────────────────────────────────────── */

.styler-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 18px 20px 14px;
    background: var(--cms-surface-3, #fff);
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
    flex-shrink: 0;
    gap: 12px;
}

.styler-header-left {
    flex: 1;
    min-width: 0;
}

.styler-header-left .cms-tagline {
    margin: 0 0 2px;
}

.styler-header-left .cms-section-title {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.styler-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-top: 2px;
}

/* Dirty indicator dot next to save */
.styler-dirty-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    background: var(--cms-warning, #ff9500);
    border-radius: 50%;
    margin-left: 5px;
    vertical-align: middle;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.styler-dirty-dot.visible {
    opacity: 1;
}

/* ── Search bar ───────────────────────────────────────────────── */

.styler-search-wrap {
    padding: 10px 20px;
    background: var(--cms-surface-3, #fff);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

/* ── Preview toggle bar ───────────────────────────────────────── */

.styler-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
    font-size: 12px;
    color: #555;
}

.styler-preview-bar.previewing {
    background: rgba(255, 149, 0, 0.08);
    border-color: rgba(255, 149, 0, 0.2);
    color: var(--cms-warning, #ff9500);
}

/* ── Scrollable body ──────────────────────────────────────────── */

.styler-body {
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 20px 16px;
    scroll-behavior: smooth;
}

.styler-body::-webkit-scrollbar {
    width: 4px;
}

.styler-body::-webkit-scrollbar-track {
    background: transparent;
}

.styler-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.13);
    border-radius: 2px;
}

/* ── Alert area ───────────────────────────────────────────────── */

#styler-alert-area .cms-alert {
    margin-bottom: 12px;
}

/* ── Token row ────────────────────────────────────────────────── */

.styler-token {
    padding: 12px 0 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.055);
    position: relative;
    transition: background 0.15s ease;
}

.styler-token:last-child {
    border-bottom: none;
}

.styler-token-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

/* Modified indicator — orange dot in the left gutter */
.styler-token::before {
    content: '';
    position: absolute;
    left: -16px;
    top: 18px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--cms-warning, #ff9500);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.styler-token.styler-token-changed::before {
    opacity: 1;
}

/* Variable name tag */
.styler-var-name {
    display: inline-block;
    font-size: 10px;
    font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
    color: var(--cms-brand, #2c4135);
    opacity: 0.45;
    margin-top: 5px;
    cursor: pointer;
    transition: opacity 0.15s ease;
    user-select: none;
    letter-spacing: 0.01em;
}

.styler-var-name:hover {
    opacity: 0.9;
}

.styler-var-name::after {
    content: ' ⎘';
    font-style: normal;
}

/* ── No-results state ─────────────────────────────────────────── */

.styler-empty {
    text-align: center;
    padding: 32px 0;
    font-size: 13px;
    color: #999;
}

/* ── Footer action bar ────────────────────────────────────────── */

.styler-footer {
    flex-shrink: 0;
    padding: 12px 20px;
    background: var(--cms-surface-3, #fff);
    border-top: 1px solid rgba(0, 0, 0, 0.07);
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}

.styler-footer .cms-btn:first-child {
    margin-right: auto;
    /* push reset to the left */
}

/* ── Section overrides (tighter inside the panel) ─────────────── */

.styler-panel .cms-form-section {
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
    background: var(--cms-surface-3, #fff);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.styler-panel .cms-form-section-body {
    padding: 0 14px 4px;
}

.styler-panel .cms-field {
    margin-bottom: 0;
    padding-bottom: 0;
}

.styler-panel .cms-label {
    font-size: 12.5px;
}

.styler-panel .cms-muted {
    font-size: 11px;
    line-height: 1.4;
    margin-bottom: 6px;
}

.styler-panel .cms-color-field {
    gap: 8px;
}

/* ── Responsive: full-width on mobile ─────────────────────────── */

@media (max-width: 480px) {
    .styler-panel {
        width: 100dvw;
        border-radius: 0;
    }

    .styler-trigger {
        bottom: 20px;
        right: 16px;
    }
}