/* Dashboard (BUILD-PLAN-2 Part 1 step 2). Design-system tokens (design.css) only.
   The .db-list / .db-drivers rules are also used by the Profit Drivers and
   Performance Breakdown cards on Analytics (analytics-drivers.js). */
:root, html[data-theme="light"] { --db-track: var(--ds-track, #eef0f3); }
html[data-theme="dark"] { --db-track: var(--ds-track, #262626); }

.db-root { display: flex; flex-direction: column; gap: 16px; }
.db-pos { color: var(--ds-pos, var(--profit)) !important; }
.db-neg { color: var(--ds-neg, var(--loss)) !important; }
.db-muted { color: var(--ds-muted, var(--muted)); }

/* ── top: greeting + today ──────────────────────────────────────────────── */
.db2-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap; }
.db2-hello { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.db2-hello .ds-h1 { overflow-wrap: anywhere; }
.db2-today { display: flex; margin: 0; }
.db2-today > div { display: flex; flex-direction: column; gap: 6px; padding: 0 22px; min-width: 0; }
.db2-today > div:first-child { padding-left: 0; }
.db2-today > div + div { border-left: 1px solid var(--ds-line-strong); }
.db2-today dt { white-space: nowrap; }
.db2-today dd { margin: 0; font-size: 22px; font-weight: 600; color: var(--ds-text); white-space: nowrap; }

/* ── toolbar (not a card) ───────────────────────────────────────────────── */
.db2-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: calc(var(--ds-section-gap) * -0.5); }
.db2-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.db2-count { display: inline-grid; place-items: center; min-width: 17px; height: 17px; border-radius: 999px; background: var(--ds-accent); color: #fff; font-size: 10px; padding: 0 4px; letter-spacing: 0; }
.db-filter-wrap { position: relative; }
.db-pop { position: absolute; right: 0; top: calc(100% + 8px); z-index: 45; width: 270px; max-width: calc(100vw - 32px); background: var(--ds-surface-solid); border: 1px solid var(--ds-line-strong); border-radius: var(--ds-radius-card); box-shadow: 0 24px 48px -16px rgba(0,0,0,.28); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.db-pop[hidden] { display: none; }
.db2-field { display: flex; flex-direction: column; gap: 6px; }
.db2-field .ds-select { max-width: none; width: 100%; }
.db-pop-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-top: 2px; }

/* ── cards ──────────────────────────────────────────────────────────────── */
.db2-stat-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 12px; min-height: 16px; }
.db2-stat { display: flex; flex-direction: column; }
.db2-stat .ds-big { margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.db2-gauge { width: 58px; height: 32px; margin: -6px 0 -10px; flex: none; }
.db2-xl { font-size: clamp(28px, 2.4vw, 34px); margin-bottom: 8px; }
.db2-equity, .db2-streak, .db2-disc { display: flex; flex-direction: column; }
.db2-spark { width: 100%; height: 48px; margin-top: auto; padding-top: 14px; display: block; overflow: visible; }
.db2-spark polyline { fill: none; stroke-width: 1.6; stroke: var(--ds-chart-line); }
.db2-spark polygon { fill: var(--ds-accent-tint); stroke: none; }
.db2-meter-row { display: flex; flex-direction: column; gap: 7px; }
.db2-meter-row + .db2-meter-row { margin-top: 16px; }
.db2-meter-line { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--ds-text-2); }
.db2-meter-line b { color: var(--ds-text); font-size: 13px; }
.db2-cap { margin-top: 2px; }
.db2-note { display: flex; gap: 8px; align-items: center; }
.db2-dots { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 10px; }
.db2-dot { width: 12px; height: 12px; border-radius: 4px; display: block; }
.db2-dot.w { background: var(--ds-pos); } .db2-dot.l { background: var(--ds-neg); } .db2-dot.b { background: var(--ds-track); box-shadow: inset 0 0 0 1px var(--ds-line-strong); }
.db2-target { display: flex; flex-direction: column; gap: 10px; }
.db2-target .db2-stat-top { margin-bottom: 0; }
.db2-target-val b { font-size: 20px; font-weight: 600; }
.db2-empty { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; border-style: dashed; }
.db2-empty > i { font-size: 20px; color: var(--ds-accent); width: 44px; height: 44px; border-radius: 12px; background: var(--ds-accent-tint); display: grid; place-items: center; }
.db2-empty > div { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 4px; }
.db2-empty b { font-size: 14px; color: var(--ds-text); }
.db2-none { font-size: 12.5px; color: var(--ds-muted); text-align: center; padding: 36px 12px; }

.db2-chart-card .db2-stat-top { margin-bottom: 8px; }
.db2-chart { height: 300px; position: relative; }

/* calendar + recent */
.db2-split { align-items: start; }
.db2-cal-nav { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.db2-cal-nav span { min-width: 118px; text-align: center; font-size: 12px; color: var(--ds-text-2); }
.db2-cal-sub { margin: 0 0 12px; }
.db-cal-scroll { overflow-x: auto; }
.db2-recent-card { padding: 8px; }
.db2-trades { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.db2-trades li + li { border-top: 1px solid var(--ds-line); }
.db2-trade { width: 100%; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 10px; background: transparent; border: 0; border-radius: 10px; text-align: left; cursor: pointer; color: var(--ds-text); font: inherit; }
.db2-trade:hover, .db2-trade:focus-visible { background: var(--ds-btn2-hover); outline: none; }
.db2-trade:focus-visible { box-shadow: 0 0 0 2px var(--ds-accent); }
.db2-side { font-family: var(--ds-mono); font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; padding: 4px 8px; border-radius: 6px; width: 54px; text-align: center; }
.db2-side.long { background: var(--ds-pos-tint); color: var(--ds-pos); }
.db2-side.short { background: var(--ds-neg-tint); color: var(--ds-neg); }
.db2-tmain, .db2-tres { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.db2-tmain b { font-size: 13px; font-weight: 600; }
.db2-tmain small, .db2-tres small { font-size: 11.5px; color: var(--ds-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.db2-tres { text-align: right; }
.db2-tres b { font-size: 13px; font-weight: 600; }
.db2-pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 10px 4px; border-top: 1px solid var(--ds-line); }
.db2-pager > div { display: flex; gap: 6px; }
.db2-pager button:disabled { opacity: .35; cursor: default; }

/* activity heatmap section (shared kit styles: journal-heatmap.js) */
.db2-act-legend { display: flex; justify-content: flex-end; margin-bottom: 8px; }
#dbActivity .ob-act-months { grid-auto-columns: var(--act-cell, 14px); }
#dbActivity .ob-act-days { grid-template-rows: repeat(7, var(--act-cell, 14px)); line-height: var(--act-cell, 14px); }
#dbActivity .ob-act-grid { grid-template-rows: repeat(7, var(--act-cell, 14px)); grid-auto-columns: var(--act-cell, 14px); }
#dbActivity .ob-act-grid .ob-act-sq { width: var(--act-cell, 14px); height: var(--act-cell, 14px); }
.db-act-summary { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--ds-line); }

/* ── shared calendar cells: tinted, no coloured outlines ────────────────── */
html .ob-jh-grid .ob-jh-cell, html .ob-jh-grid .ob-jh-week { border-color: var(--ds-line) !important; box-shadow: none !important; }
html .ob-jh-grid .ob-jh-win, html .ob-jh-grid .ob-jh-loss,
html .ob-jh-grid .ob-jh-week.ob-jh-win, html .ob-jh-grid .ob-jh-week.ob-jh-loss { border-color: transparent !important; }
html .ob-jh-grid .ob-jh-win { background: var(--ds-pos-tint) !important; }
html .ob-jh-grid .ob-jh-loss { background: var(--ds-neg-tint) !important; }
html .ob-jh-grid .ob-jh-none { background: var(--ds-surface-2) !important; }
html .ob-jh-grid .ob-jh-today { border-color: var(--ds-line) !important; }
html .ob-jh-grid .ob-jh-today .ob-jh-day { color: var(--ds-accent) !important; font-weight: 800; }
html .ob-jh-grid .ob-jh-today .ob-jh-day::after { content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 999px; background: var(--ds-accent); margin-left: 5px; vertical-align: middle; }
/* Touch screens: no "+" circle in the cells; tapping the day opens the add panel (journal-heatmap.js). */
@media (hover: none), (pointer: coarse) {
  html .ob-jh-grid .ob-jh-add { display: none !important; }
  html .ob-jh-grid .ob-jh-cell[data-date] { cursor: pointer; }
}

/* ── moved to Analytics: Performance Breakdown + Profit Drivers ─────────── */
.db-card { background: var(--ds-surface, var(--panel)); border: 1px solid var(--ds-line, var(--border)); border-radius: var(--ds-radius-card, 18px); box-shadow: var(--ds-shadow, var(--shadow)); padding: 20px; min-width: 0; }
.db-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.db-card-head h3 { font-size: 14px; font-weight: 800; color: var(--text); }
.db-card-head p { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.db-empty { font-size: 12.5px; color: var(--muted); text-align: center; padding: 28px 12px; }
.db-list { display: flex; flex-direction: column; list-style: none; margin: 0; padding: 0; }
.db-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--ds-line, var(--border-subtle)); font-size: 12.5px; color: var(--muted); }
.db-list li:last-child { border-bottom: 0; }
.db-list b { font: 700 13px 'JetBrains Mono', monospace; color: var(--text); white-space: nowrap; }
.db-drivers-top { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.db-drivers-top > div { background: var(--ds-surface-2, var(--raised)); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.db-drivers-top span { font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.db-drivers-top b { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-drivers-top em { font: 800 12px 'JetBrains Mono', monospace; font-style: normal; color: var(--muted); }
.db-drivers { display: flex; flex-direction: column; gap: 12px; list-style: none; margin: 0; padding: 0; }
.db-drv-line { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--text); font-weight: 700; }
.db-drv-line b { font-family: 'JetBrains Mono', monospace; }
.db-drv-bar { height: 6px; border-radius: 999px; background: var(--db-track); margin-top: 5px; overflow: hidden; }
.db-drv-bar i { display: block; height: 100%; border-radius: 999px; }
.db-drv-bar i.pos { background: var(--ds-pos, var(--profit)); } .db-drv-bar i.neg { background: var(--ds-neg, var(--loss)); }
.db-drv-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ── tablet / phone structure ───────────────────────────────────────────── */
@media (max-width: 1199px) and (min-width: 1024px) {
  .db2-split > .ds-span-7, .db2-split > .ds-span-5 { grid-column: span 12 !important; }
}
@media (max-width: 1023px) {
  .db2-chart { height: 260px; }
  #dbNow .ds-grid > #dbDiscipline { order: -1; }
}
@media (max-width: 640px) {
  /* Phone order: today → controls → am I safe (discipline first) → targets → performance → calendar → trades → activity */
  .db2-top { flex-direction: column; align-items: stretch; gap: 18px; }
  .db2-today { justify-content: space-between; padding: 14px 0; border-top: 1px solid var(--ds-line); border-bottom: 1px solid var(--ds-line); }
  .db2-today > div { padding: 0 10px; flex: 1; }
  .db2-today > div:last-child { padding-right: 0; }
  .db2-today dd { font-size: 18px; }
  .db2-toolbar { margin-top: calc(var(--ds-section-gap) * -0.35); flex-direction: column; align-items: stretch; gap: 10px; }
  .db2-modes { display: flex; width: 100%; overflow-x: auto; }
  .db2-modes button { flex: 1 0 auto; justify-content: center; }
  .db2-tools { display: grid; grid-template-columns: 1fr 1fr; }
  .db2-tools .ds-select { max-width: none; width: 100%; }
  .db2-tools .db-filter-wrap { grid-column: 1 / -1; }
  .db2-tools .db-filter-wrap > .ds-btn { width: 100%; }
  .db2-tools:not(:has(#dbAccount)) #dbRange { grid-column: 1 / -1; }
  .db-pop { left: 0; right: 0; width: auto; }
  .db2-stat .ds-big { font-size: 20px; }
  .db2-stat-top .ds-label { font-size: 10px; letter-spacing: .08em; }
  .db2-gauge { width: 44px; height: 26px; }
  .db2-chart { height: 230px; }
  .db2-cal-nav { width: 100%; margin-left: 0; }
  .db2-cal-nav span { flex: 1; min-width: 0; }
  .db2-recent-card { padding: 4px; }
  .db2-trade { gap: 10px; padding: 12px 8px; min-height: 60px; }
  .db2-side { width: 48px; padding: 4px 4px; }
}

/* migration flag on the equity card: unverified starting balance */
.db2-unverified { margin-top: 10px; font-size: 12px; line-height: 1.45; color: var(--ds-warn); }
.db2-unverified .ds-link { color: inherit; text-transform: none; letter-spacing: 0; font-family: inherit; font-size: inherit; text-decoration: underline; }

/* Part 3: an account that broke its rules (rule-status.js) — red card, BLOWN with the reason and the date */
.db2-blown-card { border-color: color-mix(in srgb, var(--ds-neg) 55%, transparent) !important; background: linear-gradient(0deg, var(--ds-neg-tint), var(--ds-neg-tint)), var(--ds-surface-solid, transparent); }
.db2-blown { margin-top: 10px; font-size: 12px; line-height: 1.45; color: var(--ds-neg); }
.db2-blown b { font-family: var(--ds-mono); letter-spacing: .1em; margin-right: 4px; }
.db2-blown .ds-link { color: inherit; text-transform: none; letter-spacing: 0; font-family: inherit; font-size: inherit; text-decoration: underline; }

/* Analytics: runs and overrides */
.ob-rules-table { overflow-x: auto; margin-top: 8px; }
.ob-rules-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ob-rules-table th { text-align: left; font-family: var(--ds-mono); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ds-text-2); padding: 6px 8px; border-bottom: 1px solid var(--ds-line); white-space: nowrap; }
.ob-rules-table td { padding: 8px; border-bottom: 1px solid var(--ds-line); white-space: nowrap; }
.ob-rule-dialog .ds-dialog-body { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* High-impact news (Part 5, news-panel.js) */
.ob-news-banner { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 10px 14px; margin-bottom: var(--ds-gap, 12px); border-radius: var(--ds-radius-card); border: 1px solid var(--ds-line); background: var(--ds-surface); font-size: 13px; line-height: 1.45; }
.ob-news-banner b { font-family: var(--ds-mono); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.ob-news-banner span { color: var(--ds-text-2); }
.ob-news-banner.stale { border-color: color-mix(in srgb, var(--ds-neg) 55%, transparent); background: linear-gradient(0deg, var(--ds-neg-tint), var(--ds-neg-tint)), var(--ds-surface-solid); }
.ob-news-banner.stale b { color: var(--ds-neg); }
.ob-news-banner.window { border-color: color-mix(in srgb, var(--ds-warn) 60%, transparent); background: linear-gradient(0deg, var(--ds-warn-tint), var(--ds-warn-tint)), var(--ds-surface-solid); }
.ob-news-banner.window b { color: var(--ds-warn); }
.ob-news-banner.muted { color: var(--ds-text-2); }
.ob-news-list { list-style: none; margin: 8px 0 0; padding: 0; }
.ob-news-row { display: grid; grid-template-columns: auto auto 1fr; grid-template-areas: "time cur title" ". . win"; align-items: baseline; gap: 2px 10px; padding: 9px 0; border-bottom: 1px solid var(--ds-line); font-size: 13px; }
.ob-news-row:last-child { border-bottom: 0; }
.ob-news-row.past { opacity: .55; }
.ob-news-row.live .ob-news-win b { color: var(--ds-warn); }
.ob-news-time { grid-area: time; font-family: var(--ds-mono); font-weight: 600; }
.ob-news-row .ob-news-cur { grid-area: cur; }
.ob-news-title { grid-area: title; min-width: 0; overflow-wrap: anywhere; }
.ob-news-win { grid-area: win; font-size: 12px; }
.ob-news-cur { display: inline-block; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--ds-line-strong); font-family: var(--ds-mono); font-size: 10.5px; font-weight: 600; letter-spacing: .06em; color: var(--ds-text-2); }
.ob-news-none { margin-top: 10px; }
.ob-news-week { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.ob-news-day { min-width: 0; padding: 8px; border-radius: var(--ds-radius-ctl); border: 1px solid var(--ds-line); background: var(--ds-surface-2); font-size: 12px; }
.ob-news-day.today { border-color: var(--ds-line-strong); }
.ob-news-day.danger { border-color: color-mix(in srgb, var(--ds-warn) 50%, transparent); background: var(--ds-warn-tint); }
.ob-news-day-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; margin-bottom: 4px; }
.ob-news-count { margin-left: auto; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--ds-warn); color: var(--ds-surface-solid); font-family: var(--ds-mono); font-size: 11px; font-weight: 700; text-align: center; }
.ob-news-day-list { display: grid; gap: 4px; }
.ob-news-day-list span { overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .ob-news-week { grid-template-columns: 1fr; }
  .ob-news-day { display: grid; grid-template-columns: 110px 1fr; gap: 6px; align-items: baseline; }
  .ob-news-day-head { margin: 0; }
  .ob-news-count { display: none; }
}
/* the warning at the top of the new-trade form: a warning only, never a block */
.ob-news-warn { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; border: 1px solid; font-size: 13px; line-height: 1.45; }
.ob-news-warn b { font-family: var(--ds-mono); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.ob-news-warn.window { border-color: color-mix(in srgb, var(--ds-warn) 60%, transparent); background: var(--ds-warn-tint); }
.ob-news-warn.window b { color: var(--ds-warn); }
.ob-news-warn.stale { border-color: color-mix(in srgb, var(--ds-neg) 55%, transparent); background: var(--ds-neg-tint); }
.ob-news-warn.stale b { color: var(--ds-neg); }

/* Open MT5 positions (Part 7, mt5-live.js) */
#dbPositions:empty, #dbNews:empty { display: none; }
.ob-pos-card { display: grid; gap: 10px; }
.ob-pos-sum { display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: baseline; }
.ob-pos-sum b { font-size: 16px; margin-left: 4px; }
.ob-pos-table { overflow-x: auto; }
.ob-pos-table table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ob-pos-table th { text-align: left; font-family: var(--ds-mono); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ds-text-2); padding: 6px 8px; border-bottom: 1px solid var(--ds-line); white-space: nowrap; }
.ob-pos-table td { padding: 8px; border-bottom: 1px solid var(--ds-line); white-space: nowrap; }
.ob-pos-table tr:last-child td { border-bottom: 0; }
.ob-pos-note { font-size: 12px; }
.ob-pos-stale { padding: 8px 12px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--ds-neg) 55%, transparent); background: var(--ds-neg-tint); font-size: 12.5px; }
.ob-pos-stale b { color: var(--ds-neg); font-family: var(--ds-mono); letter-spacing: .06em; text-transform: uppercase; margin-right: 6px; }
