/* =====================================================================
   PRØXY JOURNAL — Mobile Enhancements, Animations & New Features
   ===================================================================== */

/* ===== PAGE ENTRY ANIMATIONS ===== */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeSlideLeft {
  from { opacity: 0; transform: translateX(-18px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.93); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position: 200% center; }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(124,58,237,0.4); }
  50%       { box-shadow: 0 0 0 10px rgba(124,58,237,0); }
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}
@keyframes dangerPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5), inset 0 0 0 0 rgba(239,68,68,0); }
  50%       { box-shadow: 0 0 0 12px rgba(239,68,68,0), inset 0 0 20px rgba(239,68,68,0.08); }
}
@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(30px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes warningEntrance {
  0%   { opacity: 0; transform: translateY(-40px) scale(0.9); }
  60%  { transform: translateY(4px) scale(1.02); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes numberCountUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Page load — body visible transition */
body {
  animation: none;
}
body.app-ready {
  animation: fadeSlideIn 0.4s ease both;
}

/* Staggered children on page switch */
.page.active > * {
  animation: fadeSlideIn 0.35s ease both;
}
.page.active > *:nth-child(1) { animation-delay: 0.04s; }
.page.active > *:nth-child(2) { animation-delay: 0.08s; }
.page.active > *:nth-child(3) { animation-delay: 0.12s; }
.page.active > *:nth-child(4) { animation-delay: 0.16s; }
.page.active > *:nth-child(5) { animation-delay: 0.20s; }
.page.active > *:nth-child(6) { animation-delay: 0.24s; }

/* Stat cards animate in on dashboard */
.stat-card {
  animation: scaleIn 0.35s ease both;
}
#statsGrid .stat-card:nth-child(1) { animation-delay: 0.05s; }
#statsGrid .stat-card:nth-child(2) { animation-delay: 0.10s; }
#statsGrid .stat-card:nth-child(3) { animation-delay: 0.15s; }
#statsGrid .stat-card:nth-child(4) { animation-delay: 0.20s; }
#statsGrid .stat-card:nth-child(5) { animation-delay: 0.25s; }
#statsGrid .stat-card:nth-child(6) { animation-delay: 0.30s; }

/* Card hover lift — enhanced */
.card, .stat-card, .trade-card, .strategy-card, .ranking-card {
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
              border-color 0.22s ease,
              box-shadow 0.22s ease;
}

/* Nav item transitions */
.nav-item {
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nav-item.active {
  animation: pulseGlow 2.5s infinite;
}

/* Sidebar slide-in on mobile */
.sidebar {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
}
.sidebar.open {
  box-shadow: 4px 0 40px rgba(0,0,0,0.6);
}

/* Topbar entrance */
.topbar {
  animation: fadeSlideIn 0.3s ease both;
}

/* Modal entrance */
.modal-overlay.active .modal-content,
.modal-overlay[style*="flex"] .modal-content {
  animation: slideUpFade 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Button micro-interactions */
.btn {
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.15s ease,
              background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.95) !important; }
.btn-primary:hover { transform: translateY(-2px) scale(1.02); }

/* ===== DRAWDOWN WARNING BANNER ===== */
#drawdownWarning {
  display: none;
  position: relative;
  background: linear-gradient(135deg, rgba(239,68,68,0.12), rgba(239,68,68,0.06));
  border: 1px solid rgba(239,68,68,0.45);
  border-radius: 14px;
  padding: 16px 20px;
  margin-bottom: 0;
  overflow: hidden;
  animation: warningEntrance 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both, dangerPulse 2s 0.5s infinite;
}
#drawdownWarning.show { display: flex; align-items: flex-start; gap: 14px; }
#drawdownWarning::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(239,68,68,0.07) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 2.5s linear infinite;
  pointer-events: none;
}
.dw-icon {
  font-size: 1.6rem;
  animation: blink 1.1s ease-in-out infinite;
  flex-shrink: 0;
  margin-top: 2px;
}
.dw-body { flex: 1; }
.dw-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: #fca5a5;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
  text-transform: uppercase;
}
.dw-msg {
  font-size: 0.8rem;
  color: #f87171;
  line-height: 1.5;
}
.dw-metrics {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.dw-metric {
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fca5a5;
}
.dw-close {
  background: none;
  border: none;
  color: #f87171;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.6;
  padding: 0;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.dw-close:hover { opacity: 1; }

/* ===== BACKTESTING SECTION ===== */
#page-backtest {
  display: none;
  padding: 28px 24px;
  flex-direction: column;
  gap: 24px;
}
#page-backtest.active { display: flex; }

.backtest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.backtest-header h2 {
  font-size: 1.4rem;
  font-weight: 800;
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Strategy selector tabs */
.bt-strategy-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
}
.bt-strategy-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.bt-strategy-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.bt-strategy-tab.active {
  background: var(--accent-glow);
  border-color: rgba(124,58,237,0.4);
  color: var(--accent);
}
.bt-strategy-tab .tab-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}

/* Backtest dashboard grid */
.bt-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}
.bt-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  transition: all 0.2s ease;
  animation: scaleIn 0.3s ease both;
}
.bt-stat:hover { border-color: var(--accent); transform: translateY(-3px); }
.bt-stat-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.bt-stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
}
.bt-stat-value.positive { color: var(--green); }
.bt-stat-value.negative { color: var(--red); }
.bt-stat-value.neutral  { color: var(--accent); }

/* Sessions table */
.bt-sessions-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.bt-sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-wrap: wrap;
  gap: 10px;
}
.bt-sessions-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
}
.bt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.bt-table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
}
.bt-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}
.bt-table tr:last-child td { border-bottom: none; }
.bt-table tr:hover td { background: var(--bg-hover); }
.bt-result-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-block;
}
.bt-result-win  { background: var(--green-bg); color: var(--green); }
.bt-result-loss { background: var(--red-bg); color: var(--red); }

/* Trade log in backtest */
.bt-trades-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.bt-trades-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-wrap: wrap;
  gap: 10px;
}

/* Analytics in backtest */
.bt-analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.bt-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
}
.bt-chart-card .card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.bt-chart-card canvas {
  padding: 16px 20px;
  width: 100% !important;
  height: 220px !important;
}

/* Playbook */
.bt-playbook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}
.bt-playbook-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.2s ease;
  cursor: pointer;
}
.bt-playbook-card:hover {
  transform: translateY(-5px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.bt-playbook-thumb {
  width: 100%;
  height: 140px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.bt-playbook-thumb img {
  width: 100%; height: 100%; object-fit: cover;
}
.bt-playbook-no-img {
  color: var(--text-muted);
  font-size: 2.5rem;
}
.bt-playbook-body {
  padding: 16px;
}
.bt-playbook-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.bt-playbook-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.bt-playbook-tag {
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(124,58,237,0.3);
}
.bt-playbook-notes {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Backtest sub-nav tabs */
.bt-subnav {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.bt-subnav::-webkit-scrollbar { height: 0; }
.bt-sub-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}
.bt-sub-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.bt-sub-btn.active { background: var(--accent); color: white; }
.bt-sub-btn i { font-size: 0.85rem; }

/* Backtest sub-panels */
.bt-panel { display: none; flex-direction: column; gap: 20px; }
.bt-panel.active { display: flex; }

/* Add session / trade form */
.bt-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.bt-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.bt-add-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px var(--accent-glow); }

/* ===== MOBILE OVERLAY ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 99;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-overlay.show { display: block; }

/* ===== COMPREHENSIVE MOBILE FIXES ===== */
@media (max-width: 768px) {
  :root {
    --topbar-height: 58px;
    --radius: 14px;
  }

  /* Sidebar fullscreen overlay on mobile */
  .sidebar {
    transform: translateX(-100%);
    width: 270px;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }

  /* Main content takes full width */
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex !important; }

  /* Topbar */
  .topbar { padding: 0 16px; gap: 10px; }
  .topbar-title { font-size: 1rem; }
  .btn-primary span { display: none; }
  .btn-primary { padding: 9px 12px; }
  #quickAddBtn::after { content: ''; }

  /* Pages */
  .page { padding: 16px; gap: 16px; }
  #page-backtest { padding: 16px; gap: 16px; }

  /* Stats grid — 2 columns on phone */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 1.5rem; }
  .stat-icon { width: 38px; height: 38px; font-size: 1rem; }

  /* Dashboard top row */
  .dashboard-top-row { grid-template-columns: 1fr; gap: 14px; }
  .charts-row { grid-template-columns: 1fr; gap: 14px; }
  .charts-row-two { grid-template-columns: 1fr; gap: 14px; }

  /* Chart cards */
  .chart-card canvas { height: 200px !important; padding: 10px 12px; }

  /* Cards */
  .card-header { padding: 14px 16px; }
  .card-header h3 { font-size: 0.9rem; }

  /* Win ratio */
  .win-ratio-content { padding: 16px; }
  .win-loss-stats { gap: 16px; }
  .stat-number { font-size: 1.6rem; }
  .progress-circle { width: 90px; height: 90px; }
  .period-selector { gap: 4px; }
  .period-btn { padding: 5px 10px; font-size: 0.72rem; }

  /* Filters */
  .modern-filter-bar { padding: 12px; gap: 8px; }
  .filter-group { padding: 7px 12px; }
  .analytics-filter-bar { flex-wrap: wrap; }

  /* Trades table — horizontal scroll */
  .trades-table-view { padding: 0 12px 12px; }
  .trades-table { font-size: 0.75rem; }
  .trades-table th, .trades-table td { padding: 10px 10px; }

  /* Trade cards */
  .trades-grid-view { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .trade-card { padding: 16px; }

  /* Risk metrics */
  .account-risk-metrics-grid { grid-template-columns: 1fr; gap: 10px; }

  /* Accounts */
  .accounts-grid { grid-template-columns: 1fr; }

  /* Strategy */
  .strategy-stats-grid { grid-template-columns: 1fr; margin: 12px; gap: 14px; }
  .ranking-grid { grid-template-columns: 1fr; margin: 12px; gap: 10px; }

  /* Calendar */
  .calendar-month { grid-template-columns: repeat(7, 1fr); }
  .calendar-week-summary { display: none; }
  .calendar-day { min-height: 64px; padding: 6px; }
  .day-pnl { font-size: 0.75rem; }
  .day-number { font-size: 0.75rem; }
  #calendarGrid { padding: 10px; }

  /* Modal */
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal-content { border-radius: 20px 20px 0 0; max-height: 92vh; margin: 0; }

  /* Drawdown warning */
  #drawdownWarning { padding: 14px 14px; }
  .dw-title { font-size: 0.85rem; }
  .dw-msg { font-size: 0.75rem; }

  /* Backtest */
  .bt-strategy-tabs { padding: 8px 10px; gap: 6px; }
  .bt-strategy-tab { padding: 7px 12px; font-size: 0.77rem; }
  .bt-dashboard { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .bt-stat { padding: 14px 16px; }
  .bt-stat-value { font-size: 1.4rem; }
  .bt-analytics-grid { grid-template-columns: 1fr; }
  .bt-playbook-grid { grid-template-columns: 1fr; }
  .bt-form-grid { grid-template-columns: 1fr; }
  .bt-subnav { gap: 3px; }
  .bt-sub-btn { padding: 7px 12px; font-size: 0.78rem; }

  /* Toast */
  .toast { right: 16px; left: 16px; bottom: 20px; text-align: center; }
}

@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .bt-dashboard { grid-template-columns: 1fr; }
  .page { padding: 12px; }
  .topbar { padding: 0 12px; }
  .stat-value { font-size: 1.3rem; }
}

/* ===== PULL-TO-REFRESH FRIENDLY OVERSCROLL ===== */
html { overscroll-behavior-y: contain; }
.main-content { overscroll-behavior-y: auto; }

/* ===== TOUCH-FRIENDLY TAP AREAS ===== */
@media (hover: none) and (pointer: coarse) {
  .nav-item { padding: 14px 16px; }
  .btn { min-height: 44px; }
  .period-btn { min-height: 36px; padding: 6px 14px; }
  .bt-sub-btn { min-height: 40px; }
  .bt-strategy-tab { min-height: 40px; }
  .table-action-btn { padding: 10px; }
  .filter-group { padding: 10px 14px; }
}

/* ===== SAFE AREA INSETS (iPhone notch etc.) ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .sidebar-footer { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
}
