/* ---------------- Theme tokens ---------------- */
:root[data-theme="dark"], :root {
  --bg: #0b0f14;
  --bg-elevated: #12181f;
  --panel: #141b23;
  --border: #232c37;
  --text: #e9edf1;
  --text-dim: #9aa7b4;
  --text-faint: #5c6b7a;
  --accent: #3b82f6;
  --green: #22c55e;
  --green-dim: rgba(34,197,94,0.14);
  --red: #ef4444;
  --red-dim: rgba(239,68,68,0.14);
  --amber: #f59e0b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
}
:root[data-theme="light"] {
  --bg: #f4f6f8;
  --bg-elevated: #ffffff;
  --panel: #ffffff;
  --border: #e2e6ea;
  --text: #10151b;
  --text-dim: #55626e;
  --text-faint: #94a1ad;
  --accent: #2563eb;
  --green: #16a34a;
  --green-dim: rgba(22,163,74,0.10);
  --red: #dc2626;
  --red-dim: rgba(220,38,38,0.10);
  --amber: #d97706;
  --shadow: 0 10px 30px rgba(20,30,40,0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font-family: inherit; color: inherit; }
input, select, textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

/* ---------------- Lock screen ---------------- */
.lock-screen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.lock-screen.hidden { display: none; }
.lock-card { width: 100%; max-width: 320px; text-align: center; padding: 20px; }
.lock-icon {
  width: 56px; height: 56px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  color: var(--accent);
}
.lock-icon svg { width: 26px; height: 26px; }
.lock-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.lock-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 24px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 8px; }
.pin-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--text-faint); transition: all .15s;
}
.pin-dots span.filled { background: var(--accent); border-color: var(--accent); }
.pin-error { color: var(--red); font-size: 13px; height: 18px; margin: 6px 0 18px; opacity: 0; transition: opacity .15s; }
.pin-error.show { opacity: 1; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-pad button {
  aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-size: 20px; font-weight: 600;
}
.pin-pad button.ghost { border: none; background: none; font-size: 14px; color: var(--text-dim); }
.pin-pad button:active { background: var(--border); }

/* ---------------- App shell ---------------- */
.app-shell { display: none; min-height: 100vh; }
.app-shell.visible { display: flex; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg-elevated); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 24px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px var(--green); }
.brand-name { font-weight: 700; font-size: 15px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; border: none; background: none;
  color: var(--text-dim); font-size: 14px; font-weight: 500; text-align: left; cursor: pointer;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--green-dim); color: var(--green); }
.sidebar-footer { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.icon-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text-dim); cursor: pointer;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--text); }

.main { flex: 1; min-width: 0; padding: 24px 24px 100px; max-width: 1100px; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; }
.page-sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.header-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.header-controls select { width: auto; min-width: 140px; }

/* ---------------- Segmented control ---------------- */
.seg { display: inline-flex; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: none; background: none; color: var(--text-dim); padding: 7px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.seg button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.seg button.active.long { color: var(--green); }
.seg button.active.short { color: var(--red); }

/* ---------------- Stat cards ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-grid.compact { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); margin-bottom: 16px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-value.pos { color: var(--green); }
.stat-value.neg { color: var(--red); }
.stat-extra { font-size: 11px; color: var(--text-faint); margin-top: 3px; }

/* ---------------- Panels ---------------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel-title { font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 12px; }
.chart-wrap { width: 100%; position: relative; }
.chart-wrap canvas { width: 100% !important; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }

/* ---------------- Trade list ---------------- */
.trade-list { display: flex; flex-direction: column; gap: 8px; }
.trade-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; cursor: pointer;
}
.trade-row:hover { border-color: var(--accent); }
.trade-thumb, .trade-thumb-empty { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.trade-thumb-empty { background: var(--bg-elevated); display: flex; align-items: center; justify-content: center; color: var(--text-faint); font-size: 11px; }
.trade-main { flex: 1; min-width: 0; }
.trade-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.trade-meta { font-size: 12px; color: var(--text-faint); margin-top: 2px; display: flex; gap: 8px; }
.pill { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; text-transform: uppercase; letter-spacing: .03em; }
.pill-long { background: var(--green-dim); color: var(--green); }
.pill-short { background: var(--red-dim); color: var(--red); }
.pill-src { background: rgba(59,130,246,0.14); color: var(--accent); }
.trade-pnl { font-size: 14px; font-weight: 700; white-space: nowrap; }
.trade-pnl.pos { color: var(--green); }
.trade-pnl.neg { color: var(--red); }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 50px 20px; color: var(--text-faint); text-align: center; }
.empty-state svg { width: 40px; height: 40px; opacity: .5; }

/* ---------------- FAB ---------------- */
.fab {
  position: fixed; right: 24px; bottom: 90px; z-index: 40;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--green); color: #06210f;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(34,197,94,0.4); cursor: pointer;
}
.fab svg { width: 24px; height: 24px; }
@media (min-width: 860px) { .fab { bottom: 32px; } }

/* ---------------- Bottom nav (mobile) ---------------- */
.bottom-nav { display: none; }
@media (max-width: 859px) {
  .sidebar { display: none; }
  .main { padding: 16px 14px 100px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--bg-elevated); border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    border: none; background: none; color: var(--text-faint); font-size: 10px; padding: 6px 2px; cursor: pointer;
  }
  .bn-item svg { width: 20px; height: 20px; }
  .bn-item.active { color: var(--green); }
  .bn-spacer { pointer-events: none; }
}

/* ---------------- Sheet (trade form) ---------------- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.5);
  display: none; align-items: flex-end; justify-content: center;
}
.sheet-overlay.active { display: flex; }
@media (min-width: 640px) { .sheet-overlay { align-items: center; } }
.sheet {
  background: var(--bg-elevated); width: 100%; max-width: 480px; max-height: 92vh;
  border-radius: 20px 20px 0 0; padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
}
@media (min-width: 640px) { .sheet { border-radius: 20px; max-height: 88vh; } }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 4px; margin: 4px auto 0; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; }
.sheet-header h3 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; }

#tradeForm { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pnl-input { font-weight: 700; font-size: 17px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn { flex: 1; border: none; border-radius: 10px; padding: 13px; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--green); color: #06210f; }
.btn-danger { background: var(--red-dim); color: var(--red); }

/* ---------------- Ball rating (1-10) ---------------- */
.ball-row { display: flex; gap: 6px; flex-wrap: nowrap; justify-content: space-between; }
.ball-row button {
  width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--border);
  background: var(--panel); color: var(--text-faint); font-size: 10px; font-weight: 700; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ball-row button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------------- Dropzone / screenshots ---------------- */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: 12px; padding: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--text-faint); font-size: 12px; text-align: center; cursor: pointer;
}
.dropzone svg { width: 22px; height: 22px; }
.dropzone.drag { border-color: var(--accent); color: var(--accent); }
.shot-preview { display: flex; gap: 8px; flex-wrap: wrap; }
.shot-preview .shot-thumb { position: relative; width: 72px; height: 72px; }
.shot-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; cursor: pointer; }
.shot-remove {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: #fff; border: none; font-size: 13px; line-height: 1; cursor: pointer;
}

/* ---------------- Modals ---------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal { background: var(--bg-elevated); border-radius: 16px; width: 100%; max-width: 440px; max-height: 86vh; overflow-y: auto; padding: 18px 20px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h3 { margin: 0; font-size: 16px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-item { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.detail-full { grid-column: 1 / -1; }
.detail-label { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 3px; }
.detail-value { font-size: 13px; font-weight: 600; }
.detail-notes { font-size: 13px; color: var(--text-dim); white-space: pre-wrap; }

.lightbox { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,0.9); display: none; align-items: center; justify-content: center; padding: 20px; }
.lightbox.active { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 20px);
  background: var(--bg-elevated); border: 1px solid var(--border); padding: 10px 18px; border-radius: 30px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 400; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- Calendar ---------------- */
.cal-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 12px; margin-bottom: 16px; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px; color: var(--text-faint); margin-bottom: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-elevated);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; cursor: pointer; position: relative;
}
.cal-cell.empty { border: none; background: none; cursor: default; }
.cal-cell.pos { background: var(--green-dim); border-color: rgba(34,197,94,0.3); }
.cal-cell.neg { background: var(--red-dim); border-color: rgba(239,68,68,0.3); }
.cal-cell .cal-day-num { font-size: 11px; color: var(--text-faint); }
.cal-cell.pos .cal-day-num, .cal-cell.neg .cal-day-num { color: var(--text-dim); }
.cal-cell .cal-day-pnl { font-size: 10px; font-weight: 700; }
.cal-cell.pos .cal-day-pnl { color: var(--green); }
.cal-cell.neg .cal-day-pnl { color: var(--red); }
.cal-cell.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
