/*
 * 한강아니면 한강뷰 (Hanriver) - Design System & Modern Fintech Stylesheet
 * Toss & TradingView 스타일의 다크모드 대시보드
 */

:root {
  --bg-primary: #07090e;
  --bg-secondary: #0d121d;
  --bg-card: #111726;
  --bg-card-hover: #161e31;
  --bg-input: #1a2236;
  --border-color: #1e293b;
  --border-focus: #3b82f6;

  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-emerald: #10b981;
  --accent-emerald-dark: #059669;
  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;

  /* 글로벌 기본: 녹색=수익, 적색=손실 */
  --color-profit: #10b981;
  --color-loss: #ef4444;

  --font-sans: -apple-system, BlinkMacSystemFont, "Pretendard Variable", Pretendard, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --sidebar-width: 250px;
  --header-height: 64px;
  --mobile-nav-height: 60px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
}

/* 한국형 색상 테마 (빨강=수익, 파랑=손실) */
body.theme-korean {
  --color-profit: #ef4444;
  --color-loss: #3b82f6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

/* 유틸리티 */
.tabular { font-variant-numeric: tabular-nums; }
.profit { color: var(--color-profit) !important; }
.loss { color: var(--color-loss) !important; }
.muted { color: var(--text-muted); }

/* 전체 레이아웃 */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* 사이드바 */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
}

.brand-section {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-svg {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-text .brand-en {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--accent-emerald);
}

.slogan-badge {
  margin: 12px 16px 8px;
  padding: 8px 12px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.slogan-badge strong {
  display: block;
  color: var(--accent-emerald);
  font-size: 11.5px;
}

/* 네비게이션 */
.nav-menu {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-main);
}

.nav-item.active {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  font-weight: 600;
}

.nav-item .icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-bottom {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
}

.quick-action-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent-emerald);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
  transition: background 0.15s;
}

.quick-action-btn:hover {
  background: var(--accent-emerald-dark);
}

/* 메인 컨텐츠 영역 */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* 탑 헤더 */
.top-header {
  height: var(--header-height);
  background: rgba(13, 18, 29, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}

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

.page-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.account-selector {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  cursor: pointer;
}

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

.currency-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.currency-btn {
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
}

.currency-btn.active {
  background: var(--accent-emerald);
  color: #fff;
}

.btn-header-action {
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-header-action:hover {
  border-color: var(--text-secondary);
}

/* 본문 섹션 */
.content-area {
  padding: 24px;
  flex: 1;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* 카드 및 그리드 */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-card);
  position: relative;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

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

.metric-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.metric-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-main);
  margin-bottom: 4px;
}

.metric-sub {
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 목표 달성 프로그레스 */
.goal-banner {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(6, 182, 212, 0.05) 100%);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.goal-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-emerald) 0%, var(--accent-cyan) 100%);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* 차트 그리드 */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

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

.chart-period-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-input);
  padding: 2px;
  border-radius: var(--radius-sm);
}

.period-tab {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
}

.period-tab.active {
  background: var(--bg-card);
  color: var(--accent-emerald);
}

.canvas-container {
  width: 100%;
  height: 280px;
  position: relative;
}

/* 테이블 스타일 */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

th {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--bg-card-hover);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.badge-buy { background: rgba(16, 185, 129, 0.15); color: var(--accent-emerald); }
.badge-sell { background: rgba(59, 130, 246, 0.15); color: var(--accent-blue); }
.badge-short { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-cover { background: rgba(168, 85, 247, 0.15); color: #c084fc; }
.badge-deposit { background: rgba(14, 165, 233, 0.15); color: #38bdf8; }
.badge-dividend { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }

.btn-tv-chip {
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-tv-chip:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.btn-tv-chip.active {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--accent-emerald);
  color: var(--accent-emerald);
}

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

/* 모바일 네비게이션 */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--mobile-nav-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  z-index: 50;
  justify-content: space-around;
  align-items: center;
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px;
  flex: 1;
}

.mobile-nav-btn.active {
  color: var(--accent-emerald);
}

.mobile-nav-btn .icon {
  font-size: 18px;
}

/* 모달 다이얼로그 */
dialog.custom-modal {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0;
  width: 90%;
  max-width: 520px;
  margin: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 70vh;
  overflow-y: auto;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent-emerald);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-secondary {
  padding: 9px 16px;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
}

.btn-primary {
  padding: 9px 20px;
  background: var(--accent-emerald);
  border: none;
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-emerald-dark);
}

/* 토스트 알림 */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  font-size: 13px;
  z-index: 100;
  display: none;
  align-items: center;
  gap: 10px;
  border-left: 4px solid var(--accent-emerald);
}

/* 반응형 모바일 쿼리 */
@media (max-width: 860px) {
  .sidebar {
    display: none;
  }
  .main-wrapper {
    margin-left: 0;
    padding-bottom: calc(var(--mobile-nav-height) + 16px);
  }
  .mobile-nav {
    display: flex;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .content-area {
    padding: 16px;
  }
  .top-header {
    padding: 0 16px;
  }
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }
}
