:root {
    --bg-dark: #0f0f12;
    --bg-panel: #18181b;
    --primary: #FF0055;
    --primary-hover: #D90049;
    --text-main: #FFFFFF;
    --text-muted: #A1A1AA;
    --border: #27272A;
    --glass: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --font-main: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
}

/* --- Layout --- */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 3rem;
}

.brand i {
    color: var(--primary);
    font-size: 1.5rem;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-btn i {
    font-size: 1.25rem;
}

.nav-btn:hover {
    background: var(--glass);
    color: var(--text-main);
}

.nav-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 0, 85, 0.3);
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: 0.2s;
}

.icon-btn:hover {
    color: var(--text-main);
    background: var(--glass);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* Editor Layout (Split Screen) */
.editor-layout {
    display: flex;
    flex: 1;
    height: 100%;
}

.tools-panel {
    width: 400px;
    background: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 2rem;
}

.preview-panel {
    flex: 1;
    background: radial-gradient(circle at center, #1E1E1E 0%, #0f0f12 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
}

/* Configurations */
.panel-header {
    margin-bottom: 2rem;
}

.panel-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.config-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.select-wrapper {
    position: relative;
}

select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    appearance: none;
    font-family: var(--font-main);
}

.select-wrapper i {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: 0.3s;
    background: var(--glass);
}

.upload-zone:hover {
    border-color: var(--primary);
    background: rgba(255, 0, 85, 0.05);
}

.upload-zone i {
    font-size: 2rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.image-preview {
    width: 100%;
    height: 150px;
    object-fit: contain;
    /* Don't crop reference */
    border-radius: 8px;
    margin-top: 0.5rem;
    background: #000;
}

/* Color Picker */
.color-picker-grid {
    display: flex;
    gap: 0.75rem;
}

.color-option {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--c);
    cursor: pointer;
    border: 2px solid transparent;
    transition: 0.2s;
}

.color-option.selected {
    border-color: var(--text-main);
    transform: scale(1.1);
}

/* Acc Slots */
.acc-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.acc-slot {
    aspect-ratio: 1;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 8px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.slot-empty {
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
}

.slot-empty i {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 4px;
}

.slot-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.btn-icon-xs {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
}

/* Toggles */
.toggles-row {
    display: flex;
    gap: 1.5rem;
}

.toggle-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* Buttons */
.primary-btn {
    width: 100%;
    padding: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: 0.3s;
    margin-top: 2rem;
}

.primary-btn:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 15px rgba(255, 0, 85, 0.4);
}

/* Result Area */
.result-container {
    width: 100%;
    max-width: 800px;
    /* height: 80vh; Removed to fit content */
    display: flex;
    flex-direction: column;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.result-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn-sm {
    background: var(--glass);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
}

.image-wrapper {
    background: #000;
    border-radius: 12px;
    min-height: 400px;
    /* Min height for empty state */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border);
}

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

.empty-state {
    text-align: center;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

.info-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
}

/* Utilities */
.hidden {
    display: none !important;
}

.glass-panel {
    background: rgba(24, 24, 27, 0.6);
    backdrop-filter: blur(12px);
}

/* Loader */
.loader {
    width: 20px;
    height: 20px;
    border: 2px solid #FFF;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Chat Layout */
.chat-layout {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 2rem;
    height: 100vh;
}

.chat-layout.side-by-side {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    height: 85vh;
}

.chat-sidebar {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.presets-list-compact {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.preset-card-sm {
    background: var(--glass);
    border: 1px solid var(--border);
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.2s;
}

.preset-card-sm:hover {
    border-color: var(--primary);
    background: rgba(255, 0, 85, 0.05);
}

.preset-card-sm .preset-name {
    font-weight: 600;
    margin-bottom: 4px;
    display: block;
    color: var(--text-main);
}

.preset-card-sm .preset-script {
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clickable-context {
    cursor: pointer;
    transition: 0.3s;
}

.clickable-context:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px var(--primary);
}

.chat-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-panel);
}

.chat-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
}

.chat-title i {
    color: #4facfe;
    font-size: 1.5rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.message {
    display: flex;
    gap: 1rem;
    max-width: 80%;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message .msg-content {
    background: var(--glass);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    line-height: 1.5;
}

.message.user .msg-content {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.message.system .msg-content {
    background: rgba(79, 172, 254, 0.1);
    border-color: rgba(79, 172, 254, 0.3);
}

.chat-input-area {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 1rem;
}

.chat-input-area input {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: 8px;
    color: var(--text-main);
    font-family: var(--font-main);
}

.chat-input-area button {
    background: var(--primary);
    border: none;
    color: white;
    width: 50px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.25rem;
}

.chat-upload-preview {
    padding: 0.5rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid var(--border);
    position: relative;
}

.chat-upload-preview img {
    height: 60px;
    width: 60px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--primary);
}

.chat-upload-preview button {
    background: var(--primary);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* History Layout */
.history-layout {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.history-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 1;
    border: 1px solid var(--border);
    transition: 0.3s;
}

.history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-item:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
}

.item-checkbox {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 18px;
    height: 18px;
    z-index: 101;
    cursor: pointer;
    accent-color: var(--primary);
}

.history-item.selected {
    border: 2px solid var(--primary);
}

.history-item-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    transform: translateY(100%);
    transition: 0.3s;
    z-index: 100;
}

.history-item:hover .history-item-actions {
    transform: translateY(0);
}

.item-action-btn {
    background: var(--glass);
    border: 1px solid var(--border);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.item-action-btn:hover {
    background: var(--primary);
}

.btn-use-hist {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    border: none;
    padding: 5px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0;
    transition: 0.2s;
}

.history-item:hover .btn-use-hist {
    opacity: 1;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    width: 400px;
    padding: 2rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-content input {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    padding: 0.75rem;
    color: white;
    border-radius: 8px;
}

.preset-card {
    background: var(--glass);
    border: 1px solid var(--border);
    padding: 1.5rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: 0.3s;
}

.preset-card:hover {
    border-color: var(--primary);
    background: rgba(255, 0, 85, 0.05);
}

.preset-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preset-name {
    font-weight: 600;
    color: var(--primary);
}

.preset-script {
    background: #000;
    padding: 1rem;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.85rem;
    color: #4facfe;
    border: 1px solid #1a1a1a;
    word-break: break-all;
}

.preset-actions {
    display: flex;
    gap: 0.75rem;
}