#aivg-wrapper {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: transparent; /* Removed outer gradient so it blends better with themes */
    padding: 10px;
    box-sizing: border-box;
}

#aivg-wrapper * {
    box-sizing: border-box;
}

#aivg-wrapper .aivg-container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 12px; /* Slightly softer corners */
    box-shadow: 0 10px 40px rgba(0,0,0,0.15); /* Softer shadow */
    overflow: hidden;
    border: 1px solid #eaeaea;
}

/* --- HEADER IMPROVEMENTS --- */
#aivg-wrapper .header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 25px; /* Reduced padding significantly */
    text-align: center;
}

#aivg-wrapper .header h1 {
    font-size: 1.8em; /* Smaller, cleaner font size */
    margin-bottom: 5px;
    color: white;
    font-weight: 600;
}

#aivg-wrapper .header p {
    opacity: 0.9;
    font-size: 1em;
    color: white;
    margin: 0;
}

/* --- LAYOUT & SCROLLING IMPROVEMENTS --- */
#aivg-wrapper .main-content {
    display: grid;
    grid-template-columns: 380px 1fr; /* Slimmer sidebar */
    gap: 0;
    /* Removed fixed height to eliminate ugly inner scrollbars */
}

#aivg-wrapper .sidebar {
    background: #fcfcfc;
    padding: 20px; /* Reduced padding */
    border-right: 1px solid #e0e0e0;
}

#aivg-wrapper .content-area {
    padding: 25px;
}

/* --- SECTIONS --- */
#aivg-wrapper .section {
    background: white;
    padding: 20px; /* Tighter padding inside boxes */
    border-radius: 10px;
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    border: 1px solid #f0f0f0;
}

#aivg-wrapper .section h2 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 1.2em; /* Smaller headings */
    display: flex;
    align-items: center;
    gap: 8px;
}

#aivg-wrapper .section h2::before {
    content: '';
    width: 3px;
    height: 18px;
    background: #667eea;
    border-radius: 2px;
}

/* --- FORMS & BUTTONS --- */
#aivg-wrapper .form-group { margin-bottom: 15px; }

#aivg-wrapper label {
    display: block;
    margin-bottom: 6px;
    color: #444;
    font-weight: 600;
    font-size: 0.9em;
}

#aivg-wrapper input[type="text"],
#aivg-wrapper input[type="password"],
#aivg-wrapper input[type="number"],
#aivg-wrapper textarea,
#aivg-wrapper select {
    width: 100%;
    padding: 10px 12px; /* Tighter inputs */
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.95em;
    transition: all 0.3s;
    font-family: inherit;
    background: #fff;
    color: #333;
}

#aivg-wrapper input:focus,
#aivg-wrapper textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#aivg-wrapper textarea {
    resize: vertical;
    min-height: 80px;
}

#aivg-wrapper .aivg-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#aivg-wrapper .aivg-button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

#aivg-wrapper .aivg-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#aivg-wrapper .aivg-button.secondary { background: #6c757d; }
#aivg-wrapper .aivg-button.success { background: linear-gradient(135deg, #56ab2f 0%, #a8e063 100%); }

/* --- GRID ITEMS (Frames, Music) --- */
#aivg-wrapper .template-selector,
#aivg-wrapper .frame-selector,
#aivg-wrapper .music-library {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

#aivg-wrapper .template-selector { grid-template-columns: 1fr 1fr; }
#aivg-wrapper .frame-selector { grid-template-columns: repeat(3, 1fr); }

#aivg-wrapper .template-option,
#aivg-wrapper .frame-option,
#aivg-wrapper .music-item {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px; /* Reduced padding for smaller boxes */
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

#aivg-wrapper .template-option:hover,
#aivg-wrapper .frame-option:hover,
#aivg-wrapper .music-item:hover {
    border-color: #667eea;
    background: #f8f9fa;
}

#aivg-wrapper .template-option.selected,
#aivg-wrapper .frame-option.selected,
#aivg-wrapper .music-item.selected {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
    box-shadow: 0 0 0 1px #667eea; /* Crisper selected state */
}

#aivg-wrapper .music-item { display: flex; align-items: center; gap: 10px; text-align: left; }
#aivg-wrapper .music-icon { font-size: 1.5em; }

#aivg-wrapper .frame-icon { font-size: 1.5em; margin-bottom: 3px;}
#aivg-wrapper .frame-option div:last-child { font-size: 0.8em; }

#aivg-wrapper .upload-area {
    border: 2px dashed #ccc;
    border-radius: 6px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 10px;
    background: #fafafa;
}

#aivg-wrapper .upload-area:hover { background: #fff; border-color: #667eea; }
#aivg-wrapper .upload-area input { display: none; }
#aivg-wrapper .upload-area p { margin-bottom: 3px; }

/* --- NOTIFICATIONS & PREVIEWS --- */
#aivg-wrapper .status-message {
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
    display: none;
    font-size: 0.95em;
}
#aivg-wrapper .status-message.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; display: block;}
#aivg-wrapper .status-message.error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; display: block;}
#aivg-wrapper .status-message.info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; display: block;}

#aivg-wrapper .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 20px;
}

#aivg-wrapper .slides-container { display: grid; gap: 15px; }

#aivg-wrapper .slide-card {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    transition: all 0.3s;
}

#aivg-wrapper .slide-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

#aivg-wrapper .slide-number {
    background: #f1f3f5;
    color: #495057;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.85em;
}

#aivg-wrapper .image-prompt {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 6px;
    margin: 10px 0;
    border-left: 3px solid #667eea;
    font-size: 0.9em;
}

#aivg-wrapper .image-preview {
    margin-top: 10px;
    border-radius: 8px;
    overflow: hidden;
    max-height: 300px;
    border: 2px solid #eaeaea;
}
#aivg-wrapper .image-preview img { width: 100%; height: auto; display: block; }

#aivg-wrapper .preview-container {
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin: 20px auto;
    width: 300px; /* Scaled down slightly */
    height: 533px; /* Scaled down slightly */
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

#aivg-wrapper .preview-container img { width: 100%; height: 100%; object-fit: cover; }

#aivg-wrapper .video-preview {
    width: 100%;
    max-width: 300px;
    margin: 20px auto;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

#aivg-wrapper .progress-container { margin-top: 20px; display: none; }
#aivg-wrapper .progress-bar { background: #e9ecef; height: 24px; border-radius: 12px; overflow: hidden; position: relative; }
#aivg-wrapper .progress-fill { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); height: 100%; width: 0%; transition: width 0.3s; display: flex; align-items: center; justify-content: center; color: white; font-weight: 600; font-size: 0.85em; }

#aivg-wrapper .badge { display: inline-block; padding: 3px 8px; border-radius: 10px; font-size: 0.75em; font-weight: 600; }
#aivg-wrapper .badge.success { background: #d4edda; color: #155724; }
#aivg-wrapper .badge.warning { background: #fff3cd; color: #856404; }

#aivg-wrapper .spinner {
    border: 2px solid #f3f3f3;
    border-top: 2px solid #fff;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    display: inline-block;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- RESPONSIVE --- */
@media (max-width: 900px) {
    #aivg-wrapper .main-content { grid-template-columns: 1fr; }
    #aivg-wrapper .sidebar { border-right: none; border-bottom: 1px solid #e0e0e0; }
}