/* ===================================
   자동이 (Jadong-i) Trading Dashboard
   Design System - Dark Premium Theme
   =================================== */

/* === CSS Variables === */
:root {
  /* Background */
  --bg-body: #080b1a;
  --bg-primary: #0f1323;
  --bg-secondary: #141829;
  --bg-card: rgba(20, 24, 50, 0.85);
  --bg-card-hover: rgba(25, 30, 60, 0.95);
  --bg-input: rgba(15, 19, 35, 0.9);
  --bg-nav: rgba(10, 14, 30, 0.95);

  /* Accent Colors */
  --accent: #00d4ff;
  --accent-dim: rgba(0, 212, 255, 0.15);
  --accent-glow: rgba(0, 212, 255, 0.3);
  --purple: #7c4dff;
  --purple-dim: rgba(124, 77, 255, 0.15);

  /* Semantic Colors */
  --green: #00e676;
  --green-dim: rgba(0, 230, 118, 0.12);
  --red: #ff5252;
  --red-dim: rgba(255, 82, 82, 0.12);
  --yellow: #ffab40;
  --yellow-dim: rgba(255, 171, 64, 0.12);

  /* Text */
  --text-primary: #e8ecf4;
  --text-secondary: #8b92a5;
  --text-dim: #555d74;

  /* Borders */
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(0, 212, 255, 0.25);

  /* Glass */
  --glass-bg: rgba(20, 24, 50, 0.6);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s ease;

  /* Font */
  --font-main: 'Inter', 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* === Light Theme === */
[data-theme="light"] {
  --bg-body: #f0f2f5;
  --bg-primary: #ffffff;
  --bg-secondary: #f5f6f8;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: rgba(245, 246, 250, 0.95);
  --bg-input: rgba(240, 242, 245, 0.9);
  --bg-nav: rgba(255, 255, 255, 0.95);

  --accent: #0091d5;
  --accent-dim: rgba(0, 145, 213, 0.1);
  --accent-glow: rgba(0, 145, 213, 0.2);
  --purple: #6c3ce0;
  --purple-dim: rgba(108, 60, 224, 0.1);

  --green: #16a34a;
  --green-dim: rgba(22, 163, 74, 0.1);
  --red: #dc2626;
  --red-dim: rgba(220, 38, 38, 0.1);
  --yellow: #d97706;
  --yellow-dim: rgba(217, 119, 6, 0.1);

  --text-primary: #1a1a2e;
  --text-secondary: #555d74;
  --text-dim: #9ca3af;

  --border: rgba(0, 0, 0, 0.06);
  --border-light: rgba(0, 0, 0, 0.1);
  --border-accent: rgba(0, 145, 213, 0.25);

  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
}

/* === Reset & Base === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  opacity: 0.85;
}

/* === Material Symbols === */
.material-symbols-rounded {
  font-size: 1.2em;
  vertical-align: middle;
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

.nav-menu .material-symbols-rounded {
  font-size: 1.25rem;
}

.card-title .material-symbols-rounded {
  font-size: 1.15rem;
}

.logo-icon .material-symbols-rounded {
  font-size: 1.2rem;
  color: #fff;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* === Layout === */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 20px 24px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

/* === Navigation === */
.nav {
  background: var(--bg-nav);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.nav-brand .logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
}

.nav-menu li a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-menu li a:hover {
  color: var(--text-primary);
  background: var(--accent-dim);
}

.nav-menu li a.active {
  color: var(--accent);
  background: var(--accent-dim);
}

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

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-badge.online {
  background: var(--green-dim);
  color: var(--green);
}

.status-badge.offline {
  background: var(--red-dim);
  color: var(--red);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

/* === Cards === */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition-normal);
}

.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
}

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

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon {
  font-size: 1rem;
}

/* === Dashboard Grid === */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto auto;
  gap: 16px;
}

.chart-area {
  grid-column: 1;
  grid-row: 1 / 3;
}

.sidebar-area {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bottom-area {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* === Chart === */
.chart-container {
  min-height: 480px;
}

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

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

.market-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.market-price {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.market-change {
  font-size: 0.875rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
}

.market-change.up {
  color: var(--green);
  background: var(--green-dim);
}

.market-change.down {
  color: var(--red);
  background: var(--red-dim);
}

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

.timeframe-tab {
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.timeframe-tab:hover {
  color: var(--text-secondary);
}

.timeframe-tab.active {
  color: var(--accent);
  background: var(--accent-dim);
}

#chart-wrapper {
  width: 100%;
  height: 420px;
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* === Portfolio Card === */
.portfolio-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--font-mono);
  margin: 8px 0;
  letter-spacing: -0.5px;
}

.portfolio-pnl {
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.portfolio-pnl.up {
  color: var(--green);
}

.portfolio-pnl.down {
  color: var(--red);
}

.portfolio-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.portfolio-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.portfolio-amount {
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

/* === AI Signal Card === */
.ai-signal-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.ai-signal-badge.buy {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(0, 230, 118, 0.2);
}

.ai-signal-badge.sell {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(255, 82, 82, 0.2);
}

.ai-signal-badge.hold {
  background: var(--yellow-dim);
  color: var(--yellow);
  border: 1px solid rgba(255, 171, 64, 0.2);
}

.confidence-bar-wrapper {
  margin: 12px 0;
}

.confidence-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
}

.confidence-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  transition: width var(--transition-slow);
}

.confidence-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.confidence-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.ai-sources {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.ai-source {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.ai-source-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.ai-source-dot.buy {
  background: var(--green);
}

.ai-source-dot.sell {
  background: var(--red);
}

.ai-source-dot.hold {
  background: var(--yellow);
}

.ai-source-dot.off {
  background: var(--text-dim);
}

/* === Positions List === */
.position-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.position-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.position-detail {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.position-pnl {
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-mono);
  text-align: right;
}

.position-pnl.up {
  color: var(--green);
}

.position-pnl.down {
  color: var(--red);
}

.position-pnl-pct {
  font-size: 0.7rem;
  display: block;
}

/* === Tables === */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

.data-table td {
  font-size: 0.8rem;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

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

.data-table .mono {
  font-family: var(--font-mono);
}

.badge-buy {
  color: var(--green);
  background: var(--green-dim);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.7rem;
}

.badge-sell {
  color: var(--red);
  background: var(--red-dim);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.7rem;
}

/* === System Status Bar === */
.status-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  margin-top: 16px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.status-value {
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

/* === Page Tabs (for non-dashboard pages) === */
.page-section {
  display: none;
}

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

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 0.875rem;
}

/* === Metric Grid (for Portfolio page) === */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  margin: 4px 0;
}

.metric-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === Loading Animation === */
.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, rgba(255, 255, 255, 0.05) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

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

  100% {
    background-position: -200% 0;
  }
}

/* === Responsive === */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .sidebar-area {
    grid-column: 1;
    grid-row: auto;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-area .card {
    flex: 1;
    min-width: 250px;
  }

  .bottom-area {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  html {
    font-size: 13px;
  }

  .nav-menu {
    display: none;
  }

  .main-content {
    padding: 12px;
  }

  .dashboard-grid {
    gap: 12px;
  }

  .sidebar-area {
    flex-direction: column;
  }

  #chart-wrapper {
    height: 300px;
  }

  .status-bar {
    flex-wrap: wrap;
    gap: 12px;
  }
}

/* === Theme Toggle Button === */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-normal);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-accent);
  transform: rotate(15deg);
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: inline;
}

.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: inline;
}

/* Light theme table hover fix */
[data-theme="light"] .data-table tr:hover td {
  background: rgba(0, 0, 0, 0.02);
}

/* Light theme scrollbar */
[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #c4c9d4;
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: #a1a8b5;
}

/* Light theme confidence bar bg */
[data-theme="light"] .confidence-bar-bg {
  background: rgba(0, 0, 0, 0.06);
}

/* Light theme select styling */
[data-theme="light"] #market-select option {
  background: #ffffff;
  color: #1a1a2e;
}

/* === Settings Form Controls === */
.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setting-input {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 0.85rem;
  font-family: var(--font-main);
  transition: all var(--transition-fast);
  cursor: pointer;
  -webkit-appearance: none;
}

.setting-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-main);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* === Utility === */
.text-green {
  color: var(--green);
}

.text-red {
  color: var(--red);
}

.text-yellow {
  color: var(--yellow);
}

.text-accent {
  color: var(--accent);
}

.text-dim {
  color: var(--text-dim);
}

.text-mono {
  font-family: var(--font-mono);
}

.fw-bold {
  font-weight: 700;
}

.mt-1 {
  margin-top: 8px;
}

.mt-2 {
  margin-top: 16px;
}

.mb-1 {
  margin-bottom: 8px;
}

.gap-8 {
  gap: 8px;
}

.flex {
  display: flex;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

/* === Tooltip for Terms (투자 용어 설명) === */
.term {
  position: relative;
  border-bottom: 1px dotted var(--accent);
  cursor: help;
  transition: color 0.2s;
}

.term:hover {
  color: var(--accent);
}

.term::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-primary);
  border: 1px solid var(--accent-dim);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.6;
  width: max-content;
  max-width: 300px;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.term:hover::after {
  opacity: 1;
  visibility: visible;
}