/*
 * runmcp 디자인 시스템 — 방향 1a · 화이트 미니멀
 * 정보 밀도 우선 / 단일 인디고 액센트 / 얇은 보더 / 모노는 기계값에만 / 상태는 색점
 * 참조: design.md
 */

:root {
	--bg: #eceaf3;
	--surface: #ffffff;
	--surface-2: #faf9fc;
	--border: #e7e6ec;
	--border-weak: #eeedf2;
	--border-row: #f4f3f8;
	--text: #1c1c22;
	--text-2: #71717a;
	--text-3: #9a9aa4;
	--muted: #8a8a94;
	--accent: #5b5bd6;
	--accent-hover: #4a4ac4;
	--accent-weak: #f2f1f7;
	--ink: #1c1c22;
	--ink-text: #ffffff;

	--online: #22c55e;
	--session: #8b5cd6;
	--offline: #c3c3cc;
	--success: #16a34a;
	--danger: #e5484d;
	--danger-weak: #fdecec;
	--warning: #f59e0b;

	--radius-card: 14px;
	--radius-btn: 9px;
	--radius-chip: 7px;
	--shadow-card: 0 1px 2px rgba(20, 20, 40, .04), 0 12px 40px -12px rgba(30, 25, 70, .12);

	--font-ui: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
	--font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
	--font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}

:root[data-theme="dark"] {
	--bg: #0a0b10;
	--surface: #12141c;
	--surface-2: #0e111a;
	--border: #232838;
	--border-weak: #1a1e2b;
	--border-row: #1a1e2b;
	--text: #e6e9f0;
	--text-2: #8a90a3;
	--text-3: #5a6076;
	--muted: #6b7186;
	--accent: #7c6df0;
	--accent-hover: #9384f7;
	--accent-weak: #1c1830;
	--ink: #e6e9f0;
	--ink-text: #12141c;
	--danger-weak: #2a1518;
	--shadow-card: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 40px -12px rgba(0, 0, 0, .5);
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #0a0b10;
		--surface: #12141c;
		--surface-2: #0e111a;
		--border: #232838;
		--border-weak: #1a1e2b;
		--border-row: #1a1e2b;
		--text: #e6e9f0;
		--text-2: #8a90a3;
		--text-3: #5a6076;
		--muted: #6b7186;
		--accent: #7c6df0;
		--accent-hover: #9384f7;
		--accent-weak: #1c1830;
		--ink: #e6e9f0;
		--ink-text: #12141c;
		--danger-weak: #2a1518;
		--shadow-card: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 40px -12px rgba(0, 0, 0, .5);
	}
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	padding: 0;
}

body.rmcp-body {
	background: var(--bg);
	font-family: var(--font-body);
	color: var(--text);
	min-height: 100vh;
	-webkit-font-smoothing: antialiased;
}

.rmcp-mono { font-family: var(--font-mono); }

/* ---------- 앱 셸 ---------- */
.rmcp-shell {
	max-width: 1400px;
	margin: 0 auto;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-card);
	box-shadow: var(--shadow-card);
	overflow: hidden;
}

/* ---------- 상단바 ---------- */
.rmcp-topbar {
	height: 54px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 0 18px;
	border-bottom: 1px solid var(--border-weak);
	background: var(--surface);
}

.rmcp-brand {
	display: flex;
	align-items: center;
	gap: 8px;
	font-family: var(--font-ui);
	font-weight: 700;
	font-size: 14px;
	letter-spacing: -.01em;
	color: var(--text);
	text-decoration: none;
}

.rmcp-brand-badge {
	width: 22px;
	height: 22px;
	border-radius: 6px;
	background: var(--accent);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: var(--font-mono);
	font-weight: 700;
	font-size: 12px;
}

.rmcp-tabs {
	display: flex;
	align-items: center;
	gap: 4px;
	flex: 1;
	justify-content: center;
	flex-wrap: wrap;
}

.rmcp-tab {
	appearance: none;
	border: none;
	background: transparent;
	color: var(--text-2);
	font-family: var(--font-ui);
	font-weight: 600;
	font-size: 12.5px;
	padding: 6px 11px;
	border-radius: 7px;
	cursor: pointer;
	white-space: nowrap;
	transition: background .12s ease, color .12s ease;
}

.rmcp-tab:hover { color: var(--text); }

.rmcp-tab.active,
.rmcp-tab[aria-selected="true"] {
	background: var(--accent-weak);
	color: var(--text);
}

.rmcp-topbar-right {
	display: flex;
	align-items: center;
	gap: 8px;
}

.rmcp-icon-btn {
	width: 30px;
	height: 30px;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text-2);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	font-size: 14px;
	transition: background .12s ease, border-color .12s ease;
}

.rmcp-icon-btn:hover { background: var(--accent-weak); border-color: var(--accent); }

.rmcp-avatar {
	width: 30px;
	height: 30px;
	border-radius: 8px;
	background: var(--accent);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: var(--font-ui);
	font-weight: 700;
	font-size: 11px;
}

/* ---------- 스탯 바 ---------- */
.rmcp-stats {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 1px;
	background: var(--border-weak);
	border-bottom: 1px solid var(--border-weak);
}

@media (max-width: 720px) {
	.rmcp-stats { grid-template-columns: repeat(2, 1fr); }
}

.rmcp-stat-cell {
	background: var(--surface);
	padding: 14px 18px;
}

.rmcp-stat-label {
	font-size: 11px;
	font-weight: 500;
	color: var(--text-3);
	margin-bottom: 4px;
}

.rmcp-stat-value {
	font-family: var(--font-ui);
	font-size: 20px;
	font-weight: 700;
	letter-spacing: -.02em;
	color: var(--text);
}

.rmcp-stat-value.is-success { color: var(--success); }
.rmcp-stat-value.is-session { color: var(--session); }
.rmcp-stat-value.is-warning { color: var(--warning); }
.rmcp-stat-value.is-danger { color: var(--danger); }

/* ---------- 툴바 ---------- */
.rmcp-toolbar {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 18px;
	border-bottom: 1px solid var(--border-weak);
	flex-wrap: wrap;
}

.rmcp-search {
	flex: 1;
	min-width: 180px;
	height: 34px;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 0 12px;
	border: 1px solid var(--border);
	border-radius: 9px;
	background: var(--surface);
	color: var(--text-3);
}

.rmcp-search input {
	border: none;
	outline: none;
	background: transparent;
	font-size: 12.5px;
	color: var(--text);
	width: 100%;
	font-family: var(--font-body);
}

.rmcp-search input::placeholder { color: var(--text-3); }

/* ---------- 버튼 ---------- */
.rmcp-btn {
	appearance: none;
	border: 1px solid transparent;
	border-radius: var(--radius-btn);
	height: 34px;
	padding: 0 14px;
	font-family: var(--font-ui);
	font-weight: 600;
	font-size: 12.5px;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	transition: background .12s ease, border-color .12s ease, opacity .12s ease;
	white-space: nowrap;
}

.rmcp-btn:disabled { opacity: .5; cursor: not-allowed; }

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

.rmcp-btn-ink { background: var(--ink); color: var(--ink-text); }
.rmcp-btn-ink:hover { opacity: .85; }

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

.rmcp-btn-ghost-accent { background: transparent; color: var(--accent); border-color: var(--border); }
.rmcp-btn-ghost-accent:hover { background: var(--accent-weak); border-color: var(--accent); }

.rmcp-btn-warning { background: var(--warning); color: #fff; }
.rmcp-btn-warning:hover { opacity: .88; }

.rmcp-btn-danger { background: var(--danger); color: #fff; }
.rmcp-btn-danger:hover { opacity: .88; }

.rmcp-btn-sm { height: 28px; padding: 5px 12px; font-size: 11.5px; border-radius: 7px; }

/* ---------- 컴팩트 테이블 ---------- */
.rmcp-table { width: 100%; }

.rmcp-table-head,
.rmcp-table-row {
	display: grid;
	align-items: center;
	gap: 14px;
	padding: 9px 18px;
}

.rmcp-table-head {
	padding: 8px 18px;
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--text-3);
	border-bottom: 1px solid var(--border-weak);
}

.rmcp-table-row {
	border-top: 1px solid var(--border-row);
	transition: background .1s ease;
}

.rmcp-table-row:first-child { border-top: none; }
.rmcp-table-row:hover { background: var(--accent-weak); }

.rmcp-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--offline);
	flex-shrink: 0;
}

.rmcp-dot.is-online { background: var(--online); }
.rmcp-dot.is-session { background: var(--session); }
.rmcp-dot.is-offline { background: var(--offline); }
.rmcp-dot.is-installed { background: var(--online); }
.rmcp-dot.is-installing { background: var(--warning); }
.rmcp-dot.is-not-installed { background: var(--offline); }

.rmcp-cell-name {
	font-family: var(--font-mono);
	font-size: 12.5px;
	font-weight: 600;
	color: var(--text);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.rmcp-cell-desc {
	font-size: 12px;
	color: var(--text-2);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.rmcp-cell-mono {
	font-family: var(--font-mono);
	font-size: 12px;
	color: var(--muted);
	text-align: right;
}

.rmcp-cell-action { text-align: right; }

/* ---------- 명령어 바 ---------- */
.rmcp-cmdbar {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 18px;
	background: var(--surface-2);
	border-top: 1px solid var(--border-weak);
}

.rmcp-cmdbar-prefix {
	font-family: var(--font-mono);
	font-weight: 600;
	font-size: 13px;
	color: var(--accent);
}

.rmcp-cmdbar input {
	flex: 1;
	border: 1px solid var(--border);
	border-radius: 8px;
	height: 32px;
	padding: 0 10px;
	font-family: var(--font-mono);
	font-weight: 500;
	font-size: 13px;
	background: var(--surface);
	color: var(--text);
	outline: none;
}

.rmcp-cmdbar input:focus {
	border-color: var(--accent);
	box-shadow: 0 0 0 2px rgba(91, 91, 214, .15);
}

.rmcp-cmdbar-meta {
	font-size: 11px;
	color: var(--text-3);
	white-space: nowrap;
}

/* ---------- 배지 / 칩 ---------- */
.rmcp-badge {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: var(--accent-weak);
	color: var(--accent);
	border-radius: 6px;
	font-size: 11px;
	font-weight: 600;
	padding: 2px 7px;
}

.rmcp-status-tag {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	color: var(--text-2);
}

/* ---------- 인풋 ---------- */
.rmcp-field label {
	display: block;
	font-size: 12px;
	font-weight: 600;
	color: var(--text);
	margin-bottom: 6px;
}

.rmcp-input {
	width: 100%;
	height: 34px;
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0 12px;
	font-size: 13px;
	font-family: var(--font-body);
	background: var(--surface);
	color: var(--text);
	outline: none;
	transition: border-color .12s ease, box-shadow .12s ease;
}

.rmcp-input:focus {
	border-color: var(--accent);
	box-shadow: 0 0 0 2px rgba(91, 91, 214, .15);
}

.rmcp-input::placeholder { color: var(--text-3); }

/* ---------- 배너 / 토스트 ---------- */
.rmcp-banner {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 14px;
	background: var(--danger-weak);
	border: 1px solid var(--danger);
	border-radius: 8px;
	color: var(--danger);
	font-size: 12.5px;
}

.rmcp-toast {
	position: fixed;
	right: 20px;
	bottom: 20px;
	display: flex;
	align-items: center;
	gap: 8px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	box-shadow: var(--shadow-card);
	padding: 10px 14px;
	font-size: 12.5px;
	color: var(--text);
	z-index: 1000;
}

/* ---------- 스켈레톤 ---------- */
.rmcp-skeleton {
	background: linear-gradient(90deg, var(--border-weak) 25%, var(--border) 50%, var(--border-weak) 75%);
	background-size: 200% 100%;
	animation: rmcp-shimmer 1.4s ease infinite;
	border-radius: 6px;
}

@keyframes rmcp-shimmer {
	0% { background-position: 200% 0; }
	100% { background-position: -200% 0; }
}

.rmcp-empty {
	text-align: center;
	padding: 40px 20px;
	color: var(--text-2);
	font-size: 13px;
}

/* =====================================================================
 * 모바일 레이어 (mobile-design.md · 360–767px)
 * 데스크톱 토큰은 그대로 상속. 아래는 <768px에서만 적용되는 구조 변경.
 * ===================================================================== */

/* ---------- 표시 유틸 ---------- */
.rmcp-mobile-only { display: none; }

@media (max-width: 767px) {
	.rmcp-desktop-only { display: none !important; }
	.rmcp-mobile-only { display: block; }
	.rmcp-mobile-only.rmcp-flex { display: flex; }
}

/* ---------- 뷰포트 / safe-area ---------- */
@media (max-width: 767px) {
	.rmcp-shell {
		max-width: none;
		border-left: none;
		border-right: none;
		border-radius: 0;
		box-shadow: none;
	}

	body.rmcp-body {
		padding-left: max(16px, env(safe-area-inset-left));
		padding-right: max(16px, env(safe-area-inset-right));
	}

	/* iOS 자동 확대 방지: 인풋 폰트 16px 이상 */
	.rmcp-input,
	.rmcp-search input,
	.rmcp-cmdbar input {
		font-size: 16px;
	}

	/* 터치 타깃 최소 44px */
	.rmcp-btn { min-height: 44px; }
	.rmcp-btn-sm { min-height: 36px; }
	.rmcp-icon-btn,
	.rmcp-avatar { width: 40px; height: 40px; }
	.rmcp-tab { min-height: 44px; }
}

/* ---------- 하단 탭바 (Bottom Tab Bar) ---------- */
.rmcp-bottom-tabbar {
	display: none;
}

@media (max-width: 767px) {
	.rmcp-bottom-tabbar {
		display: flex;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		height: 56px;
		padding-bottom: env(safe-area-inset-bottom);
		background: var(--surface);
		border-top: 1px solid var(--border);
		z-index: 500;
	}

	.rmcp-bottom-tab {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		gap: 2px;
		min-height: 44px;
		color: var(--text-3);
		text-decoration: none;
		font-family: var(--font-ui);
	}

	.rmcp-bottom-tab-icon { font-size: 20px; line-height: 1; }

	.rmcp-bottom-tab-label {
		font-size: 10px;
		font-weight: 500;
	}

	.rmcp-bottom-tab.active {
		color: var(--accent);
	}

	.rmcp-bottom-tab.active .rmcp-bottom-tab-label { font-weight: 600; }

	/* 하단 탭바에 가려지지 않도록 본문 하단 여백 확보 */
	.rmcp-has-bottom-tabbar {
		padding-bottom: calc(56px + env(safe-area-inset-bottom));
	}
}

/* ---------- 카드 리스트 (테이블 대체) ---------- */
@media (max-width: 767px) {
	.rmcp-table-head { display: none; }

	.rmcp-table-row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 4px 10px;
		border: 1px solid var(--border);
		border-top: 1px solid var(--border);
		border-radius: 12px;
		margin: 0 14px 10px;
		padding: 14px;
		min-height: 44px;
	}

	.rmcp-table-row:first-child { margin-top: 14px; border-top: 1px solid var(--border); }

	.rmcp-cell-name { flex: 1; min-width: 0; font-size: 13px; }
	.rmcp-cell-mono { flex: 0 0 auto; text-align: right; }
	.rmcp-cell-desc { flex-basis: 100%; order: 4; }
	.rmcp-cell-action,
	.server-actions {
		flex-basis: 100%;
		order: 5;
		display: flex;
		justify-content: flex-end;
		margin-top: 4px;
	}
}

/* ---------- 바텀시트 ---------- */
.rmcp-sheet-overlay {
	position: fixed;
	inset: 0;
	background: rgba(20, 20, 40, .4);
	display: none;
	align-items: flex-end;
	justify-content: center;
	z-index: 900;
}

.rmcp-sheet-overlay.open { display: flex; }

.rmcp-sheet {
	width: 100%;
	max-width: 480px;
	max-height: 85vh;
	overflow-y: auto;
	background: var(--surface);
	border-radius: 16px 16px 0 0;
	padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
	transform: translateY(100%);
	transition: transform .2s ease-out;
}

.rmcp-sheet-overlay.open .rmcp-sheet {
	transform: translateY(0);
}

.rmcp-sheet-handle {
	width: 36px;
	height: 4px;
	border-radius: 2px;
	background: var(--border);
	margin: 6px auto 14px;
}

.rmcp-sheet h2 {
	font-family: var(--font-ui);
	font-size: 16px;
	font-weight: 700;
	color: var(--text);
	margin: 0 0 16px;
}

/* ---------- 하단 고정 명령어 바 (모바일) ---------- */
.rmcp-cmdbar-fixed {
	display: none;
}

@media (max-width: 767px) {
	.rmcp-cmdbar-fixed {
		display: flex;
		align-items: center;
		gap: 8px;
		position: fixed;
		left: 0;
		right: 0;
		bottom: calc(56px + env(safe-area-inset-bottom));
		padding: 10px 14px;
		background: var(--surface-2);
		border-top: 1px solid var(--border-weak);
		z-index: 400;
	}

	.rmcp-cmdbar-fixed input {
		flex: 1;
		height: 40px;
		border: 1px solid var(--border);
		border-radius: 10px;
		padding: 0 12px;
		font-family: var(--font-mono);
		font-size: 16px;
		background: var(--surface);
		color: var(--text);
		outline: none;
	}

	.rmcp-cmdbar-fixed-run {
		flex-shrink: 0;
		width: 44px;
		height: 44px;
		border-radius: 50%;
		border: none;
		background: var(--ink);
		color: var(--ink-text);
		font-size: 16px;
		display: flex;
		align-items: center;
		justify-content: center;
		cursor: pointer;
	}
}

/* ---------- 다중 선택 액션 바 ---------- */
.rmcp-select-actionbar {
	display: none;
}

@media (max-width: 767px) {
	.rmcp-select-actionbar.open {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 10px;
		position: fixed;
		left: 0;
		right: 0;
		bottom: calc(56px + env(safe-area-inset-bottom));
		padding: 10px 14px;
		background: var(--ink);
		color: var(--ink-text);
		font-size: 12.5px;
		font-weight: 600;
		z-index: 400;
	}
}
