/* ============================================================
   Trading Journal — TradeZella Style Dark Theme
   ============================================================ */

:root {
  /* Base colors */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a24;
  --bg-card: #1e1e2a;
  --bg-input: #16161f;
  --bg-hover: #252535;
  --bg-active: #2a2a3a;

  /* Text colors */
  --text-primary: #e8e8ed;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --text-dim: #404050;

  /* Accent */
  --accent: #f5a524;
  --accent-dim: #a0701a;
  --accent-glow: rgba(245, 165, 36, 0.15);

  /* Semantic */
  --green: #22c55e;
  --green-dim: #166534;
  --green-bg: rgba(34, 197, 94, 0.12);
  --green-bg-strong: rgba(34, 197, 94, 0.2);
  --red: #ef4444;
  --red-dim: #7f1d1d;
  --red-bg: rgba(239, 68, 68, 0.12);
  --red-bg-strong: rgba(239, 68, 68, 0.2);
  --yellow: #f5a524;
  --yellow-bg: rgba(245, 165, 36, 0.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.12);

  /* Borders */
  --border: #2a2a38;
  --border-light: #3a3a48;
  --border-focus: var(--accent);

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px var(--accent-glow);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition: 0.2s ease;
  --transition-slow: 0.3s ease;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Selection */
::selection {
  background: var(--accent);
  color: #000;
}

/* ===== Container ===== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px;
}

/* ===== Header ===== */
header {
  margin-bottom: 24px;
}

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

.header-left h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-left .subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 500;
}

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

/* ===== Stats Bar ===== */
.stats-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-top: 12px;
  backdrop-filter: blur(8px);
}

.stat {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-width: 100px;
  flex: 1;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--border);
}

.stat.positive::before {
  background: var(--green);
}

.stat.negative::before {
  background: var(--red);
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: -0.02em;
}

.stat-value.positive {
  color: var(--green);
  text-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

.stat-value.negative {
  color: var(--red);
  text-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}

.stat-divider {
  color: var(--text-muted);
  margin: 0 2px;
  font-weight: 300;
}

/* ===== Filters ===== */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.6;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-select {
  padding: 10px 32px 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a0a0b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--transition);
  font-family: inherit;
  min-width: 120px;
}

.filter-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-select option {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ===== Buttons ===== */
.btn {
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all var(--transition);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--border-light);
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 700;
}

.btn-primary:hover {
  background: #e0951e;
  border-color: #e0951e;
  box-shadow: var(--shadow-glow);
}

.btn-outline {
  background: transparent;
  border-color: var(--border-light);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-tertiary);
  border-color: var(--border);
  color: var(--text-secondary);
}

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

.btn-danger {
  background: var(--red);
  color: white;
  border-color: var(--red);
}

.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* ===== Trade List ===== */
.trade-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 0.9rem;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* ===== Trade Card ===== */
.trade-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: relative;
  overflow: hidden;
}

.trade-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--border);
  transition: background var(--transition);
}

.trade-card:hover {
  border-color: var(--border-light);
  background: var(--bg-hover);
  transform: translateX(2px);
}

.trade-card:hover::before {
  background: var(--accent);
}

.trade-card .trade-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 180px;
}

.trade-card .trade-pair {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.trade-card .trade-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.trade-card .trade-details {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.trade-card .detail {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.trade-card .detail strong {
  color: var(--text-primary);
  font-weight: 600;
}

.trade-card .detail.r-multiple strong {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
}

.r-multiple-display {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-secondary);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.9rem;
  text-align: center;
}

.r-multiple-display.positive {
  color: var(--green);
  border-color: var(--green-dim);
  background: var(--green-bg);
}

.r-multiple-display.negative {
  color: var(--red);
  border-color: var(--red-dim);
  background: var(--red-bg);
}

.pnl-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', monospace;
  white-space: nowrap;
}

.pnl-badge.positive {
  background: var(--green-bg);
  color: var(--green);
}

.pnl-badge.negative {
  background: var(--red-bg);
  color: var(--red);
}

.trade-card .actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.trade-card:hover .actions {
  opacity: 1;
}

.trade-card .actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 1rem;
  transition: color var(--transition), background var(--transition);
  border-radius: var(--radius-sm);
}

.trade-card .actions button:hover {
  color: var(--text-primary);
  background: var(--bg-active);
}

.trade-card .actions .delete-btn:hover {
  color: var(--red);
  background: var(--red-bg);
}

/* ===== Modal ===== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-lg {
  max-width: 640px;
}

.modal-xl {
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.close {
  position: absolute;
  top: 16px;
  right: 18px;
  font-size: 1.6rem;
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  line-height: 1;
  transition: color var(--transition);
  padding: 4px;
}

.close:hover {
  color: var(--text-primary);
}

/* ===== Form ===== */
form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.form-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-dim);
}

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

.form-row,
.form-row-3 {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.form-row-3 .form-group {
  flex: 1;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.form-actions .btn {
  flex: 1;
  justify-content: center;
}

/* ===== View Detail ===== */
.view-detail {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.view-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.view-row:last-child {
  border-bottom: none;
}

.view-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  min-width: 120px;
  flex-shrink: 0;
}

.view-value {
  font-weight: 600;
  text-align: right;
  font-size: 0.9rem;
  color: var(--text-primary);
  flex: 1;
}

.view-value.positive {
  color: var(--green);
}

.view-value.negative {
  color: var(--red);
}

.view-note {
  background: var(--bg-input);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  white-space: pre-wrap;
  line-height: 1.6;
  margin: 0;
  text-align: left;
  width: 100%;
}

.view-row:has(.view-note) {
  flex-direction: column;
  align-items: stretch;
}

.view-row:has(.view-note) .view-label {
  margin-bottom: 4px;
}

.tag {
  display: inline-block;
  background: var(--blue-bg);
  color: var(--blue);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-right: 4px;
  margin-bottom: 2px;
}

.view-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.view-actions .btn {
  flex: 1;
  justify-content: center;
}

/* ===== Analytics Modal ===== */
.analytics-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.analytics-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  border: none;
  padding: 0;
  margin: 0;
}

/* Analytics KPI Grid */
.analytics-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.analytics-kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
}

.analytics-kpi .kpi-label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 4px;
}

.analytics-kpi .kpi-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.analytics-kpi .kpi-value.positive {
  color: var(--green);
}

.analytics-kpi .kpi-value.negative {
  color: var(--red);
}

/* Analytics Charts */
.analytics-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.chart-title {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chart-card canvas {
  width: 100%;
  height: 180px;
  display: block;
}

/* Analytics Tabs */
.analytics-tabs {
  margin-top: 4px;
}

.tabs-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 4px;
  width: fit-content;
}

.tab-btn {
  padding: 7px 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: tabIn 0.2s ease;
}

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

/* Breakdown Table */
.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.breakdown-table thead {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

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

.breakdown-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.breakdown-table tbody tr:hover {
  background: var(--bg-hover);
}

.breakdown-table tbody tr:last-child td {
  border-bottom: none;
}

.breakdown-table td:first-child {
  font-weight: 600;
  color: var(--text-primary);
}

.breakdown-table td:nth-child(3),
.breakdown-table td:nth-child(4),
.breakdown-table td:nth-child(5),
.breakdown-table td:nth-child(6) {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
}

.breakdown-table td.positive {
  color: var(--green);
}

.breakdown-table td.negative {
  color: var(--red);
}

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

  .analytics-kpis {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats-bar {
    flex-wrap: wrap;
  }

  .stat {
    min-width: calc(50% - 6px);
  }
}

@media (max-width: 640px) {
  .container {
    padding: 12px;
  }

  .header-row {
    flex-direction: column;
    gap: 12px;
  }

  .header-right {
    width: 100%;
    flex-direction: column;
  }

  .header-right .btn {
    width: 100%;
    justify-content: center;
  }

  .stats-bar {
    flex-direction: column;
    padding: 12px;
  }

  .stat {
    min-width: 100%;
  }

  .filters {
    flex-direction: column;
  }

  .search-wrap {
    width: 100%;
  }

  .filter-select {
    width: 100%;
  }

  .form-row,
  .form-row-3 {
    flex-direction: column;
    gap: 10px;
  }

  .trade-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .trade-card .actions {
    width: 100%;
    justify-content: flex-end;
    opacity: 1;
  }

  .modal-content {
    padding: 18px;
    max-width: 100%;
    margin: 10px;
    border-radius: var(--radius-lg);
  }

  .modal-xl {
    max-width: 100%;
  }

  .analytics-kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .analytics-charts {
    grid-template-columns: 1fr;
  }

  .tabs-nav {
    overflow-x: auto;
    width: 100%;
  }

  .tab-content {
    overflow-x: auto;
  }

  .breakdown-table {
    font-size: 0.75rem;
  }

  .breakdown-table th,
  .breakdown-table td {
    padding: 6px 8px;
  }
}

/* ===== Loading State ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
}

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

/* ===== Fade Transition ===== */
.fade-in {
  animation: fadeIn 0.3s ease;
}

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

/* ===== Tag Input Styling ===== */
#tags {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
