:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand-badge {
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 0.85rem;
}

.engine-nav { display: flex; gap: 6px; }
.engine-tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.engine-tab.active { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
.pill-ro {
  font-size: 0.68rem;
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 99px;
  margin-left: 4px;
}
.sync-badge, .user-badge {
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-2);
  padding: 5px 10px;
  border-radius: 99px;
}

.container { max-width: 1380px; margin: 0 auto; padding: 16px; }
.engine-section { display: none; }
.engine-section.active { display: block; }
.subpane { display: none; }
.subpane.active { display: block; }

.section-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.subtabs { display: flex; flex-wrap: wrap; gap: 6px; }
.subtab {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}
.subtab.active { background: var(--accent); color: #071324; border-color: var(--accent); }

.bar-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.period-pills { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.pill {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}
.pill.active { background: var(--surface-2); color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h3 { margin: 0 0 12px; font-size: 1rem; }
.card-head-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head-row h3 { margin: 0; }

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 10px;
}
.heat-tile {
  border-radius: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.heat-tile.pos { border-color: rgba(16, 185, 129, 0.5); background: rgba(16, 185, 129, 0.12); }
.heat-tile.neg { border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.12); }
.heat-name { font-weight: 700; font-size: 0.88rem; margin-bottom: 4px; }
.heat-pct { font-size: 1.15rem; font-weight: 800; }
.heat-ltp { font-size: 0.78rem; color: var(--muted); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.kpi-label { font-size: 0.76rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-val { font-size: 1.3rem; font-weight: 800; margin-top: 4px; }

.two-col-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.chart-box { min-height: 210px; display: flex; align-items: center; justify-content: center; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-head { text-align: center; font-size: 0.72rem; color: var(--muted); font-weight: 700; padding-bottom: 4px; }
.cal-cell {
  border-radius: 7px;
  padding: 6px 4px;
  min-height: 54px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.74rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.cal-cell.empty { background: transparent; border-color: transparent; }
.cal-cell.win { background: rgba(16, 185, 129, 0.18); border-color: rgba(16, 185, 129, 0.5); }
.cal-cell.loss { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.5); }
.cal-pnl { font-weight: 700; font-size: 0.72rem; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }

.pos-txt { color: var(--green); font-weight: 700; }
.neg-txt { color: var(--red); font-weight: 700; }
.badge { padding: 2px 8px; border-radius: 99px; font-size: 0.74rem; font-weight: 700; display: inline-block; }
.badge-buy { background: rgba(16, 185, 129, 0.18); color: var(--green); }
.badge-sell { background: rgba(239, 68, 68, 0.18); color: var(--red); }
.badge-open { background: rgba(245, 158, 11, 0.18); color: var(--amber); }

.btn-primary, .btn-ghost, .btn-danger {
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  font-size: 0.86rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-primary { background: var(--accent); color: #071324; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border-color: rgba(239, 68, 68, 0.45); }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.full-width { width: 100%; }

input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 0.88rem;
  width: 100%;
}
.input-sm { padding: 6px 9px; font-size: 0.82rem; width: auto; min-width: 140px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.76rem; color: var(--muted); font-weight: 600; }
.full-span { grid-column: 1 / -1; }
.action-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.muted-msg { color: var(--muted); font-size: 0.84rem; margin-left: 8px; }
.form-error { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.4); border-radius: 7px; padding: 8px 10px; font-size: 0.84rem; margin-top: 8px; }

.breakdown-list { display: flex; flex-direction: column; gap: 8px; }
.breakdown-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 10px; background: var(--surface-2); border-radius: 8px; font-size: 0.86rem; }
.calc-output { margin-top: 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 1000;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 780px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.modal-header, .modal-footer { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-footer { border-bottom: 0; border-top: 1px solid var(--border); justify-content: flex-end; gap: 10px; }
.modal-body { padding: 16px; }
.trade-preview { margin-top: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font-size: 0.84rem; display: flex; flex-wrap: wrap; gap: 14px; }

/* Login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 390px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 26px; }
.login-brand h1 { margin: 12px 0 4px; font-size: 1.3rem; }
.login-brand p { margin: 0 0 18px; color: var(--muted); font-size: 0.86rem; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-footer { margin-top: 16px; text-align: center; color: var(--muted); font-size: 0.78rem; }

@media (max-width: 900px) {
  .two-col-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .container { padding: 10px; }
  .heatmap-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .input-sm { min-width: 110px; }
}
