/* CSS Custom Properties */
:root {
	/* Cool color palette */
	--color-primary: #0891b2;
	--color-primary-light: #06b6d4;
	--color-primary-dark: #0e7490;
	--color-accent: #22d3ee;

	/* Light theme */
	--bg-primary: #f8fafc;
	--bg-secondary: #f1f5f9;
	--bg-tertiary: #e2e8f0;
	--bg-gradient: radial-gradient(ellipse at top, #f1f5f9 0%, #f8fafc 50%, #e0f2fe 100%);

	--text-primary: #0f172a;
	--text-secondary: #475569;
	--text-muted: #94a3b8;

	--border-color: #cbd5e1;
	--border-light: #e2e8f0;

	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
	--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
	--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

	--message-user-bg: #0891b2;
	--message-user-text: #ffffff;
	--message-assistant-bg: #f1f5f9;
	--message-assistant-text: #0f172a;

	--modal-backdrop: rgba(15, 23, 42, 0.6);
}

[data-theme="dark"] {
	--bg-primary: #0f172a;
	--bg-secondary: #1e293b;
	--bg-tertiary: #334155;
	--bg-gradient: radial-gradient(ellipse at top, #164e63 0%, #0f172a 40%, #020617 100%);

	--text-primary: #f8fafc;
	--text-secondary: #cbd5e1;
	--text-muted: #64748b;

	--border-color: #334155;
	--border-light: #1e293b;

	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
	--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
	--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);

	--message-assistant-bg: #1e293b;
	--message-assistant-text: #f8fafc;

	--modal-backdrop: rgba(2, 6, 23, 0.8);
}

/* Reset & Base */
*,
*::before,
*::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

html {
	font-size: 16px;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

body {
	font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Oxygen', sans-serif;
	background: var(--bg-gradient);
	background-attachment: fixed;
	color: var(--text-primary);
	min-height: 100vh;
	line-height: 1.6;
	transition: background 0.3s ease, color 0.3s ease;
}

/* App Container */
.app-container {
	max-width: 700px;
	margin: 0 auto;
	padding: 1rem;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

/* Header */
.app-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 1rem 0;
	margin-bottom: 1rem;
}

.logo {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.logo-icon {
	width: 2rem;
	height: 2rem;
	color: var(--color-primary);
}

.logo h1 {
	font-size: 1.5rem;
	font-weight: 600;
	color: var(--text-primary);
}

.theme-toggle {
	width: 2.5rem;
	height: 2.5rem;
	border: none;
	/* background: var(--bg-secondary); */
	background: none;
	border-radius: 0.5rem;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--text-secondary);
	transition: all 0.2s ease;
}

.theme-toggle:hover {
	background: var(--bg-tertiary);
	color: var(--color-primary);
}

.theme-toggle svg {
	width: 1.25rem;
	height: 1.25rem;
}

.icon-moon {
	display: none;
}

[data-theme="dark"] .icon-sun {
	display: none;
}

[data-theme="dark"] .icon-moon {
	display: block;
}

/* Main Content */
.main-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

/* Chat Section */
.chat-section {
	background: var(--bg-secondary);
	border-radius: 1rem;
	box-shadow: var(--shadow-md);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	min-height: 300px;
	max-height: 400px;
}

.chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.message {
	display: flex;
	max-width: 85%;
	animation: messageIn 0.3s ease;
}

@keyframes messageIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.message.user {
	align-self: flex-end;
}

.message.assistant {
	align-self: flex-start;
}

.message-content {
	padding: 0.75rem 1rem;
	border-radius: 1rem;
	word-wrap: break-word;
}

.message.user .message-content {
	background: var(--message-user-bg);
	color: var(--message-user-text);
	border-bottom-right-radius: 0.25rem;
}

.message.assistant .message-content {
	background: var(--message-assistant-bg);
	color: var(--message-assistant-text);
	border-bottom-left-radius: 0.25rem;
}

.message-content p {
	margin: 0;
}

.message-content p + p {
	margin-top: 0.5rem;
}

/* Typing indicator */
.typing-indicator {
	display: flex;
	gap: 0.3rem;
	padding: 0.75rem 1rem;
}

.typing-indicator span {
	width: 0.5rem;
	height: 0.5rem;
	background: var(--text-muted);
	border-radius: 50%;
	animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
	animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
	animation-delay: -0.16s;
}

@keyframes bounce {
	0%, 80%, 100% {
		transform: scale(0);
	}
	40% {
		transform: scale(1);
	}
}

/* Chat Input */
.chat-input-container {
	border-top: 1px solid var(--border-light);
	padding: 0.75rem;
}

.turnstile-container {
	display: none;
	margin-bottom: 0.5rem;
}

.turnstile-container.visible {
	display: block;
}

.chat-input-wrapper {
	display: flex;
	gap: 0.5rem;
	align-items: stretch;
}

.chat-input {
	flex: 1;
	padding: 0.75rem 1rem;
	border: 1px solid var(--border-color);
	border-radius: 0.75rem;
	background: var(--bg-primary);
	color: var(--text-primary);
	font-size: 1rem;
	font-family: inherit;
	resize: none;
	max-height: 120px;
	min-height: 2.75rem;
	line-height: 1.5;
	transition: border-color 0.2s ease;
}

.chat-input:focus {
	outline: none;
	border-color: var(--color-primary);
}

.chat-input::placeholder {
	color: var(--text-muted);
}

.send-button {
	width: 2.75rem;
	min-height: 2.75rem;
	height: 48px;
	border: none;
	background: var(--color-primary);
	color: white;
	border-radius: 0.75rem;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s ease;
	flex-shrink: 0;
	align-self: flex-end;
}

.send-button:hover:not(:disabled) {
	background: var(--color-primary-dark);
	transform: scale(1.05);
}

.send-button:disabled {
	background: var(--text-muted);
	cursor: not-allowed;
}

.send-button svg {
	width: 1.25rem;
	height: 1.25rem;
}

/* Carousel Section */
.carousel-section {
	background: var(--bg-secondary);
	border-radius: 1rem;
	box-shadow: var(--shadow-md);
	padding: 1rem;
	position: relative;
}

.carousel-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 0.75rem;
}

.image-count {
	font-size: 0.875rem;
	color: var(--text-secondary);
}

.selection-controls {
	display: flex;
	gap: 0.5rem;
}

.select-all-btn {
	width: 2rem;
	height: 2rem;
	border: none;
	background: transparent;
	color: var(--text-secondary);
	border-radius: 0.5rem;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s ease;
}

.select-all-btn:hover {
	background: var(--bg-tertiary);
	color: var(--color-primary);
}

.select-all-btn svg {
	width: 1.25rem;
	height: 1.25rem;
}

.carousel-container {
	overflow-x: auto;
	scrollbar-width: thin;
	scrollbar-color: var(--border-color) transparent;
}

.carousel-container::-webkit-scrollbar {
	height: 6px;
}

.carousel-container::-webkit-scrollbar-track {
	background: transparent;
}

.carousel-container::-webkit-scrollbar-thumb {
	background: var(--border-color);
	border-radius: 3px;
}

.carousel-track {
	display: flex;
	gap: 0.75rem;
	padding: 0.25rem;
}

.carousel-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 2rem;
	color: var(--text-muted);
	gap: 0.75rem;
}

.carousel-empty svg {
	width: 3rem;
	height: 3rem;
	opacity: 0.5;
}

.carousel-empty p {
	font-size: 0.875rem;
}

.carousel-empty.hidden {
	display: none;
}

/* Thumbnail */
.thumbnail {
	position: relative;
	width: 80px;
	height: 80px;
	flex-shrink: 0;
	border-radius: 0.5rem;
	overflow: hidden;
	cursor: pointer;
	border: 2px solid transparent;
	transition: all 0.2s ease;
}

.thumbnail:hover {
	border-color: var(--color-primary-light);
	transform: scale(1.05);
}

.thumbnail.selected {
	border-color: var(--color-primary);
	box-shadow: 0 0 0 2px var(--color-accent);
}

.thumbnail img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.thumbnail-check {
	position: absolute;
	top: 4px;
	right: 4px;
	width: 1.25rem;
	height: 1.25rem;
	background: var(--color-primary);
	border-radius: 50%;
	display: none;
	align-items: center;
	justify-content: center;
	color: white;
}

.thumbnail-check svg {
	width: 0.75rem;
	height: 0.75rem;
}

.thumbnail.selected .thumbnail-check {
	display: flex;
}

.thumbnail-processing {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	display: none;
	align-items: center;
	justify-content: center;
}

.thumbnail-processing.active {
	display: flex;
}

.thumbnail-spinner {
	width: 1.5rem;
	height: 1.5rem;
	border: 2px solid rgba(255, 255, 255, 0.3);
	border-top-color: white;
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* Toolbar */
.toolbar {
	display: flex;
	gap: 0.5rem;
	flex-wrap: wrap;
	justify-content: center;
}

.toolbar-btn {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.75rem 1rem;
	border: 1px solid var(--border-color);
	background: var(--bg-secondary);
	color: var(--text-primary);
	border-radius: 0.75rem;
	cursor: pointer;
	font-size: 0.875rem;
	font-family: inherit;
	font-weight: 500;
	transition: all 0.2s ease;
}

.toolbar-btn:hover:not(:disabled) {
	background: var(--bg-tertiary);
	border-color: var(--color-primary);
}

.toolbar-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.toolbar-btn.primary {
	background: var(--color-primary);
	border-color: var(--color-primary);
	color: white;
}

.toolbar-btn.primary:hover:not(:disabled) {
	background: var(--color-primary-dark);
}

.toolbar-btn svg {
	width: 1.125rem;
	height: 1.125rem;
}

/* Modals */
.modal {
	position: fixed;
	inset: 0;
	z-index: 1000;
	display: none;
	align-items: center;
	justify-content: center;
	padding: 1rem;
}

.modal.open {
	display: flex;
}

.modal-backdrop {
	position: absolute;
	inset: 0;
	background: var(--modal-backdrop);
	animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

.modal-content {
	position: relative;
	background: var(--bg-secondary);
	border-radius: 1rem;
	box-shadow: var(--shadow-lg);
	max-width: 90vw;
	max-height: 90vh;
	overflow: auto;
	animation: modalIn 0.3s ease;
}

@keyframes modalIn {
	from {
		opacity: 0;
		transform: scale(0.95);
	}
	to {
		opacity: 1;
		transform: scale(1);
	}
}

.modal-close {
	position: absolute;
	top: 1rem;
	right: 1rem;
	width: 2.5rem;
	height: 2.5rem;
	border: none;
	background: var(--bg-tertiary);
	color: var(--text-primary);
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s ease;
	z-index: 10;
}

.modal-close:hover {
	background: var(--color-primary);
	color: white;
}

.modal-close svg {
	width: 1.25rem;
	height: 1.25rem;
}

/* Image Modal */
.image-modal-content {
	padding: 1rem;
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

.image-preview-container {
	display: flex;
	align-items: center;
	justify-content: center;
	max-width: 80vw;
	max-height: 70vh;
}

.image-preview-container img {
	max-width: 100%;
	max-height: 70vh;
	object-fit: contain;
	border-radius: 0.5rem;
}

.image-info {
	text-align: center;
	font-size: 0.875rem;
	color: var(--text-secondary);
}

/* Help Modal */
.help-modal-content {
	padding: 2rem;
	width: 100%;
	max-width: 550px;
}

.help-modal-content h2 {
	font-size: 1.5rem;
	margin-bottom: 1.5rem;
	padding-right: 2rem;
	color: var(--text-primary);
}

.help-content {
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
}

.help-section h3 {
	font-size: 1rem;
	color: var(--color-primary);
	margin-bottom: 0.5rem;
}

.help-section p {
	color: var(--text-secondary);
	font-size: 0.9375rem;
}

.help-section ul {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.help-section li {
	color: var(--text-secondary);
	font-size: 0.9375rem;
	padding-left: 1.25rem;
	position: relative;
}

.help-section li::before {
	content: '';
	position: absolute;
	left: 0;
	top: 0.6rem;
	width: 0.375rem;
	height: 0.375rem;
	background: var(--color-primary);
	border-radius: 50%;
}

.help-section li strong {
	color: var(--text-primary);
}

/* Drop Zone Overlay */
.drop-zone-overlay {
	position: fixed;
	inset: 0;
	z-index: 999;
	background: var(--modal-backdrop);
	display: none;
	align-items: center;
	justify-content: center;
}

.drop-zone-overlay.active {
	display: flex;
}

.drop-zone-content {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1rem;
	padding: 3rem;
	background: var(--bg-secondary);
	border: 3px dashed var(--color-primary);
	border-radius: 1.5rem;
	color: var(--color-primary);
}

.drop-zone-content svg {
	width: 4rem;
	height: 4rem;
}

.drop-zone-content p {
	font-size: 1.25rem;
	font-weight: 500;
}

/* Error message */
.message.error .message-content {
	background: #fef2f2;
	color: #991b1b;
	border-left: 3px solid #ef4444;
}

[data-theme="dark"] .message.error .message-content {
	background: #450a0a;
	color: #fecaca;
}

/* Success message */
.message.success .message-content {
	background: #f0fdf4;
	color: #166534;
	border-left: 3px solid #22c55e;
}

[data-theme="dark"] .message.success .message-content {
	background: #052e16;
	color: #bbf7d0;
}

/* Processing state */
.processing .chat-input,
.processing .send-button {
	pointer-events: none;
}

/* Mobile Responsive */
@media (max-width: 640px) {
	.app-container {
		padding: 0.75rem;
	}

	.logo h1 {
		font-size: 1.25rem;
	}

	.chat-section {
		min-height: 250px;
		max-height: 350px;
	}

	.chat-input {
		font-size: 1rem;
	}

	.toolbar {
		gap: 0.375rem;
	}

	.toolbar-btn {
		padding: 0.625rem 0.75rem;
		font-size: 0.8125rem;
	}

	.toolbar-btn span {
		display: none;
	}

	.thumbnail {
		width: 64px;
		height: 64px;
	}

	.help-modal-content {
		padding: 1.5rem;
	}

	.help-modal-content h2 {
		font-size: 1.25rem;
	}
}

/* Utility classes */
.hidden {
	display: none !important;
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

