:root {
  /* 텔레그램 웹앱 네이티브 CSS 변수 연동 */
  --bg-color: var(--tg-theme-bg-color, #0f172a);
  --secondary-bg-color: var(--tg-theme-secondary-bg-color, #1e293b);
  --card-bg: rgba(30, 41, 59, 0.9);
  --text-color: var(--tg-theme-text-color, #f8fafc);
  --hint-color: var(--tg-theme-hint-color, #94a3b8);
  --link-color: var(--tg-theme-link-color, #38bdf8);
  --button-color: var(--tg-theme-button-color, #2563eb);
  --button-text-color: var(--tg-theme-button-text-color, #ffffff);
  
  --primary-accent: #3b82f6;
  --unread-badge: #ef4444;
  --border-color: rgba(255, 255, 255, 0.08);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg-color: var(--tg-theme-bg-color, #f8fafc);
    --secondary-bg-color: var(--tg-theme-secondary-bg-color, #f1f5f9);
    --card-bg: #ffffff;
    --text-color: var(--tg-theme-text-color, #0f172a);
    --hint-color: var(--tg-theme-hint-color, #64748b);
    --border-color: rgba(0, 0, 0, 0.06);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

#app-container {
  width: 100%;
  max-width: 540px;
  padding: 16px;
  padding-bottom: 70px;
}

/* 상단 헤더 */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.brand-info h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--hint-color);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background-color: var(--secondary-bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s;
}

.icon-btn:active {
  transform: scale(0.92);
}

/* 상태 배너 */
.status-banner {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.status-banner .banner-icon {
  color: #f59e0b;
  font-size: 18px;
  flex-shrink: 0;
}

.status-banner .banner-text {
  font-size: 0.78rem;
}

.status-banner .banner-text strong {
  display: block;
  color: #f59e0b;
  margin-bottom: 2px;
}

.status-banner .banner-text code {
  background: rgba(0, 0, 0, 0.2);
  padding: 1px 4px;
  border-radius: 4px;
}

/* 통계 요약 카드 */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.icon-blue { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.icon-red { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

.stat-details {
  display: flex;
  flex-direction: column;
}

.stat-title {
  font-size: 0.72rem;
  color: var(--hint-color);
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
}

/* 검색창 */
.search-section {
  margin-bottom: 12px;
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--secondary-bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 42px;
}

.search-bar i {
  color: var(--hint-color);
  font-size: 14px;
}

.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-color);
  font-size: 0.88rem;
  padding: 0 10px;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--hint-color);
  cursor: pointer;
  padding: 4px;
}

/* 카테고리 칩 바 */
.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.chip {
  background: var(--secondary-bg-color);
  color: var(--hint-color);
  border: 1px solid var(--border-color);
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.chip.active {
  background: var(--button-color);
  color: var(--button-text-color);
  border-color: var(--button-color);
}

.chip .badge {
  background: rgba(0, 0, 0, 0.2);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.7rem;
}

/* 아코디언 섹션 */
.accordion-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.category-block {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}

.category-header {
  padding: 14px 16px;
  background: var(--secondary-bg-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

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

.cat-icon-badge {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.cat-name {
  font-size: 0.95rem;
  font-weight: 700;
}

.cat-counter {
  font-size: 0.75rem;
  color: var(--hint-color);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 7px;
  border-radius: 10px;
}

.cat-chevron {
  color: var(--hint-color);
  font-size: 13px;
  transition: transform 0.25s ease;
}

.category-block.collapsed .cat-chevron {
  transform: rotate(-90deg);
}

.category-block.collapsed .dialog-list {
  display: none;
}

/* 대화방 리스트 */
.dialog-list {
  display: flex;
  flex-direction: column;
}

.dialog-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s;
}

.dialog-item:last-child {
  border-bottom: none;
}

.dialog-item:active {
  background: rgba(255, 255, 255, 0.03);
}

.dialog-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.dialog-main {
  flex: 1;
  min-width: 0;
}

.dialog-top-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.dialog-title {
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
}

.dialog-time {
  font-size: 0.72rem;
  color: var(--hint-color);
  flex-shrink: 0;
}

.dialog-bottom-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-preview {
  font-size: 0.78rem;
  color: var(--hint-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  padding-right: 8px;
}

.dialog-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.unread-badge {
  background-color: var(--unread-badge);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
}

.btn-open-chat {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.15);
  color: var(--primary-accent);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
}

.btn-change-cat {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--secondary-bg-color);
  color: var(--hint-color);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
}

/* 로딩 & 상태 */
.state-container {
  text-align: center;
  padding: 40px 20px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--button-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 바텀시트 모달 */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  width: 100%;
  max-width: 540px;
  background: var(--secondary-bg-color);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-md);
}

.modal-backdrop.open .modal-sheet {
  transform: translateY(0);
}

.modal-drag-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--hint-color);
  opacity: 0.4;
  margin: -8px auto 14px;
}

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

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-subtitle {
  font-size: 0.78rem;
  color: var(--hint-color);
}

.category-select-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cat-select-btn {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.15s;
}

.cat-select-btn:active {
  background: var(--button-color);
  color: var(--button-text-color);
}

/* 대화방 관리 / 삭제 옵션 */
.modal-danger-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}

.danger-action-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #f87171;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.danger-action-btn:hover,
.danger-action-btn:active {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

.danger-action-btn.secondary {
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: var(--hint-color);
}

.danger-action-btn.secondary:hover,
.danger-action-btn.secondary:active {
  background: rgba(148, 163, 184, 0.15);
}

/* 토스트 */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(15, 23, 42, 0.95);
  color: #fff;
  border: 1px solid var(--border-color);
  padding: 9px 16px;
  border-radius: 24px;
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* 유저 전환 버튼 & 뱃지 */
.user-badge-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #38bdf8;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.user-badge-btn:active {
  background: rgba(59, 130, 246, 0.3);
  transform: scale(0.96);
}

/* 활성 사용자 정보 바 */
.active-user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  font-size: 0.82rem;
}

.user-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-shield-icon {
  color: #10b981;
  font-size: 14px;
}

.user-bar-text strong {
  color: var(--text-color);
  font-weight: 700;
}

.user-id-sub {
  color: var(--hint-color);
  font-size: 0.76rem;
  margin-left: 4px;
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--link-color);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}

.text-link-btn:hover {
  text-decoration: underline;
}

/* 배너 경고 및 액션 버튼 */
.banner-warning {
  background: rgba(245, 158, 11, 0.1) !important;
  border: 1px solid rgba(245, 158, 11, 0.3) !important;
}

.banner-warning .banner-icon {
  background: rgba(245, 158, 11, 0.2) !important;
  color: #f59e0b !important;
}

.banner-action-btn {
  background: #f59e0b;
  color: #0f172a;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  margin-left: 8px;
}

/* 유저 입력 섹션 */
.user-input-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.input-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--hint-color);
}

.input-group {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.input-prefix {
  padding: 0 12px;
  color: var(--hint-color);
  font-size: 16px;
}

.input-group input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 6px;
  color: var(--text-color);
  font-size: 0.92rem;
  outline: none;
}

.primary-btn {
  background: var(--button-color);
  color: var(--button-text-color);
  border: none;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}

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

.input-helper {
  font-size: 0.75rem;
  color: var(--hint-color);
  line-height: 1.4;
}

.saved-accounts-section {
  border-top: 1px solid var(--border-color);
  padding-top: 14px;
}

.section-sub-title {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--hint-color);
  margin-bottom: 10px;
}

.account-chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.account-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-color);
  transition: all 0.15s ease;
}

.account-chip.active {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.15);
  font-weight: 700;
}

.account-chip .chip-badge {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 0.72rem;
  color: var(--hint-color);
}

