/* Customize Template Page Styles */

/* Minimal header bar */
.customizer-navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 20px;
    background: #000;
}

.back-link {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 6px;
    transition: all 0.2s;
    min-width: 100px;
}

.back-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.logo-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.header-logo {
    height: 36px;
    width: auto;
}

/* Full-viewport customizer layout */
.customizer-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Alert messages positioned at top */
.alert-container {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    min-width: 300px;
}

.alert-custom {
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 10px;
    display: none;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Main grid layout - takes remaining height */
.customizer-grid {
    display: grid;
    grid-template-columns: clamp(400px, 35vw, 620px) 1fr;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Left Panel: Customization Options */
.customizer-panel {
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.customizer-panel > form {
    flex: 1;
    overflow-y: auto;
    overflow-x: visible;
    padding: 0 24px 20px 24px;
}

/* Right Panel: Live Preview */
.preview-panel {
    background: #e5e7eb;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    position: relative;
}

.preview-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    flex-shrink: 0;
}

.preview-header-left {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-header-left .guide-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    padding: 0;
    cursor: pointer;
    transition: color 0.2s;
    vertical-align: middle;
}

.preview-header-left .guide-toggle-btn:hover {
    color: #fff;
}

.preview-header-left .guide-toggle-btn.guide-hidden {
    color: rgba(255, 255, 255, 0.5);
}

.preview-header-left .guide-toggle-btn.guide-hidden:hover {
    color: rgba(255, 255, 255, 0.85);
}

.preview-header-left .guide-toggle-btn i {
    font-size: 14px;
}

.preview-header-center {
    flex-shrink: 0;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.preview-header-center i {
    font-size: 11px;
}

.preview-header-right {
    flex: 1;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.zoom-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    transition: background 0.15s;
}

.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.zoom-level {
    min-width: 40px;
    text-align: center;
    font-size: 12px;
    color: #fff;
    font-weight: 500;
    user-select: none;
}

.preview-container {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

/* Wrapper accounts for scaled dimensions - dimensions set by JS via PREVIEW_CONFIG */
.preview-frame-wrapper {
    flex-shrink: 0;
    overflow: hidden; /* Prevent any overflow from scaled iframe */
}

/* Full-page preview scaled to fit - scale calculated dynamically by JS */
.preview-frame {
    border: none;
    border-radius: 2px;
    background: #ffffff;
    box-shadow:
        0 2px 4px rgba(0,0,0,0.1),
        0 8px 16px rgba(0,0,0,0.1);
    transform-origin: top left;
    overflow: hidden; /* Prevent iframe scrollbars */
    /* transform: scale() is set dynamically by applyPreviewDimensions() */
}

/* Collapsible Sections */
.section-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 12px 20px;
    margin: 0 -24px 16px -24px;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: opacity 0.2s;
}

.section-header:first-of-type {
    margin-top: 0;
}

.section-header:hover {
    opacity: 0.95;
}

.section-header.collapsed {
    margin-bottom: 0;
    opacity: 0.85;
}

.section-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.section-header h3 i {
    margin-right: 8px;
}

.section-icon {
    transition: transform 0.3s;
    font-size: 16px;
    color: rgba(255,255,255,0.9);
}

.section-header.collapsed .section-icon {
    transform: rotate(-90deg);
}

.section-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s;
    opacity: 1;
    padding-bottom: 8px;
    /* Left/right padding to accommodate highlight effect (negative margins on form-group) */
    padding-left: 10px;
    padding-right: 10px;
    margin-left: -10px;
    margin-right: -10px;
}

.section-content.collapsed {
    max-height: 0;
    opacity: 0;
    padding-bottom: 0;
}

/* Template Details section needs visible overflow for dropdown */
#templateDetailsSection,
#templateDetailsSection .section-content {
    overflow: visible !important;
}

/* Ensure Template Details dropdown appears above sibling sections and selection banner */
#templateDetailsSection {
    position: relative;
    z-index: 100;
}

/* Subsequent sections should have lower stacking context */
#pageSettingsSection,
#headerFooterSection,
#dynamicControlsContainer {
    position: relative;
    z-index: 1;
}

.form-section {
    margin-bottom: 8px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 5px;
    color: #555;
    font-size: 12px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.form-group input[type="color"] {
    height: 36px;
    cursor: pointer;
    padding: 4px;
}

/* Textarea styling for header/footer editors */
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.form-group textarea::placeholder {
    color: #aaa;
    font-style: italic;
}

.help-box {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 6px;
    font-size: 11px;
    color: #666;
    margin-top: 12px;
}

.help-box ul {
    margin: 8px 0 0 0;
    padding-left: 18px;
}

.help-box li {
    margin-bottom: 4px;
}

.help-box code {
    background: #e9ecef;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 10px;
}

/* Font selector styling */
.font-selector {
    font-size: 14px;
    padding: 10px 12px;
    height: auto;
    line-height: 1.4;
}

.font-selector option {
    padding: 8px 12px;
    font-size: 15px;
}

/* Base template dropdown */
#baseTemplateDropdown {
    z-index: 1060 !important;
    max-height: 450px;
    overflow: visible;
    padding: 0;
}

#baseTemplateDropdown .category-pill.active {
    background-color: #667eea !important;
    color: #fff !important;
    border-color: #667eea !important;
}

#baseTemplateDropdown .dropdown-header {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 10;
    padding: 10px 12px;
    border-bottom: 1px solid #dee2e6;
}

#baseTemplateDropdown #templateListContainer {
    max-height: 350px;
    overflow-y: auto;
}

.color-input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.color-input-group input[type="color"] {
    width: 44px;
    flex-shrink: 0;
}

.color-input-group input[type="text"] {
    flex: 1;
    min-width: 0; /* Allow text input to shrink */
}

/* Transparent toggle checkbox styling */
.transparent-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.transparent-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.transparent-indicator {
    width: 24px;
    height: 24px;
    border: 2px solid #ccc;
    border-radius: 4px;
    /* Checkerboard pattern for transparency indicator */
    background-image:
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
    background-color: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.transparent-toggle:hover .transparent-indicator {
    border-color: #999;
}

.transparent-toggle input[type="checkbox"]:checked + .transparent-indicator {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.25);
}

.transparent-toggle input[type="checkbox"]:checked + .transparent-indicator::after {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 14px;
    font-weight: bold;
    color: #667eea;
    background: rgba(255, 255, 255, 0.85);
}

/* Disabled state for color picker when transparent is selected */
.color-picker-disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.color-input-group input[type="text"]:disabled {
    background-color: #f5f5f5;
    color: #888;
    cursor: not-allowed;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-grid h4 {
    grid-column: 1 / -1;
    margin: 12px 0 4px;
    font-size: 13px;
    font-weight: 600;
    color: #444;
}

/* Checkbox styling for toggle controls */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    padding: 8px 0;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #667eea;
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-label span {
    font-weight: 500;
}

/* Radio button group styling */
.radio-group {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #555;
    padding: 6px 10px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.radio-label:hover {
    background-color: #f5f5f5;
}

.radio-label input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: #667eea;
    cursor: pointer;
    flex-shrink: 0;
}

.radio-label input[type="radio"]:checked + span {
    color: #667eea;
    font-weight: 500;
}

/* Action Buttons - sticky at bottom */
.btn-group-custom {
    display: flex;
    gap: 10px;
    padding: 16px 24px;
    background: white;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.btn-custom {
    flex: 1;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 14px;
}

.btn-primary-custom {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary-custom:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-secondary-custom {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary-custom:hover {
    background: #e0e0e0;
}

.loading-spinner {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(255,255,255,0.95);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 200;
}

/* Getting Started Guide Panel */
/* Hidden by default - JS shows it only for first-time visitors */
/* Positioned as an overlay so it never affects preview container sizing */
.customizer-guide {
    display: none;
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 600px;
    z-index: 50;
    padding: 10px 32px 10px 12px;
    align-items: flex-start;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.customizer-guide .info-icon {
    font-size: 0.9rem;
    margin-right: 8px;
    margin-top: 2px;
    margin-bottom: 6px;
    color: #8B5CF6;
    flex-shrink: 0;
}

.customizer-guide .info-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.customizer-guide .info-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #7C3AED;
    margin-bottom: 4px;
}

.customizer-guide .info-steps {
    margin: 0;
    padding-left: 20px;
    color: #6B7280;
    font-size: 0.75rem;
    line-height: 1.5;
    list-style-position: outside;
}

.customizer-guide .info-steps li {
    margin-bottom: 3px;
    padding-left: 4px;
}

.customizer-guide .info-steps li:last-child {
    margin-bottom: 0;
}

.customizer-guide .info-steps strong {
    color: #7C3AED;
    font-weight: 500;
}

.customizer-guide .info-tutorial-link {
    font-size: 0.8rem;
    color: #6B7280;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    padding-top: 8px;
}

.customizer-guide .info-tutorial-link a {
    color: #7C3AED;
    font-weight: 500;
    text-decoration: underline;
}

/* Close button - sits on top of everything */
.guide-dismiss-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    color: #6B7280;
    cursor: pointer;
    font-size: 14px;
    z-index: 100;
    transition: all 0.15s;
    padding: 0;
    line-height: 1;
}

.guide-dismiss-btn:hover {
    background: #fff;
    color: #374151;
    border-color: rgba(0, 0, 0, 0.2);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.guide-dismiss-btn:active {
    background: #f3f4f6;
    transform: scale(0.95);
}


/* Section Help Trigger */
.section-help-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    vertical-align: middle;
}

.section-help-trigger:hover,
.section-help-trigger:focus {
    opacity: 1;
}

.section-help-trigger i {
    font-size: 14px;
}

/* Section Help Popover Styling (same pattern as header help popover) */
.section-help-popover {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 8px;
    width: 300px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1100;
    text-align: left;
    font-weight: normal;
}

.section-help-popover.show {
    opacity: 1;
    visibility: visible;
}

.section-help-popover::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid #667eea;
}

.section-help-popover-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    padding: 10px 14px;
    border-radius: 10px 10px 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.section-help-popover-body {
    padding: 12px 14px;
    color: #444;
    line-height: 1.5;
    font-size: 13px;
}

.section-help-popover-body p {
    margin: 0 0 10px 0;
}

.section-help-popover-body p:last-child {
    margin-bottom: 0;
}

.section-help-popover-body ul {
    margin: 6px 0 10px 0;
    padding-left: 18px;
}

.section-help-popover-body li {
    margin-bottom: 4px;
}

.section-help-popover-body .help-tip {
    background: #f0f4ff;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 12px;
    color: #5a6fd6;
    margin-top: 10px;
}

.section-help-popover-body .help-tip i {
    margin-right: 4px;
}

/* Responsive handling */
@media (max-width: 1024px) {
    .customizer-grid {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .customizer-panel {
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
    }
}

/* Premium lock overlay - covers the customizer panel */
.customizer-lock-overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(1px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.customizer-lock-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 16px;
    padding: 24px 36px;
    box-shadow: 0 4px 24px rgba(102, 126, 234, 0.18);
    color: #667eea;
    font-weight: 600;
    font-size: 15px;
    pointer-events: none;
}

.customizer-lock-badge i {
    font-size: 36px;
}

/* Transparent click-blocker over the preview iframe */
.preview-lock-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    cursor: pointer;
    background: transparent;
}
