/* === CSS Custom Properties (Dark Theme) === */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2333;
  --bg-card: #1c2333;
  --bg-input: #0d1117;
  --border: #30363d;
  --border-light: #21262d;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;

  --positive: #22c55e;
  --positive-bg: rgba(34, 197, 94, 0.1);
  --negative: #ef4444;
  --negative-bg: rgba(239, 68, 68, 0.1);

  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --accent-bg: rgba(88, 166, 255, 0.1);

  --danger: #f85149;
  --danger-hover: #da3633;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);

  --sidebar-width: 240px;
  --header-height: 60px;
}

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

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

h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.3;
}

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.25rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-link {
  display: block;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.93rem;
  font-weight: 500;
  transition: all 0.15s ease;
}
.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}
.nav-link.active {
  color: var(--accent);
  background: var(--accent-bg);
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-email {
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 2rem;
  max-width: 1200px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #fff;
}

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

/* === Forms === */
.form-group {
  margin-bottom: 1rem;
}

.form-hint {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.93rem;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

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

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* === Alerts === */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.87rem;
}

.alert-success {
  background: var(--positive-bg);
  color: var(--positive);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.alert-error {
  background: var(--negative-bg);
  color: var(--negative);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* === Page Header === */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-header h1 {
  font-size: 1.5rem;
}

.page-actions {
  display: flex;
  gap: 0.5rem;
}

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* === P/L Colors === */
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.positive-bg { background: var(--positive-bg); }
.negative-bg { background: var(--negative-bg); }

/* === Section === */
.section {
  margin-top: 2rem;
}

.section h2 {
  font-size: 1.15rem;
  margin-bottom: 1rem;
}

/* === Trades Table === */
.trades-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.trades-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.trades-table th {
  padding: 0.7rem 1rem;
  text-align: left;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.trades-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border-light);
  font-variant-numeric: tabular-nums;
}

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

.trades-table tr:hover td {
  background: var(--bg-tertiary);
}

.notes-cell {
  color: var(--text-secondary);
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions-cell {
  display: flex;
  gap: 0.4rem;
  white-space: nowrap;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* === Trade Detail === */
.trade-detail {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.detail-row {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  gap: 1rem;
}
.detail-row:last-child {
  border-bottom: none;
}

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

.detail-value {
  font-size: 1.1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.detail-notes {
  color: var(--text-secondary);
  line-height: 1.7;
}

/* === Auth Pages === */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.auth-card h1 {
  margin-bottom: 1.5rem;
  text-align: center;
}

.auth-link {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.87rem;
  color: var(--text-secondary);
}

/* === Calendar === */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.calendar-title {
  font-size: 1.15rem;
  min-width: 180px;
  text-align: center;
}

.calendar-grid {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.calendar-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 0.8fr;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.calendar-header-cell {
  padding: 0.6rem 0.5rem;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.calendar-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 0.8fr;
  border-bottom: 1px solid var(--border-light);
}
.calendar-row:last-child {
  border-bottom: none;
}

.calendar-cell {
  min-height: 72px;
  padding: 0.4rem;
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  position: relative;
}
.calendar-cell:last-child {
  border-right: none;
}

.calendar-cell.other-month {
  opacity: 0.3;
}

.calendar-cell.weekend {
  background: rgba(255, 255, 255, 0.015);
}

.cell-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.cell-pnl {
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s ease;
}
.cell-pnl:hover {
  opacity: 0.8;
}
.cell-pnl.positive {
  background: var(--positive-bg);
  color: var(--positive);
}
.cell-pnl.negative {
  background: var(--negative-bg);
  color: var(--negative);
}

.cell-add {
  font-size: 0.85rem;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s ease;
  text-decoration: none;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.calendar-cell:hover .cell-add {
  opacity: 1;
  background: var(--bg-tertiary);
  color: var(--accent);
}

.week-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
}

.cell-pnl-small {
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* === Charts === */
.charts-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.range-buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

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

.chart-wrapper h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.chart-wrapper canvas {
  height: 300px !important;
}

/* === Grade Badges === */
.grade-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  min-width: 28px;
}
.grade-a { background: rgba(34, 197, 94, 0.15); color: var(--positive); }
.grade-b { background: var(--accent-bg); color: var(--accent); }
.grade-c { background: rgba(234, 179, 8, 0.15); color: #eab308; }
.grade-d { background: var(--negative-bg); color: var(--negative); }

/* === Trade Form === */
.trade-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 680px;
}

/* === Mobile Responsive === */
@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    flex-direction: column;
    z-index: 200;
  }

  .sidebar-toggle {
    display: block;
  }

  .sidebar-header {
    padding: 0.75rem 1rem;
  }

  .sidebar-nav,
  .sidebar-footer {
    display: none;
    border-right: none;
  }
  .sidebar-nav.open {
    display: flex;
    background: var(--bg-secondary);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-footer.open {
    display: flex;
    background: var(--bg-secondary);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
  }

  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: calc(var(--header-height) + 0.5rem);
  }

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

  .form-row {
    grid-template-columns: 1fr;
  }

  .calendar-cell {
    min-height: 56px;
    padding: 0.25rem;
  }

  .cell-pnl {
    font-size: 0.7rem;
    padding: 0.1rem 0.25rem;
  }

  .calendar-header-cell {
    font-size: 0.68rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }

  .stat-card {
    padding: 0.85rem;
  }

  .stat-value {
    font-size: 1.1rem;
  }
}
