/* =========================================
   1. CSS VARIABLES, FONTS & BASE THEME
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --brand-color: #9061f9;
    --brand-color-light: color-mix(in srgb, var(--brand-color) 10%, transparent);
    --glass: rgba(255, 255, 255, 0.95);
    --sidebar-width: 400px;
    --text-dark: #1e293b;
    --text-light: #64748b;
    --border-color: #e2e8f0;
}

body, html { margin: 0; padding: 0; height: 100%; font-family: 'Inter', system-ui, -apple-system, sans-serif; overflow: hidden; background: #f8fafc; }

/* ENTERPRISE SCROLLBARS */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

#bg-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: #f8fafc; background-size: 100% auto; background-position: center -40px; 
    background-repeat: no-repeat; z-index: 1;
    transition: background-image 0.4s ease-in-out;
}

/* =========================================
   2. MAIN NAVIGATION (SEMANTIC HEADER)
   ========================================= */
.navbar {
    position: fixed; top: 0; width: 100%; height: 72px;
    background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(0,0,0,0.05); border-top: 4px solid var(--brand-color);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 48px; box-sizing: border-box; z-index: 1000;
}

.nav-logo { font-weight: 800; font-size: 24px; color: var(--text-dark); display: flex; align-items: center; gap: 12px; letter-spacing: -0.5px;}
.nav-logo img { height: 32px; max-width: 160px; object-fit: contain; }

.nav-right { display: flex; align-items: center; gap: 32px; }
.nav-item { cursor: pointer; font-weight: 500; color: #475569; position: relative; list-style: none; font-size: 15px; transition: color 0.2s; padding: 24px 0; }

.nav-item::before {
    content: ''; position: absolute; bottom: 18px; left: 0; width: 0%; height: 2px;
    background-color: var(--brand-color); transition: width 0.2s ease-out;
}
.nav-item:hover::before { width: 100%; }
.nav-item:hover { color: var(--brand-color-dark, var(--brand-color)); }

.primary-btn {
    background: var(--brand-color); color: var(--brand-contrast-color, #fff); padding: 10px 24px;
    border-radius: 50px; font-weight: 600; box-shadow: 0 4px 12px var(--brand-color-light);
    transition: transform 0.2s, filter 0.2s; margin-left: 10px;
}
.primary-btn::before { display: none; }
.primary-btn:hover { transform: translateY(-1px); filter: brightness(1.1); color: white;}

/* Dropdown Architecture */
.dropdown {
    display: none; position: absolute; top: 100%; right: 0;
    background: #fff; border-radius: 12px; width: 260px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1); border: 1px solid var(--border-color); margin-top: -10px; padding: 8px 0;
}
.nav-item::after { content: ""; position: absolute; bottom: -20px; left: 0; width: 100%; height: 25px; }
.nav-item:hover .dropdown, .dropdown:hover { display: block; animation: slideDown 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes slideDown { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.drop-link { padding: 12px 20px; font-size: 14px; color: var(--text-dark); transition: all 0.2s ease; cursor: pointer;}
.drop-link:hover { background: var(--brand-color-light); color: var(--brand-color-dark, var(--brand-color)); padding-left: 24px; font-weight: 600;}

/* =========================================
   3. FLOATING EDITOR PALETTE
   ========================================= */
#editor {
    position: fixed; top: 90px; left: 20px; 
    width: 480px; height: 80vh; background: #fff; z-index: 5000; 
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    border-radius: 12px; border: 1px solid var(--border-color);
    display: flex; flex-direction: column;
    resize: both; overflow: hidden; /* Enables stretching */
    min-width: 320px; min-height: 400px;
    opacity: 0; pointer-events: none; transform: translateY(20px);
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
#editor.open { opacity: 1; pointer-events: auto; transform: translateY(0); }

.editor-header { 
    padding: 20px 24px; border-bottom: 1px solid #f1f5f9; display: flex; justify-content: space-between; align-items: center; background: #fff;
    cursor: grab; /* Drag indicator */
}
.editor-header:active { cursor: grabbing; }

.editor-content { flex: 1; overflow-y: auto; padding: 24px; }
.editor-footer { padding: 20px 24px; border-top: 1px solid #f1f5f9; background: #f8fafc; }

/* Accordion resets */
details { background: #fff; border: 1px solid var(--border-color); border-radius: 12px; margin-bottom: 16px; overflow: hidden; }
details[open] { box-shadow: 0 4px 15px rgba(0,0,0,0.03); border-color: #cbd5e1;}
summary { padding: 16px; font-weight: 600; font-size: 14px; color: var(--text-dark); cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; background: #f8fafc; transition: background 0.2s; }
summary:hover { background: #f1f5f9; }
summary::-webkit-details-marker { display: none; }
summary::after { content: '+'; font-size: 18px; color: var(--text-light); transition: transform 0.2s; }
details[open] summary { border-bottom: 1px solid var(--border-color); background: #fff; }
details[open] summary::after { content: '−'; transform: rotate(180deg); }
.details-content { padding: 20px 16px; background: #fff; }

/* Icon Theme Styling */
.icon-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    margin-right: 10px;
    flex-shrink: 0;
}
.icon-box svg { width: 16px; height: 16px; }

/* Remove old global forced color */
/* Form Controls */
.field-group { margin-bottom: 24px; }
label { display: block; font-size: 11px; font-weight: 700; color: var(--text-light); text-transform: uppercase; margin-bottom: 8px; letter-spacing: 0.05em; }
input, textarea, select { width: 100%; padding: 12px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; box-sizing: border-box; font-family: inherit; transition: border-color 0.2s, box-shadow 0.2s; color: var(--text-dark); background: #fff; }
textarea { min-height: 80px; resize: vertical; } 
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand-color); box-shadow: 0 0 0 3px var(--brand-color-light); }

input[type="color"] {
    -webkit-appearance: none;
    border: none;
    border-radius: 50%;
    padding: 0 !important;
    overflow: hidden;
    box-shadow: 0 0 0 1px #cbd5e1;
}
input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}
input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.btn-main { background: var(--brand-color); color: var(--brand-contrast-color, #fff); border: none; padding: 14px; width: 100%; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px; transition: all 0.2s ease;}
.btn-main:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 4px 12px var(--brand-color-light);}
.btn-ghost { background: #f1f5f9; border: none; padding: 8px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; font-weight: 600; color: #475569; transition: background 0.2s;}
.btn-ghost:hover { background: #e2e8f0; }

/* Color-Coded Action Buttons */
.btn-action-edit { color: #3b82f6; background: #eff6ff; }
.btn-action-edit:hover { background: #dbeafe; }
.btn-action-delete { color: #ef4444; background: #fef2f2; }
.btn-action-delete:hover { background: #fee2e2; }
.btn-action-save { color: #ffffff; background: #22c55e; }
.btn-action-save:hover { background: #16a34a; }
.btn-action-cancel { color: #64748b; background: #f1f5f9; }
.btn-action-cancel:hover { background: #e2e8f0; }

/* Custom Dropdown UI */
.custom-select-wrapper { position: relative; user-select: none; margin-bottom: 12px; }
.custom-select-trigger {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px; border: 1px solid #cbd5e1; border-radius: 8px;
    background: #fff; font-size: 14px; color: var(--text-dark); cursor: pointer; transition: 0.2s;
}
.custom-select-trigger:hover { border-color: var(--brand-color); }
.custom-select-trigger::after { content: "▼"; font-size: 10px; color: #888; }
.custom-select-options {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: #fff; border: 1px solid #cbd5e1; border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1); z-index: 100; margin-top: 4px; overflow: hidden;
    max-height: 200px; overflow-y: auto;
}
.custom-select-options.open { display: block; animation: fadeIn 0.15s ease; }
.custom-option { padding: 12px; font-size: 14px; color: var(--text-dark); cursor: pointer; transition: 0.2s; border-bottom: 1px solid #f1f5f9; }
.custom-option:last-child { border-bottom: none; }
.custom-option:hover { background: #f8fafc; color: var(--brand-color-dark, var(--brand-color)); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* Masked Input UI */
.password-wrapper { position: relative; display: flex; align-items: center; margin-bottom: 12px; }
.password-wrapper input { padding-right: 40px; margin-bottom: 0; }
.eye-toggle { position: absolute; right: 12px; background: none; border: none; cursor: pointer; font-size: 16px; color: #64748b; opacity: 0.7; transition: 0.2s; padding: 0; }
.eye-toggle:hover { opacity: 1; color: var(--brand-color-dark, var(--brand-color)); }

/* COMPACT PRODUCT BLOCKS */
.prod-compact {
    display: flex; justify-content: space-between; align-items: center;
    background: #f8fafc; padding: 12px 16px; border-radius: 8px; margin-bottom: 8px;
    border: 1px solid var(--border-color); border-left: 4px solid var(--brand-color);
    transition: background 0.2s;
}
.prod-compact:hover { background: #f1f5f9; }
.prod-name-display { font-size: 14px; font-weight: 600; color: var(--text-dark); }
.prod-actions { display: flex; gap: 8px; }

.prod-expanded {
    display: none; background: #fff; padding: 16px; border-radius: 8px; margin-bottom: 16px;
    border: 1px solid var(--brand-color); box-shadow: 0 4px 12px var(--brand-color-light);
    animation: fadeIn 0.2s ease;
}
.prod-expanded.open { display: block; }
.prod-expanded label { color: var(--brand-color); }

.tid-block { background: #f8fafc; padding: 16px; border-radius: 8px; border: 1px solid var(--border-color);}

/* Gear Trigger */
.gear-trigger { position: fixed; bottom: 0; left: 0; width: 80px; height: 80px; z-index: 6000; cursor: pointer; }
.gear-icon { position: absolute; bottom: 24px; left: 24px; font-size: 24px; background: #fff; padding: 10px; border-radius: 50%; box-shadow: 0 4px 12px rgba(0,0,0,0.1); opacity: 0; transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1); transform: rotate(0deg) scale(0.8); }
.gear-trigger:hover .gear-icon { opacity: 1; transform: rotate(90deg) scale(1); }

/* Modal & Login Modal */
.modal-overlay { display: none; position: fixed; z-index: 9000; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px); align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s; }
.modal-overlay.visible { display: flex; opacity: 1; }
.modal-card { position: relative; background: #fff; padding: 40px; border-radius: 16px; width: 400px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); border-top: 6px solid var(--brand-color); transform: translateY(20px); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.modal-overlay.visible .modal-card { transform: translateY(0); }
#modal-body { white-space: pre-wrap; }

/* Toast Notification */
.toast {
    position: fixed; bottom: 24px; right: 24px; 
    background: #0f172a; color: #f8fafc;
    padding: 14px 20px; border-radius: 12px; 
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.4);
    font-size: 14px; font-weight: 500; z-index: 10000;
    transform: translateY(100px); opacity: 0; 
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid #1e293b;
    max-width: 400px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border: 1px solid rgba(239, 68, 68, 0.3); background: #1e1014; }
.toast.success { border: 1px solid rgba(16, 185, 129, 0.3); background: #0c1a15; }

/* Modal Close Button */
.modal-close-btn {
    position: absolute; top: 16px; right: 16px; background: transparent; border: none;
    font-size: 20px; color: #94a3b8; cursor: pointer; transition: color 0.2s; padding: 4px; line-height: 1;
}
.modal-close-btn:hover { color: #1e293b; }

/* =========================================
   6. RESPONSIVE DESIGN (MOBILE READY)
   ========================================= */
@media (max-width: 768px) {
    /* Header optimization */
    header { padding: 0 16px; height: 64px; }
    #ui-logo img { height: 28px; }
    .nav-item:not(.primary-btn) { display: none; } /* Hide secondary links */
    .primary-btn { padding: 8px 16px; font-size: 13px; margin-left: 0; }

    /* Editor Bottom Sheet Transformation */
    #editor {
        top: auto !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 65vh !important;
        border-radius: 20px 20px 0 0 !important;
        box-shadow: 0 -10px 40px rgba(0,0,0,0.15) !important;
        transform: translateY(100%);
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    }
    #editor.open { transform: translateY(0); }
    
    .editor-header {
        padding: 12px 20px 16px;
        border-radius: 20px 20px 0 0;
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
    .editor-header h2 { font-size: 16px; }
    
    /* Drag Handle visual */
    .editor-header::before {
        content: '';
        width: 36px;
        height: 4px;
        background: #e2e8f0;
        border-radius: 10px;
        margin-bottom: 4px;
    }

    #pin-editor { display: none; } /* Pinning makes no sense on mobile sheet */

    .editor-content { padding: 20px; }
    
    /* Modal sizing */
    .modal-card { width: calc(100% - 40px); padding: 30px 20px; }
    
    /* Toast centering */
    .toast {
        left: 20px;
        right: 20px;
        bottom: 20px;
        width: auto;
        max-width: none;
        text-align: center;
        justify-content: center;
    }
}