:root {
  --bg: #0a0a0f;
  --bg2: #12121a;
  --bg3: #1a1a26;
  --border: rgba(130,110,200,0.15);
  --accent: #7c5cbf;
  --accent2: #a07ee0;
  --accent3: #c8a7ff;
  --gold: #e4c97e;
  --gold2: #f0dfa0;
  --red: #e06060;
  --green: #60c090;
  --blue: #60a0e0;
  --text: #e8e4f0;
  --text2: #9990b8;
  --text3: #5a5478;
  --card-shadow: 0 4px 24px rgba(0,0,0,0.5);
  --radius: 12px;
}

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

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── 배경 파티클 ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(124,92,191,0.08) 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 80% 80%, rgba(228,201,126,0.05) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ── 로그인 화면 ── */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 1000;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 380px;
  text-align: center;
  box-shadow: var(--card-shadow), 0 0 60px rgba(124,92,191,0.1);
}
.login-card .logo {
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  color: var(--accent3);
  margin-bottom: 8px;
}
.login-card .sub { color: var(--text2); font-size: 13px; margin-bottom: 32px; }
.login-card input {
  width: 100%; padding: 12px 16px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
  margin-bottom: 12px; outline: none;
  font-family: 'Noto Sans KR', sans-serif;
  transition: border-color .2s;
}
.login-card input:focus { border-color: var(--accent2); }
.btn-primary {
  width: 100%; padding: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; border-radius: 8px;
  color: #fff; font-size: 15px; font-weight: 500;
  cursor: pointer; transition: opacity .2s;
  font-family: 'Noto Sans KR', sans-serif;
}
.btn-primary:hover { opacity: .85; }
.login-error { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 18px; }

/* ── 앱 레이아웃 ── */
#app { display: flex; min-height: 100vh; position: relative; z-index: 1; }
#app.hidden { display: none; }

/* ── 사이드바 ── */
.sidebar {
  width: 240px; min-height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; left: 0; top: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  padding: 28px 24px 20px;
  font-family: 'Playfair Display', serif;
  font-size: 20px; color: var(--accent3);
  border-bottom: 1px solid var(--border);
}
.sidebar-logo span { font-family: 'Noto Sans KR', sans-serif; font-size: 11px; color: var(--text3); display: block; margin-top: 2px; }
.nav { flex: 1; padding: 16px 12px; }
.nav-section { font-size: 10px; color: var(--text3); letter-spacing: .1em; text-transform: uppercase; padding: 12px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text2); font-size: 14px; cursor: pointer;
  transition: all .2s; margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(124,92,191,0.2); color: var(--accent3); }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }
.admin-info { display: flex; align-items: center; gap: 10px; }
.admin-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.admin-name { font-size: 13px; color: var(--text2); }
.logout-btn { margin-left: auto; background: none; border: none; color: var(--text3); cursor: pointer; font-size: 16px; transition: color .2s; }
.logout-btn:hover { color: var(--red); }

/* ── 메인 콘텐츠 ── */
.main { margin-left: 240px; flex: 1; padding: 32px; }
.page { display: none; }
.page.active { display: block; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

.page-header { margin-bottom: 28px; }
.page-title { font-family: 'Playfair Display', serif; font-size: 26px; color: var(--text); }
.page-subtitle { color: var(--text2); font-size: 13px; margin-top: 4px; }

/* ── 카드 ── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--card-shadow);
}
.card-title { font-size: 14px; color: var(--text2); margin-bottom: 16px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.card-title .ct-icon { font-size: 16px; }

/* ── 통계 카드 그리드 ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 24px;
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.stat-card.purple::before { background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.stat-card.gold::before { background: linear-gradient(90deg, #c09040, var(--gold)); }
.stat-card.green::before { background: linear-gradient(90deg, #30a060, var(--green)); }
.stat-card.blue::before { background: linear-gradient(90deg, #3070b0, var(--blue)); }
.stat-label { font-size: 12px; color: var(--text3); margin-bottom: 8px; }
.stat-value { font-family: 'JetBrains Mono', monospace; font-size: 28px; color: var(--text); font-weight: 600; }
.stat-change { font-size: 11px; margin-top: 6px; }
.stat-change.up { color: var(--green); }
.stat-change.down { color: var(--red); }
.stat-icon { position: absolute; right: 20px; top: 20px; font-size: 28px; opacity: .15; }

/* ── 그리드 레이아웃 ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 20px; }

/* ── 테이블 ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 14px; color: var(--text3); font-weight: 500; border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
td { padding: 12px 14px; border-bottom: 1px solid rgba(130,110,200,0.07); vertical-align: middle; }
tr:hover td { background: rgba(124,92,191,0.04); }
tr:last-child td { border-bottom: none; }

/* ── 배지 ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 500;
}
.badge.purple { background: rgba(124,92,191,0.2); color: var(--accent3); }
.badge.gold { background: rgba(228,201,126,0.15); color: var(--gold2); }
.badge.green { background: rgba(96,192,144,0.15); color: var(--green); }
.badge.red { background: rgba(224,96,96,0.15); color: var(--red); }
.badge.gray { background: rgba(90,84,120,0.3); color: var(--text3); }
.badge.blue { background: rgba(96,160,224,0.15); color: var(--blue); }

/* ── 필터 / 검색 ── */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px;
  flex: 1; min-width: 200px;
}
.search-box input { background: none; border: none; color: var(--text); font-size: 13px; outline: none; width: 100%; font-family: 'Noto Sans KR', sans-serif; }
.search-box .icon { color: var(--text3); }
.filter-btn {
  padding: 8px 16px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); font-size: 13px; cursor: pointer;
  transition: all .2s; white-space: nowrap;
  font-family: 'Noto Sans KR', sans-serif;
}
.filter-btn:hover, .filter-btn.active { background: rgba(124,92,191,0.15); border-color: var(--accent); color: var(--accent3); }
.action-btn {
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; border-radius: 8px;
  color: #fff; font-size: 13px; cursor: pointer;
  transition: opacity .2s; white-space: nowrap;
  font-family: 'Noto Sans KR', sans-serif;
}
.action-btn:hover { opacity: .8; }
.action-btn.secondary {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
}
.action-btn.secondary:hover { border-color: var(--accent); color: var(--accent3); }

/* ── 차트 컨테이너 ── */
.chart-container { position: relative; }
canvas { max-width: 100%; }

/* ── 키워드 태그 클라우드 ── */
.keyword-cloud { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0; }
.keyword-tag {
  padding: 6px 14px; border-radius: 20px;
  font-size: 13px; cursor: default;
  border: 1px solid;
  transition: transform .1s;
}
.keyword-tag:hover { transform: scale(1.05); }
.kw-1 { background: rgba(124,92,191,0.25); border-color: rgba(124,92,191,0.5); color: var(--accent3); font-size: 16px; font-weight: 600; }
.kw-2 { background: rgba(124,92,191,0.18); border-color: rgba(124,92,191,0.35); color: var(--accent3); font-size: 14px; font-weight: 500; }
.kw-3 { background: rgba(124,92,191,0.1); border-color: rgba(124,92,191,0.2); color: var(--text2); font-size: 13px; }
.kw-4 { background: rgba(90,84,120,0.15); border-color: rgba(90,84,120,0.3); color: var(--text3); font-size: 12px; }

/* ── 모달 ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10,10,15,0.85); backdrop-filter: blur(4px);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px;
  width: min(700px, 95vw); max-height: 85vh;
  overflow-y: auto; box-shadow: var(--card-shadow);
  transform: scale(.95); transition: transform .2s;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); }
.modal-close { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 20px; transition: color .2s; }
.modal-close:hover { color: var(--text); }

/* ── Ask 상세 카드 ── */
.ask-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; margin-bottom: 10px;
}
.ask-item .ask-concern { font-size: 14px; color: var(--text); margin-bottom: 8px; line-height: 1.6; }
.ask-meta { display: flex; gap: 12px; flex-wrap: wrap; }
.ask-meta span { font-size: 11px; color: var(--text3); }

/* ── 구독 만료 경고 ── */
.expiry-alert {
  background: rgba(224,96,96,0.08); border: 1px solid rgba(224,96,96,0.2);
  border-radius: 10px; padding: 14px 18px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 12px;
}
.expiry-alert .alert-icon { font-size: 20px; }
.expiry-alert .alert-text { flex: 1; }
.expiry-alert .alert-title { font-size: 13px; font-weight: 600; color: var(--red); }
.expiry-alert .alert-sub { font-size: 12px; color: var(--text3); margin-top: 2px; }

/* ── 로딩 ── */
.loading-state { text-align: center; padding: 60px 20px; color: var(--text3); }
.spinner { width: 36px; height: 36px; border: 2px solid var(--border); border-top-color: var(--accent2); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 빈 상태 ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }

/* ── 설정 화면 ── */
.settings-section { margin-bottom: 28px; }
.settings-label { font-size: 12px; color: var(--text3); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .05em; }
.settings-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.settings-field label { font-size: 13px; color: var(--text2); }
.settings-input {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
  color: var(--text); font-size: 13px; outline: none;
  font-family: 'JetBrains Mono', monospace;
  transition: border-color .2s;
}
.settings-input:focus { border-color: var(--accent2); }
.save-msg { font-size: 12px; color: var(--green); margin-top: 8px; min-height: 18px; }

/* ── 반응형 ── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-240px); }
  .main { margin-left: 0; padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── 프로그레스 바 ── */
.progress-bar { background: var(--bg3); border-radius: 4px; height: 6px; margin-top: 6px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .5s ease; }

/* ── 유저 아바타 ── */
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
}

/* ── 구분선 ── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ── 링크 버튼 ── */
.link-btn { background: none; border: none; color: var(--accent2); cursor: pointer; font-size: 13px; text-decoration: underline; text-underline-offset: 2px; font-family: 'Noto Sans KR', sans-serif; }
.link-btn:hover { color: var(--accent3); }

/* Firebase 설정 안내 */
.firebase-notice {
  background: rgba(228,201,126,0.08); border: 1px solid rgba(228,201,126,0.2);
  border-radius: 10px; padding: 16px 20px; margin-bottom: 20px;
}
.firebase-notice .notice-title { font-size: 13px; font-weight: 600; color: var(--gold2); margin-bottom: 4px; }
.firebase-notice .notice-body { font-size: 12px; color: var(--text3); line-height: 1.7; }
.firebase-notice code { font-family: 'JetBrains Mono', monospace; background: var(--bg3); padding: 1px 6px; border-radius: 4px; font-size: 11px; color: var(--accent3); }

/* 토글 스위치 */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-size: 13px; color: var(--text2); }
.toggle-sub { font-size: 11px; color: var(--text3); }
.toggle { position: relative; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--bg3); border-radius: 22px;
  cursor: pointer; transition: .2s;
  border: 1px solid var(--border);
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 16px; height: 16px; left: 2px; top: 2px;
  background: var(--text3); border-radius: 50%; transition: .2s;
}
.toggle input:checked + .toggle-slider { background: rgba(124,92,191,0.3); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: var(--accent3); }
