/* ==========================================================================
   InvestFlow Modern Dark/Light Fintech Design System
   With Rich Micro-animations, Glassmorphism, and Global Floating Tooltip System
   ========================================================================== */

:root {
  --font-family: 'Inter', 'Noto Sans Thai', system-ui, -apple-system, sans-serif;

  /* Dark Theme Palette (Default) */
  --bg-app: #0b0f19;
  --bg-sidebar: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-card-hover: rgba(51, 65, 85, 0.8);
  --bg-input: #1e293b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(99, 102, 241, 0.4);

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

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-secondary: #06b6d4;
  
  --profit: #10b981;
  --loss: #f43f5e;
  --warning: #f59e0b;
  --info: #3b82f6;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);

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

  --sidebar-width: 260px;
}

[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-sidebar: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: #ffffff;
  --bg-input: #f8fafc;
  --border-color: #e2e8f0;
  --border-hover: rgba(99, 102, 241, 0.5);

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

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-overflow-scrolling: touch;
}

/* Explicit targeted transitions (fixes scroll lag & eliminates 60fps frame drops) */
a, button, .btn, .btn-icon, .nav-item, .mobile-nav-item, .currency-btn, .card, .stat-card, input, select, .badge, .pnl-pill {
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.card, .stat-card, .table-container {
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* ==========================================================================
   Global Body-Level Floating Tooltip (100% Immune to Any Overflow / Stacking)
   ========================================================================== */
#globalFloatingTooltip {
  position: fixed;
  z-index: 999999999;
  background-color: #0f172a;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 9px 13px;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.45;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(99, 102, 241, 0.2);
  pointer-events: none;
  max-width: 320px;
  width: max-content;
  white-space: normal;
  text-align: left;
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  transition: opacity 0.18s cubic-bezier(0.4, 0, 0.2, 1), transform 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  display: none;
}

[data-theme="light"] #globalFloatingTooltip {
  background-color: #0f172a;
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.2);
}

#globalFloatingTooltip.active {
  display: block;
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* In-Card Tooltip Target Indicator */
.has-tooltip {
  position: relative;
  cursor: help;
  display: inline-flex;
  align-items: center;
}

/* Hide standard child tooltip when JS floating portal is active */
.has-tooltip .tooltip-text {
  display: none !important;
}

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  backdrop-filter: blur(16px);
}

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

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.brand-info h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .brand-info h1 {
  background: linear-gradient(90deg, #0f172a, #334155);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-info span {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item i {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

.nav-item:hover {
  color: var(--text-primary);
  background-color: var(--bg-card-hover);
  transform: translateX(3px);
}

.nav-item.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-primary), #4f46e5);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background-color: rgba(255, 255, 255, 0.15);
  font-weight: 600;
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

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

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--profit);
  box-shadow: 0 0 8px var(--profit);
}

/* Main Layout */
.main-layout {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 28px 36px 60px;
  min-height: 100vh;
}

/* Top Header */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 20px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-search {
  flex: 1;
  max-width: 400px;
  position: relative;
}

.header-search input {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 9px 16px 9px 40px;
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
}

.header-search input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.header-search i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.88rem;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-primary-hover));
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

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

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

/* Currency Pill */
.currency-pill {
  display: flex;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 2px;
}

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

.currency-btn.active {
  background-color: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
}

/* KPI Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  backdrop-filter: blur(12px);
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-icon.primary { background: rgba(99, 102, 241, 0.15); color: var(--accent-primary); }
.stat-icon.secondary { background: rgba(6, 182, 212, 0.15); color: var(--accent-secondary); }
.stat-icon.success { background: rgba(16, 185, 129, 0.15); color: var(--profit); }
.stat-icon.warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.stat-icon.info { background: rgba(59, 130, 246, 0.15); color: var(--info); }

.stat-details {
  position: relative;
}

.stat-details h3 {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-trend {
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-weight: 500;
}

.pnl-positive { color: var(--profit); }
.pnl-negative { color: var(--loss); }

/* Dashboard Charts Grid (Sankey & Bar) */
.dashboard-charts-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.25fr;
  gap: 24px;
  margin-bottom: 28px;
}

@media (max-width: 1100px) {
  .dashboard-charts-grid {
    grid-template-columns: 1fr;
  }
}

/* Modern Typography for Google Charts Sankey Diagram */
#sankeyChartContainer svg text {
  font-family: 'Inter', 'Noto Sans Thai', system-ui, sans-serif !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em;
}

.google-visualization-tooltip {
  background: rgba(15, 23, 42, 0.95) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6) !important;
  font-family: 'Inter', 'Noto Sans Thai', sans-serif !important;
  font-size: 0.72rem !important;
  line-height: 1.4 !important;
  color: #f8fafc !important;
  padding: 6px 10px !important;
  z-index: 999999 !important;
}

.google-visualization-tooltip * {
  font-family: 'Inter', 'Noto Sans Thai', sans-serif !important;
  font-size: 0.72rem !important;
  line-height: 1.4 !important;
  color: #f8fafc !important;
}

.google-visualization-tooltip li,
.google-visualization-tooltip span,
.google-visualization-tooltip div {
  font-size: 0.72rem !important;
}

/* Dashboard Content Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 28px;
}

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

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(12px);
  position: relative;
}

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

.card-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

/* Allocation Bars */
.allocation-bar-wrap {
  margin-bottom: 14px;
}

.allocation-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 5px;
}

.progress-track {
  height: 8px;
  background-color: var(--bg-input);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Tables */
/* Tables & Freeze Header (Sticky Column Headers) */
.table-container {
  overflow-x: auto;
  overflow-y: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.custom-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
  font-size: 0.85rem;
}

.custom-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.custom-table th {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: var(--bg-card);
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border-color);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .custom-table th {
  background-color: #f1f5f9;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.custom-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

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

[data-theme="light"] .custom-table tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
}

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

.badge-available {
  background-color: rgba(16, 185, 129, 0.12);
  color: var(--profit);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.pnl-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
}

.pnl-pill.positive {
  background-color: rgba(16, 185, 129, 0.12);
  color: var(--profit);
}

.pnl-pill.negative {
  background-color: rgba(244, 63, 94, 0.12);
  color: var(--loss);
}

.action-badge {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

.action-buy {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--profit);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.action-sell {
  background-color: rgba(244, 63, 94, 0.15);
  color: var(--loss);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.action-balanced {
  background-color: rgba(99, 102, 241, 0.15);
  color: var(--accent-primary);
  border: 1px solid rgba(99, 102, 241, 0.3);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

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

.modal-box {
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.modal-backdrop.active .modal-box {
  transform: scale(1);
}

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

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background-color: rgba(0, 0, 0, 0.05);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.form-group.full-width {
  grid-column: 1 / -1;
}

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

.form-input, .form-select, .form-textarea {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Views display switcher */
.content-view {
  display: none;
  animation: fadeIn 0.2s ease-in;
}

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.select-filter {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

/* --- Killer Features: Stress Test, Freedom Milestones & Print Sheet --- */
.milestone-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.milestone-card.completed {
  border-color: rgba(16, 185, 129, 0.4);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.06) 0%, var(--bg-card) 100%);
}

.milestone-progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  margin: 10px 0 6px 0;
}

.milestone-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.stress-stat-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

@media print {
  body * {
    visibility: hidden;
  }
  #taxFilingModal,
  #taxFilingModalContent,
  #taxFilingPrintArea,
  #taxFilingPrintArea * {
    visibility: visible;
  }
  #taxFilingModal {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    background: #fff !important;
    display: block !important;
    opacity: 1 !important;
  }
  .modal-header, .modal-footer, .btn, .sidebar, .top-header {
    display: none !important;
  }
  #taxFilingPrintArea {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    color: #000 !important;
  }
}

/* --- Animated Gamified Freedom Journey Track --- */
.journey-track-wrapper {
  position: relative;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 85px 28px 32px 28px;
  overflow-x: auto;
  overflow-y: visible;
  margin-top: 20px;
}

.journey-road-container {
  position: relative;
  min-width: 720px;
  height: 80px;
  display: flex;
  align-items: center;
}

.journey-base-road {
  position: absolute;
  top: 50%;
  left: 30px;
  right: 30px;
  height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  transform: translateY(-50%);
  z-index: 1;
}

.journey-progress-road {
  position: absolute;
  top: 50%;
  left: 30px;
  height: 8px;
  background: linear-gradient(90deg, #10b981 0%, #06b6d4 45%, #6366f1 75%, #f59e0b 100%);
  border-radius: 6px;
  transform: translateY(-50%);
  z-index: 2;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.6);
  transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.journey-nodes-list {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: space-between;
  z-index: 3;
  padding: 0 10px;
}

.journey-checkpoint {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  cursor: pointer;
}

.checkpoint-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.journey-checkpoint.completed .checkpoint-circle {
  border-color: #10b981;
  background: #064e3b;
  color: #34d399;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.5);
}

.journey-checkpoint.active-target .checkpoint-circle {
  border-color: #06b6d4;
  background: #164e63;
  color: #67e8f9;
  animation: beaconPulse 2s infinite;
}

@keyframes beaconPulse {
  0% { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.6); }
  70% { box-shadow: 0 0 0 12px rgba(6, 182, 212, 0); }
  100% { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0); }
}

.checkpoint-label {
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 8px;
  text-align: center;
  white-space: nowrap;
}

.checkpoint-sub {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Vector Animated Walker Character Facing Right (Zero-Clipping) */
/* --- Authentic 8-Bit Pixel Art Hero Traveler --- */
.journey-walker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -100%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transition: left 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
  margin-top: -8px;
}

/* 8-Bit Retro RPG Dialogue / Status Bubble */
.walker-bubble {
  background: #090d16;
  border: 2px solid #10b981;
  box-shadow: 0 0 0 2px #0f172a, 0 6px 20px rgba(16, 185, 129, 0.5);
  color: #f8fafc;
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  font-family: 'Inter', 'Noto Sans Thai', monospace, sans-serif;
  animation: pixelBubbleHover 2s steps(4) infinite;
}

.walker-bubble::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #10b981;
}

.walker-pixel-container {
  width: 48px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* 8-Bit Ground Shadow */
.pixel-shadow {
  position: absolute;
  bottom: 0px;
  width: 28px;
  height: 6px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 2px;
  animation: pixelShadowStep 0.6s steps(2) infinite alternate;
}

/* 8-Bit Pixel Dust Particle */
.pixel-dust {
  position: absolute;
  bottom: 4px;
  left: -6px;
  width: 6px;
  height: 6px;
  background: #38bdf8;
  opacity: 0.7;
  border-radius: 1px;
  animation: pixelDustPuff 0.6s steps(3) infinite;
}

/* 4-Frame Authentic 8-Bit Walk Cycle Engine (Cross-Browser Rock Solid) */
.pixel-hero-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.pixel-frame {
  opacity: 0;
  visibility: hidden;
}

.pixel-f1 { animation: showF1 0.72s steps(1) infinite; }
.pixel-f2 { animation: showF2 0.72s steps(1) infinite; }
.pixel-f3 { animation: showF3 0.72s steps(1) infinite; }
.pixel-f4 { animation: showF4 0.72s steps(1) infinite; }

@keyframes showF1 {
  0%, 24.9% { opacity: 1; visibility: visible; }
  25%, 100% { opacity: 0; visibility: hidden; }
}
@keyframes showF2 {
  0%, 24.9% { opacity: 0; visibility: hidden; }
  25%, 49.9% { opacity: 1; visibility: visible; }
  50%, 100% { opacity: 0; visibility: hidden; }
}
@keyframes showF3 {
  0%, 49.9% { opacity: 0; visibility: hidden; }
  50%, 74.9% { opacity: 1; visibility: visible; }
  75%, 100% { opacity: 0; visibility: hidden; }
}
@keyframes showF4 {
  0%, 74.9% { opacity: 0; visibility: hidden; }
  75%, 99.9% { opacity: 1; visibility: visible; }
  100% { opacity: 0; visibility: hidden; }
}

@keyframes pixelBubbleHover {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-4px); }
}

@keyframes pixelShadowStep {
  0% { transform: scaleX(1); opacity: 0.6; }
  100% { transform: scaleX(0.8); opacity: 0.35; }
}

@keyframes pixelDustPuff {
  0% { transform: translate(0, 0) scale(1); opacity: 0.8; }
  50% { transform: translate(-8px, -4px) scale(0.6); opacity: 0.4; }
  100% { transform: translate(-14px, -6px) scale(0); opacity: 0; }
}

/* --- Daily Market Close Tracker Styles --- */
.daily-stat-badge {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.daily-timeline-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 2px;
}

.daily-timeline-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.daily-timeline-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent-primary);
}

.daily-timeline-item.positive {
  border-left: 3px solid var(--profit);
}

.daily-timeline-item.negative {
  border-left: 3px solid var(--loss);
}

@keyframes pulseDot {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   Global Floating Micro-Tooltip System (Ultra-Sleek, Compact, Glassmorphism)
   ========================================================================== */
.has-tooltip {
  position: relative;
  cursor: help;
}

.has-tooltip .tooltip-text {
  display: none !important;
}

#globalFloatingTooltip {
  position: fixed;
  z-index: 9999999;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(3px) scale(0.97);
  transition: opacity 0.15s ease-out, transform 0.15s ease-out, visibility 0.15s;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55), 0 2px 5px rgba(0, 0, 0, 0.3);
  color: #f8fafc;
  font-family: var(--font-family);
  font-size: 0.70rem;
  font-weight: 500;
  line-height: 1.38;
  padding: 5px 10px;
  border-radius: 6px;
  max-width: 220px;
  text-align: center;
  letter-spacing: -0.01em;
  word-break: break-word;
}

#globalFloatingTooltip.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

[data-theme="light"] #globalFloatingTooltip {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(0, 0, 0, 0.12);
  color: #0f172a;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   SMARTPHONE VERTICAL (PORTRAIT) NATIVE UI DESIGN SYSTEM
   ========================================================================== */
.mobile-menu-btn {
  display: none;
}

.header-brand-mobile {
  display: none;
}

.mobile-bottom-nav {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 15, 29, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.sidebar-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 900px) {
  .top-header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 14px;
  }
  
  .header-search {
    order: 3;
    width: 100%;
    margin-top: 4px;
  }
}

@media (max-width: 768px) {
  /* Layout Reflow */
  :root {
    --sidebar-width: 0px;
  }

  body {
    -webkit-tap-highlight-color: transparent;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .app-container {
    display: block;
    width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    width: 290px;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.7);
    background: var(--bg-sidebar);
    padding: 20px 16px;
    overflow-y: auto;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-layout {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 12px 12px 84px 12px !important;
  }

  /* Smartphone Header */
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1.05rem;
    cursor: pointer;
  }

  .header-brand-mobile {
    display: flex;
    align-items: center;
  }

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

  .page-title {
    font-size: 1rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 190px;
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .header-actions .btn span {
    display: none;
  }

  .header-actions .btn {
    padding: 8px 11px !important;
    min-width: 38px;
    justify-content: center;
  }

  .currency-pill {
    padding: 2px;
  }

  .currency-btn {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  /* Compact Stats Grid for Smartphone */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 16px !important;
  }

  .stat-card {
    padding: 12px 12px !important;
    border-radius: var(--radius-md) !important;
  }

  .stat-card h3 {
    font-size: 0.72rem !important;
    margin-bottom: 2px !important;
  }

  .stat-value {
    font-size: 1.18rem !important;
  }

  .stat-trend {
    font-size: 0.70rem !important;
  }

  .stat-icon {
    width: 36px !important;
    height: 36px !important;
    font-size: 1rem !important;
  }

  /* Cards & Forms */
  .card {
    padding: 16px 14px !important;
    border-radius: var(--radius-md) !important;
    margin-bottom: 16px !important;
    overflow: hidden !important;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 8px;
    margin-bottom: 14px !important;
  }

  .card-header h2 {
    font-size: 0.98rem !important;
  }

  /* Mobile Charts */
  .dashboard-charts-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    margin-bottom: 18px !important;
  }

  #sankeyChartContainer {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }

  #sankeyChartContainer svg {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Tables Mobile Touch Optimization */
  .table-container {
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
  }

  .custom-table {
    font-size: 0.78rem;
  }

  .custom-table th {
    padding: 9px 10px;
    font-size: 0.70rem;
    white-space: nowrap;
  }

  .custom-table td {
    padding: 10px 10px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  /* Bottom Sheet Modals on Mobile */
  .modal-backdrop {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .modal-box {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 88vh !important;
    padding: 20px 16px !important;
    animation: slideUpSheet 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  @keyframes slideUpSheet {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* Native Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    z-index: 990;
    align-items: center;
    justify-content: space-around;
    padding: 0 4px;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  }

  [data-theme="light"] .mobile-bottom-nav {
    background: rgba(255, 255, 255, 0.94);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 500;
    gap: 3px;
    transition: color 0.18s ease, transform 0.18s ease;
    user-select: none;
  }

  .mobile-nav-icon {
    font-size: 1.15rem;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .mobile-nav-item.active {
    color: var(--accent-primary);
    font-weight: 700;
  }

  .mobile-nav-item.active .mobile-nav-icon {
    transform: scale(1.18);
    color: var(--accent-primary);
  }
}

@media (max-width: 420px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .stat-value {
    font-size: 1.05rem !important;
  }

  .mobile-nav-item span {
    font-size: 0.62rem;
  }
}

