/* ── CSS Variables ───────────────────────────────────────────── */
:root {
  --bg:      #f4f6f9;
  --surface: #ffffff;
  --border:  #e2e8f0;
  --text:    #1e293b;
  --muted:   #64748b;
  --accent:  #d97706;
  --green:   #16a34a;
  --red:     #dc2626;
  --radius:  10px;
}

/* Override Bootstrap light theme base */
[data-bs-theme="light"] { --bs-body-bg: var(--bg); --bs-body-color: var(--text); }
html, body { overflow-x: hidden; }
body { background: var(--bg); color: var(--text); padding-bottom: env(safe-area-inset-bottom); }

/* Lock to portrait — counter-rotate if device flips to landscape on mobile */
@media screen and (orientation: landscape) and (max-height: 600px) {
  html {
    transform: rotate(-90deg);
    transform-origin: left top;
    width: 100vh;
    height: 100vw;
    overflow-x: hidden;
    position: absolute;
    top: 100%;
    left: 0;
  }
}

/* ── Sticky header ──────────────────────────────────────────── */
.tj-header {
  position: sticky; top: 0; z-index: 1030;
  background: rgba(244,246,249,0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.tj-header .brand { color: var(--accent); font-weight: 700; font-size: 1rem; white-space: nowrap; }

/* ── Nav pills ───────────────────────────────────────────────── */
.tj-nav { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; }
.tj-nav .nav-link {
  flex: 1; text-align: center;
  color: var(--muted); font-size: 0.8rem; font-weight: 600;
  padding: 6px 14px; border-radius: 6px; white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}
.tj-nav .nav-link.active { background: var(--accent) !important; color: #0f1117 !important; }
.tj-nav .nav-link:not(.active):hover { color: var(--text); }

/* ── Profit mode toggle ──────────────────────────────────────── */
.pct-toggle {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); font-size: 0.8rem; font-weight: 700;
  padding: 4px 10px; cursor: pointer; white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.pct-toggle.active { background: rgba(217,119,6,0.1); border-color: var(--accent); color: var(--accent); }

/* ── Settings modal ─────────────────────────────────────────── */
#settingsModal .modal-content {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
}
#settingsModal .modal-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
}
#settingsModal .modal-title { font-size: 1rem; font-weight: 700; }
#settingsModal .modal-body  { padding: 0; }

.settings-group { padding: 4px 20px 14px; }
.settings-group + .settings-group { border-top: 1px solid var(--border); }
.settings-group-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); padding: 12px 0 8px;
}
.settings-group-sub { font-size: 0.78rem; color: var(--muted); margin-bottom: 8px; margin-top: -4px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 0;
}
.settings-row + .settings-row { border-top: 1px solid var(--border); }
.settings-row-title { font-size: 0.9rem; font-weight: 500; color: var(--text); }
.settings-row-sub   { font-size: 0.74rem; color: var(--muted); margin-top: 3px; }

/* Segmented control (profit mode) */
.settings-segmented {
  display: flex; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.seg-opt {
  background: none; border: none; padding: 5px 14px;
  font-size: 0.8rem; font-weight: 600; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s; white-space: nowrap;
}
.seg-opt + .seg-opt { border-left: 1px solid var(--border); }
.seg-opt.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Toggle switch */
.settings-switch {
  position: relative; display: inline-block;
  width: 44px; height: 24px; cursor: pointer; flex-shrink: 0;
}
.settings-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.settings-switch-track {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 999px;
  transition: background .2s;
}
.settings-switch input:checked ~ .settings-switch-track { background: var(--accent); }
.settings-switch-track::after {
  content: ''; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25);
  top: 3px; left: 3px; transition: transform .2s;
}
.settings-switch input:checked ~ .settings-switch-track::after { transform: translateX(20px); }

.bal-input {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 0.78rem; padding: 4px 8px; width: 90px; outline: none;
}
.bal-input:focus { border-color: var(--accent); }

.tj-badge {
  font-size: 0.72rem; padding: 3px 9px; border-radius: 999px;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}

.refresh-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); padding: 5px 9px; font-size: 1rem; cursor: pointer; line-height: 1;
  transition: color .15s, border-color .15s;
}
.refresh-btn:hover { color: var(--accent); border-color: var(--accent); }
.spinning { animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Custom select / filter dropdown ────────────────────────── */
.trades-filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tj-select {
  appearance: none; -webkit-appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%2364748b' d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 0.82rem; font-weight: 600;
  padding: 6px 32px 6px 12px; cursor: pointer; outline: none;
  transition: border-color .15s;
  flex: 1; min-width: 140px;
}
.tj-select:focus  { border-color: var(--accent); }
.tj-select:hover  { border-color: var(--accent); }
.tj-select option { background: var(--surface); color: var(--text); }

/* Status pills (All / Open / Closed) */
.status-pills { display: flex; gap: 4px; flex-shrink: 0; }
.status-pill {
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 0.75rem; font-weight: 600; padding: 5px 13px;
  cursor: pointer; white-space: nowrap; transition: color .15s, border-color .15s, background .15s;
}
.status-pill.active { background: rgba(217,119,6,0.1); border-color: var(--accent); color: var(--accent); }
.status-pill:not(.active):hover { color: var(--text); border-color: #94a3b8; }

/* ── Filter bar ─────────────────────────────────────────────── */
.filter-bar {
  position: sticky; top: 80px; z-index: 1029;
  background: rgba(244,246,249,0.97); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.chips { display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 0.75rem; font-weight: 600; padding: 4px 12px;
  cursor: pointer; white-space: nowrap; transition: color .15s, border-color .15s, background .15s;
}
.chip.active { background: rgba(217,119,6,0.1); border-color: var(--accent); color: var(--accent); }
.chip:not(.active):hover { color: var(--text); border-color: #444; }
.custom-dates { display: flex; align-items: center; gap: 6px; }
.custom-dates input[type="date"] {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 0.78rem; padding: 4px 8px; outline: none;
}
.custom-dates input[type="date"]:focus { border-color: var(--accent); }

/* ── Cards ──────────────────────────────────────────────────── */
.tj-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.85rem 1rem;
}
.tj-card .label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.3rem; }
.tj-card .value { font-size: 1.2rem; font-weight: 700; }
.trades-sub    { font-size: 0.72rem; margin-top: 4px; }
.trades-open   { color: var(--accent); font-weight: 600; }
.trades-closed { color: var(--muted); }
.trades-sep    { color: var(--border); }
.positive { color: var(--green); }
.negative { color: var(--red); }

/* ── Section title ───────────────────────────────────────────── */
.section-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }

/* ── Strategy card ───────────────────────────────────────────── */
.strat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.strat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); gap: 0.5rem;
}
.strat-name { font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strat-profit { font-size: 1rem; font-weight: 700; white-space: nowrap; }
.strat-stats { display: grid; grid-template-columns: repeat(4,1fr); text-align: center; }
.strat-stat { padding: 0.5rem 0.25rem; border-right: 1px solid var(--border); }
.strat-stat:last-child { border-right: none; }
.strat-stat .sl { font-size: 0.6rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 2px; }
.strat-stat .sv { font-size: 0.82rem; font-weight: 600; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap th, .table-wrap td { padding: 0.7rem 0.9rem; text-align: left; white-space: nowrap; }
.table-wrap th {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface);
}
.table-wrap tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
.table-wrap tr:hover td { background: rgba(0,0,0,0.025); }
.profit-cell { font-weight: 600; }
.thumb {
  width: 64px; height: 40px; object-fit: cover; border-radius: 4px;
  border: 1px solid var(--border); cursor: pointer; transition: transform .15s;
}
.thumb:hover { transform: scale(1.15); }
.status-msg { text-align: center; padding: 3rem; color: var(--muted); font-size: 0.95rem; }

/* ── Mobile trade card ───────────────────────────────────────── */
.trade-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); gap: 0.5rem;
}
.tc-left { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.dir-badge { font-size: 0.8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.dir-buy  { background: rgba(34,197,94,0.15);  color: var(--green); }
.dir-sell { background: rgba(239,68,68,0.15);   color: var(--red); }
.tc-symbol { font-weight: 600; font-size: 0.95rem; }
.tc-meta   { font-size: 0.75rem; color: var(--muted); }
.tc-profit { font-size: 1.1rem; font-weight: 700; white-space: nowrap; }
.tc-body   { display: grid; grid-template-columns: 1fr 1fr; }
.tc-field  { padding: 0.55rem 1rem; border-bottom: 1px solid var(--border); }
.tc-field:nth-child(odd) { border-right: 1px solid var(--border); }
.tc-field .fl { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px; }
.tc-field .fv { font-size: 0.85rem; font-weight: 500; }
.tc-images { display: grid; grid-template-columns: 1fr 1fr; }
.tc-img-wrap { padding: 0.6rem 1rem; border-top: 1px solid var(--border); }
.tc-img-wrap:first-child { border-right: 1px solid var(--border); }
.tc-img-wrap .fl { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 0.4rem; }
.tc-thumb { width: 100%; height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; }
.tc-no-img { font-size: 0.8rem; color: var(--muted); }

/* ── Lightbox ────────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; cursor: zoom-out; padding: 1rem;
}
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: var(--radius); }

/* ── Responsive visibility ───────────────────────────────────── */
@media (min-width: 768px) { .mobile-only  { display: none !important; } }
@media (max-width: 767px) { .desktop-only { display: none !important; } }
@media (min-width: 768px) {
  #page-summary, #page-analytics { max-width: 1400px; margin-left: auto; margin-right: auto; }
}

/* ── Analytics ───────────────────────────────────────────────── */
.chart-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 0.6rem; font-weight: 600; }
.chart-wrap  { position: relative; }
.an-stat-card .value { font-size: 1.05rem; }
