/* ─── Custom styles beyond Tailwind ─────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-base:    #0f1117;
  --bg-card:    #1a1d2e;
  --bg-card2:   #222639;
  --border:     #2e3352;
  --primary:    #6366f1;
  --primary-h:  #818cf8;
  --success:    #22c55e;
  --danger:     #ef4444;
  --warning:    #f59e0b;
  --text-1:     #f1f5f9;
  --text-2:     #94a3b8;
  --text-3:     #64748b;
  --sidebar-w:  240px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', sans-serif;
  background: var(--bg-base);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

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

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo span {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -.3px;
}

.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--bg-card2);
  color: var(--text-1);
}

.nav-item.active {
  background: rgba(99,102,241,.15);
  color: var(--primary-h);
}

.nav-item.active svg { color: var(--primary); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-2);
  font-size: 13px;
}

.topbar-user .avatar {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}

.btn-logout {
  background: none; border: 1px solid var(--border);
  color: var(--text-2); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; cursor: pointer;
  transition: all .15s; font-family: inherit;
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

/* ── Page content ────────────────────────────────────────────────────────── */
.page-content { padding: 24px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.card-sm { padding: 14px 16px; }

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

/* ── Metric cards ────────────────────────────────────────────────────────── */
.metric-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.2;
}

.metric-value.positive { color: var(--success); }
.metric-value.negative { color: var(--danger); }

.metric-delta {
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
}

.metric-delta.up { color: var(--success); }
.metric-delta.down { color: var(--danger); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-buy    { background: rgba(34,197,94,.15);  color: #4ade80; }
.badge-sell   { background: rgba(239,68,68,.15);  color: #f87171; }
.badge-win    { background: rgba(34,197,94,.15);  color: #4ade80; }
.badge-loss   { background: rgba(239,68,68,.15);  color: #f87171; }
.badge-open   { background: rgba(99,102,241,.15); color: #818cf8; }
.badge-cancelled { background: rgba(100,116,139,.15); color: #94a3b8; }
.badge-running   { background: rgba(245,158,11,.15);  color: #fbbf24; }
.badge-completed { background: rgba(34,197,94,.15);   color: #4ade80; }
.badge-failed    { background: rgba(239,68,68,.15);   color: #f87171; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--bg-card2);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 9px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid rgba(46,51,82,.5);
  transition: background .12s;
}

tbody tr:hover { background: rgba(255,255,255,.025); }

tbody td {
  padding: 10px 14px;
  color: var(--text-1);
  vertical-align: middle;
}

.td-muted { color: var(--text-2); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }

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

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary-h); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

input::placeholder, textarea::placeholder { color: var(--text-3); }

select option { background: var(--bg-card2); color: var(--text-1); }

/* ── Progress bar ────────────────────────────────────────────────────────── */
.progress-bar {
  height: 4px;
  background: var(--bg-card2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--primary);
  transition: width .3s ease;
}

.progress-fill.success { background: var(--success); }
.progress-fill.danger  { background: var(--danger); }

/* ── Circular progress (win rate) ────────────────────────────────────────── */
.circle-progress {
  position: relative;
  width: 56px; height: 56px;
}

.circle-progress svg {
  transform: rotate(-90deg);
  width: 56px; height: 56px;
}

.circle-progress .circle-bg {
  fill: none;
  stroke: var(--bg-card2);
  stroke-width: 4;
}

.circle-progress .circle-fill {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 150.796;
  stroke-dashoffset: 150.796;
  transition: stroke-dashoffset .6s ease;
}

.circle-progress .circle-text {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: var(--text-1);
}

/* ── Toast notifications ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-1);
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  animation: slideIn .25s ease;
  display: flex; align-items: flex-start; gap: 8px;
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes fadeOut {
  to { transform: translateX(100%); opacity: 0; }
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 16px; font-weight: 700; }

.modal-close {
  width: 28px; height: 28px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: all .15s;
}
.modal-close:hover { color: var(--text-1); border-color: var(--text-2); }

/* ── Heatmap grid ────────────────────────────────────────────────────────── */
.heatmap-grid {
  display: grid;
  grid-template-columns: 48px repeat(24, 1fr);
  gap: 2px;
  font-size: 10px;
}

.heatmap-cell {
  height: 26px;
  border-radius: 3px;
  cursor: default;
  transition: transform .1s;
  position: relative;
}
.heatmap-cell:hover { transform: scale(1.3); z-index: 10; }

.heatmap-label {
  height: 26px;
  display: flex; align-items: center;
  color: var(--text-3);
  font-weight: 500;
  font-size: 10px;
  padding-right: 4px;
  justify-content: flex-end;
}

/* ── Charts ──────────────────────────────────────────────────────────────── */
.chart-container { position: relative; width: 100%; }

/* Lightweight Charts host */
#candle-chart {
  width: 100%;
  height: 480px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-card2);
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
}
.empty-state svg { margin: 0 auto 12px; opacity: .4; }
.empty-state p { font-size: 14px; margin: 0; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-base);
  background-image: radial-gradient(ellipse at 20% 50%, rgba(99,102,241,.08) 0%, transparent 60%),
                    radial-gradient(ellipse at 80% 20%, rgba(168,85,247,.06) 0%, transparent 50%);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .icon-wrap {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  margin: 0 auto 12px;
}

.login-logo h1 {
  font-size: 20px; font-weight: 700; margin: 0 0 4px;
  color: var(--text-1);
}

.login-logo p {
  font-size: 13px; color: var(--text-2); margin: 0;
}

/* ── Section headers ─────────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
}

/* ── Grid helpers ────────────────────────────────────────────────────────── */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

/* ── Toggle switch ───────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }

.toggle {
  position: relative;
  width: 44px; height: 24px;
  cursor: pointer;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: .2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: var(--text-3);
  border-radius: 50%;
  transition: .2s;
}

.toggle input:checked + .toggle-slider {
  background: rgba(99,102,241,.3);
  border-color: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: var(--primary);
}

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 6px;
  justify-content: center;
  padding-top: 16px;
}

.page-btn {
  width: 32px; height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 13px; font-family: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}

.page-btn:hover { border-color: var(--primary); color: var(--primary-h); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Filters bar ─────────────────────────────────────────────────────────── */
.filters-bar {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: flex-end;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.filter-group label { margin-bottom: 0; }
.filter-group input,
.filter-group select { width: auto; min-width: 120px; }

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

@media (max-width: 640px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .grid-4, .grid-3, .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* ── SMC legend ──────────────────────────────────────────────────────────── */
.smc-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card2);
  border-radius: 8px;
  margin-top: 10px;
}

.legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-2);
}

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 2px;
}

/* ── Alert box ───────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: flex; align-items: flex-start; gap: 8px;
}

.alert-warning {
  background: rgba(245,158,11,.1);
  border: 1px solid rgba(245,158,11,.3);
  color: #fbbf24;
}

.alert-danger {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  color: #f87171;
}
