/* ============================================================
   Forex Trading Tool - Professional Design System
   ============================================================ */
:root {
  /* surfaces */
  --app: #0a0d13;
  --surface: #11151d;
  --surface-2: #161b25;
  --elevated: #1b2230;
  --border: #232b39;
  --border-2: #2d3748;

  /* text */
  --text: #e7edf5;
  --text-2: #aeb9c8;
  --muted: #6b7689;

  /* brand / semantic */
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --green: #22c55e;
  --green-dim: #16a34a;
  --red: #ef4444;
  --red-dim: #dc2626;
  --amber: #f59e0b;
  --violet: #8b5cf6;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --sidebar-w: 232px;

  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(59, 130, 246, .08), transparent 60%),
    var(--app);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

/* scrollbars */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: #2a3342;
  border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
  background: #36425a;
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ============================================================
   App shell: sidebar + main
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--surface), var(--app));
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 8px 22px;
}

.brand .logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  font-size: 16px;
  box-shadow: 0 4px 14px rgba(59, 130, 246, .4);
}

.brand .name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .2px;
}

.brand .sub {
  font-size: 11px;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav a.active {
  background: rgba(59, 130, 246, .14);
  color: var(--accent-2);
}

.nav a .ico {
  width: 18px;
  text-align: center;
  opacity: .9;
}

.sidebar-foot {
  margin-top: auto;
  font-size: 11px;
  color: var(--muted);
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 21, 29, .6);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 650;
  letter-spacing: .2px;
}

.topbar .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.content {
  padding: 24px 28px 40px;
  max-width: 1320px;
  width: 100%;
}

/* ============================================================
   Badges / pills
   ============================================================ */
.badge {
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.badge.ok {
  color: #7ee2a8;
  background: rgba(34, 197, 94, .12);
  border-color: rgba(34, 197, 94, .25);
}

.badge.ok::before {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.badge.err {
  color: #ff9b95;
  background: rgba(239, 68, 68, .12);
  border-color: rgba(239, 68, 68, .25);
}

.badge.err::before {
  background: var(--red);
}

.badge.plain::before {
  display: none;
}

/* ============================================================
   Cards & stat tiles
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-head h2 {
  font-size: 13px;
  margin: 0;
  color: var(--text-2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
}

.card-body {
  padding: 16px 18px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  opacity: .8;
}

.stat.green::after {
  background: var(--green);
}

.stat.red::after {
  background: var(--red);
}

.stat.violet::after {
  background: var(--violet);
}

.stat.amber::after {
  background: var(--amber);
}

.stat .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  font-weight: 600;
}

.stat .value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: -.5px;
}

.stat .sub {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 4px;
}

.value.pos,
.pos {
  color: #4ade80;
}

.value.neg,
.neg {
  color: #f87171;
}

.muted {
  color: var(--muted);
}

/* ============================================================
   Controls
   ============================================================ */
.controls {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}

.input,
select.input,
input.input {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  min-width: 150px;
  outline: none;
  transition: border .15s, box-shadow .15s;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .18);
}

.btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: filter .15s, transform .05s;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:active {
  transform: translateY(1px);
}

.btn.ghost {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text-2);
}

.btn.ghost:hover {
  color: var(--text);
}

/* segmented toggle */
.segment {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segment button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 9px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.segment button.active {
  background: var(--accent);
  color: #fff;
}

/* ============================================================
   Tables
   ============================================================ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.tbl th {
  text-align: right;
  padding: 12px 14px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  letter-spacing: .3px;
}

table.tbl th.left,
table.tbl td.left {
  text-align: left;
}

table.tbl th:hover {
  color: var(--text);
}

table.tbl td {
  text-align: right;
  padding: 11px 14px;
  border-bottom: 1px solid #1a212d;
  white-space: nowrap;
}

table.tbl tbody tr {
  transition: background .12s;
}

table.tbl tbody tr:hover {
  background: var(--surface-2);
}

table.tbl tbody tr:last-child td {
  border-bottom: none;
}

.rank {
  color: var(--muted);
  width: 34px;
  font-variant-numeric: tabular-nums;
}

.sname {
  font-weight: 600;
  color: var(--text);
}

td,
.num {
  font-variant-numeric: tabular-nums;
}

/* group badges */
.gbadge {
  display: inline-block;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
}

.g-Trend {
  background: rgba(59, 130, 246, .15);
  color: #7cb1ff;
}

.g-SmartMoney {
  background: rgba(139, 92, 246, .15);
  color: #c4a7ff;
}

.g-MarketStructure {
  background: rgba(34, 197, 94, .15);
  color: #6ee7a0;
}

.g-Candlestick {
  background: rgba(245, 158, 11, .15);
  color: #fbbf6b;
}

.g-Session {
  background: rgba(45, 212, 191, .15);
  color: #5fe3d6;
}

.g-ChartPattern {
  background: rgba(239, 68, 68, .15);
  color: #ff9b95;
}

/* mini perf bar in tables */
.perfbar {
  position: relative;
  width: 130px;
  height: 8px;
  background: #1a212d;
  border-radius: 999px;
  display: inline-block;
  vertical-align: middle;
  overflow: hidden;
}

.perfbar>span {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
}

.perfbar>span.p {
  background: linear-gradient(90deg, var(--green-dim), var(--green));
}

.perfbar>span.n {
  background: linear-gradient(90deg, var(--red), var(--red-dim));
}

.empty {
  padding: 48px;
  text-align: center;
  color: var(--muted);
}

.section-title {
  margin: 32px 0 16px;
  font-size: 16px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.footnote {
  font-size: 12px;
  color: var(--muted);
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* responsive: phones = hide the desktop sidebar, show the bottom tab bar */
@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    padding: 14px 16px calc(14px);
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  .topbar h1 {
    font-size: 16px;
  }

  .topbar .sub {
    font-size: 11px;
  }

  .content {
    padding: 16px 16px calc(80px + env(safe-area-inset-bottom));
  }

  .table-wrap {
    overflow-x: auto;
  }

  .bottom-nav {
    display: flex;
  }
}

/* ============================================================
   Login page
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 28px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.login-brand .logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
}

.login-brand .name {
  font-weight: 700;
}

.login-brand .sub {
  font-size: 12px;
  color: var(--muted);
}

.login-title {
  font-size: 22px;
  margin: 0 0 4px;
}

.login-desc {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 20px;
}

.login-field {
  display: block;
  margin-bottom: 16px;
}

.login-field span {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
}

.login-field .input {
  width: 100%;
}

.login-btn {
  width: 100%;
  padding: 12px;
  margin-top: 4px;
  font-size: 15px;
}

.login-error {
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .3);
  color: #ff9b95;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.login-foot {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin-top: 20px;
}

/* nav logout button */
.nav .logout {
  margin-top: 4px;
  color: #ff9b95;
}

.nav .logout:hover {
  background: rgba(239, 68, 68, .1);
}

/* builder page */
.builder-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.parse-out {
  font-size: 13px;
  color: var(--text-2);
}

.chip {
  display: inline-block;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, .15);
  color: #7cb1ff;
  margin: 3px 4px 3px 0;
}

.chip.pending {
  background: rgba(245, 158, 11, .15);
  color: #fbbf6b;
}

.run-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 16px 0;
  flex-wrap: wrap;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

textarea.input {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  font-family: var(--font);
}

/* small inline buttons (saved strategy actions) */
.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  margin-right: 6px;
}

/* ============================================================
   Strategy Builder form layout
   ============================================================ */
.field-full {
  width: 100%;
}

.field-full>.input,
.field-full>textarea.input {
  width: 100%;
  max-width: 100%;
}

.param-divider {
  height: 1px;
  background: var(--border);
  margin: 22px 0;
}

.param-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}

.param-grid .field .input {
  width: 100%;
  min-width: 0;
}

.form-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 22px;
}

@media (max-width: 760px) {
  .param-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================================
   UX polish: no stray text-caret on UI, stable scrollbar
   ============================================================ */

/* Always reserve the vertical scrollbar so content never shifts
   sideways when a page grows/shrinks (fixes the "shaky" layout). */
html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

/* Default arrow cursor for the whole app; suppress the mobile tap flash. */
body {
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}

/* Don't show the text (I-beam) cursor or let users select UI chrome. */
.app,
.sidebar,
.topbar,
.nav,
.brand,
.card-head,
.section-title,
.btn,
.badge,
.gbadge,
.chip,
label,
th,
.stat .label,
.stat .value,
.stat .sub,
.segment,
.perfbar,
.legend,
.run-row .muted {
  user-select: none;
  -webkit-user-select: none;
}

/* Re-enable selection only where it is genuinely useful (form fields,
   parsed output and result/data tables so values can be copied). */
input,
textarea,
select,
.input,
.parse-out,
#saved_meta,
#pb_datainfo,
table.tbl td {
  user-select: text;
  -webkit-user-select: text;
}

/* Correct cursors per control type. */
a,
.btn,
button,
.nav a,
.segment button,
[data-load],
[data-del],
table.tbl th {
  cursor: pointer;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
textarea {
  cursor: text;
}

select,
select.input {
  cursor: pointer;
}

/* Avoid a focus caret/outline jump on non-input clickable elements. */
.btn:focus,
.nav a:focus,
.segment button:focus {
  outline: none;
}

/* ============================================================
   Brand logo images (sidebar + login)
   ============================================================ */
.brand {
  padding: 8px 8px 22px;
}

.brand-logo {
  display: block;
  height: 34px;
  width: auto;
  max-width: 100%;
}

.login-brand {
  justify-content: center;
}

.login-logo {
  height: 46px;
}

/* ============================================================
   Native-app feel (PWA): no zoom / pull-to-refresh / long-press,
   safe-area insets for notch, momentum scrolling
   ============================================================ */
* {
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  /* stop the browser pull-to-refresh and rubber-band bounce */
  overscroll-behavior: none;
  /* remove the 300ms tap delay and double-tap-to-zoom */
  touch-action: manipulation;
}

body {
  -webkit-touch-callout: none;
  /* no long-press callout menu */
  user-select: none;
  /* app-like; inputs/tables re-enabled below */
  -webkit-user-select: none;
}

/* keep selection usable in fields + result tables (override the body rule) */
input,
textarea,
select,
.input,
.parse-out,
#saved_meta,
#pb_datainfo,
table.tbl td {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

img,
.brand-logo {
  -webkit-user-drag: none;
  user-select: none;
}

/* notch / status-bar + home-indicator safe areas (env()=0 on normal screens) */
.sidebar {
  padding-top: calc(20px + env(safe-area-inset-top));
}

.topbar {
  padding-top: calc(16px + env(safe-area-inset-top));
}

.content {
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
  /* momentum scroll */
}

@media (max-width: 880px) {

  /* on phones the sidebar is the top row — it carries the status-bar inset */
  .topbar {
    padding-top: 16px;
  }
}

/* ============================================================
   Mobile bottom navigation (native-app tab bar)
   ============================================================ */
.bottom-nav {
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: rgba(17, 21, 29, .94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  justify-content: space-around;
  align-items: center;
  gap: 2px;
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1 1 0;
  max-width: 84px;
  padding: 5px 4px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .2px;
  transition: color .15s, background .15s, transform .08s;
}

.bottom-nav a .bn-ico {
  font-size: 19px;
  line-height: 1;
}

.bottom-nav a:active {
  transform: scale(.92);
}

.bottom-nav a.active {
  color: var(--accent-2);
  background: rgba(59, 130, 246, .12);
}

/* Desktop (>=881px) uses the left sidebar, so hide the bottom tab bar.
   Defined last so it reliably wins over the base .bottom-nav rule. */
@media (min-width: 881px) {
  .bottom-nav {
    display: none;
  }
}