/**
 * Aaima Section Editor Styles
 */

/* Section Editor Container */
.aaima-section-editor {
    background: #f0f0f1;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}

.section-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ddd;
}

.section-editor-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.business-type-badge {
    background: #2271b1;
    color: #fff;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

/* Sections List */
.aaima-sections-list {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.aaima-section-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #eee;
    background: #fff;
    gap: 12px;
}

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

.aaima-section-item:hover {
    background: #f9f9f9;
}

.aaima-section-item.disabled {
    opacity: 0.5;
}

.aaima-section-item.ui-sortable-helper {
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    border-radius: 6px;
}

.section-placeholder {
    background: #e8f4fc !important;
    border: 2px dashed #2271b1 !important;
    height: 50px;
    border-radius: 6px;
}

/* Drag Handle */
.section-drag-handle {
    cursor: grab;
    color: #999;
    padding: 5px;
}

.section-drag-handle:hover {
    color: #2271b1;
}

.section-drag-handle svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* Section Icon */
.section-icon-wrap {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.section-icon-wrap.hero { background: linear-gradient(135deg, #f093fb, #f5576c); }
.section-icon-wrap.categories { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.section-icon-wrap.products { background: linear-gradient(135deg, #43e97b, #38f9d7); }
.section-icon-wrap.services { background: linear-gradient(135deg, #a18cd1, #fbc2eb); }
.section-icon-wrap.social { background: linear-gradient(135deg, #fa709a, #fee140); }
.section-icon-wrap.cta { background: linear-gradient(135deg, #ff9a9e, #fecfef); }

/* Section Info */
.section-info {
    flex: 1;
    min-width: 0;
}

.section-title {
    font-weight: 600;
    color: #1d2327;
    font-size: 14px;
    margin: 0 0 2px;
}

.section-type {
    font-size: 10px;
    font-weight: 500;
    color: #fff;
    background: #72aee6;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 8px;
    vertical-align: middle;
}

.section-subtitle {
    font-size: 12px;
    color: #757575;
    margin: 0;
}

/* Section Controls */
.section-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Toggle Switch */
.section-toggle {
    position: relative;
}

.section-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.section-toggle .toggle-slider {
    display: inline-block;
    width: 40px;
    height: 22px;
    background: #ccc;
    border-radius: 22px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.section-toggle .toggle-slider:before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.section-toggle input:checked + .toggle-slider {
    background: #2271b1;
}

.section-toggle input:checked + .toggle-slider:before {
    transform: translateX(18px);
}

/* Action Buttons */
.section-actions {
    display: flex;
    gap: 4px;
}

.section-action-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: #f0f0f1;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
    transition: all 0.2s;
}

.section-action-btn:hover {
    background: #e0e0e0;
}

.section-action-btn.edit-btn:hover {
    background: #e8f4fc;
    color: #2271b1;
}

.section-action-btn.delete-btn:hover {
    background: #fcf0f1;
    color: #d63638;
}

.section-action-btn svg {
    width: 16px;
    height: 16px;
}

/* Add Section Button */
.add-section-wrap {
    margin-top: 16px;
    text-align: center;
}

.add-section-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: #fff;
    border: 2px dashed #c3c4c7;
    border-radius: 8px;
    color: #666;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.add-section-btn:hover {
    border-color: #2271b1;
    color: #2271b1;
    background: #f0f6fc;
}

.add-section-btn svg {
    width: 18px;
    height: 18px;
}

/* Empty State */
.sections-empty-state {
    padding: 50px 20px;
    text-align: center;
    background: #fff;
    border-radius: 8px;
}

.sections-empty-state h4 {
    margin: 10px 0 5px;
    color: #1d2327;
}

.sections-empty-state p {
    margin: 0;
    color: #666;
}

/* =============================================
   MODAL STYLES
   ============================================= */
#section-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100000;
    display: none;
}

#section-modal-backdrop.open {
    display: block;
}

#section-modal-box {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    width: 750px;
    max-width: 95%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    z-index: 100001;
    display: none;
    flex-direction: column;
}

/* Wider modal for Add Section */
#section-modal-box.add-section-mode {
    width: 900px;
}

#section-modal-box.open {
    display: flex;
}

#section-modal-box .modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f5f5f5;
    border-radius: 8px 8px 0 0;
    flex-shrink: 0;
}

#section-modal-box .modal-header h3,
#section-modal-box .modal-header .modal-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1d2327;
}

#section-modal-box #modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#section-modal-box #modal-close:hover {
    color: #d63638;
}

#section-modal-box .modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    max-height: calc(90vh - 140px);
}

#section-modal-box .modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #f5f5f5;
    border-radius: 0 0 8px 8px;
    flex-shrink: 0;
}

/* Modal Form */
.modal-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.field-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field-row label {
    font-weight: 500;
    font-size: 13px;
    color: #1d2327;
}

.field-row input[type="text"],
.field-row input[type="number"],
.field-row input[type="url"],
.field-row select,
.field-row textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}

.field-row input:focus,
.field-row select:focus,
.field-row textarea:focus {
    border-color: #2271b1;
    outline: none;
    box-shadow: 0 0 0 1px #2271b1;
}

.field-row input[type="color"] {
    width: 80px;
    height: 36px;
    padding: 2px;
    cursor: pointer;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.field-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.field-row textarea {
    min-height: 70px;
    resize: vertical;
}

.modal-field {
    margin-bottom: 16px;
}

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

.modal-field label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: #1d2327;
    font-size: 13px;
}

.modal-field input[type="text"],
.modal-field input[type="number"],
.modal-field input[type="url"],
.modal-field select,
.modal-field textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.modal-field input:focus,
.modal-field select:focus,
.modal-field textarea:focus {
    border-color: #2271b1;
    outline: none;
    box-shadow: 0 0 0 1px #2271b1;
}

.modal-field input[type="color"] {
    width: 80px;
    height: 36px;
    padding: 2px;
    cursor: pointer;
}

.modal-field .checkbox-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-field .checkbox-wrap input {
    width: 18px;
    height: 18px;
}

/* Field Divider */
.field-divider {
    margin: 24px 0 16px;
    padding: 10px 0 8px;
    border-bottom: 2px solid #2271b1;
    position: relative;
}

.field-divider:first-child {
    margin-top: 0;
}

.field-divider span {
    background: #2271b1;
    color: #fff;
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 3px;
    letter-spacing: 0.5px;
    letter-spacing: 0.5px;
}

/* Add Section Modal - Categories (Legacy) */
.section-categories {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.section-category h4 {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

/* Legacy Add Section Grid */
.section-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.section-grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 12px;
    background: #f8f9fa;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: #1d2327;
    min-height: 50px;
}

.section-grid-item:hover {
    background: #e8f4fc;
    border-color: #2271b1;
    color: #2271b1;
}

/* ============================================
   NEW IMPROVED SECTION PICKER
   ============================================ */

.add-section-modal {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 70vh;
}

/* Search Bar */
.section-search-bar {
    position: relative;
    display: flex;
    align-items: center;
    background: #f0f2f5;
    border-radius: 10px;
    padding: 0 16px;
    transition: all 0.2s;
}

.section-search-bar:focus-within {
    background: #fff;
    box-shadow: 0 0 0 2px #2271b1;
}

.section-search-bar svg {
    width: 20px;
    height: 20px;
    color: #8c8f94;
    flex-shrink: 0;
}

.section-search-bar input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 12px;
    font-size: 14px;
    outline: none;
    color: #1d2327;
}

.section-search-bar input::placeholder {
    color: #8c8f94;
}

.section-search-bar .search-clear {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #dcdcde;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    color: #50575e;
    transition: all 0.2s;
}

.section-search-bar .search-clear:hover {
    background: #c3c4c7;
    color: #1d2327;
}

/* Category Tabs */
.section-category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
}

.cat-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid #dcdcde;
    border-radius: 20px;
    background: #fff;
    font-size: 13px;
    font-weight: 500;
    color: #50575e;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.cat-tab .tab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
}

.cat-tab .tab-icon svg {
    width: 14px;
    height: 14px;
}

.cat-tab .cat-count {
    background: #f0f0f1;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    color: #646970;
}

.cat-tab:hover {
    border-color: var(--tab-color, #2271b1);
    color: var(--tab-color, #2271b1);
}

.cat-tab:hover .tab-icon svg {
    stroke: var(--tab-color, #2271b1);
}

.cat-tab.active {
    background: var(--tab-color, #2271b1);
    border-color: var(--tab-color, #2271b1);
    color: #fff;
}

.cat-tab.active .tab-icon svg {
    stroke: #fff;
}

.cat-tab.active .cat-count {
    background: rgba(255,255,255,0.25);
    color: #fff;
}

/* Section Picker Grid */
.section-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    overflow-y: auto;
    max-height: calc(70vh - 160px);
    padding-right: 8px;
}

.section-picker-grid::-webkit-scrollbar {
    width: 6px;
}

.section-picker-grid::-webkit-scrollbar-track {
    background: #f0f0f1;
    border-radius: 3px;
}

.section-picker-grid::-webkit-scrollbar-thumb {
    background: #c3c4c7;
    border-radius: 3px;
}

.section-picker-grid::-webkit-scrollbar-thumb:hover {
    background: #8c8f94;
}

/* Section Picker Item */
.section-picker-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.section-picker-item:hover {
    border-color: #2271b1;
    background: #f8fbfd;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.section-picker-item.is-added {
    background: #f0f7f0;
    border-color: #43a047;
}

.section-picker-item.is-added:hover {
    background: #e8f5e9;
}

/* Picker Item Icon */
.picker-item-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--icon-color, #667eea), color-mix(in srgb, var(--icon-color, #667eea), #000 20%));
    border-radius: 10px;
    flex-shrink: 0;
}

.picker-item-icon svg {
    width: 22px;
    height: 22px;
    stroke: #fff;
}

/* Picker Item Content */
.picker-item-content {
    flex: 1;
    min-width: 0;
}

.picker-item-title {
    font-size: 14px;
    font-weight: 600;
    color: #1d2327;
    margin: 0 0 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.picker-item-desc {
    font-size: 12px;
    color: #646970;
    margin: 0;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Added Badge */
.added-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: #43a047;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Add Button */
.picker-item-add {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f1;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s;
    flex-shrink: 0;
}

.picker-item-add svg {
    width: 18px;
    height: 18px;
    stroke: #2271b1;
}

.section-picker-item:hover .picker-item-add {
    opacity: 1;
    transform: scale(1);
    background: #2271b1;
}

.section-picker-item:hover .picker-item-add svg {
    stroke: #fff;
}

/* No Results */
.section-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #646970;
}

.section-no-results svg {
    width: 48px;
    height: 48px;
    stroke: #c3c4c7;
    margin-bottom: 12px;
}

.section-no-results p {
    font-size: 14px;
    margin: 0;
}

/* Toast */
#section-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #1d2327;
    color: #fff;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 14px;
    z-index: 100002;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
}

#section-toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 782px) {
    .section-picker-grid {
        grid-template-columns: 1fr;
    }
    
    .section-category-tabs {
        gap: 6px;
    }
    
    .cat-tab {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .cat-tab .cat-count {
        display: none;
    }
}

@media (max-width: 600px) {
    .section-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .aaima-modal-box {
        width: 95%;
    }
    
    .add-section-modal {
        max-height: 80vh;
    }
    
    .section-picker-grid {
        max-height: calc(80vh - 180px);
    }
}

/* Image Field */
.image-field-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.image-preview {
    width: 150px;
    height: 80px;
    border: 2px dashed #ddd;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9f9f9;
    position: relative;
    overflow: hidden;
}

.image-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.image-preview .no-image {
    color: #999;
    font-size: 12px;
    text-align: center;
}

.image-preview .remove-image {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.image-preview:hover .remove-image {
    opacity: 1;
}

.image-preview .remove-image:hover {
    background: rgba(200, 0, 0, 0.8);
}

.select-image-btn {
    width: 150px;
}
