/* ============================================================================
   FDN Journal: design system
   Dark, data-dense trading dashboard. Self-contained (no external fonts/CDN).
   ========================================================================== */
:root {
  --bg:        #0a0e17;
  --bg-2:      #0d1220;
  --surface:   #121826;
  --surface-2: #171f30;
  --surface-3: #1e2740;
  --border:    #232c40;
  --border-2:  #2e3a54;
  --text:      #e7ecf5;
  --text-2:    #9aa5bd;
  --text-3:    #6b7590;
  --pos:       #16c784;
  --pos-dim:   #0e5c40;
  --neg:       #f6465d;
  --neg-dim:   #6e1f2c;
  --accent:    #4c82fb;
  --accent-2:  #7aa2ff;
  --gold:      #f0b90b;
  --violet:    #a78bfa;
  --cyan:      #22d3ee;

  --r-sm: 6px;  --r: 10px;  --r-lg: 14px;  --r-xl: 20px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.5);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  --nav-w: 216px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: radial-gradient(1200px 800px at 80% -10%, #101a30 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ------------------------------------------------------------- passcode gate */
.gate {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(900px 600px at 50% 0%, #12203c, var(--bg));
  padding: var(--sp-4);
}
.gate-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-6);
  box-shadow: var(--shadow-lg); text-align: center;
}
.gate-logo {
  width: 52px; height: 52px; margin: 0 auto var(--sp-4);
  border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  box-shadow: 0 6px 20px rgba(76,130,251,.4);
}
.gate h1 { font-size: 20px; margin-bottom: var(--sp-2); }
.gate p { color: var(--text-2); font-size: 13px; margin: 0 0 var(--sp-5); }
.gate input {
  width: 100%; height: 46px; padding: 0 var(--sp-4);
  background: var(--bg-2); border: 1px solid var(--border-2);
  border-radius: var(--r); color: var(--text); font-size: 15px;
  font-family: var(--mono); letter-spacing: .04em; text-align: center;
}
.gate input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,130,251,.25); }
.gate-err { color: var(--neg); font-size: 12.5px; min-height: 18px; margin-top: var(--sp-3); }
.gate .btn { width: 100%; margin-top: var(--sp-4); height: 46px; justify-content: center; }

/* --------------------------------------------------------------------- shell */
.app { display: none; min-height: 100dvh; }
.app.ready { display: block; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--nav-w);
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border); padding: var(--sp-4) var(--sp-3);
  display: flex; flex-direction: column; gap: var(--sp-1); z-index: 40;
}
.brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-2) var(--sp-5); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  display: grid; place-items: center; box-shadow: 0 4px 14px rgba(76,130,251,.35);
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.02em; }
.brand-sub { font-size: 10.5px; color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; }

.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 10px var(--sp-3); border-radius: var(--r); color: var(--text-2);
  cursor: pointer; font-size: 13.5px; font-weight: 550; min-height: 44px;
  border: 1px solid transparent; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.nav-item.active svg { color: var(--accent-2); }
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-spacer { flex: 1; }
.nav-foot { padding: var(--sp-3) var(--sp-3) var(--sp-2); font-size: 10.5px; color: var(--text-3); line-height: 1.5; }

.main { margin-left: var(--nav-w); padding: var(--sp-5) var(--sp-6) 96px; max-width: 1520px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  margin-bottom: var(--sp-5); flex-wrap: wrap;
}
.topbar h2 { font-size: 22px; }
.topbar .sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.scope { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* --------------------------------------------------------------- primitives */
.card {
  background: linear-gradient(180deg, var(--surface), var(--surface) 60%, #10182a);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.card-pad { padding: var(--sp-5); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card-title { font-size: 13px; font-weight: 650; color: var(--text); letter-spacing: .01em; }
.card-title .hint { color: var(--text-3); font-weight: 400; font-size: 11.5px; margin-left: 6px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 999px;
  color: var(--text-2); font-size: 12.5px; cursor: pointer; font-weight: 550;
  transition: .15s; white-space: nowrap;
}
.pill:hover { color: var(--text); border-color: var(--accent); }
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.active.pos { background: var(--pos); border-color: var(--pos); }
select.pill, input.pill { height: 34px; -webkit-appearance: none; appearance: none; padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa5bd' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; cursor: pointer; }
select.pill:focus, input.pill:focus { outline: none; border-color: var(--accent); color: var(--text); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: var(--r); border: 1px solid var(--border-2); background: var(--surface-2);
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: linear-gradient(135deg, var(--accent), #3b6ff0); border-color: transparent; color: #fff; }
.btn svg { width: 16px; height: 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 650; letter-spacing: .02em; border: 1px solid transparent; white-space: nowrap;
}
.badge.pass  { background: rgba(22,199,132,.14); color: var(--pos); border-color: rgba(22,199,132,.3); }
.badge.fail  { background: rgba(246,70,93,.13); color: var(--neg); border-color: rgba(246,70,93,.3); }
.badge.live  { background: rgba(76,130,251,.15); color: var(--accent-2); border-color: rgba(76,130,251,.3); }
.badge.idle  { background: var(--surface-3); color: var(--text-2); border-color: var(--border-2); }
.badge.gold  { background: rgba(240,185,11,.14); color: var(--gold); border-color: rgba(240,185,11,.3); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------------------------------------------------------------- KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); margin-bottom: var(--sp-4); }
.kpi {
  background: linear-gradient(180deg, var(--surface), #0f1728);
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-4) var(--sp-5);
  position: relative; overflow: hidden; min-height: 104px;
}
.kpi::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: .8; }
.kpi.k-pos::after { background: var(--pos); }
.kpi.k-neg::after { background: var(--neg); }
.kpi.k-gold::after { background: var(--gold); }
.kpi-label { font-size: 11.5px; color: var(--text-2); font-weight: 550; display: flex; align-items: center; gap: 6px; }
.kpi-val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 27px; font-weight: 680; margin-top: 8px; letter-spacing: -.02em; line-height: 1.1; }
.kpi-sub { font-size: 11.5px; color: var(--text-3); margin-top: 6px; }
.kpi-spark { position: absolute; right: 12px; bottom: 10px; opacity: .9; }

/* ------------------------------------------------------------------- layout */
.grid { display: grid; gap: var(--sp-4); }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.row { display: flex; gap: var(--sp-3); align-items: center; }
.wrap { flex-wrap: wrap; }
.mb-4 { margin-bottom: var(--sp-4); }

/* -------------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r); }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 520px; }
table.data th {
  text-align: left; font-weight: 600; color: var(--text-3); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .06em; padding: 8px 12px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); cursor: pointer; white-space: nowrap;
}
table.data th.sortable:hover { color: var(--text); }
table.data th .arr { opacity: .5; font-size: 9px; }
table.data td { padding: 9px 12px; border-bottom: 1px solid rgba(35,44,64,.6); white-space: nowrap; }
table.data tbody tr { transition: background .12s; cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.mini-bar { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; min-width: 44px; }
.mini-bar > span { display: block; height: 100%; border-radius: 3px; }

/* -------------------------------------------------------------------- insights */
.insight {
  display: flex; gap: var(--sp-3); padding: var(--sp-4); border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--border); align-items: flex-start;
}
.insight-ic { width: 34px; height: 34px; border-radius: 9px; flex: none; display: grid; place-items: center; }
.insight.warn .insight-ic { background: rgba(246,70,93,.13); color: var(--neg); }
.insight.good .insight-ic { background: rgba(22,199,132,.14); color: var(--pos); }
.insight.tip  .insight-ic { background: rgba(240,185,11,.14); color: var(--gold); }
.insight h4 { font-size: 13px; margin-bottom: 3px; }
.insight p { margin: 0; font-size: 12px; color: var(--text-2); line-height: 1.5; }
.insight b { color: var(--text); font-family: var(--mono); }

/* -------------------------------------------------------------------- charts */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.eq-slot { flex: 1; min-height: 220px; display: flex; }
.chart.fill { width: 100%; height: 100%; display: flex; }
.chart.fill svg { height: 100%; width: 100%; }
.axis text { fill: var(--text-3); font-size: 10px; font-family: var(--mono); }
.grid-line { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.tt {
  position: fixed; z-index: 200; pointer-events: none; background: #0b1020; color: var(--text);
  border: 1px solid var(--border-2); border-radius: 8px; padding: 8px 10px; font-size: 11.5px;
  box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .1s; max-width: 240px;
}
.tt .k { color: var(--text-3); }
.tt .mono { font-size: 12px; }

/* calendar heatmap */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell { aspect-ratio: 1; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; padding: 4px 5px; cursor: default; position: relative; }
.cal-cell .d { font-size: 9.5px; color: var(--text-3); font-family: var(--mono); }
.cal-cell .p { font-size: 9px; font-family: var(--mono); font-weight: 600; }
.cal-dow { font-size: 9.5px; color: var(--text-3); text-align: center; text-transform: uppercase; letter-spacing: .05em; padding-bottom: 2px; }

/* segmented distribution bar */
.seg { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-3); }
.seg > span { display: block; height: 100%; }

/* -------------------------------------------------------------------- journal */
.journal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-4); }
.trade-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; }
.trade-shot { aspect-ratio: 16/9; background: var(--bg-2); position: relative; display: grid; place-items: center; cursor: pointer; overflow: hidden; border-bottom: 1px solid var(--border); }
.trade-shot img { width: 100%; height: 100%; object-fit: cover; }
.trade-shot .ph { color: var(--text-3); font-size: 11.5px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px; }
.trade-shot .ph svg { width: 26px; height: 26px; opacity: .7; }
.trade-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: 10px; flex: 1; }
.trade-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.trade-sym { font-weight: 680; font-size: 14px; }
.trade-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11px; color: var(--text-2); }
.trade-meta span b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.trade-note { width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--text); font-size: 12px; padding: 8px 10px; resize: vertical; min-height: 40px; font-family: var(--sans); }
.trade-note:focus { outline: none; border-color: var(--accent); }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 10.5px; padding: 3px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border-2); cursor: pointer; }
.tag.on { background: rgba(76,130,251,.16); color: var(--accent-2); border-color: rgba(76,130,251,.4); }

/* -------------------------------------------------------------------- modal */
.modal-scrim { position: fixed; inset: 0; background: rgba(4,7,14,.72); backdrop-filter: blur(3px); z-index: 300; display: none; align-items: flex-start; justify-content: center; padding: var(--sp-5); overflow-y: auto; }
.modal-scrim.open { display: flex; }
.modal { width: 100%; max-width: 940px; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); margin: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; border-radius: var(--r-lg) var(--r-lg) 0 0; }
.modal-body { padding: var(--sp-5); }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text-2); display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

/* -------------------------------------------------------------------- rules */
.rule-topic { border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); margin-bottom: var(--sp-3); overflow: hidden; }
.rule-head { display: flex; align-items: center; justify-content: space-between; padding: 14px var(--sp-4); cursor: pointer; gap: var(--sp-3); min-height: 44px; }
.rule-head:hover { background: var(--surface-2); }
.rule-head h4 { font-size: 13.5px; }
.rule-body { padding: 0 var(--sp-4) var(--sp-4); display: none; }
.rule-topic.open .rule-body { display: block; }
.rule-chunk { border-top: 1px solid var(--border); padding: var(--sp-3) 0; font-size: 12.5px; color: var(--text-2); line-height: 1.6; }
.rule-chunk .t { color: var(--text); font-weight: 600; font-size: 12.5px; margin-bottom: 3px; }
.chev { transition: transform .2s; color: var(--text-3); }
.rule-topic.open .chev { transform: rotate(90deg); }

.empty { text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--text-3); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: var(--sp-3); }

/* ---------------------------------------------------------------- bottom nav */
.botnav { display: none; }

/* ============================================================== RESPONSIVE == */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 1000px) {
  .g-2-1, .g-1-2, .g-2 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .g-3 { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { margin-left: 0; padding: var(--sp-4) var(--sp-4) 88px; }
  .botnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    background: rgba(13,18,32,.96); backdrop-filter: blur(12px); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around;
  }
  .botnav .nav-item {
    flex-direction: column; gap: 3px; font-size: 10px; padding: 6px 4px; min-width: 56px; min-height: 48px;
    border: none; justify-content: center; text-align: center;
  }
  .botnav .nav-item svg { width: 20px; height: 20px; }
  .botnav .nav-item.active { background: transparent; color: var(--accent-2); }
}
@media (max-width: 760px) {
  .main { padding: var(--sp-3) var(--sp-3) 88px; }
  .topbar h2 { font-size: 19px; }
  .kpi-val { font-size: 23px; }
  .card-pad { padding: var(--sp-4); }
  .journal-grid { grid-template-columns: 1fr; }
  .cal-cell .p { font-size: 8.5px; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
  .kpi { padding: var(--sp-3) var(--sp-4); min-height: 92px; }
  .kpi-val { font-size: 21px; }
  /* hide low-priority table columns on phones */
  .hide-sm { display: none !important; }
  table.data th, table.data td { padding: 8px 9px; }
  .modal-scrim { padding: 0; }
  .modal { border-radius: 0; min-height: 100dvh; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
