* { box-sizing: border-box; }

:root {
	--text: #2C2C2B;
	--text-secondary: #7D7A75;
	--canvas: #FFFFFF;
	--surface: #F9F8F7;
	--surface-2: #F0EFED;
	--border: #E6E5E3;
	--accent: #2783DE;
	--accent-soft: #E5F2FC;
	--green: #46A171;
	--green-soft: #E8F1EC;
	--orange: #D5803B;
	--orange-soft: #FBEBDE;
	--red: #E56458;
	--red-soft: #FCE9E7;
	--radius: 8px;
	--radius-lg: 12px;
	--shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 12px rgba(0,0,0,.04);
}

@media (prefers-color-scheme: dark) {
	:root {
		--text: #FFFFFF;
		--text-secondary: rgba(255,255,255,0.65);
		--canvas: #191919;
		--surface: #202020;
		--surface-2: #383836;
		--border: rgba(255,255,255,0.20);
		--accent: #5E9FE8;
		--accent-soft: rgba(94,159,232,0.12);
		--green: #72BC8F;
		--green-soft: rgba(114,188,143,0.12);
		--orange: #DE9255;
		--orange-soft: rgba(222,146,85,0.12);
		--red: #E97366;
		--red-soft: rgba(233,115,102,0.12);
	}
}

html, body {
	margin: 0;
	padding: 0;
	background: var(--canvas);
	color: var(--text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 16px;
	line-height: 1.5;
	overflow-x: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--text-secondary); font-size: 14px; }

.app {
	max-width: 1120px;
	margin: 0 auto;
	padding: 0 24px 88px;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

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

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 18px; }
.brand-mark { font-size: 22px; }

.icon-btn {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	width: 40px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	font-size: 16px;
	color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }

.layout {
	display: grid;
	grid-template-columns: 1.1fr 1fr;
	gap: 24px;
	margin-top: 32px;
	align-items: start;
}

@media (max-width: 860px) {
	.layout { grid-template-columns: 1fr; }
}

.panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	padding: 24px;
}

.panel-header h1 { font-size: 22px; margin: 0 0 4px; }
.panel-header p { margin: 0 0 20px; }

.address-card {
	background: var(--canvas);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 16px;
	margin-bottom: 20px;
}

.address-row { display: flex; gap: 8px; margin-bottom: 12px; }

.address-input {
	flex: 1;
	font-size: 16px;
	font-weight: 600;
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--text);
}

.address-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.text-input, .select-input {
	flex: 1 1 130px;
	min-width: 0;
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--canvas);
	color: var(--text);
	font-size: 14px;
}

.btn {
	padding: 10px 16px;
	border-radius: var(--radius);
	border: 1px solid transparent;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	min-height: 44px;
	white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.9; }

.btn-secondary { background: var(--canvas); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }

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

.status-line { display: flex; align-items: center; gap: 8px; }

.status-dot {
	width: 8px; height: 8px; border-radius: 50%;
	background: var(--text-secondary);
	display: inline-block;
}
.status-dot.active { background: var(--green); }

.toolbar-actions { display: flex; align-items: center; gap: 12px; }

.toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-secondary); cursor: pointer; }

.inbox-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 8px;
	max-height: 460px;
	overflow-y: auto;
}

.inbox-item {
	background: var(--canvas);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 12px 14px;
	cursor: pointer;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.inbox-item:hover { border-color: var(--accent); }
.inbox-item.selected { border-color: var(--accent); background: var(--accent-soft); }

.inbox-item-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.inbox-item-subject { font-weight: 600; font-size: 14px; }
.inbox-item-from { font-size: 13px; color: var(--text-secondary); }

.empty-state {
	padding: 32px 16px;
	text-align: center;
	color: var(--text-secondary);
	font-size: 14px;
}

.viewer-panel { min-height: 460px; display: flex; flex-direction: column; }

.viewer-empty {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 8px;
	color: var(--text-secondary);
	text-align: center;
	padding: 32px;
}
.viewer-empty-icon { font-size: 32px; }

.viewer-content { display: flex; flex-direction: column; gap: 16px; height: 100%; }

.viewer-header h2 { margin: 0 0 8px; font-size: 18px; }

.viewer-meta { display: flex; gap: 24px; margin: 0; flex-wrap: wrap; }
.viewer-meta div { display: flex; gap: 6px; font-size: 13px; }
.viewer-meta dt { color: var(--text-secondary); margin: 0; }
.viewer-meta dd { margin: 0; font-weight: 500; }

.viewer-body { flex: 1; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--canvas); }

#viewerFrame { width: 100%; height: 380px; border: 0; display: block; background: #fff; }

.app-footer { margin-top: 32px; text-align: center; }

.overlay {
	position: fixed; inset: 0;
	background: rgba(0,0,0,0.45);
	display: flex; align-items: center; justify-content: center;
	padding: 24px;
	z-index: 50;
}

.dialog {
	background: var(--canvas);
	border-radius: var(--radius-lg);
	border: 1px solid var(--border);
	max-width: 480px;
	width: 100%;
	box-shadow: var(--shadow);
	max-height: 90vh;
	display: flex;
	flex-direction: column;
}

.dialog-header {
	display: flex; align-items: center; justify-content: space-between;
	padding: 16px 20px;
	border-bottom: 1px solid var(--border);
}
.dialog-header h2 { margin: 0; font-size: 16px; }

.dialog-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.field .text-input { width: 100%; }

.advanced { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.advanced summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text); }
.advanced .field { margin-top: 12px; }

.hint { font-size: 12px; color: var(--text-secondary); margin: 0; }

.dialog-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }

.debug-drawer {
	position: static;
	background: var(--surface);
	border-top: 1px solid var(--border);
	max-height: 40vh;
}

.debug-toggle {
	width: 100%;
	text-align: left;
	background: transparent;
	border: 0;
	padding: 10px 24px;
	font-size: 13px;
	color: var(--text-secondary);
	cursor: pointer;
}

.debug-log {
	margin: 0;
	padding: 0 24px 16px;
	font-family: Menlo, Consolas, monospace;
	font-size: 12px;
	max-height: 32vh;
	overflow-y: auto;
	white-space: pre-wrap;
	word-break: break-all;
	color: var(--text-secondary);
}

.toast {
	position: fixed;
	bottom: 24px;
	left: 50%;
	transform: translateX(-50%);
	background: var(--text);
	color: var(--canvas);
	padding: 10px 16px;
	border-radius: var(--radius);
	font-size: 13px;
	z-index: 60;
	box-shadow: var(--shadow);
}

@media (max-width: 480px) {
	.app { padding: 0 16px 40px; }
	.address-actions { flex-direction: column; }
	.text-input, .select-input, .btn { width: 100%; flex: 1 1 auto; }
	.inbox-toolbar { flex-direction: column; align-items: flex-start; }
}
