/* CSS Variables for theming */
:root {
	--bg-page: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	--bg-window: #ffffff;
	--bg-header: #f6f6f8;
	--bg-toolbar: #fafafa;
	--bg-hover: #f0f0f0;
	--bg-active: #e5e5e5;

	--text-primary: #1d1d1f;
	--text-secondary: #86868b;
	--text-tertiary: #aeaeb2;

	--border-color: #d2d2d7;
	--border-light: #e5e5e7;

	--accent-purple: #7c3aed;
	--accent-purple-hover: #6d28d9;

	--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
	--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
	--shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);

	--traffic-red: #ff5f57;
	--traffic-yellow: #ffbd2e;
	--traffic-green: #28c840;
}

/* Dark mode variables */
[data-theme="dark"] {
	--bg-page: linear-gradient(135deg, #1e1b4b 0%, #4c1d95 100%);
	--bg-window: #2c2c2e;
	--bg-header: #1c1c1e;
	--bg-toolbar: #252527;
	--bg-hover: #3a3a3c;
	--bg-active: #48484a;

	--text-primary: #f5f5f7;
	--text-secondary: #98989d;
	--text-tertiary: #636366;

	--border-color: #424245;
	--border-light: #38383a;

	--accent-purple: #a78bfa;
	--accent-purple-hover: #c4b5fd;

	--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
	--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
	--shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
}

/* System preference detection */
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg-page: linear-gradient(135deg, #1e1b4b 0%, #4c1d95 100%);
		--bg-window: #2c2c2e;
		--bg-header: #1c1c1e;
		--bg-toolbar: #252527;
		--bg-hover: #3a3a3c;
		--bg-active: #48484a;

		--text-primary: #f5f5f7;
		--text-secondary: #98989d;
		--text-tertiary: #636366;

		--border-color: #424245;
		--border-light: #38383a;

		--accent-purple: #a78bfa;
		--accent-purple-hover: #c4b5fd;

		--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
		--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
		--shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
	}
}

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

body {
	font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	background: var(--bg-page);
	color: var(--text-primary);
	line-height: 1.6;
	padding: 40px 20px;
	transition: color 0.3s ease;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	min-height: 100vh;
}

/* Email Client Window */
.email-client {
	max-width: 900px;
	margin: 0 auto;
	background: var(--bg-window);
	border-radius: 12px;
	overflow: hidden;
	box-shadow: var(--shadow-lg);
	transition: background-color 0.3s ease;
}

/* Window Header with Traffic Lights */
.window-header {
	background: var(--bg-header);
	border-bottom: 1px solid var(--border-light);
	padding: 12px 20px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	transition: background-color 0.3s ease, border-color 0.3s ease;
}

.traffic-lights {
	display: flex;
	gap: 8px;
	align-items: center;
}

.light {
	width: 12px;
	height: 12px;
	border-radius: 50%;
	cursor: pointer;
	transition: all 0.2s ease;
}

.light.close {
	background: var(--traffic-red);
}

.light.minimize {
	background: var(--traffic-yellow);
}

.light.maximize {
	background: var(--traffic-green);
}

.light:hover {
	filter: brightness(0.9);
}

.window-title {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	font-size: 13px;
	font-weight: 600;
	color: var(--text-primary);
	letter-spacing: 0.2px;
}

.header-actions {
	display: flex;
	gap: 8px;
	margin-left: auto;
}

/* Toolbar */
.toolbar {
	background: var(--bg-toolbar);
	border-bottom: 1px solid var(--border-light);
	padding: 10px 20px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	transition: background-color 0.3s ease, border-color 0.3s ease;
}

.toolbar-left,
.toolbar-right {
	display: flex;
	gap: 4px;
	align-items: center;
}

.toolbar-divider {
	width: 1px;
	height: 20px;
	background: var(--border-color);
	margin: 0 8px;
}

/* Icon Buttons */
.icon-btn {
	background: transparent;
	border: none;
	color: var(--text-secondary);
	padding: 6px 8px;
	border-radius: 6px;
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 13px;
	font-weight: 500;
}

.icon-btn:hover {
	background: var(--bg-hover);
	color: var(--text-primary);
}

.icon-btn:active {
	background: var(--bg-active);
}

.icon-btn svg {
	stroke: currentColor;
}

/* Theme Toggle */
.theme-toggle {
	position: relative;
}

.theme-toggle .sun-icon {
	display: none;
}

.theme-toggle .moon-icon {
	display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
	display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
	display: none;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .theme-toggle .sun-icon {
		display: block;
	}

	:root:not([data-theme="light"]) .theme-toggle .moon-icon {
		display: none;
	}
}

/* Email Content */
.email-content {
	padding: 24px 32px 32px;
	max-height: 70vh;
	overflow-y: auto;
}

/* Message Header */
.message-header {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	padding-bottom: 20px;
	border-bottom: 1px solid var(--border-light);
	margin-bottom: 24px;
	gap: 20px;
}

.sender-info {
	display: flex;
	gap: 12px;
	flex: 1;
}

.avatar {
	width: 48px;
	height: 48px;
	border-radius: 50%;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: white;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20px;
	font-weight: 600;
	flex-shrink: 0;
	object-fit: cover;
}

.sender-details {
	flex: 1;
	min-width: 0;
}

.sender-name {
	font-size: 16px;
	font-weight: 600;
	color: var(--text-primary);
	margin-bottom: 2px;
}

.sender-meta {
	font-size: 14px;
	color: var(--text-secondary);
	margin-bottom: 4px;
}

.sender-email {
	font-weight: 500;
}

.recipients {
	font-size: 13px;
	color: var(--text-tertiary);
	margin-top: 4px;
}

.recipient-label {
	font-weight: 500;
	margin-right: 4px;
}

.recipient-value {
	color: var(--text-secondary);
}

.message-meta {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
}

.message-date {
	font-size: 13px;
	color: var(--text-tertiary);
	white-space: nowrap;
}

.reply-btn {
	background: var(--accent-purple);
	color: white;
	padding: 8px 16px;
	font-weight: 600;
}

.reply-btn:hover {
	background: var(--accent-purple-hover);
}

.reply-btn svg {
	stroke: white;
}

/* Message Body */
.message-body {
	font-size: 17px;
	line-height: 1.7;
	color: var(--text-primary);
}

.message-body p {
	margin-bottom: 16px;
}

.message-body p:last-child {
	margin-bottom: 0;
}

.message-body a {
	color: var(--accent-purple);
	text-decoration: none;
	transition: color 0.2s ease;
}

.message-body a:hover {
	color: var(--accent-purple-hover);
	text-decoration: underline;
}

/* Technical Details */
.tech-details {
	margin-top: 32px;
	padding-top: 24px;
	border-top: 1px solid var(--border-light);
}

.tech-details summary {
	font-size: 13px;
	color: var(--text-secondary);
	cursor: pointer;
	user-select: none;
	list-style: none;
	padding: 8px 12px;
	border-radius: 6px;
	transition: all 0.2s ease;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-weight: 500;
}

.tech-details summary::-webkit-details-marker {
	display: none;
}

.tech-details summary:hover {
	background: var(--bg-hover);
	color: var(--text-primary);
}

.tech-details[open] summary {
	margin-bottom: 16px;
}

/* Inline Technical Details in Header */
.tech-details-inline {
	margin-top: 8px;
}

.tech-details-inline summary {
	font-size: 12px;
	color: var(--text-tertiary);
	cursor: pointer;
	user-select: none;
	list-style: none;
	padding: 0;
	transition: all 0.2s ease;
	font-weight: 400;
}

.tech-details-inline summary::-webkit-details-marker {
	display: none;
}

.tech-details-inline summary:hover {
	color: var(--accent-purple);
}

.tech-details-inline[open] summary {
	margin-bottom: 12px;
	color: var(--text-secondary);
}

.header-content {
	background: var(--bg-toolbar);
	border: 1px solid var(--border-light);
	border-radius: 8px;
	padding: 16px;
	font-family: "SF Mono", Monaco, "Cascadia Code", "Courier New", monospace;
	font-size: 12px;
	line-height: 1.6;
}

.header-row {
	display: grid;
	grid-template-columns: 140px 1fr;
	gap: 12px;
	padding: 6px 0;
	word-break: break-word;
}

.header-key {
	color: var(--text-tertiary);
	font-weight: 600;
	text-align: right;
}

.header-value {
	color: var(--text-secondary);
}

/* Scrollbar Styling */
.email-content::-webkit-scrollbar {
	width: 8px;
}

.email-content::-webkit-scrollbar-track {
	background: transparent;
}

.email-content::-webkit-scrollbar-thumb {
	background: var(--border-color);
	border-radius: 4px;
}

.email-content::-webkit-scrollbar-thumb:hover {
	background: var(--text-tertiary);
}

/* Responsive Design */
@media only screen and (max-width: 768px) {
	body {
		padding: 20px 10px;
	}

	.email-client {
		border-radius: 8px;
	}

	.window-header {
		padding: 10px 16px;
	}

	.window-title {
		font-size: 12px;
	}

	.toolbar {
		padding: 8px 12px;
		flex-wrap: wrap;
	}

	.toolbar-divider {
		display: none;
	}

	.email-content {
		padding: 20px 16px;
	}

	.message-header {
		flex-direction: column;
		gap: 16px;
	}

	.message-meta {
		width: 100%;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.sender-info {
		width: 100%;
	}

	.header-row {
		grid-template-columns: 1fr;
		gap: 4px;
	}

	.header-key {
		text-align: left;
	}

	.icon-btn {
		padding: 6px;
	}

	.icon-btn span {
		display: none;
	}
}

/* Animations */
@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.email-content {
	animation: fadeIn 0.5s ease-out;
}

/* Print styles */
@media print {
	body {
		background: white;
		padding: 0;
	}

	.email-client {
		box-shadow: none;
		border-radius: 0;
	}

	.window-header,
	.toolbar,
	.tech-details {
		display: none;
	}
}
