:root {
	--bg-base: #0b0e14;
	--bg-card: #151a23;
	--border-color: #232a38;
	--text-main: #f0f4f8;
	--text-muted: #848e9c;
	/* 국내 거래소 기준: 상승 빨강, 하락 파랑 */
	--accent-up: #c84a31;
	--accent-down: #1261c4;
	--accent-blue: #2962ff;
	--font-family: -apple-system, BlinkMacSystemFont, "Malgun Gothic", "맑은 고딕", "Segoe UI", Roboto, sans-serif;
}

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

body {
	background-color: var(--bg-base);
	color: var(--text-main);
	font-family: var(--font-family);
	line-height: 1.5;
	display: flex;
	flex-direction: column;
	min-height: 100vh;
}

/* 상단 헤더 */
header {
	background-color: var(--bg-card);
	border-bottom: 1px solid var(--border-color);
	height: 56px;
	padding: 0 16px;
	display: grid;
	grid-template-columns: repeat(4, 1fr); /* 4개의 컬럼을 동일한 비율(1fr)로 분할 */
	box-sizing: border-box;
	align-items: center;
}

.header-value {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	text-align: right;
	gap: 12px;
}

.header-actions {
	align-items: center;
	justify-content: space-between;
	text-align: right;
	gap: 12px;
}

.desktop {
	display: flex;
	align-items: center;
	width: 100%;
	justify-content: space-between;
}

.mobile {
	display: none;
	align-items: center;
	width: 100%;
}

.brand {
	font-size: 1.15rem;
	font-weight: 800;
	letter-spacing: 0.5px;
	display: flex;
	align-items: center;
	gap: 6px;
}

.brand span {
	color: var(--accent-blue);
}

.btn-login,
.btn-login:link,
.btn-login:visited,
.btn-login:hover,
.btn-login:active {
	display: inline-block;
	background-color: var(--accent-blue);
	color: #fff;
	border: none;
	padding: 6px 14px;
	border-radius: 4px;
	font-size: 0.8rem;
	font-weight: 600;
	cursor: pointer;
	transition: opacity 0.2s;
	text-decoration: none;
}

.header-balance-label { color: var(--text-muted); font-size: 0.75rem; font-weight: 400; }
.balance-header { height: auto; min-height: 32px; padding-top: 4px; padding-bottom: 4px; }
.balance-header .header-value { min-width: 0; overflow-wrap: anywhere; }
.header-wallet-summary { min-width: 0; max-width: 40%; text-align: right; padding: 6px 0; }
header.desktop:has(.header-wallet-address) { height: auto; min-height: 56px; }
.header-wallet-address { display: inline-block; color: var(--text-muted); background: var(--bg-base); border: 1px solid var(--border-color); border-radius: 8px; padding: 6px 14px; font-size: 0.85rem; text-decoration: none; white-space: nowrap; }
.header-wallet-summary .header-wallet-address { margin-bottom: 4px; }
.header-wallet-address:hover { color: var(--text-main); }
.header-wallet-address:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.wallet-address-header { gap: 12px; }
.wallet-address-header .header-balance-label { flex-shrink: 0; }
.wallet-address-header .header-wallet-address { min-width: 0; justify-self: end; text-align: center; }

.logged-in-name {
	color: var(--text-muted);
	font-size: 0.8rem;
}

.btn-login:hover {
	opacity: 0.9;
}

/* 메인 레이아웃 */
.container {
	flex: 1;
	max-width: 1360px;
	width: 100%;
	margin: 12px auto;
	padding: 0 12px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

/* 단일 코인 원화 시세 바 */
.login-notice {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	flex-wrap: wrap;
	padding: 12px 16px;
	border: 1px solid var(--border-color);
	border-left: 3px solid var(--accent-blue);
	border-radius: 8px;
	background: var(--bg-card);
	font-size: 0.85rem;
}

.login-notice-error { border-left-color: var(--accent-up); }
.login-notice p { flex: 1 1 200px; overflow-wrap: anywhere; }
.login-notice-actions { display: flex; align-items: center; gap: 12px; }
.login-notice-actions button {
	background: transparent;
	color: var(--text-muted);
	border: 1px solid var(--border-color);
	border-radius: 4px;
	padding: 4px 10px;
	cursor: pointer;
	font: inherit;
}
.login-notice-actions a:focus-visible,
.login-notice-actions button:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 3px; }

.ticker-bar {
	background-color: var(--bg-card);
	border: 1px solid var(--border-color);
	border-radius: 8px;
	padding: 12px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 12px;
}

.coin-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
}

.coin-title {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}

.coin-icon {
	width: 32px;
	height: 32px;
	background: #2962ff;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	color: #fff;
	font-size: 0.85rem;
}

.coin-info-text h2 {
	font-size: 1rem;
}

.coin-info-text small {
	font-size: 0.75rem;
	color: var(--text-muted);
}

.current-price {
	padding-left: 0;
	font-size: 1.8rem;
	font-weight: 700;
	color: var(--accent-up);
	display: flex;
	align-items: baseline;
	justify-content: space-between;
}

.current-price small {
	font-size: 0.8rem;
	color: var(--text-muted);
	margin-left: 4px;
}

.stats-group {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 8px 16px;
	font-size: 0.8rem;
	width: 100%;
	border-top: 1px solid var(--border-color);
	padding-top: 8px;
}

.stats-item span {
	color: var(--text-muted);
	display: inline-block;
	margin-right: 6px;
}

/* 메인 거래 영역 */
.trading-layout {
	display: grid;
	grid-template-columns: 1fr 340px;
	gap: 12px;
}

.card {
	background-color: var(--bg-card);
	border: 1px solid var(--border-color);
	border-radius: 8px;
	padding: 12px;
}

/* 차트 */
.chart-container {
	display: flex;
	flex-direction: column;
	height: 450px;
	gap: 10px;
}

.chart-toolbar {
	display: flex;
	gap: 6px;
}

.time-btn {
	background: #1e2634;
	border: 1px solid var(--border-color);
	color: var(--text-muted);
	padding: 4px 8px;
	border-radius: 4px;
	font-size: 0.75rem;
	cursor: pointer;
}

.time-btn.active {
	background: var(--accent-blue);
	color: #fff;
	border-color: var(--accent-blue);
}

.canvas-wrapper {
	position: relative;
	width: 100%;
	height: 240px;
	background-color: #0d1117;
	border-radius: 6px;
	border: 1px solid var(--border-color);
	overflow: hidden;
}

canvas {
	display: block;
	width: 100%;
	height: 100%;
}

/* 우측사이드바 영역 */
.side-panel {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

/* 호가창 & 주문 폼 */
.order-book table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.8rem;
}

.order-book th {
	color: var(--text-muted);
	text-align: right;
	padding-bottom: 6px;
	font-weight: 400;
}

.order-book th:first-child {
	text-align: left;
}

.order-book td {
	padding: 4px 0;
	text-align: right;
}

.order-book td:first-child {
	text-align: left;
}

.up {
	color: var(--accent-up);
}

.down {
	color: var(--accent-down);
}

.order-panel {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.input-group {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 0.75rem;
	color: var(--text-muted);
}

.input-group input {
	background-color: var(--bg-base);
	border: 1px solid var(--border-color);
	border-radius: 4px;
	padding: 8px 10px;
	color: var(--text-main);
	outline: none;
	text-align: right;
	font-size: 0.9rem;
}

.btn-group {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	margin-top: 4px;
}

.order-btn {
	width: 100%;
	padding: 10px;
	border: none;
	border-radius: 4px;
	font-weight: 600;
	cursor: pointer;
	color: #fff;
	font-size: 0.9rem;
}

.btn-buy {
	background-color: var(--accent-up);
}

.btn-sell {
	background-color: var(--accent-down);
}

.order-btn:disabled {
	opacity: 0.6;
	cursor: wait;
}

#orderRequestMessage {
	min-height: 1.4em;
	color: var(--text-muted);
	font-size: 0.75rem;
}

/* 푸터 */
.funding-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.funding-btn { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: 4px; color: #fff; font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; }
.funding-deposit { background: var(--accent-down); }
.funding-withdraw { background: var(--accent-up); }
.funding-btn:hover { filter: brightness(1.1); }
.funding-btn:focus-visible { outline: 2px solid var(--text-main); outline-offset: 3px; }
.deposit-bank-info { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 16px; padding: 16px; margin-bottom: 16px; border-radius: 8px; background: var(--bg-base); }
.deposit-bank-info dt, .deposit-guide { color: var(--text-muted); font-size: 0.85rem; }
.deposit-bank-info dd { overflow-wrap: anywhere; font-size: 0.85rem; }
.deposit-guide { margin-bottom: 16px; }
.deposit-dialog .input-group + .input-group { margin-top: 12px; }
#depositRequestMessage { margin-top: 12px; font-size: 0.85rem; }
.funding-review-form { display: grid; gap: 8px; margin-top: 16px; }
.funding-review-form textarea { background: var(--bg-base); color: var(--text-main); border: 1px solid var(--border-color); border-radius: 4px; padding: 10px; font: inherit; }
.funding-note { white-space: pre-wrap; }
.funding-pending[hidden] { display: none; }
.funding-pending-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px 16px; font-size: 0.85rem; }
.funding-pending-row strong { text-align: right; overflow-wrap: anywhere; }
.funding-pending-cancel { justify-self: end; }
.funding-pending-row + .funding-pending-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-color); }
.funding-pending-row time { color: var(--text-muted); font-size: 0.75rem; }
.trade-history-card { min-width: 0; }
.trade-history-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.trade-history-heading h2 { font-size: 1rem; }
.history-tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border-color); margin-bottom: 10px; }
.history-tab { border: none; border-bottom: 2px solid transparent; padding: 9px 12px; background: transparent; color: var(--text-muted); font: inherit; font-size: 0.85rem; cursor: pointer; }
.history-tab.active { color: var(--text-main); border-bottom-color: var(--accent-blue); }
.history-action { padding: 6px 12px; background: #1e2634; border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-main); font: inherit; font-size: 0.75rem; cursor: pointer; }
.history-action:disabled { opacity: 0.45; cursor: default; }
.history-cancel { color: var(--accent-blue); border-color: var(--accent-blue); white-space: nowrap; }
.history-cards { display: none; }
.cancel-dialog { margin: auto; width: min(440px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; border: 1px solid var(--border-color); border-radius: 12px; background: var(--bg-card); color: var(--text-main); }
.cancel-dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
#orderAlertText, #cancelOrderDetails { white-space: pre-line; }
.cancel-dialog h2 { font-size: 1.1rem; margin-bottom: 16px; }
.cancel-dialog p { font-size: 0.85rem; color: var(--text-muted); overflow-wrap: anywhere; }
.cancel-dialog .cancel-dialog-details { color: var(--text-main); padding: 12px; margin-bottom: 12px; border-radius: 6px; background: var(--bg-base); }
.cancel-dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.cancel-dialog-actions button { min-height: 44px; padding: 10px 16px; }
.cancel-dialog-confirm { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
.history-item { padding: 16px; border: 1px solid var(--border-color); border-radius: 12px; background: var(--bg-card, #151a23); min-width: 0; }
.history-item-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.history-item-badge { padding: 4px 10px; border-radius: 20px; background: #1e2634; color: var(--text-main); font-size: 0.75rem; }
.history-item-date { color: var(--text-muted); font-size: 0.75rem; }
.history-item-details { margin: 16px 0; display: grid; gap: 10px; }
.history-item-details > div { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 12px; align-items: baseline; }
.history-item-details dt { color: var(--text-muted); font-size: 0.8rem; }
.history-item-details dd { margin: 0; text-align: right; color: var(--text-main); font-size: 0.85rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.history-item-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; border-top: 1px solid var(--border-color); padding-top: 12px; }
.history-item-footer > div { display: grid; gap: 5px; color: var(--text-muted); font-size: 0.75rem; min-width: 0; overflow-wrap: anywhere; }
.history-item-footer .history-cancel { min-height: 44px; padding: 10px 14px; }
.history-tab:focus-visible, .history-action:focus-visible, .history-table-scroll:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.history-status { min-height: 1.5em; color: var(--text-muted); font-size: 0.75rem; margin-bottom: 8px; }
.history-table-scroll { overflow-x: auto; }
.history-table { width: 100%; min-width: 800px; border-collapse: collapse; font-size: 0.75rem; }
.history-table th, .history-table td { padding: 10px; border-bottom: 1px solid var(--border-color); text-align: right; white-space: nowrap; }
.history-table th { color: var(--text-muted); font-weight: 500; }
.history-table th:first-child, .history-table td:first-child { text-align: left; }
.history-table .history-empty { text-align: center; color: var(--text-muted); padding: 24px 12px; }
.history-pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; color: var(--text-muted); font-size: 0.75rem; }

footer {
	background-color: var(--bg-card);
	border-top: 1px solid var(--border-color);
	padding: 16px;
	margin-top: auto;
}

.footer-content {
	max-width: 1360px;
	margin: 0 auto;
	display: flex;
	justify-content: space-between;
	align-items: center;
	flex-wrap: wrap;
	gap: 12px;
	font-size: 0.75rem;
	color: var(--text-muted);
}

.footer-links {
	display: flex;
	gap: 16px;
	flex-wrap: wrap;
}

.footer-links a {
	color: var(--text-muted);
	text-decoration: none;
}

.footer-links a:hover {
	color: var(--text-main);
}

/* 반응형 데스크톱 스타일 분기 (900px 초과) */
@media (min-width: 901px) {
	.current-price {
		width: auto;
		padding-left: 2rem;
		font-size: 2.5rem;
	}

	.coin-title {
		flex-wrap: nowrap;
	}

	.stats-group {
		display: flex;
		width: auto;
		border-top: none;
		padding-top: 0;
		gap: 24px;
		font-size: 0.85rem;
	}

	.stats-item span {
		display: block;
		margin-right: 0;
		margin-bottom: 2px;
	}

	.trading-layout {
		align-items: stretch;
		min-height: 0;
	}

	.chart-container {
		height: auto;
		min-height: 0;
		min-width: 0;
	}

	.chart-toolbar { flex: 0 0 auto; }

	.canvas-wrapper {
		flex: 1 1 0;
		height: auto;
		min-height: 0;
	}

	.canvas-wrapper canvas {
		position: absolute;
		inset: 0;
	}

	.side-panel { min-width: 0; }
	.order-panel-card { flex: 0 0 auto; }
	.order-book-card {
		flex: 0 0 auto;
		display: flex;
		flex-direction: column;
	}
	.order-book-card .order-book {
		flex: 0 0 auto;
		display: flex;
		flex-direction: column;
	}
	.order-book-card table { flex: 0 0 auto; }
	.order-book-card td { padding: 2px 0; vertical-align: middle; }
}

/* 모바일 최적화 (900px 이하) */
@media (max-width: 900px) {
	.trade-history-card .history-table-scroll { display: none; }
	.history-cards { display: grid; gap: 12px; }
	.desktop {
		display: none;
	}

	.mobile {
		display: grid;
		grid-template-columns: repeat(2, 1fr);
	}

	.chart-container {
		height: 280px;
	}

	.trading-layout {
		grid-template-columns: 1fr;
	}

	.side-panel {
		display: flex;
		flex-direction: column;
	}

	.order-panel-card {
		order: 1;
	}

	.order-book-card {
		order: 2;
	}
}
