:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --gradient-1: #8b5cf6;
    --gradient-2: #3b82f6;
    --error-color: #ef4444;
    --border-color: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(15, 23, 42, 0.6);
    --hover-bg: rgba(255, 255, 255, 0.05);

    --sidebar-width: 340px;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg-color: #f3f0e8;
        /* Soft Beige */
        --card-bg: rgba(243, 240, 232, 0.7);
        --text-primary: #1e293b;
        /* Dark text */
        --text-secondary: #475569;
        --border-color: rgba(0, 0, 0, 0.08);
        --input-bg: rgba(255, 255, 255, 0.7);
        --hover-bg: rgba(0, 0, 0, 0.05);
    }
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

.background-globes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
}

.globe {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.5;
}

.globe-1 {
    width: 500px;
    height: 500px;
    background: var(--gradient-1);
    top: -100px;
    left: -100px;
    animation: float 10s infinite alternate ease-in-out;
}

.globe-2 {
    width: 400px;
    height: 400px;
    background: var(--gradient-2);
    bottom: -50px;
    right: 20%;
    animation: float 12s infinite alternate-reverse ease-in-out;
}

@keyframes float {
    0% {
        transform: translateY(0) translateX(0);
    }

    100% {
        transform: translateY(30px) translateX(-30px);
    }
}

.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    padding: 0;
    gap: 0;
}

.glass-panel {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: none;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
}

/* Main Content Area */
.main-content {
    flex: 1;
    overflow: hidden;
    padding: 24px;
    gap: 0;
    border-right: 1px solid var(--border-color);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.brand h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--gradient-1), var(--gradient-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.settings {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

input,
select,
textarea {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--gradient-2);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.image-stage {
    flex: 1;
    background: var(--input-bg);
    border-top: 1px dashed var(--border-color);
    border-bottom: 1px dashed var(--border-color);
    border-radius: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    min-height: 200px;
    margin: 20px 0;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.empty-state svg {
    opacity: 0.5;
}

#main-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.overlay-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s;
}

.image-stage:hover .overlay-controls {
    opacity: 1;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    border: 1px solid var(--border-color);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.05);
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    z-index: 10;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--gradient-2);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}

.prompt-area {
    display: flex;
    gap: 16px;
    align-items: stretch;
}

.prompt-input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 0;
    padding: 12px;
    transition: all 0.3s ease;
}

.prompt-input-wrapper:focus-within {
    border-color: var(--gradient-2);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.prompt-input-wrapper.drag-active {
    border-color: var(--gradient-1);
    background: rgba(139, 92, 246, 0.1);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

.prompt-area textarea {
    width: 100%;
    resize: none;
    padding: 4px;
    border: none;
    background: transparent;
    outline: none;
    min-height: 50px;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
}

.reference-upload-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-color);
}

.upload-btn {
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s;
}

.upload-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.reference-preview {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.ref-thumb-container {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    overflow: hidden;
}

.ref-thumb-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ref-thumb-remove {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border-bottom-left-radius: 8px;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.prompt-area button {
    padding: 0 32px;
    border: none;
    border-radius: 0;
    background: linear-gradient(135deg, var(--gradient-1), var(--gradient-2));
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-width: 140px;
}

.prompt-area button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(59, 130, 246, 0.4);
}

.prompt-area button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    filter: grayscale(0.5);
}

#error-message {
    padding: 12px;
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 12px;
    color: var(--error-color);
    text-align: center;
    font-size: 0.9rem;
}

.error-hidden {
    display: none;
}

/* Sidebar Area */
.history-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.2s;
}

.text-btn:hover {
    color: var(--error-color);
}

.history-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.history-empty {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 40px;
    font-size: 0.95rem;
}

.history-item {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
    flex-shrink: 0;
}

.history-item:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
}

.history-thumb {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
    cursor: pointer;
}

.history-info {
    padding: 12px;
    font-size: 0.85rem;
}

.history-prompt {
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 8px;
    line-height: 1.4;
}

.history-meta {
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
}

.history-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.history-item:hover .history-actions {
    opacity: 1;
}

.history-actions .icon-btn {
    width: 32px;
    height: 32px;
}

.history-actions .icon-btn svg {
    width: 16px;
    height: 16px;
}

/* Responsive */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
        height: auto;
    }

    body {
        overflow: auto;
        height: auto;
    }

    .main-content {
        min-height: 80vh;
    }

    .history-sidebar {
        width: 100%;
        min-height: 300px;
        border-top: 1px solid var(--border-color);
    }

    .settings {
        width: 100%;
    }

    .settings>* {
        flex: 1 1 100%;
    }

    .prompt-area {
        flex-direction: column;
    }

    .prompt-area button {
        padding: 16px;
        flex-direction: row;
    }
}