/* ========================================
   공통 스타일 — llm-agent
   CSS 변수, 사이드바, 공통 컴포넌트
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Montserrat:wght@400;500;600;700;800&display=swap');
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css');

/* ─── CSS 변수 ─── */
:root {
  /* ─── 라이트 테마 배경/표면 ─── */
  --bg: #f4f4f8;
  --surface: #ffffff;
  --surface2: #ededf3;
  --border: #dddde8;
  --border-bright: #c2c2d8;
  --text: #141420;
  --text-muted: #5a5a75;
  --text-dim: #9898b0;

  /* ─── 액센트 — 라이트 배경 명도비 확보 ─── */
  --accent-pm: #d4860a;
  --accent-dev: #16a34a;
  --accent-design: #7c3aed;
  --accent-qa: #2563eb;
  --accent-pipe: #e11d48;

  /* ─── 글로우 — 라이트 모드 opacity 낮춤 ─── */
  --glow-pm: rgba(212, 134, 10, 0.10);
  --glow-dev: rgba(22, 163, 74, 0.10);
  --glow-design: rgba(124, 58, 237, 0.10);
  --glow-qa: rgba(37, 99, 235, 0.10);

  --font-sans: 'Montserrat', 'Pretendard Variable', 'Pretendard', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --sidebar-width: 220px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --transition-fast: 0.15s;
  --transition-mid: 0.25s;
}

/* ─── 리셋 & 기본 ─── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* 노이즈 오버레이 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 999;
  opacity: 0; /* 라이트 모드에서 노이즈 오버레이 비활성화 */
}

/* ─── 사이드바 ─── */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  z-index: 100;
  transition: transform var(--transition-mid);
}

.logo {
  padding: 0 20px 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-pipe), var(--accent-design));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  margin-bottom: 10px;
}

.logo-text {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}

.logo-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.beta-badge {
  display: inline-block;
  background: var(--accent-pipe);
  color: #000;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.05em;
}

/* ─── 내비게이션 ─── */
.nav-section {
  padding: 0 12px;
  margin-bottom: 4px;
}

.nav-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  padding: 0 8px;
  margin-bottom: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  margin-bottom: 2px;
  text-decoration: none;
  min-height: 44px; /* 터치 영역 최소 44px */
}

.nav-item:hover {
  background: var(--surface2);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface2);
  color: var(--text);
}

.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── 에이전시 유형 선택 카드 ─── */
.agency-selector-wrap {
  margin-bottom: 24px;
}

.agency-selector-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 10px;
}

.agency-selector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

.agency-select-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.agency-select-card:hover {
  border-color: var(--agency-color, var(--border-bright));
  background: var(--agency-glow, var(--surface2));
}

.agency-card-icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

.agency-card-body {
  flex: 1;
  min-width: 0;
}

.agency-card-label {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 2px;
}

.agency-card-desc {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agency-card-check {
  font-size: 11px;
  font-weight: 700;
  color: var(--agency-color, var(--text));
  flex-shrink: 0;
}

/* ─── 서브 내비게이션 (에이전시 유형 등) ─── */
.sub-nav-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-left: 26px;
  margin-bottom: 2px;
}

.sub-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
  transition: all var(--transition-fast);
  min-height: 34px;
  border-left: 1px solid var(--border);
}

.sub-nav-item:hover {
  background: var(--surface2);
  color: var(--text-muted);
  border-left-color: var(--border-bright);
}

.sub-nav-item.active {
  color: var(--text);
  border-left-color: var(--border-bright);
  background: var(--surface2);
}

.sub-nav-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* 사이드바 하단 토큰 잔여량 */
.sidebar-footer {
  margin-top: auto;
  padding: 0 20px;
}

.token-balance {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1.6;
}

.token-balance-value {
  color: var(--accent-design);
  font-size: 11px;
}

/* ─── 메인 영역 ─── */
.main {
  margin-left: var(--sidebar-width);
  padding: 32px 40px;
  min-height: 100vh;
}

/* ─── 페이지 헤더 ─── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.page-title span {
  background: linear-gradient(90deg, var(--accent-pipe), var(--accent-design));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-subtitle {
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ─── 버튼 ─── */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
  min-height: 44px; /* 터치 영역 */
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover {
  border-color: var(--border-bright);
  color: var(--text);
}

.btn-primary {
  background: var(--accent-pipe);
  color: #000;
  font-weight: 700;
}

.btn-primary:hover {
  opacity: 0.85;
}

/* ─── 전체 실행 버튼 — 쉬머 스타일 ─── */
#run-btn-header {
  position: relative;
  background: linear-gradient(90deg, #4b5563 0%, #e2e8f0 40%, #ffffff 55%, #e2e8f0 70%, #4b5563 100%);
  background-size: 250% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: run-btn-shimmer 2.8s linear infinite;
  color: transparent;
}

#run-btn-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: #111213;
  border-radius: var(--radius-sm);
  z-index: -1;
}

#run-btn-header:hover { opacity: 0.75; }

#run-btn-header:disabled {
  animation: none;
  -webkit-text-fill-color: #6b7280;
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes run-btn-shimmer {
  0%   { background-position: 200% center; }
  100% { background-position: -50% center; }
}

.btn-sm {
  padding: 5px 12px;
  font-size: 11px;
  min-height: 32px;
}

/* ─── 배지 ─── */
.rank-badge {
  font-size: 9px;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* ─── 상태 도트 ─── */
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-dot.pulse {
  animation: pulse 2s infinite;
}

/* ─── 카드 ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.card-subtitle {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── 실행 중 인디케이터 ─── */
.running-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.running-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-pipe);
  animation: bounce 0.8s infinite;
}

.running-dot:nth-child(2) { animation-delay: 0.15s; }
.running-dot:nth-child(3) { animation-delay: 0.3s; }

/* ─── 섹션 헤더 ─── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ─── 알림 배너 ─── */
.context-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(124, 58, 237, 0.08);
  border: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.context-icon { font-size: 12px; }

.context-text {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent-design);
  opacity: 0.8;
}

/* ─── 햄버거 메뉴 (모바일) ─── */
.hamburger {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  font-size: 16px;
  min-height: 44px;
  min-width: 44px;
  align-items: center;
  justify-content: center;
}

/* ─── 애니메이션 ─── */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes grow {
  from { width: 20%; }
  to { width: 45%; }
}

/* ─── 반응형: 모바일 768px 이하 ─── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    padding: 72px 16px 24px;
  }

  .hamburger {
    display: flex;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
}
