/* Trading Journal — shared design system.
   Visual language adapted from the TradeLog dashboard reference: dark-first
   layered surfaces, Syne for headings/UI, DM Mono for every number, thin
   hairline borders, 14px radii, gradient-topped stat cards, sliding toasts.
   Light theme is the same system re-toned (green/red darkened so they stay
   legible on white — the reference's #00d68f only reaches 3.07:1 there).
   No build step: plain CSS. See assets/js/theme.js (toggle + nav + toast)
   and assets/js/charts.js (Chart.js PnL curve). */

/* ---------- Tokens ---------- */
:root,
[data-theme="dark"] {
  --bg: #0d0f14;
  --surface: #13161d;
  --surface2: #1a1e28;
  --surface3: #212633;
  --border: #ffffff0d;
  --border2: #ffffff18;

  --green: #00d68f;
  --green-dim: #00d68f22;
  --green-wash: #00d68f0f;
  --green-edge: #00d68f30;
  --red: #ff4757;
  --red-dim: #ff475722;
  --red-wash: #ff47570f;
  --red-edge: #ff475730;
  --blue: #4f8ef7;
  --blue-dim: #4f8ef720;
  --purple: #a78bfa;
  --yellow: #fbbf24;

  --text: #e8eaf0;
  --text2: #8891a8;
  --text3: #4a5168;

  --shadow: 0 4px 24px #00000040;
  --shadow-lg: 0 12px 40px #00000060;
  --chart-grid: #ffffff0f;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface2: #eef1f6;
  --surface3: #e4e8f0;
  --border: #0b132808;
  --border2: #0b132818;

  /* Darkened so they clear 4.5:1 on white — the dark-theme steps do not. */
  --green: #00875a;
  --green-dim: #00875a1f;
  --green-wash: #00875a10;
  --green-edge: #00875a38;
  --red: #d12d3d;
  --red-dim: #d12d3d1f;
  --red-wash: #d12d3d10;
  --red-edge: #d12d3d38;
  --blue: #2f6fe0;
  --blue-dim: #2f6fe01c;
  --purple: #7c5cf0;
  --yellow: #b7791f;

  --text: #12151c;
  --text2: #5a6478;
  --text3: #98a0b3;

  --shadow: 0 4px 24px #0b132814;
  --shadow-lg: 0 12px 40px #0b132824;
  --chart-grid: #0b13280f;
}

:root {
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 28px;

  --font-ui: 'Syne', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --nav-height: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Reset / base ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { font-weight: 800; letter-spacing: -0.5px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }

p { color: var(--text); }

/* Numbers wear DM Mono everywhere — the core of the trading look. */
.mono,
.stat-value,
.stat-sub,
.day-row__pnl,
.day-row__date,
.calendar-cell__pnl,
.calendar-cell__num,
.result-summary__value,
.result-meta,
.table td,
.month-nav__label {
  font-family: var(--font-mono);
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }

/* index.html JS sets className directly, so .error must stay a real class. */
.error { color: var(--red); }

/* ---------- Top nav (sticky) ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border2);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-5);
  /* iOS PWA standalone mode (status-bar-style=black-translucent) draws page
     content under the notch/status bar/Dynamic Island — without this, the
     top row of the nav sits under that system UI and its taps never reach
     the page. The background still fills the true top since this element
     is sticky at top:0; only the content is pushed below the safe area. */
  padding-top: var(--safe-top);
  min-height: calc(var(--nav-height) + var(--safe-top));
  flex-wrap: wrap;
}

.topnav__logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
  white-space: nowrap;
}

.topnav__logo span { color: var(--blue); }

.topnav__tabs {
  display: flex;
  gap: var(--sp-1);
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.topnav__tabs::-webkit-scrollbar { display: none; }

.topnav__tab {
  padding: 7px 16px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
  transition: all .2s;
}

.topnav__tab:hover { color: var(--text); background: var(--surface2); }
.topnav__tab.active { background: var(--blue-dim); color: var(--blue); }

.topnav__right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

/* ---------- Layout ---------- */
.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-5) calc(var(--sp-6) + var(--safe-bottom));
}

.page--narrow { max-width: 720px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

.page-title { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }

.page-sub { font-size: 12px; color: var(--text2); font-family: var(--font-mono); }

.stack { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 9px 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-ui);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .18s;
  white-space: nowrap;
}

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #6ba3ff; transform: translateY(-1px); }

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border2);
}
.btn-ghost:hover { background: var(--surface3); transform: translateY(-1px); }

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border-color: var(--red-dim);
}
.btn-danger:hover { transform: translateY(-1px); }

.btn-icon { padding: 9px 11px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 20px; font-size: 15px; }
.btn-block { display: flex; width: 100%; }

.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
  overflow-wrap: anywhere;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.card-sub { font-size: 12px; color: var(--text2); margin-bottom: var(--sp-4); }

.card__link { display: inline-block; margin-top: var(--sp-3); font-size: 13px; font-weight: 700; }

/* ---------- Stat cards (gradient top edge) ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: var(--sp-5);
  position: relative;
  overflow: hidden;
  min-width: 0;
  transition: transform .18s, box-shadow .18s;
}

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

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

.stat-card.green::before { background: linear-gradient(90deg, var(--green), transparent); }
.stat-card.red::before { background: linear-gradient(90deg, var(--red), transparent); }
.stat-card.blue::before { background: linear-gradient(90deg, var(--blue), transparent); }
.stat-card.purple::before { background: linear-gradient(90deg, var(--purple), transparent); }
.stat-card.yellow::before { background: linear-gradient(90deg, var(--yellow), transparent); }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: var(--sp-2);
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: var(--sp-1);
  overflow-wrap: anywhere;
}

.stat-sub { font-size: 11px; color: var(--text2); }

.pos, .stat-value.pos { color: var(--green); }
.neg, .stat-value.neg { color: var(--red); }
.stat-value.blue { color: var(--blue); }
.stat-value.purple { color: var(--purple); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }

.field__label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .6px;
}

.input, .textarea {
  width: 100%;
  max-width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 9px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color .15s;
}

.input:focus, .textarea:focus { border-color: var(--blue); }
.input::placeholder, .textarea::placeholder { color: var(--text3); }

.textarea { resize: vertical; font-family: var(--font-ui); }
.textarea-mono { font-family: var(--font-mono); font-size: 13px; }

input[type="file"] {
  max-width: 100%;
  font-size: 13px;
  color: var(--text2);
  font-family: var(--font-ui);
}

/* ---------- Status / results ---------- */
.status-text { font-size: 13px; color: var(--text2); overflow-wrap: anywhere; }
.status-text:empty { display: none; }

.result-panel { margin-top: var(--sp-3); }
.result-panel:empty { display: none; }

.result-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface2);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-2);
}

.result-summary__value { font-size: 20px; font-weight: 800; }
.result-meta { color: var(--text2); font-size: 11px; }

.result-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text2);
  margin-top: var(--sp-2);
}

details.raw-details { margin-top: var(--sp-2); }
details.raw-details > summary {
  cursor: pointer;
  color: var(--text2);
  font-size: 11px;
  font-family: var(--font-mono);
}

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }

.table th {
  font-size: 10px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .7px;
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-family: var(--font-ui);
}

.table td {
  padding: 10px var(--sp-3);
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover td { background: var(--surface2); }

.table .num { text-align: right; }
.table .sym { font-family: var(--font-ui); font-weight: 700; color: var(--text); }

/* Wide tables stack into label/value blocks on phones — no sideways scroll. */
@media (max-width: 720px) {
  .table--stack thead { display: none; }

  .table--stack tbody tr {
    display: block;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    padding: var(--sp-3);
    margin-bottom: var(--sp-2);
  }

  .table--stack tbody tr:hover td { background: transparent; }

  .table--stack tbody td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-3);
    border-bottom: none;
    padding: 3px 0;
    text-align: left;
  }

  .table--stack tbody td::before {
    content: attr(data-label);
    color: var(--text2);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .7px;
    font-family: var(--font-ui);
    flex: 0 0 auto;
  }

  .table--stack tbody td.full { display: block; }
  .table--stack tbody td.full::before { display: block; margin-bottom: 6px; }
}

/* ---------- Pills / chips ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
  font-family: var(--font-ui);
}

.pill-win, .pill-green, .pill-long { background: var(--green-dim); color: var(--green); }
.pill-loss, .pill-red, .pill-short { background: var(--red-dim); color: var(--red); }
.pill-open { background: var(--surface3); color: var(--text2); }
.pill-blue { background: var(--blue-dim); color: var(--blue); }

.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.tag-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
}

.tag-chip small { color: var(--text3); font-size: 10px; font-family: var(--font-mono); }

/* ---------- Recent-days list ---------- */
.day-list { display: flex; flex-direction: column; }

.day-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 11px var(--sp-2);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  transition: background .15s;
  border-radius: var(--radius-xs);
}

.day-row:last-child { border-bottom: none; }
.day-row:hover { background: var(--surface2); }

.day-row__date { font-size: 13px; color: var(--text2); }
.day-row__meta { display: flex; align-items: center; gap: var(--sp-3); }
.day-row__pnl { font-weight: 700; font-size: 14px; white-space: nowrap; }

/* ---------- Chart ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { max-width: 100%; }

/* ---------- Calendar ---------- */
.month-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.month-nav__label { font-size: 18px; font-weight: 800; letter-spacing: -0.5px; }

.cal-nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .18s;
}

.cal-nav-btn:hover { background: var(--surface3); transform: translateY(-1px); }

.cal-month-stats { display: flex; gap: var(--sp-5); flex-wrap: wrap; }
.cal-stat { font-size: 13px; color: var(--text2); }
.cal-stat span { font-family: var(--font-mono); font-weight: 700; color: var(--text); }
.cal-stat span.pos { color: var(--green); }
.cal-stat span.neg { color: var(--red); }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }

.calendar-weekday {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  padding: 6px 0;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.calendar-cell {
  display: block;
  border-radius: var(--radius-sm);
  padding: 10px;
  min-height: 90px;
  border: 1px solid var(--border);
  color: var(--text);
  transition: all .15s;
  min-width: 0;
  overflow: hidden;
}

.calendar-cell:hover { border-color: var(--border2); transform: translateY(-1px); }

.calendar-cell--empty { background: transparent; border-color: transparent; }
.calendar-cell--empty:hover { transform: none; border-color: transparent; }

.calendar-cell--green { background: var(--green-wash); border-color: var(--green-edge); }
.calendar-cell--red { background: var(--red-wash); border-color: var(--red-edge); }

.calendar-cell--today { border-color: var(--blue); }
.calendar-cell--selected { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue) inset; }

.calendar-cell__num { font-size: 12px; font-weight: 700; color: var(--text3); margin-bottom: 6px; }

.calendar-cell__pnl {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-cell--green .calendar-cell__pnl { color: var(--green); }
.calendar-cell--red .calendar-cell__pnl { color: var(--red); }

/* ---------- Day detail ---------- */
.day-detail__heading {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

.day-detail__field { margin-bottom: var(--sp-2); font-size: 13px; overflow-wrap: anywhere; }
.day-detail__field-label { color: var(--text2); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.day-detail audio { width: 100%; margin: var(--sp-2) 0 var(--sp-4); }

/* ---------- Bars (state vs result) ---------- */
.bar-track { background: var(--surface3); height: 8px; border-radius: 99px; overflow: hidden; min-width: 60px; }
.bar-fill { height: 100%; border-radius: 99px; transition: width .6s cubic-bezier(.4,0,.2,1); }
.bar-fill.pos { background: var(--green); }
.bar-fill.neg { background: var(--red); }

/* ---------- Misc ---------- */
.note { color: var(--text2); font-size: 13px; }

.empty-state { text-align: center; padding: 36px 16px; color: var(--text2); font-size: 14px; }
.empty-icon { font-size: 34px; margin-bottom: 10px; }

/* ---------- Toast (slides up) ---------- */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--green);
  border-radius: 12px;
  padding: 14px 20px;
  color: var(--green);
  font-weight: 700;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  transform: translateY(80px);
  opacity: 0;
  pointer-events: none;
  transition: all .3s cubic-bezier(.4,0,.2,1);
  max-width: calc(100vw - 48px);
}

.toast.show { transform: translateY(0); opacity: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .topnav {
    padding: var(--sp-2) var(--sp-4);
    padding-top: calc(var(--sp-2) + var(--safe-top));
    gap: var(--sp-2);
    row-gap: var(--sp-2);
  }

  .topnav__logo { font-size: 16px; }

  /* Tabs drop to their own scrollable row under the logo + actions. */
  .topnav__tabs { order: 3; flex-basis: 100%; padding-bottom: 2px; }
  .topnav__right { order: 2; }

  .page { padding: var(--sp-4) var(--sp-3) calc(var(--sp-6) + var(--safe-bottom)); }

  .stats-row { gap: var(--sp-2); }
  .stat-card { padding: var(--sp-4); }
  .stat-value { font-size: 20px; }
  .card { padding: var(--sp-4); }

  .calendar-grid { gap: 3px; }
  .calendar-cell { min-height: 58px; padding: 6px; border-radius: var(--radius-xs); }
  .calendar-cell__num { font-size: 11px; margin-bottom: 3px; }
  .calendar-cell__pnl { font-size: 11px; }

  .toast { left: 16px; right: 16px; max-width: none; }
}

@media (max-width: 420px) {
  .stat-value { font-size: 18px; }
  .page-title { font-size: 19px; }
}

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