@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
    --primary-color: #6a5af9;
    --secondary-color: #d151c6;
    --bg-color: #f4f7fc;
    --card-bg: #ffffff;
    --text-color: #2c3e50;
    --text-muted: #7f8c8d;
    --border-color: #e0e6ed;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.07);
    --header-bg: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    --chat-bubble-ai: #eef2f7;
    --chat-bubble-user: #e2f5ea;
    --monospace-font: 'Fira Code', 'Courier New', monospace;
}

.dark-theme {
    --primary-color: #9b59b6;
    --secondary-color: #3498db;
    --bg-color: #1e272e;
    --card-bg: #2c3a47;
    --text-color: #ecf0f1;
    --text-muted: #95a5a6;
    --border-color: #4a6173;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    --chat-bubble-ai: #3b4d5e;
    --chat-bubble-user: #2c3e50;
}

*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app-preloader {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-color);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 10000;
}
.spinner {
    border: 4px solid rgba(127, 140, 141, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 50px; height: 50px;
    animation: spin 1s linear infinite;
}
#app-preloader p { margin-top: 1rem; color: var(--text-muted); font-weight: 500; }

#global-message-banner {
    background-color: var(--card-bg); border: 1px solid var(--border-color);
    padding: 1rem; margin: 1rem auto; border-radius: 8px; max-width: 900px;
    display: none; position: relative; box-shadow: var(--shadow);
    text-align: center; font-weight: 500;
}
.close-btn { position: absolute; top: 8px; right: 10px; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); opacity: 0.7; }

.page { display: none; }
.page.active { display: flex; }

button { font-family: 'Poppins', sans-serif; cursor: pointer; border-radius: 8px; transition: all 0.3s ease; border: none; font-weight: 600; padding: 12px 25px; font-size: 1rem; }
.btn-primary { background: var(--header-bg); color: white; display: inline-flex; align-items: center; gap: 10px; }
.btn-primary:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(106, 90, 249, 0.3); }
.btn-secondary { background-color: var(--chat-bubble-ai); color: var(--text-color); border: 1px solid var(--border-color); }
.btn-secondary:hover { background-color: var(--border-color); }
.btn-danger { background-color: #e74c3c; color: white; }
button:disabled { background-color: #bdc3c7; cursor: not-allowed; transform: none; box-shadow: none; opacity: 0.7; }
.icon-btn { background: none; border: none; color: var(--text-muted); padding: 8px; border-radius: 50%; }
.icon-btn:hover { background-color: var(--chat-bubble-ai); color: var(--primary-color); }

#builder-screen { flex-direction: row; height: 100vh; max-height: 100vh; overflow: hidden; }
#asset-panel { width: 300px; background: var(--card-bg); border-right: 1px solid var(--border-color); flex-shrink: 0; display: flex; flex-direction: column; padding: 1.5rem; }
.builder-main { flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; }

.header-brand { display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem; }
.header-brand img { height: 40px; }
.header-brand h2 { margin: 0; font-size: 1.3rem; }

.asset-library { flex-grow: 1; overflow-y: auto; }
.asset-library h3 { margin-top: 0; color: var(--primary-color); }
.asset-group { margin-bottom: 2rem; }
.asset-group h4 { margin: 0 0 0.8rem 0; font-size: 0.9rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.asset-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 10px; min-height: 80px; background-color: var(--bg-color); border-radius: 8px; padding: 10px; border: 1px dashed var(--border-color); }
.placeholder-text { grid-column: 1 / -1; text-align: center; align-self: center; color: var(--text-muted); font-size: 0.9rem; }
.asset-thumbnail { position: relative; width: 100%; padding-bottom: 100%; border-radius: 6px; overflow: hidden; background-color: var(--border-color); }
.asset-thumbnail img, .asset-thumbnail video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.asset-thumbnail .overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; opacity: 0; transition: opacity 0.3s; }
.asset-thumbnail:hover .overlay { opacity: 1; }
.asset-thumbnail .copy-url-btn { background: white; color: black; border: none; border-radius: 50%; width: 30px; height: 30px; padding: 0; font-size: 1rem; cursor: pointer; }
.asset-thumbnail .spinner { width: 24px; height: 24px; border-width: 3px; border-top-color: white; border-left-color: transparent; border-right-color: transparent; border-bottom-color: transparent; }
.asset-thumbnail .video-icon { position: absolute; bottom: 5px; right: 5px; background: rgba(0,0,0,0.6); color: white; border-radius: 50%; width: 24px; height: 24px; display: flex; justify-content: center; align-items: center; }
.full-width { width: 100%; margin-top: 1rem; }
.settings-footer-btn { margin-top: auto; width: 100%; justify-content: center; background-color: var(--chat-bubble-ai); color: var(--text-muted); display: flex; align-items: center; gap: 8px; }
.settings-footer-btn:hover { background-color: var(--border-color); color: var(--text-color); }

#chat-window { flex-grow: 1; overflow-y: auto; padding: 1.5rem; }
.message { display: flex; margin-bottom: 1.2rem; max-width: 80%; }
.message.user { margin-left: auto; flex-direction: row-reverse; }
.message-content { padding: 10px 15px; border-radius: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
.message.user .message-content { background: var(--primary-color); color: white; border-bottom-right-radius: 2px; }
.message.ai .message-content { background: var(--card-bg); border: 1px solid var(--border-color); border-bottom-left-radius: 2px; }
.message-content p { margin: 0 0 0.5rem 0; }
.message-content code { background-color: rgba(0,0,0,0.1); padding: 2px 5px; border-radius: 4px; font-family: var(--monospace-font); font-size: 0.9em; }
.message-content pre { background-color: var(--chat-bubble-ai); padding: 10px; border-radius: 6px; overflow-x: auto; }
.message.user .message-content code { background-color: rgba(255,255,255,0.2); }
.message.user .message-content pre { background-color: rgba(0,0,0,0.2); }
.thinking-indicator { display: flex; align-items: center; gap: 10px; }
.thinking-indicator .spinner { width: 20px; height: 20px; border-width: 2px; }
.image-card { border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; }
.image-card img { display: block; max-width: 100%; cursor: zoom-in; }

.input-area { display: flex; padding: 1rem 1.5rem; background: var(--card-bg); border-top: 1px solid var(--border-color); align-items: flex-end; }
#text-input { flex-grow: 1; border: 1px solid var(--border-color); background: var(--bg-color); color: var(--text-color); border-radius: 8px; padding: 12px 15px; font-size: 1rem; margin-right: 1rem; resize: none; line-height: 1.4; max-height: 120px; overflow-y: auto; }
#send-btn { background: var(--primary-color); color: white; padding: 12px; width: 48px; height: 48px; display: flex; justify-content: center; align-items: center; flex-shrink: 0; }
#send-btn:disabled { background: var(--text-muted); }

#output-panel { padding: 1rem 1.5rem; background: var(--card-bg); border-top: 1px solid var(--border-color); flex-shrink: 0; display: flex; justify-content: space-between; align-items: center; }
#output-panel h3 { margin: 0; font-size: 1rem; color: var(--text-muted); }
.output-controls { display: flex; gap: 1rem; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 2000; display: none; justify-content: center; align-items: center; }
.modal { background: var(--card-bg); border-radius: 12px; padding: 2rem; width: 90%; max-width: 500px; text-align: center; }
.modal h3 { margin-top: 0; color: var(--primary-color); }
.share-link-input-wrapper { display: flex; margin: 1.5rem 0; }
#share-link-input { flex-grow: 1; border: 1px solid var(--border-color); padding: 10px; border-radius: 6px 0 0 6px; background: var(--bg-color); color: var(--text-color); }
#copy-share-link-btn { border-radius: 0 6px 6px 0; }

#settings-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 998; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
#settings-panel { position: fixed; top: 0; right: -350px; width: 350px; height: 100%; background: var(--card-bg); box-shadow: -10px 0 30px rgba(0,0,0,0.1); z-index: 999; transition: right 0.3s; padding: 2rem; overflow-y: auto; }
#settings-panel.open { right: 0; }
#settings-backdrop.visible { opacity: 1; pointer-events: auto; }

footer { display: none; /* Hidden in builder view */ }

@media (max-width: 768px) {
    #asset-panel { display: none; /* Hide asset panel on smaller screens for now */ }
}