/* ---------------------------------------------------------------
   Token system
   Background:  #0b0d10 (near-black)
   Surface:     #14171c
   Surface-alt: #1a1e24
   Border:      #262b33
   Text:        #e8eaed / muted #8b93a1
   Win (muted): #2e5339   Win (perfect): #22c55e
   Loss:        #5c2626   Loss (bright, for negatives): #ef4444
   Grey (no trades): #2b2d31
   Gold accent: #fbbf24
   Display face: IBM Plex Mono (data, numbers)
   Body face:    Inter (labels, UI chrome)
------------------------------------------------------------------*/

* { box-sizing: border-box; }

:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-alt: #1a1e24;
  --border: #262b33;
  --text: #e8eaed;
  --muted: #8b93a1;
  --win: #2e5339;
  --win-bright: #22c55e;
  --loss: #5c2626;
  --loss-bright: #ef4444;
  --grey: #2b2d31;
  --gold: #fbbf24;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: 'IBM Plex Mono', monospace; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px 60px;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 22px 0 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  filter: drop-shadow(0 0 6px rgba(34,197,94,0.35));
}
.brand-title {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1.5px;
}
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.5px; }

.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  background: none;
  border: none;
  color: var(--muted);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.2px;
}
.tab:hover { color: var(--text); background: var(--surface-alt); }
.tab.active { color: var(--bg); background: var(--win-bright); }

.tab-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 6px 4px;
  flex: 0 0 auto;
}

.topbar-right { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.last-updated { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--muted); }

.refresh-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, transform 0.1s;
}
.refresh-btn:hover { border-color: var(--win-bright); }
.refresh-btn:active { transform: scale(0.97); }
.refresh-icon { display: inline-block; transition: transform 0.4s; }
.refresh-btn.spinning .refresh-icon { transform: rotate(360deg); }

/* ---------- Views ---------- */

.view { display: none; padding-top: 26px; }
.view.active { display: block; animation: fadeIn 0.25s ease; }

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

/* ---------- Streak strip (signature element) ---------- */

.streak-strip-wrap { margin-bottom: 26px; }
.streak-strip-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 8px;
}
.streak-strip { display: flex; gap: 3px; height: 34px; }
.streak-cell {
  flex: 1;
  border-radius: 3px;
  position: relative;
  cursor: default;
  transition: transform 0.1s;
}
.streak-cell:hover { transform: scaleY(1.15); }
.streak-cell.win { background: var(--win-bright); }
.streak-cell.loss { background: var(--loss-bright); opacity: 0.85; }

/* ---------- Hero ---------- */

.hero {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 28px 10px;
  margin-bottom: 22px;
}
.hero-stat { margin-bottom: 6px; }
.hero-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.hero-number {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 52px;
  font-weight: 700;
  line-height: 1;
}
.hero-number.pos { color: var(--win-bright); }
.hero-number.neg { color: var(--loss-bright); }

.equity-chart-wrap { position: relative; height: 220px; }
.equity-chart-wrap canvas { width: 100% !important; height: 100% !important; }

.firm-selector { display: flex; gap: 8px; flex-wrap: wrap; }

/* Groups several selector rows (period/asset/metric) into one visually distinct block,
   with a small uppercase label above each row so it's clear what it controls at a
   glance - rather than several unlabeled rows of identical-looking pill buttons. */
.weekday-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.selector-label {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 7px;
}
.firm-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.firm-btn:hover { border-color: var(--win-bright); color: var(--text); }
.firm-btn.active { background: var(--win-bright); color: var(--bg); border-color: var(--win-bright); }

/* ---------- Stat grid / cards ---------- */

.grid { display: grid; gap: 12px; }
.stat-grid { grid-template-columns: repeat(4, 1fr); margin-bottom: 22px; }
.two-col { grid-template-columns: repeat(2, 1fr); }

/* For grids with a variable card count (2 prop firms, 3 asset groups, etc.) - cards get a
   natural width instead of stretching to fill a fixed 4-column template, and the whole
   row centers in the available space instead of leaving empty space bunched on one side. */
.stat-grid-auto {
  grid-template-columns: repeat(auto-fit, minmax(220px, 260px));
  justify-content: center;
  margin-bottom: 22px;
}

/* A single full-width tile sized to match a 3-card .stat-grid-auto row exactly (3 cards
   at up to 260px each, plus 2 gaps of 12px) - used for tiles that need to span the same
   footprint as the cards above/below them without being part of that same grid. */
.stat-tile-wide {
  max-width: 804px;
  margin-left: auto;
  margin-right: auto;
}
.stat-tile-wide .stat-card { width: 100%; }
.stat-tile-wide .stat-card-label { text-align: center; }

@media (max-width: 760px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .stat-grid-auto { grid-template-columns: repeat(2, minmax(0, 1fr)); justify-content: stretch; }
  .stat-tile-wide { max-width: 100%; }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat-card-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.4px;
  margin-bottom: 6px;
  text-transform: uppercase;
  font-weight: 600;
}
.stat-card-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 22px;
  font-weight: 600;
}
.stat-card-value.pos { color: var(--win-bright); }
.stat-card-value.neg { color: var(--loss-bright); }
.stat-card-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- Panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.asset-list { display: flex; flex-direction: column; gap: 10px; }
.asset-row { display: flex; align-items: center; gap: 12px; }
.asset-row.clickable { cursor: pointer; padding: 4px 6px; margin: -4px -6px; border-radius: 6px; transition: background 0.15s; }
.asset-row.clickable:hover { background: var(--surface-alt); }
.asset-name { font-family: 'IBM Plex Mono', monospace; font-weight: 600; width: 90px; font-size: 13px; }
.asset-bar-track { flex: 1; height: 8px; background: var(--surface-alt); border-radius: 4px; overflow: hidden; }
.asset-bar-fill { height: 100%; background: var(--win-bright); }
.asset-meta { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); width: 190px; text-align: right; }

/* ---------- Nav row (week/month/day) ---------- */

.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.nav-title { font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 15px; }
.nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
}
.nav-btn:hover { border-color: var(--win-bright); }

.nav-btn-group { display: flex; gap: 6px; }
.nav-btn-current { color: var(--win-bright); border-color: var(--win-bright); }
.nav-btn-current:hover { background: var(--win-bright); color: var(--bg); }

/* ---------- Week strip ---------- */

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-bottom: 22px;
}
.week-tile {
  background: var(--grey);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: outline 0.1s, transform 0.1s;
}
.week-tile:hover { outline: 1.5px solid rgba(255,255,255,0.35); transform: scale(1.02); }
.week-tile.win { background: var(--win); }
.week-tile.perfect { background: var(--win-bright); }
.week-tile.loss { background: var(--loss); }
.week-tile.locked { background: var(--loss); }
.week-tile-day { font-weight: 700; font-size: 13px; }
.week-tile-date { font-size: 10.5px; color: rgba(255,255,255,0.6); margin-top: 2px; }
.week-tile-r { font-family: 'IBM Plex Mono', monospace; font-size: 15px; font-weight: 600; margin-top: 8px; }
.week-tile-tag { font-size: 9px; font-weight: 700; letter-spacing: 0.4px; margin-top: 6px; }
.week-tile.perfect .week-tile-tag { color: #123; }
.week-tile-tag.tag-perfect { color: var(--gold); }
.week-tile-tag.tag-out { color: #ffb3b3; }
.week-tile-tag.tag-locked { color: #ffb3b3; }

/* ---------- Month grid ---------- */

.month-grid-wrap { margin-bottom: 22px; }
.month-day-labels {
  display: grid;
  grid-template-columns: 46px repeat(7, 1fr);
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
  text-align: center;
}
.month-week-row {
  display: grid;
  grid-template-columns: 46px repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.month-week-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.month-cell {
  background: var(--grey);
  border-radius: 8px;
  min-height: 74px;
  padding: 8px;
  position: relative;
  cursor: pointer;
  transition: outline 0.1s, transform 0.1s;
}
.month-cell:hover:not(.empty) { outline: 1.5px solid rgba(255,255,255,0.35); transform: scale(1.03); z-index: 1; }
.month-cell.empty { background: transparent; cursor: default; }
.month-cell.win { background: var(--win); }
.month-cell.perfect { background: var(--win-bright); }
.month-cell.loss { background: var(--loss); }
.month-cell.locked { background: var(--loss); }
.month-cell-num { font-size: 11px; color: rgba(255,255,255,0.75); }
.month-cell-r { font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 600; margin-top: 8px; }
.month-cell-tag { font-size: 8px; font-weight: 700; margin-top: 6px; letter-spacing: 0.3px; }
.month-cell-tag.tag-perfect { color: #123; }
.month-cell-tag.tag-out, .month-cell-tag.tag-locked { color: #ffd8d8; }

/* Simlog monthly calendar - taller cells than the main month grid, since each one shows
   a win/loss line per asset instead of just one R value. */
.simlog-month-cell {
  background: var(--grey);
  border-radius: 8px;
  min-height: 108px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.simlog-month-cell.empty { background: transparent; }
.simlog-month-cell.win { background: var(--win); }
.simlog-month-cell.loss { background: var(--loss); }
.simlog-month-cell-num { font-size: 10px; color: rgba(255,255,255,0.75); }
.simlog-month-cell-line { font-family: 'IBM Plex Mono', monospace; font-size: 9px; margin-top: 4px; line-height: 1.4; }

.month-week-label {
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.1s;
}
.month-week-label:hover { background: var(--surface-alt); color: var(--text); }

/* ---------- Year month-tile grid ---------- */

.month-tile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
@media (max-width: 700px) {
  .month-tile-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 460px) {
  .month-tile-grid { grid-template-columns: repeat(2, 1fr); }
}
.month-tile {
  background: var(--grey);
  border-radius: 10px;
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: outline 0.1s, transform 0.1s;
}
.month-tile:hover { outline: 1.5px solid rgba(255,255,255,0.35); transform: scale(1.03); }
.month-tile.win { background: var(--win); }
.month-tile.loss { background: var(--loss); }
.month-tile-name { font-weight: 700; font-size: 14px; }
.month-tile-r { font-family: 'IBM Plex Mono', monospace; font-size: 13px; margin-top: 6px; color: rgba(255,255,255,0.85); }

/* ---------- Trade list (Day view) ---------- */

.trade-list { display: flex; flex-direction: column; gap: 6px; }
.trade-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  background: var(--surface-alt);
  border-radius: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
}
.trade-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.trade-dot.win { background: var(--win-bright); }
.trade-dot.loss { background: var(--loss-bright); }
.trade-time { color: var(--muted); width: 55px; }
.trade-asset { width: 60px; font-weight: 600; }
.trade-r { margin-left: auto; font-weight: 600; }
.trade-r.pos { color: var(--win-bright); }
.trade-r.neg { color: var(--loss-bright); }

.empty-state {
  color: var(--muted);
  font-size: 13px;
  padding: 30px 0;
  text-align: center;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Mobile / vertical layout ---------- */

@media (max-width: 640px) {
  .app { padding: 0 10px 104px; }

  .topbar {
    gap: 10px;
    padding: 14px 0 10px;
    flex-wrap: nowrap;
  }
  .brand-sub { display: none; }
  .brand-title { font-size: 13px; }

  /* Tabs move to a fixed bottom bar, native-app style, instead of living in the topbar.
     Extra bottom padding (beyond the safe-area inset) keeps it clear of the iPhone home
     indicator so it doesn't feel cramped or collide with the swipe-up gesture zone. */
  .tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    margin-left: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    padding: 8px 2px calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 100;
    gap: 0;
  }
  .tab {
    flex: 1 1 0;
    background: none;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    padding: 9px 2px 7px;
    border-radius: 0;
    white-space: nowrap;
    position: relative;
  }
  .tab.active {
    color: var(--win-bright);
    background: none;
  }
  .tab.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 26%;
    right: 26%;
    height: 2px;
    background: var(--win-bright);
    border-radius: 0 0 2px 2px;
  }

  .topbar-right { margin-left: auto; gap: 8px; }
  .last-updated { display: none; }
  .refresh-btn { padding: 7px 12px; font-size: 12px; }

  /* Hero */
  .hero { padding: 20px 16px 10px; margin-bottom: 16px; }
  .hero-number { font-size: 38px; }
  .equity-chart-wrap { height: 280px; }

  /* Stat cards: 2 per row, like a native app dashboard rather than one long column */
  .stat-grid, .two-col {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  .stat-card { padding: 14px; }
  .stat-card-label { font-size: 10px; }
  .stat-card-value { font-size: 20px; }
  .stat-card-sub { font-size: 11px; }

  .panel { padding: 16px; margin-bottom: 14px; }

  /* Streak strip: cells flex to fill the full screen width exactly, rather than staying a
     fixed size and needing a horizontal scroll - no longer square, but nothing gets cut off */
  .streak-strip { height: 32px; gap: 2px; }
  .streak-cell { flex: 1 1 0; min-width: 0; }

  /* Week strip: 7 columns is too cramped on a phone - switch to a vertical list of
     bigger, full-width rows instead, each day laid out horizontally within its own row */
  .week-strip {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 16px;
  }
  .week-tile {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    padding: 14px 18px;
    text-align: left;
  }
  .week-tile-day { font-size: 15px; }
  .week-tile-date { margin-top: 0; margin-left: 8px; display: inline; font-size: 12px; }
  .week-tile-r { margin-top: 0; font-size: 17px; }
  .week-tile-tag { margin-top: 0; }

  /* Month calendar: rebuilt to feel like a native phone calendar app - full-bleed
     edge-to-edge, no week-number sidebar eating into cell width, big tappable cells */
  .month-grid-wrap {
    margin: 0 -10px;
    padding: 0 4px;
  }
  .month-day-labels {
    grid-template-columns: repeat(7, 1fr);
    font-size: 13px;
    padding: 0 2px;
  }
  .month-day-labels span:first-child { display: none; }
  .month-week-row {
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
    margin-bottom: 3px;
    padding: 0 2px;
  }
  .month-week-label { display: none; }
  .month-cell {
    min-height: 68px;
    padding: 6px 4px;
    border-radius: 4px;
  }
  .month-cell-num { font-size: 13px; font-weight: 600; }
  .month-cell-r { font-size: 10px; margin-top: 6px; }
  .month-cell-tag { font-size: 6px; margin-top: 3px; }

  /* Year month tiles: 2 per row to match the rest of the mobile layout */
  .month-tile-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .month-tile { padding: 20px 12px; }
  .month-tile-name { font-size: 16px; }
  .month-tile-r { font-size: 14px; margin-top: 8px; }

  .nav-row { margin-bottom: 14px; }
  .nav-title { font-size: 14px; }
  .nav-btn { padding: 7px 12px; font-size: 12px; }

  .asset-name { width: 66px; font-size: 12px; }
  .asset-meta { width: auto; font-size: 11px; }

  .trade-row { flex-wrap: wrap; font-size: 13px; padding: 11px 14px; }
}


/* ---------- Accessibility ---------- */

button:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--win-bright);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
