/* ============================================================
   HTML to Image — html-to-image.css
   Prefix: hti-   Accent: #8B5CF6 (violet)   RGB: 139, 92, 246
   ============================================================ */

.hti-section {
    --accent: #8B5CF6;
    --accent-dark: #7C3AED;
    --accent-rgb: 139, 92, 246;
    padding: 40px 0 80px;
}

/* ── Workspace ─────────────────────────────────────────────── */
.hti-workspace {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================================
   Settings panel
   ============================================================ */
.hti-settings-panel {
    background: #FFFFFF;
    border: 1px solid rgba(100, 116, 139, 0.14);
    border-radius: 14px;
    overflow: hidden;
}

.hti-settings-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 11px 18px;
    border-bottom: 1px solid rgba(100, 116, 139, 0.08);
    flex-wrap: wrap;
}

.hti-settings-row:last-child {
    border-bottom: none;
}

.hti-row-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-light);
    min-width: 50px;
    flex-shrink: 0;
}

/* ── Presets row ────────────────────────────────────────────── */
.hti-presets-row {
    background: #F8FAFC;
}

.hti-preset-btns {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.hti-preset-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 8px;
    background: #FFFFFF;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s, box-shadow 0.15s;
    white-space: nowrap;
    line-height: 1.2;
}

.hti-preset-btn:hover {
    border-color: #8B5CF6;
    color: #8B5CF6;
    background: rgba(139, 92, 246, 0.04);
}

.hti-preset-btn--active {
    border-color: #8B5CF6;
    background: rgba(139, 92, 246, 0.08);
    color: #8B5CF6;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.12);
}

.hti-preset-dim {
    font-size: 0.6875rem;
    font-weight: 400;
    opacity: 0.65;
}

.hti-preset-sep {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    flex-shrink: 0;
    padding: 0 2px;
}

/* ── Dimensions ─────────────────────────────────────────────── */
.hti-dim-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.hti-num-input {
    width: 72px;
    padding: 6px 8px;
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 8px;
    background: #FFFFFF;
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    text-align: center;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.hti-num-input:focus {
    border-color: #8B5CF6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.hti-num-input:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.hti-opt-label {
    font-size: 0.78125rem;
    font-weight: 700;
    color: var(--text-secondary);
    white-space: nowrap;
}

.hti-opt-unit {
    font-size: 0.8125rem;
    color: var(--text-light);
}

.hti-dim-sep {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-light);
    margin: 0 2px;
}

/* Auto-height toggle */
.hti-auto-h-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    margin-left: 6px;
}

.hti-native-cb {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.hti-cb-track {
    display: inline-block;
    width: 34px;
    height: 18px;
    border-radius: 9px;
    background: rgba(100, 116, 139, 0.2);
    position: relative;
    flex-shrink: 0;
    transition: background 0.2s;
}

.hti-cb-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
    transition: left 0.2s;
}

.hti-native-cb:checked+.hti-cb-track {
    background: #8B5CF6;
}

.hti-native-cb:checked+.hti-cb-track::after {
    left: 19px;
}

.hti-cb-text {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* ── Output options row ─────────────────────────────────────── */
.hti-output-opts {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.hti-opt-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Tab group (scale + format) */
.hti-tab-group {
    display: flex;
    gap: 4px;
}

.hti-tab {
    padding: 5px 10px;
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 7px;
    background: #F8FAFC;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
}

.hti-tab:hover:not(.hti-tab--active):not(:disabled) {
    border-color: #8B5CF6;
    color: #8B5CF6;
}

.hti-tab--active {
    border-color: #8B5CF6;
    background: rgba(139, 92, 246, 0.1);
    color: #8B5CF6;
}

.hti-tab:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Quality slider */
.hti-val-badge {
    background: rgba(139, 92, 246, 0.12);
    color: #8B5CF6;
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 0.75rem;
    font-weight: 700;
}

.hti-quality-slider {
    width: 100px;
    appearance: none;
    -webkit-appearance: none;
    height: 4px;
    border-radius: 2px;
    background: rgba(100, 116, 139, 0.2);
    cursor: pointer;
    outline: none;
}

.hti-quality-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #8B5CF6;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(139, 92, 246, 0.35);
    transition: transform 0.1s;
}

.hti-quality-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

/* ── More options row (background + filename) ───────────────── */
.hti-more-opts {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.hti-color-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Background pill toggle */
.hti-bg-pill {
    display: inline-flex;
    border: 1px solid rgba(100, 116, 139, 0.25);
    border-radius: 8px;
    overflow: hidden;
}

.hti-bg-pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 11px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.hti-bg-pill-btn+.hti-bg-pill-btn {
    border-left: 1px solid rgba(100, 116, 139, 0.25);
}

.hti-bg-pill-btn.hti-bg-pill-active {
    background: #8B5CF6;
    color: #ffffff;
}

.hti-bg-pill-btn:not(.hti-bg-pill-active):hover {
    background: rgba(139, 92, 246, 0.08);
    color: #8B5CF6;
}

.hti-bg-pill-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.hti-bg-pill-swatch {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

/* Color input lives inside the pill button as an invisible overlay */
.hti-bg-pill-color-btn {
    position: relative;
}

.hti-color-input-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border: none;
    padding: 0;
}


.hti-color-input {
    width: 30px;
    height: 30px;
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 6px;
    padding: 2px;
    cursor: pointer;
    background: none;
    outline: none;
}

.hti-color-hex {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
}

.hti-filename-group {
    gap: 8px;
}

.hti-filename-wrap {
    display: flex;
    align-items: stretch;
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 8px;
    overflow: hidden;
    background: #FFFFFF;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.hti-filename-wrap:focus-within {
    border-color: #8B5CF6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.hti-filename-input {
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    width: 160px;
    outline: none;
}

.hti-filename-ext {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    background: #F8FAFC;
    border-left: 1px solid rgba(100, 116, 139, 0.14);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-light);
    white-space: nowrap;
    user-select: none;
}

/* ============================================================
   Render button (lives in editor header)
   ============================================================ */
.hti-btn-render {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #8B5CF6;
    color: #FFFFFF;
    border: none;
    border-radius: 7px;
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
    margin: 4px 0;
}

.hti-btn-render:hover {
    background: #7C3AED;
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.4);
}

.hti-btn-render:disabled {
    background: #94A3B8;
    box-shadow: none;
    cursor: not-allowed;
}

.hti-btn-reset {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    color: var(--text-light);
    border: 1px solid rgba(100, 116, 139, 0.25);
    border-radius: 7px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.18s, color 0.18s, border-color 0.18s;
    flex-shrink: 0;
}

.hti-btn-reset:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #EF4444;
    border-color: rgba(239, 68, 68, 0.3);
}

.hti-btn-copy,
.hti-btn-dl {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 18px;
    background: #FFFFFF;
    border: 1px solid rgba(100, 116, 139, 0.2);
    color: var(--text-primary);
    border-radius: 9px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    white-space: nowrap;
}

.hti-btn-copy:hover,
.hti-btn-dl:hover {
    border-color: #8B5CF6;
    color: #8B5CF6;
    background: rgba(139, 92, 246, 0.04);
}

/* ============================================================
   Progress bar
   ============================================================ */
.hti-render-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hti-render-wrap[hidden] {
    display: none;
}

.hti-render-bar {
    flex: 1;
    height: 6px;
    background: rgba(100, 116, 139, 0.14);
    border-radius: 3px;
    overflow: hidden;
}

.hti-render-fill {
    height: 100%;
    width: 0;
    background: #8B5CF6;
    border-radius: 3px;
    transition: width 0.4s ease;
}

.hti-render-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 140px;
}

/* ============================================================
   Split layout — editor | preview
   ============================================================ */
.hti-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: start;
}

/* ── Editor column ──────────────────────────────────────────── */
.hti-editor-col {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid rgba(100, 116, 139, 0.14);
    border-radius: 12px;
    overflow: hidden;
}

.hti-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #F8FAFC;
    border-bottom: 1px solid rgba(100, 116, 139, 0.12);
    padding: 0 6px 0 0;
}

.hti-editor-tabs {
    display: flex;
}

.hti-etab {
    padding: 10px 18px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px;
}

.hti-etab--active {
    border-bottom-color: #8B5CF6;
    color: #8B5CF6;
}

.hti-etab:hover:not(.hti-etab--active) {
    color: #8B5CF6;
}

/* Templates dropdown */
.hti-editor-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 6px;
}

.hti-tpl-wrap {
    position: relative;
    flex-shrink: 0;
}

.hti-tpl-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 7px;
    background: #FFFFFF;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    white-space: nowrap;
    margin: 4px 0;
}

.hti-tpl-btn:hover {
    border-color: #8B5CF6;
    color: #8B5CF6;
    background: rgba(139, 92, 246, 0.04);
}

.hti-caret {
    font-size: 0.6875rem;
    transition: transform 0.15s;
}

.hti-tpl-btn[aria-expanded="true"] .hti-caret {
    transform: rotate(180deg);
}

.hti-tpl-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 200;
    background: #FFFFFF;
    border: 1px solid rgba(100, 116, 139, 0.14);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    min-width: 180px;
    overflow: hidden;
    padding: 4px;
}

.hti-tpl-menu[hidden] {
    display: none;
}

.hti-tpl-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 7px;
    text-align: left;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
}

.hti-tpl-item i {
    color: #8B5CF6;
    font-size: 1rem;
    flex-shrink: 0;
}

.hti-tpl-item:hover {
    background: rgba(139, 92, 246, 0.06);
    color: #8B5CF6;
}

/* Editor panel */
.hti-editor-panel {
    display: flex;
    flex-direction: column;
}

/* CodeMirror 6 container */
.hti-editor-cm {
    width: 100%;
    min-height: 380px;
    overflow: hidden;
    border: none;
}

.hti-editor-cm .cm-editor {
    min-height: 380px;
    outline: none !important;
}

.hti-editor-cm .cm-editor.cm-focused {
    outline: 2px solid rgba(139, 92, 246, 0.3) !important;
    outline-offset: -2px;
}

.hti-editor-cm .cm-scroller {
    min-height: 380px;
    font-size: 0.8125rem;
    line-height: 1.65;
}

.hti-editor-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 14px;
    background: #F8FAFC;
    border-top: 1px solid rgba(100, 116, 139, 0.08);
    font-size: 0.875rem;
    color: var(--text-light);
    line-height: 1.5;
    margin: 0;
}

.hti-editor-hint i {
    color: #8B5CF6;
    font-size: 0.875rem;
    flex-shrink: 0;
}

/* ── Preview column ─────────────────────────────────────────── */
.hti-preview-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hti-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 2px;
}

.hti-preview-label {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0;
}

.hti-preview-hint {
    font-size: 0.75rem;
    color: var(--text-light);
    margin: 0;
    flex: 1;
    text-align: right;
}

.hti-preview-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.hti-btn-copy,
.hti-btn-dl {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid rgba(100, 116, 139, 0.3);
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, color 0.18s;
    white-space: nowrap;
}

.hti-btn-copy:not(:disabled):hover,
.hti-btn-dl:not(:disabled):hover {
    background: rgba(139, 92, 246, 0.08);
    border-color: #8B5CF6;
    color: #8B5CF6;
}

.hti-btn-copy:disabled,
.hti-btn-dl:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.hti-preview-box {
    border: 1px solid rgba(100, 116, 139, 0.14);
    border-radius: 12px;
    background: repeating-conic-gradient(#F1F5F9 0% 25%, #FFFFFF 0% 50%) 0 0 / 20px 20px;
    overflow: hidden;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hti-preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-light);
    padding: 40px 20px;
    text-align: center;
}

.hti-preview-empty i {
    font-size: 2.5rem;
    opacity: 0.3;
    display: block;
}

.hti-preview-empty p {
    font-size: 0.875rem;
    margin: 0;
}

.hti-preview-img {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 4px;
}

/* ============================================================
   Hidden render host (off-screen)
   ============================================================ */
.hti-render-host-wrap {
    position: fixed;
    top: -9999px;
    left: -9999px;
    pointer-events: none;
    z-index: -1;
}

.hti-render-iframe {
    border: none;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 960px) {
    .hti-split {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .hti-section {
        padding: 24px 0 60px;
    }

    .hti-settings-row {
        padding: 10px 12px;
        gap: 10px;
    }

    .hti-row-label {
        min-width: 42px;
    }

    /* Preset buttons */
    .hti-preset-btns {
        gap: 4px;
    }

    .hti-preset-btn {
        padding: 5px 8px;
        font-size: 0.75rem;
    }

    /* Scale + format tabs: tighter */
    .hti-tab {
        padding: 5px 8px;
        font-size: 0.75rem;
    }

    .hti-output-opts {
        gap: 8px;
    }

    .hti-more-opts {
        gap: 10px;
    }

    /* Filename: shrink input */
    .hti-filename-input {
        width: 100px;
    }

    /* ── Editor header: tabs on top row, actions on second row ── */
    .hti-editor-header {
        flex-wrap: wrap;
        padding: 0;
    }

    .hti-editor-tabs {
        flex: 1;
        min-width: 0;
    }

    .hti-editor-actions {
        width: 100%;
        box-sizing: border-box;
        border-top: 1px solid rgba(100, 116, 139, 0.1);
        padding: 5px 8px;
        justify-content: flex-end;
        gap: 5px;
    }

    /* Hide "Samples" text — keep icon + caret */
    .hti-tpl-text {
        display: none;
    }

    /* Render button: don't stretch */
    .hti-btn-render {
        flex-shrink: 0;
    }

    /* Editor min-height */
    .hti-editor-cm,
    .hti-editor-cm .cm-editor,
    .hti-editor-cm .cm-scroller {
        min-height: 260px;
    }

    /* ── Preview header: icon-only Copy/Download ── */
    .hti-btn-copy span,
    .hti-btn-dl span {
        display: none;
    }

    .hti-btn-copy,
    .hti-btn-dl {
        padding: 5px 8px;
    }

    /* Hide dimension hint — saves space */
    .hti-preview-hint {
        display: none;
    }
}

@media (max-width: 400px) {
    .hti-preset-btn {
        padding: 4px 6px;
        font-size: 0.7rem;
    }

    .hti-tab {
        padding: 4px 7px;
        font-size: 0.7rem;
    }

    .hti-etab {
        padding: 9px 13px;
        font-size: 0.8125rem;
    }

    .hti-num-input {
        width: 60px;
    }

    .hti-filename-input {
        width: 80px;
    }
}