/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

/* ── CSS Custom Properties ─────────────────────────────── */
:root {
  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-surface-hover: #F1F5F9;
  --color-border: #E2E8F0;
  --color-border-subtle: #F1F5F9;

  --color-text-primary: #0F172A;
  --color-text-secondary: #475569;
  --color-text-tertiary: #94A3B8;

  --color-accent: #1E40AF;
  --color-accent-hover: #1E3A8A;
  --color-accent-light: #EFF6FF;
  --color-accent-glow: rgba(30, 64, 175, 0.12);

  /* 記帳慣例：獲利黑字(深藍) / 虧損紅字(赤字) */
  --color-profit: #1E40AF;
  --color-profit-bg: rgba(30, 64, 175, 0.06);
  --color-loss: #DC2626;
  --color-loss-bg: rgba(220, 38, 38, 0.06);
  --color-warning: #D97706;
  --color-warning-bg: rgba(217, 119, 6, 0.08);

  --color-nav-bg: #1E3A8A;
  --color-nav-border: #1E40AF;

  --font-display: "Noto Sans TC", system-ui, sans-serif;
  --font-body: "Noto Sans TC", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;

  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-card-hover: 0 8px 24px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-nav-dropdown: 0 12px 36px rgba(0, 0, 0, 0.2);
  --shadow-hero-glow-profit: 0 0 40px rgba(30, 64, 175, 0.12), 0 0 16px rgba(30, 64, 175, 0.06);
  --shadow-hero-glow-loss: 0 0 40px rgba(220, 38, 38, 0.12), 0 0 16px rgba(220, 38, 38, 0.06);
}

/* ── Semantic color utilities ─────────────────────────── */
.text-profit { color: var(--color-profit); }
.text-loss { color: var(--color-loss); }
.bg-profit { background-color: var(--color-profit-bg); }
.bg-loss { background-color: var(--color-loss-bg); }

/* ── Page background ───────────────────────────────────── */
body {
  background-color: var(--color-bg);
  font-family: var(--font-body);
  color: var(--color-text-primary);
}

/* ── Page Load Animations ──────────────────────────────── */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Staggered entrance for cards */
.animate-in {
  animation: fadeInUp 0.4s ease-out backwards;
}
.animate-in-1 { animation-delay: 0.05s; }
.animate-in-2 { animation-delay: 0.1s; }
.animate-in-3 { animation-delay: 0.15s; }
.animate-in-4 { animation-delay: 0.2s; }
.animate-in-5 { animation-delay: 0.25s; }
.animate-in-6 { animation-delay: 0.3s; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

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

/* Card type variants — colored left accent border */
.card-metric {
  border-left: 3px solid var(--color-accent);
}

.card-chart {
  border-left: 3px solid #60A5FA;
}

.card-risk {
  border-left: 3px solid var(--color-warning);
}

.card-performance {
  border-left: 3px solid var(--color-profit);
}

.card-data {
  border: 1px solid var(--color-border);
  border-top: 2px solid var(--color-accent);
}

/* ── Metric numbers ────────────────────────────────────── */
.metric-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.metric-value-sm {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

/* ── Typography ────────────────────────────────────────── */
h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.01em;
}

h2.card-title,
.card h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: var(--color-text-secondary);
  margin-bottom: 1rem;
}

/* Display h2 in cards that use text-lg — override to styled version */
.card .text-lg.font-semibold {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: var(--color-text-secondary);
}

/* Section header — used above card groups */
.section-header {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: 0;
  margin-bottom: 0.75rem;
}

/* ── Hero P&L Display ─────────────────────────────────── */
.hero-pnl {
  position: relative;
  text-align: center;
  padding: 2rem 1.5rem;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.hero-pnl-profit {
  background: linear-gradient(135deg, #EFF6FF 0%, #F0F9FF 30%, var(--color-surface) 60%, #EFF6FF 100%);
  border-color: rgba(30, 64, 175, 0.2);
  box-shadow: var(--shadow-hero-glow-profit);
}

.hero-pnl-loss {
  background: linear-gradient(135deg, #FEF2F2 0%, var(--color-surface) 50%, #FFF1F2 100%);
  border-color: rgba(220, 38, 38, 0.15);
  box-shadow: var(--shadow-hero-glow-loss);
}

.hero-pnl-neutral {
  background: linear-gradient(135deg, var(--color-accent-light) 0%, var(--color-surface) 50%, #EFF6FF 100%);
  border-color: rgba(30, 64, 175, 0.12);
}

.hero-pnl-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-tertiary);
  margin-bottom: 0.5rem;
}

.hero-pnl-value {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.hero-pnl-value.profit { color: var(--color-profit); }
.hero-pnl-value.loss { color: var(--color-loss); }
.hero-pnl-value.neutral { color: var(--color-accent); }

.hero-pnl-subtitle {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  margin-top: 0.5rem;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 768px) {
  .hero-pnl {
    padding: 2.5rem 2rem;
  }
  .hero-pnl-value {
    font-size: 4rem;
  }
}

/* ── Table refinement ──────────────────────────────────── */
.data-table th {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-tertiary);
  border-bottom: 2px solid var(--color-border);
  padding: 0.75rem 1rem;
  background: var(--color-surface);
}
.data-table td {
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--color-border-subtle);
}
.data-table tbody tr {
  transition: background-color 0.15s ease;
}
.data-table tbody tr:hover {
  background-color: var(--color-surface-hover);
}

/* PnL cell tinted backgrounds — 台灣慣例：紅漲綠跌 */
.pnl-positive {
  color: var(--color-profit);
  background-color: var(--color-profit-bg);
  font-weight: 600;
}
.pnl-negative {
  color: var(--color-loss);
  background-color: var(--color-loss-bg);
  font-weight: 600;
}

/* ── Button system ─────────────────────────────────────── */
.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
}

/* Primary: cheerful blue fill */
.btn-primary {
  background-color: var(--color-accent);
  color: #FFFFFF;
  font-weight: 600;
}
.btn-primary:hover {
  background-color: var(--color-accent-hover);
  box-shadow: 0 2px 8px var(--color-accent-glow);
}

/* Ghost: subtle outline */
.btn-ghost {
  background-color: var(--color-surface);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
.btn-ghost:hover {
  background-color: var(--color-surface-hover);
  border-color: var(--color-text-tertiary);
}

/* Success: same as primary (profit = accent blue in this palette) */
.btn-success {
  background-color: var(--color-profit);
  color: #FFFFFF;
}
.btn-success:hover {
  background-color: var(--color-accent-hover);
  box-shadow: 0 2px 8px var(--color-accent-glow);
}

/* Danger: red for destructive actions */
.btn-danger {
  background-color: #DC2626;
  color: #FFFFFF;
}
.btn-danger:hover {
  background-color: #B91C1C;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.2);
}

/* Cancel: muted */
.btn-cancel {
  background-color: var(--color-bg);
  color: var(--color-text-tertiary);
  border-color: var(--color-border);
}
.btn-cancel:hover {
  background-color: var(--color-border);
  color: var(--color-text-secondary);
}

/* ── Navigation ────────────────────────────────────────── */
.nav-link {
  position: relative;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  text-decoration: none;
}
.nav-link:hover {
  color: #FFFFFF;
  background-color: rgba(255, 255, 255, 0.12);
}

/* Active: filled pill with glow */
.nav-link-active {
  color: #FFFFFF !important;
  background-color: rgba(255, 255, 255, 0.2);
  font-weight: 600;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  border-bottom: none;
}

/* Logo */
.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: linear-gradient(135deg, #FFFFFF 0%, #BFDBFE 100%);
  border-radius: 0.5rem;
  color: var(--color-accent);
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 900;
  margin-right: 0.5rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: 0;
}

.logo-tagline {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* Nav group separator */
.nav-separator {
  width: 1px;
  height: 1.25rem;
  background-color: rgba(255, 255, 255, 0.2);
  margin: 0 0.25rem;
}

/* ── Filter pills (trade type tabs) ───────────────────── */
.filter-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.375rem 0.875rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.2s ease;
  text-decoration: none;
  border: 1px solid transparent;
}

.filter-pill-inactive {
  background-color: rgba(30, 64, 175, 0.06);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}

.filter-pill-inactive:hover {
  background-color: rgba(30, 64, 175, 0.12);
  color: var(--color-text-primary);
  border-color: var(--color-accent);
}

.filter-pill-active {
  background-color: var(--color-accent);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: 0 2px 8px var(--color-accent-glow);
}

/* ── Calendar blue theme ─────────────────────────────── */
.cal-selected-week {
  background-color: rgba(30, 64, 175, 0.08);
}

.cal-today {
  position: relative;
}

.cal-today::after {
  content: "";
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--color-accent);
}

/* ── Empty state ──────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--color-surface);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
}

.empty-state-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(30, 64, 175, 0.08) 0%, rgba(96, 165, 250, 0.08) 100%);
  margin-bottom: 1rem;
}

.empty-state-icon svg {
  width: 1.75rem;
  height: 1.75rem;
  color: var(--color-accent);
}

.empty-state-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 0.5rem;
}

.empty-state-text {
  font-size: 0.875rem;
  color: var(--color-text-tertiary);
  margin-bottom: 1.25rem;
  max-width: 24rem;
  margin-left: auto;
  margin-right: auto;
}

/* ── Chart tooltip customization ──────────────────────── */
.chart-container canvas {
  border-radius: var(--radius-md);
}

/* ── Button micro-interactions ────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  border: 1px solid transparent;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
  transition-duration: 0.1s;
}

/* ── Full-width chart (Overall page) ──────────────────── */
.chart-featured {
  position: relative;
}

.chart-featured .card {
  border-left: none;
  border-top: 3px solid var(--color-accent);
}

/* ── Summary stat cards (Overall page) ─────────────────── */
.stat-card {
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-border);
}
.stat-card-accent::after {
  background: var(--color-accent);
}
.stat-card-profit::after {
  background: var(--color-profit);
}
.stat-card-loss::after {
  background: var(--color-loss);
}

/* ── Risk indicator badges ─────────────────────────────── */
.risk-safe {
  color: var(--color-text-primary);
}
.risk-caution {
  color: var(--color-warning);
  font-weight: 700;
}
.risk-danger {
  color: var(--color-loss);
  font-weight: 700;
}

/* ── Misc ──────────────────────────────────────────────── */
/* Smooth transitions for Turbo page loads */
.turbo-progress-bar {
  background-color: var(--color-accent);
  height: 3px;
}

/* Turbo page transition fade */
[data-turbo-preview] {
  opacity: 0.7;
  transition: opacity 0.15s ease;
}

/* Summary bar at top of trade tables */
.summary-bar {
  background: linear-gradient(180deg, #F8FAFC 0%, var(--color-surface) 100%);
  border-bottom: 1px solid var(--color-border);
}

/* Dividers inside cards */
.card-divider {
  border-top: 1px solid var(--color-border-subtle);
  margin: 1rem 0;
}

/* ── Mobile Navigation ─────────────────────────────────── */
.mobile-nav-link {
  display: block;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  transition: all 0.15s ease;
}
.mobile-nav-link:hover,
.mobile-nav-link:active {
  color: #FFFFFF;
  background-color: rgba(255, 255, 255, 0.08);
}
.mobile-nav-link-active {
  color: #FFFFFF !important;
  background-color: rgba(255, 255, 255, 0.15);
  border-right: 2px solid #FFFFFF;
}

/* ── Responsive ────────────────────────────────────────── */
/* Mobile-first: tighter spacing below md (768px) */
@media (max-width: 767px) {
  h1 {
    font-size: 1.25rem;
  }

  .metric-value {
    font-size: 1.125rem;
  }

  .metric-value-sm {
    font-size: 0.875rem;
  }

  /* Tighter card padding on mobile */
  .card.p-6,
  .card .p-6 {
    padding: 1rem;
  }

  /* Tighter table cells on mobile */
  .data-table th,
  .data-table td {
    padding: 0.5rem 0.625rem;
    font-size: 0.75rem;
  }

  .data-table th {
    font-size: 0.625rem;
  }

  /* Summary bar wraps on mobile */
  .summary-bar .flex.items-center.gap-8 {
    gap: 0.75rem;
    flex-wrap: wrap;
  }

  .summary-bar .px-6 {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Page header stacking helper */
  .page-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.75rem;
  }

  /* Date nav wraps */
  .date-nav-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .date-nav-controls .btn {
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
  }

  /* Overall page date range form */
  .date-range-form {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .date-range-form .flex.items-center.gap-2 {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Stat cards: smaller metric on mobile */
  .stat-card .metric-value {
    font-size: 1.125rem;
  }

  /* Buttons: slightly smaller on mobile */
  .btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
  }

  /* Hero PnL: tighter on mobile */
  .hero-pnl {
    padding: 1.5rem 1rem;
  }
  .hero-pnl-value {
    font-size: 2.5rem;
  }

  /* Empty state: tighter */
  .empty-state {
    padding: 2rem 1rem;
  }
  .empty-state-icon {
    width: 3rem;
    height: 3rem;
  }
  .empty-state-icon svg {
    width: 1.25rem;
    height: 1.25rem;
  }
}
