@import url('https://fonts.googleapis.com/css2?family=Pretendard:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Dark Theme (Default) */
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.3);

  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-primary-glow: rgba(99, 102, 241, 0.25);

  --color-stock: #3b82f6;
  --color-deposit: #10b981;
  --color-cash: #f59e0b;
  
  --profit-up: #ef4444; /* 한국식 주식 상승 레드 */
  --profit-down: #3b82f6; /* 한국식 주식 하락 블루 */
  --profit-up-soft: rgba(239, 68, 68, 0.15);
  --profit-down-soft: rgba(59, 130, 246, 0.15);

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px var(--accent-primary-glow);
}

[data-theme='light'] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: #ffffff;
  --bg-glass: rgba(0, 0, 0, 0.02);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.4);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.02);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background-image: 
    radial-gradient(at 15% 15%, rgba(99, 102, 241, 0.08) 0px, transparent 50%),
    radial-gradient(at 85% 85%, rgba(16, 185, 129, 0.05) 0px, transparent 50%);
  background-attachment: fixed;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  min-width: 0;
}

/* Navbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-badge {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  background: linear-gradient(to right, #6366f1, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  background: rgba(99, 102, 241, 0.12);
  color: #818cf8;
  border-radius: 6px;
  font-weight: 600;
}

/* Member Selector Pills & Carousel */
.member-carousel-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 700px;
  position: relative;
  min-width: 0;
}

.member-pills-scroll {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-glass);
  padding: 4px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  scroll-behavior: smooth;
  flex: 1;
}

.member-pills-scroll::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.member-scroll-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
  padding: 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.member-scroll-btn:hover:not(:disabled) {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
  transform: scale(1.08);
}

.member-scroll-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
  transform: none;
}

.member-pills {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-glass);
  padding: 4px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.member-pill {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.member-pill:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.member-pill.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

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

/* Nav Actions */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.fx-rate-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 4px 10px;
  background: var(--bg-glass);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
}

/* Tab Navigation */
.tabs-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  white-space: nowrap;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

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

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.15s ease;
  flex-shrink: 0;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}

.tab-btn.active {
  color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding: 1.5rem;
  max-width: 1440px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin: 0 auto;
}

/* Cards & Glassmorphism */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.glass-card:hover {
  border-color: var(--border-highlight);
}

/* Metric Summary Grid */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.metric-sub {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-profit {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-profit.up {
  color: var(--profit-up);
  background: var(--profit-up-soft);
}
.badge-profit.down {
  color: var(--profit-down);
  background: var(--profit-down-soft);
}

/* Dashboard Charts Grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }

@media (max-width: 1024px) {
  .col-8, .col-4, .col-6 {
    grid-column: span 12;
  }
}

.card-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Tables */
.modern-table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.modern-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.modern-table th {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.modern-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  white-space: nowrap;
}

.modern-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 4px 12px var(--accent-primary-glow);
}
.btn-primary:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-glass);
  color: var(--text-primary);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.2s ease-out;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.form-input, .form-select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-primary-glow);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Loading Modal & Overlay */
.loading-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: loadingFadeIn 0.25s ease-out;
  user-select: none;
}

.loading-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 2.2rem 2.5rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), 0 0 35px rgba(99, 102, 241, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  min-width: 290px;
  max-width: 360px;
  animation: loadingScaleUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.loading-modal-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #6366f1, #a855f7, #ec4899);
  animation: loadingShimmer 2s infinite linear;
  background-size: 200% 100%;
}

.loading-spinner-wrapper {
  position: relative;
  width: 68px;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: #6366f1;
  border-right-color: #a855f7;
  animation: loadingSpin 1s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
}

.loading-spinner-ring-outer {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px dashed rgba(168, 85, 247, 0.35);
  animation: loadingSpinReverse 3s linear infinite;
}

.loading-spinner-icon {
  color: #818cf8;
  animation: loadingPulse 1.6s ease-in-out infinite;
}

.loading-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.01em;
}

.loading-modal-subtext {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  margin-bottom: 0;
}

.loading-dots span {
  animation: loadingDotBlink 1.4s infinite;
  opacity: 0;
}
.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.25s; }
.loading-dots span:nth-child(3) { animation-delay: 0.5s; }

@keyframes loadingFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes loadingScaleUp {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes loadingSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes loadingSpinReverse {
  0% { transform: rotate(360deg); }
  100% { transform: rotate(0deg); }
}

@keyframes loadingPulse {
  0%, 100% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 1; }
}

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

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

/* ========================================================
   Device Visibility Utilities (데스크탑/모바일 분기)
   ======================================================== */
.mobile-only {
  display: none !important;
}
.desktop-only {
  display: block;
}
nav.desktop-only {
  display: flex !important;
}

/* ========================================================
   모바일 최적화 반응형 레이아웃 (max-width: 768px)
   * PC(769px 이상)의 기존 레이아웃은 100% 그대로 보존됨
   ======================================================== */
@media (max-width: 768px) {
  .mobile-only {
    display: block !important;
  }
  .mobile-only-flex,
  nav.mobile-only {
    display: flex !important;
  }
  .desktop-only,
  nav.desktop-only {
    display: none !important;
  }

  /* 1. 상단 네비게이션 바 (Navbar): 2행 반응형 배치 및 화면 밖 넘침 원천 차단 */
  .navbar {
    display: flex;
    flex-wrap: wrap;
    padding: 0.5rem 0.65rem;
    gap: 0.4rem;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
  }

  .brand-section {
    order: 1;
    flex-shrink: 0;
    gap: 0.4rem;
  }

  .brand-name {
    font-size: 1.1rem;
  }

  .logo-badge {
    width: 30px;
    height: 30px;
    border-radius: 8px;
  }

  .nav-actions {
    order: 2;
    margin-left: auto;
    gap: 0.25rem;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    max-width: calc(100% - 75px);
    min-width: 0;
  }

  .nav-actions .btn-sm {
    padding: 0.25rem 0.4rem;
    flex-shrink: 0;
  }

  .user-profile-chip {
    padding: 2px 5px !important;
    gap: 3px !important;
    max-width: 90px;
    flex-shrink: 1;
  }

  .user-name-text {
    max-width: 45px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
  }

  .user-admin-badge {
    display: none; /* 모바일에서는 텍스트 넘침 방지를 위해 왕관/실드 아이콘으로 대체 */
  }

  .fx-rate-chip {
    font-size: 0.68rem;
    padding: 2px 4px;
    gap: 3px;
    max-width: 105px;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .member-carousel-wrapper {
    order: 3;
    width: 100%;
    max-width: 100%;
    margin-top: 2px;
    min-width: 0;
  }

  .member-pills-scroll {
    padding: 3px;
    gap: 0.25rem;
  }

  .member-pill {
    padding: 4px 10px;
    font-size: 0.78rem;
  }

  .member-scroll-btn {
    width: 24px;
    height: 24px;
  }

  /* 2. 모바일 하단 내비게이션 바 (Bottom Navigation Bar): 작은 폰 및 safe-area 완벽 대응 */
  .bottom-nav-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    z-index: 1000;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 2px 2px calc(4px + env(safe-area-inset-bottom, 0px)) 2px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    overflow: hidden;
  }

  .bottom-nav-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    font-size: clamp(0.6rem, 2.3vw, 0.72rem);
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 3px 1px;
    border-radius: 8px;
    transition: all 0.15s ease;
    user-select: none;
    box-sizing: border-box;
  }

  .bottom-nav-item svg {
    width: 18px;
    height: 18px;
  }

  .bottom-nav-item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
    line-height: 1.2;
  }

  .bottom-nav-item:hover,
  .bottom-nav-item.active {
    color: var(--accent-primary);
  }

  .bottom-nav-item.active {
    font-weight: 700;
  }

  .bottom-nav-item.active svg {
    transform: scale(1.08);
    filter: drop-shadow(0 0 6px var(--accent-primary-glow));
  }

  /* 3. 메인 컨텐츠 영역 여백 (하단 내비바 및 플로팅 위젯에 가려지지 않도록 충분한 하단 간격 확보) */
  .main-content {
    padding: 0.75rem 0.65rem calc(76px + env(safe-area-inset-bottom, 12px)) 0.65rem;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
  }

  /* 4. 대시보드 2x2 메트릭 요약 그리드 */
  .summary-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
  }

  .metric-card {
    padding: 0.75rem 0.65rem;
    gap: 0.3rem;
  }

  .metric-header {
    font-size: 0.72rem;
  }

  .metric-value {
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .metric-sub {
    font-size: 0.7rem;
    flex-wrap: wrap;
    gap: 0.2rem;
  }

  /* 5. 카드 및 차트 그리드 모바일 정돈 */
  .glass-card {
    padding: 0.85rem;
    border-radius: var(--radius-md);
  }

  .charts-grid {
    gap: 0.75rem;
    margin-bottom: 0.85rem;
  }

  .card-title {
    font-size: 0.95rem;
  }

  /* 차트 모바일 높이 최적화 (스크롤 압박 완화 및 가독성 향상) */
  .dashboard-chart-treemap {
    height: 250px !important;
  }
  .dashboard-chart-pie {
    height: 220px !important;
  }
  .dashboard-chart-bar {
    height: 220px !important;
  }
  .asset-trend-echarts {
    height: 210px !important;
  }

  /* 6. 모달 팝업 & 폼 모바일 맞춤 */
  .modal-overlay {
    padding: 0.5rem;
  }

  .modal-content {
    width: 95%;
    max-width: 95%;
    padding: 1.1rem;
    max-height: 85vh;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  /* 7. 모바일 전용 주식 카드 리스트 스타일 */
  .stock-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
  }

  .stock-mobile-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    box-shadow: var(--shadow-card);
    transition: border-color 0.2s;
  }

  .stock-mobile-card:hover {
    border-color: var(--border-highlight);
  }

  .stock-mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }

  .stock-mobile-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
  }

  .stock-mobile-sub {
    font-size: 0.75rem;
    color: var(--accent-primary);
    font-family: var(--font-mono);
  }

  .stock-mobile-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    padding: 0.6rem;
    border-radius: 8px;
    font-size: 0.8rem;
  }

  .stock-mobile-body-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .stock-mobile-body-label {
    font-size: 0.7rem;
    color: var(--text-muted);
  }

  .stock-mobile-body-val {
    font-family: var(--font-mono);
    font-weight: 700;
  }

  .stock-mobile-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
    font-size: 0.78rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* 8. 거래내역 모바일 카드 */
  .tx-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .tx-mobile-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }

  /* 9. 반응형 그리드 (저축, 계좌, 구성원 카드) */
  .responsive-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  /* 10. 모바일 차트 및 탭 텍스트 겹침 방지 */
  .echarts-for-react {
    overflow: visible;
  }

  .glass-card {
    padding: 1rem !important;
  }
}

/* ========================================================
   중간 해상도 (태블릿 및 소형 PC: 769px ~ 1250px) 상단 메뉴 넘침 방지
   ======================================================== */
@media (min-width: 769px) and (max-width: 1250px) {
  .navbar {
    padding: 0.65rem 1rem;
    gap: 0.5rem;
  }
  .member-carousel-wrapper {
    max-width: 360px;
  }
  .user-name-text {
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
  }
  .fx-rate-chip {
    font-size: 0.75rem;
    padding: 3px 6px;
  }
}

/* ========================================================
   전역 컨텐츠 동적 반응형 및 디스플레이 영역 잘림 방지 규칙
   ======================================================== */
img, svg, canvas {
  max-width: 100%;
}

.echarts-for-react {
  max-width: 100% !important;
  width: 100% !important;
}

/* 모든 그리드 컨테이너의 자식이 컨테이너를 뚫지 않도록 min-width: 0 보장 */
.summary-grid > *,
.charts-grid > *,
.responsive-grid > * {
  min-width: 0;
}



/* AI Chat Float & Widget Styles */

.ai-float-wrapper {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: inherit;
}

/* 플로팅 트리거 버튼 (FAB) */
.ai-fab-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
  color: #ffffff;
  border: none;
  border-radius: 9999px;
  padding: 12px 20px 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: visible;
}

.ai-fab-btn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 30px rgba(99, 102, 241, 0.55), 0 4px 10px rgba(0, 0, 0, 0.25);
}

.ai-fab-btn:active {
  transform: translateY(0) scale(0.98);
}

.ai-fab-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  backdrop-filter: blur(4px);
}

.ai-fab-pulse {
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  animation: ai-fab-ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
  pointer-events: none;
}

@keyframes ai-fab-ping {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  70%, 100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

.ai-fab-label {
  letter-spacing: -0.2px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}

.ai-fab-title {
  font-size: 13.5px;
  font-weight: 700;
}

.ai-fab-sub {
  font-size: 10.5px;
  opacity: 0.85;
  font-weight: 500;
}

/* 챗 윈도우 컨테이너 */
.ai-chat-window {
  width: 410px;
  height: 640px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 100px);
  background: var(--bg-card, #181920);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
  border-radius: 20px;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5), 0 0 1px 1px rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ai-slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  backdrop-filter: blur(20px);
}

@keyframes ai-slide-up {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* 윈도우 헤더 */
.ai-chat-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(139, 92, 246, 0.08) 100%);
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

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

.ai-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
  flex-shrink: 0;
}

.ai-header-titles {
  display: flex;
  flex-direction: column;
}

.ai-header-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary, #ffffff);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.ai-header-sub {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-tag-linked {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 9.5px;
  font-weight: 600;
}

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

.ai-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted, #94a3b8);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.ai-icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #ffffff);
}

.ai-icon-btn.active {
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
}

/* 설정 오버레이 패널 */
.ai-settings-panel {
  padding: 16px;
  background: var(--bg-secondary, #20222b);
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 12px;
  animation: ai-fade-in 0.2s ease;
}

@keyframes ai-fade-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-setting-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-setting-label {
  font-weight: 600;
  color: var(--text-secondary, #cbd5e1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-setting-input,
.ai-setting-select {
  background: var(--bg-card, #14151b);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
  color: var(--text-primary, #ffffff);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  outline: none;
  transition: border-color 0.2s ease;
}

.ai-setting-input:focus,
.ai-setting-select:focus {
  border-color: #6366f1;
}

.ai-setting-help {
  font-size: 10.5px;
  color: var(--text-muted, #94a3b8);
  line-height: 1.35;
}

.ai-setting-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.ai-btn-sm {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ai-btn-primary {
  background: #6366f1;
  color: #fff;
  border: none;
}
.ai-btn-primary:hover {
  background: #4f46e5;
}

.ai-btn-outline {
  background: transparent;
  color: var(--text-secondary, #cbd5e1);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
}
.ai-btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* 메시지 스크롤 영역 */
.ai-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 웰컴 인트로 */
.ai-welcome-card {
  background: linear-gradient(145deg, rgba(99, 102, 241, 0.08) 0%, rgba(168, 85, 247, 0.04) 100%);
  border: 1px dashed rgba(99, 102, 241, 0.25);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.ai-welcome-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary, #ffffff);
}

.ai-welcome-text {
  font-size: 12px;
  color: var(--text-secondary, #94a3b8);
  line-height: 1.5;
}

.ai-welcome-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-chip-btn {
  background: var(--bg-secondary, #232530);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
  color: var(--text-secondary, #cbd5e1);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chip-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
  transform: translateX(3px);
}

/* 메시지 버블 */
.ai-message-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.ai-message-row.user {
  justify-content: flex-end;
}

.ai-message-row.assistant {
  justify-content: flex-start;
}

.ai-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  font-size: 12px;
  margin-top: 2px;
}

.ai-msg-content-wrap {
  display: flex;
  flex-direction: column;
  max-width: 84%;
}

.ai-message-row.user .ai-msg-content-wrap {
  align-items: flex-end;
}

.ai-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.55;
  word-break: break-word;
}

.ai-message-row.user .ai-msg-bubble {
  background: #6366f1;
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.ai-message-row.assistant .ai-msg-bubble {
  background: var(--bg-secondary, #22242f);
  color: var(--text-primary, #e2e8f0);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
  border-bottom-left-radius: 4px;
}

.ai-msg-meta {
  font-size: 10px;
  color: var(--text-muted, #64748b);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 마크다운 렌더링 스타일 */
.ai-markdown {
  white-space: pre-wrap;
}

.ai-markdown p {
  margin: 0 0 8px 0;
}
.ai-markdown p:last-child {
  margin-bottom: 0;
}

.ai-markdown strong {
  font-weight: 700;
  color: #a5b4fc;
}

.ai-message-row.user .ai-markdown strong {
  color: #ffffff;
}

.ai-markdown ul,
.ai-markdown ol {
  margin: 4px 0 8px 18px;
  padding: 0;
}

.ai-markdown li {
  margin-bottom: 4px;
}

.ai-markdown table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 11px;
}

.ai-markdown th,
.ai-markdown td {
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
  padding: 5px 8px;
  text-align: left;
}

.ai-markdown th {
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
}

/* 에러 알림 카드 */
.ai-error-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  padding: 12px;
  color: #fca5a5;
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  line-height: 1.45;
}

.ai-error-title {
  font-weight: 700;
  color: #ef4444;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 타이핑 인디케이터 */
.ai-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--bg-secondary, #22242f);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.ai-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #818cf8;
  animation: ai-dot-bounce 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-dot:nth-child(2) { animation-delay: -0.16s; }

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

/* 하단 영역: 토큰 프로그레스 바 & 인풋 */
.ai-chat-footer {
  border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
  background: var(--bg-secondary, #1b1c24);
  padding: 10px 14px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

/* 토큰 사용량 & 남은량 프로그레스 바 카드 */
.ai-token-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.06));
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-token-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
}

.ai-token-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: var(--text-secondary, #cbd5e1);
}

.ai-token-badge-free {
  font-size: 9.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
  font-weight: 600;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.ai-token-counts {
  color: var(--text-muted, #94a3b8);
  font-variant-numeric: tabular-nums;
}

.ai-token-current {
  font-weight: 700;
  color: var(--text-primary, #ffffff);
}

/* 프로그레스 바 */
.ai-progress-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.ai-progress-bar {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s ease;
}

.ai-progress-bar.tier-safe {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.ai-progress-bar.tier-warning {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.ai-progress-bar.tier-danger {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

.ai-token-details {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted, #94a3b8);
}

.ai-token-percent {
  font-weight: 600;
}

.ai-token-remaining {
  color: #34d399;
}

/* 입력 바 영역 */
.ai-input-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-card, #14151b);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
  border-radius: 12px;
  padding: 6px 8px 6px 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-input-box:focus-within {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.ai-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary, #ffffff);
  font-size: 12.5px;
  line-height: 1.45;
  resize: none;
  max-height: 90px;
  outline: none;
  padding: 4px 0;
  font-family: inherit;
}

.ai-textarea::placeholder {
  color: var(--text-muted, #64748b);
}

.ai-send-btn {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.ai-send-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: scale(1.05);
}

.ai-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-input-bottom-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 10px;
  color: var(--text-muted, #64748b);
  padding: 0 4px;
}

.ai-shortcut-hint {
  font-size: 10.5px;
  color: var(--text-muted, #64748b);
}

/* 모바일 반응형 (하단 내비게이션 바 높이 58px 회피 및 크기 최적화) */
@media (max-width: 768px) {
  .ai-float-wrapper {
    bottom: 68px;
    right: 12px;
  }
  .ai-fab-btn {
    padding: 9px 14px 9px 12px;
    gap: 8px;
  }
  .ai-fab-icon-wrap {
    width: 28px;
    height: 28px;
  }
  .ai-fab-title {
    font-size: 12.5px;
  }
  .ai-fab-sub {
    font-size: 9.5px;
  }
  .ai-chat-window {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    height: calc(100vh - 84px);
    max-height: calc(100vh - 84px);
    border-radius: 16px;
  }
}
