:root {
	--font-main: 'Inter', system-ui, -apple-system, sans-serif;
	--font-mono: 'Fira Code', ui-monospace, SFMono-Regular, monospace;
	
	/* Light Theme Colors (Default to Dark overridden later) */
	--bg-body: #f8fafc;
	--bg-surface: #ffffff;
	--bg-sidebar: #f1f5f9;
	--bg-input: #ffffff;
	--text-main: #0f172a;
	--text-muted: #64748b;
	--border: #e2e8f0;
	
	--primary: #3b82f6;
	--primary-hover: #2563eb;
	--danger: #ef4444;
	--danger-hover: #dc2829;
	--success: #10b981;
	
	--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
	--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
	--shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
	
	--radius: 12px;
	--transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
	--bg-body: #0f172a;
	--bg-surface: #1e293b;
	--bg-sidebar: #0b1120;
	--bg-input: #0f172a;
	--text-main: #f8fafc;
	--text-muted: #94a3b8;
	--border: #334155;
	
	--primary: #3b82f6;
	--primary-hover: #60a5fa;
	--danger: #ef4444;
	--danger-hover: #f87171;
	
	--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
}

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

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

.emoji {
	font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

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

/* Sidebar */
.sidebar {
	width: clamp(220px, 20vw, 280px);
	background-color: var(--bg-sidebar);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	transition: var(--transition);
}

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

.sidebar-header h2 {
	font-size: 1.1rem;
	font-weight: 600;
	display: flex;
	align-items: center;
	gap: 8px;
}

.history-list {
	flex: 1;
	overflow-y: auto;
	padding: 10px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.history-empty {
	padding: 20px;
	text-align: center;
	color: var(--text-muted);
	font-size: 0.9rem;
}

.history-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px;
	background: var(--bg-surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	cursor: pointer;
	transition: var(--transition);
	box-shadow: var(--shadow-sm);
}

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

.history-item-title {
	font-size: 0.9rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	flex: 1;
}

.delete-btn {
	background: none;
	border: none;
	cursor: pointer;
	opacity: 0.5;
	transition: var(--transition);
	padding: 4px;
	border-radius: 4px;
}

.delete-btn:hover {
	opacity: 1;
	background: rgba(239, 68, 68, 0.1);
}

/* Main Content */
.main-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
}

/* Topbar */
.topbar {
	min-height: 70px;
	height: auto;
	padding: 10px 24px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 10px;
	background-color: var(--bg-surface);
	border-bottom: 1px solid var(--border);
}

.brand {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	min-width: 0;
	gap: 12px;
}

.brand h1 {
	font-size: 1.4rem;
	font-weight: 700;
	letter-spacing: -0.5px;
}
.model-badge {
	font-size: 0.75rem;
	vertical-align: middle;
	color: white;
	padding: 3px 8px;
	border-radius: 6px;
	margin-left: 0;
	font-weight: 600;
	font-family: monospace;
	display: inline-block;
}
.badge-pro    { background: #3b82f6; }
.badge-flash  { background: #64748b; }
.badge-free   { background: #16a34a; }
.badge-custom { background: #8b5cf6; }
#api-key-btn.has-key { border-color: #8b5cf6; background: rgba(139, 92, 246, 0.2); color: #a78bfa; }

.badge {
	font-size: 0.8rem;
	padding: 4px 10px;
	border-radius: 20px;
	background: var(--bg-body);
	border: 1px solid var(--border);
	display: flex;
	align-items: center;
	gap: 6px;
	color: var(--text-muted);
}

.indicator {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--text-muted);
}

.indicator.online  { background: var(--success); box-shadow: 0 0 8px rgba(16, 185, 129, 0.5); }
.indicator.busy    { background: #f59e0b; box-shadow: 0 0 8px rgba(245, 158, 11, 0.6); animation: pulse-busy 1.2s infinite ease-in-out; }
.indicator.error   { background: var(--danger); box-shadow: 0 0 8px rgba(239, 68, 68, 0.6); }
.indicator.offline { background: var(--danger); }
@keyframes pulse-busy { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.8); } }

.controls {
	display: flex;
	gap: 8px;
}

/* Buttons */
button {
	font-family: inherit;
	cursor: pointer;
	border: none;
	outline: none;
	transition: var(--transition);
}

.icon-btn {
	background: var(--bg-body);
	border: 1px solid var(--border);
	width: 40px;
	height: 40px;
	border-radius: var(--radius);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.2rem;
	color: var(--text-main);
}

.icon-btn:hover {
	background: var(--border);
}

.primary-btn, .secondary-btn, .danger-btn {
	padding: 10px 16px;
	border-radius: var(--radius);
	font-weight: 600;
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 0.95rem;
}

.primary-btn {
	background: var(--primary);
	color: white;
	box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.39);
}

.primary-btn:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }

.secondary-btn {
	background: var(--bg-body);
	color: var(--text-main);
	border: 1px solid var(--border);
}

.secondary-btn:hover:not(:disabled) { background: var(--border); }

.danger-btn {
	background: rgba(239, 68, 68, 0.1);
	color: var(--danger);
	border: 1px solid rgba(239, 68, 68, 0.2);
}

.danger-btn:hover:not(:disabled) { background: var(--danger); color: white; }

button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Prompt Section */
.prompt-section {
	padding: 24px;
	background: var(--bg-surface);
	border-bottom: 1px solid var(--border);
}

.input-group {
	display: flex;
	gap: 12px;
	margin-bottom: 8px;
}

input[type="text"] {
	flex: 1;
	background: var(--bg-input);
	border: 1px solid var(--border);
	color: var(--text-main);
	padding: 0 16px;
	border-radius: var(--radius);
	font-size: 1rem;
	font-family: inherit;
	transition: var(--transition);
}

input[type="text"]:focus {
	border-color: var(--primary);
	box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
	outline: none;
}

.status-message {
	font-size: 0.85rem;
	color: var(--text-muted);
	height: 20px;
}

.status-message.error { color: var(--danger); }
.status-message.success { color: var(--success); }

/* Editor Section */
.editor-section {
	flex: 1;
	display: flex;
	flex-direction: column;
	padding: 24px;
	background: var(--bg-body);
	overflow: hidden;
}

.editor-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 12px;
}

.editor-title {
	font-weight: 600;
	color: var(--text-main);
	display: flex;
	align-items: center;
	gap: 8px;
}

.editor-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
}

.editor-body {
	flex: 1;
	position: relative;
	border-radius: var(--radius);
	border: 1px solid var(--border);
	background: var(--bg-surface);
	overflow: hidden;
	box-shadow: var(--shadow-md);
}

#code-editor {
	width: 100%;
	height: 100%;
	border: none;
	background: transparent;
	color: var(--text-main);
	padding: 20px;
	font-family: var(--font-mono);
	font-size: 14px;
	line-height: 1.6;
	resize: none;
	outline: none;
	white-space: pre;
	overflow-wrap: normal;
	overflow-x: auto;
}

#code-editor::placeholder {
	color: var(--text-muted);
	opacity: 0.5;
}

/* Loader Overlay */
.loader-overlay {
	position: absolute;
	inset: 0;
	background: rgba(var(--bg-surface), 0.8);
	backdrop-filter: blur(4px);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	z-index: 10;
}

.spinner {
	width: 40px;
	height: 40px;
	border: 3px solid var(--border);
	border-top-color: var(--primary);
	border-radius: 50%;
	animation: spin 1s linear infinite;
}

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

/* Modals */
.modal {
	position: fixed;
	inset: 0;
	background: rgba(0,0,0,0.5);
	backdrop-filter: blur(4px);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100;
}

.modal-content {
	background: var(--bg-surface);
	border: 1px solid var(--border);
	border-radius: calc(var(--radius) * 1.5);
	width: 90%;
	max-width: 500px;
	box-shadow: var(--shadow-lg);
	overflow: hidden;
}

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

.modal-body {
	padding: 24px;
	color: var(--text-muted);
}

.modal-body p { margin-bottom: 12px; }
.modal-body hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

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

/* Responsive */
@media (max-width: 768px) {
	.app-container { flex-direction: column; }
	.sidebar { width: 100%; height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
	.topbar { padding: 0 16px; }
	.prompt-section, .editor-section { padding: 16px; }
}
.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 5px 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 6px;
    transition: all 0.2s;
}
.tab-btn.active {
    background: var(--surface2);
    color: var(--text);
}
.preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff; /* Always white so HTML previews look normal */
    border-radius: 8px;
}

.editor-title-tabs {
    display: flex;
    gap: 10px;
}
.preview-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* Multi-file Support */
.editor-title-tabs {
    display: flex;
    gap: 10px;
}
.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 5px 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 6px;
    transition: all 0.2s;
}
.tab-btn:hover {
    color: var(--text);
}
.tab-btn.active {
    background: var(--surface2);
    color: var(--text);
}
.editor-body-flex {
    display: flex;
    flex-direction: column;
}
.file-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-sidebar);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.file-tab {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 4px 10px;
    font-size: 0.85rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-mono);
}
.file-tab.active {
    background: var(--bg-surface);
    border-color: var(--border);
    color: var(--text);
}
.editor-content-wrapper {
    position: relative;
    flex: 1;
    overflow: hidden;
}
.preview-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* Helper classes for CSP strict compliance */
.select-transparent { background: transparent; color: inherit; border: none; outline: none; cursor: pointer; font-size: inherit; font-weight: inherit; font-family: inherit; appearance: auto; }
.text-black { color: #000; }
.no-underline { text-decoration: none !important; color: inherit !important; }
.mt-1rem { margin-top: 1rem; }
.mt-075rem { margin-top: 0.75rem; }
.mt-05rem { margin-top: 0.5rem; }
.ml-05rem { margin-left: 0.5rem; }
.text-center { text-align: center; }
.cursor-default { cursor: default; }
.login-form-flex { display: flex; gap: 0.5rem; align-items: center; }
.login-input { flex: 1; padding: 0.4rem 0.6rem; border-radius: 6px; border: 1px solid var(--border, #444); background: var(--bg2, #222); color: inherit; font-size: 0.9rem; }
.login-btn { padding: 0.4rem 0.8rem; border-radius: 6px; background: var(--accent, #3b82f6); color: #fff; border: none; cursor: pointer; font-size: 0.9rem; }
.w-100 { width: 100%; box-sizing: border-box; }
.mb-05rem { margin-bottom: 0.5rem; }
.d-block { display: block; }
.text-bold { font-weight: 600; color: var(--text); }
.text-sm { font-size: 0.85rem; }
.text-success { color: #22c55e; }
.text-warning { color: #f59e0b; }
.text-danger { color: #ef4444; }
.modal-actions-flex { display: flex; gap: 8px; align-items: center; }
optgroup.d-none, option.d-none { display: none !important; }

/* Easter Egg Footer */
.easter-egg-footer-text { text-align: center; color: var(--text-muted, #888); margin-top: 2rem; margin-bottom: 1rem; font-size: 0.85rem; }
#easter-egg-heart, #login-heart { display: inline-block; color: #ff4b4b; cursor: pointer; transition: transform 0.2s ease; user-select: none;  animation: heartbeat 2s infinite; }
@keyframes heartbeat { 0% { transform: scale(1); } 14% { transform: scale(1.3); } 28% { transform: scale(1); } 42% { transform: scale(1.3); } 70% { transform: scale(1); } }
.easter-egg-spin { animation: spin-heart 2s cubic-bezier(0.68, -0.55, 0.265, 1.55); }
@keyframes spin-heart { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ==========================================================================
   COMPACT DESKTOP / 125%-150% WINDOWS SCALING OVERRIDES (WEBSITEPAGEMAKER)
   ========================================================================== */
@media (max-width: 1500px), (max-height: 820px) {
    .sidebar {
        width: clamp(200px, 18vw, 240px);
    }

    .sidebar-header {
        padding: 12px 16px;
    }

    .sidebar-header h2 {
        font-size: 1rem;
    }

    .history-item {
        padding: 8px 10px;
    }

    .topbar {
        min-height: 52px;
        height: auto;
        padding: 6px 16px;
        gap: 8px;
    }

    .brand h1 {
        font-size: 1.15rem;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
        font-size: 1rem;
    }

    .prompt-section {
        padding: 10px 16px;
    }

    .input-group {
        gap: 8px;
        margin-bottom: 4px;
    }

    input[type="text"] {
        font-size: 0.9rem;
        padding: 0 12px;
    }

    .status-message {
        font-size: 0.78rem;
        height: 16px;
    }

    .editor-section {
        padding: 10px 16px;
        min-height: 0;
    }

    .editor-header {
        margin-bottom: 8px;
    }

    .editor-actions {
        gap: 6px;
    }

    .primary-btn, .secondary-btn, .danger-btn {
        padding: 7px 11px;
        font-size: 0.85rem;
        gap: 6px;
        white-space: nowrap;
    }

    #improve-section.mt-1rem {
        margin-top: 0;
        border-top: 1px solid var(--border);
        border-bottom: none;
    }
}

/* ==========================================================================
   MOBILE RESPONSIVENESS OVERRIDES (WEBSITEPAGEMAKER)
   ========================================================================== */
@media (max-width: 768px) {
    /* Release fixed height constraints so mobile can scroll freely */
    body {
        height: auto;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app-container {
        height: auto;
        min-height: 100vh;
        flex-direction: column;
    }

    /* Topbar stacking */
    .topbar {
        height: auto;
        flex-direction: column;
        padding: 16px;
        gap: 12px;
    }

    .controls {
        width: 100%;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Sidebar height and width */
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 250px; /* Don't let history consume entire screen */
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    /* Prompt section adjustments */
    .prompt-section {
        padding: 16px;
    }

    .input-group {
        flex-direction: column;
    }

    /* Editor wrapping */
    .editor-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .editor-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .editor-body {
        min-height: 300px;
    }
}



/* Unified ComputerBas Top-Right Control Buttons */
.topbar .controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.topbar .controls .icon-btn {
    background: rgba(34, 51, 68, 0.9);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(10px);
    text-decoration: none;
}

@media (max-width: 1500px), (max-height: 820px) {
    .topbar .controls .icon-btn {
        width: 34px;
        height: 34px;
        font-size: 1.05rem;
    }
}

[data-theme="light"] .topbar .controls .icon-btn {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.topbar .controls .icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
    border-color: var(--primary);
}
