/* MDB Microcap Terminal — light, navy, instrument-grade.
   Tokens derived from mdb.com brand: navy #004B87, blue #0073AA. */
:root {
  --paper: #f7f9fb;
  --surface: #ffffff;
  --ink: #10202e;
  --muted: #5b6b7e;
  --faint: #8b98a8;
  --line: #e3e9ef;
  --navy: #004b87;
  --blue: #0073aa;
  --blue-soft: #e8f2f8;
  --rise: #0b7a4b;
  --fall: #b3541e;
  --display: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: var(--body); color: var(--ink); background: var(--paper);
  font-size: 13px; -webkit-font-smoothing: antialiased;
}
.num { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
#app { display: grid; grid-template: "top top" 56px "rail main" 1fr / 196px 1fr; height: 100vh; }
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 28px;
  background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 20px;
}
.brand { display: flex; align-items: baseline; gap: 9px; white-space: nowrap; }
.brand .mark {
  font-family: var(--display); font-weight: 700; font-size: 15px; color: #fff;
  background: var(--navy); padding: 3px 7px; border-radius: 3px; letter-spacing: .5px;
}
.brand .name { font-family: var(--display); font-weight: 600; font-size: 14px; letter-spacing: .2px; }
.brand .sub { color: var(--faint); font-size: 11px; letter-spacing: .8px; text-transform: uppercase; }

/* ---------- signature: the cap ruler ---------- */
.ruler { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 14px; }
.ruler-label { font-size: 10.5px; letter-spacing: .8px; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
.ruler-track { position: relative; flex: 1; height: 34px; }
.ruler-ticks { position: absolute; inset: 0 0 14px 0; display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; }
.ruler-ticks i { width: 1px; height: 6px; background: var(--line); }
.ruler-ticks i:nth-child(5n+1) { height: 11px; background: #c9d4de; }
.ruler input[type=range] {
  position: absolute; inset: auto 0 8px 0; width: 100%; appearance: none;
  height: 4px; border-radius: 2px; outline: none;
  background: linear-gradient(to right, var(--navy) var(--fill, 100%), var(--line) var(--fill, 100%));
}
.ruler input[type=range]::-webkit-slider-thumb {
  appearance: none; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--navy);
  box-shadow: 0 1px 4px rgba(16, 32, 46, .25); cursor: grab;
}
.ruler-value {
  font-family: var(--display); font-weight: 700; font-size: 19px; color: var(--navy);
  min-width: 96px; text-align: right; white-space: nowrap;
}
.ruler-value small { display: block; font-family: var(--body); font-weight: 400; font-size: 10px; color: var(--faint); letter-spacing: .6px; text-transform: uppercase; }
.top-meta { margin-left: auto; text-align: right; color: var(--muted); font-size: 11.5px; line-height: 1.5; }

/* index-like holder control */
.idx-ctl { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.idx-ctl label { display: flex; align-items: center; gap: 5px; cursor: pointer; font-weight: 600; }
.idx-ctl input[type=checkbox] { accent-color: var(--navy); }
.idx-thr { color: var(--faint); font-size: 10.5px; }
.idx-thr input[type=number] {
  width: 46px; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 3px; text-align: right;
}
.btn.sm { padding: 4px 10px; font-size: 11px; }

/* position-change chips (13d) */
.chg {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  font-size: 9px; font-weight: 700; letter-spacing: .5px;
}
.chg-new { background: var(--blue-soft); color: var(--navy); }
.chg-added { background: #e6f4ec; color: var(--rise); }
.chg-trimmed { background: #fbeee4; color: var(--fall); }
.chg-exited { background: #eef1f4; color: var(--muted); }

/* watchlist stars */
.star {
  background: none; border: none; cursor: pointer; padding: 0 4px;
  font-size: 15px; line-height: 1; color: var(--faint); vertical-align: -1px;
}
.star:hover { color: var(--blue); }
.star.on { color: #c9a227; }
.wl-count {
  margin-left: auto; background: var(--navy); color: #fff; border-radius: 9px;
  font-size: 10px; font-weight: 700; padding: 1px 7px;
}

.badge-idx {
  display: inline-block; margin-left: 7px; padding: 1px 6px; border-radius: 4px;
  font-size: 9px; font-weight: 700; letter-spacing: .6px; vertical-align: 1px;
  background: #eef1f4; color: var(--muted); border: 1px solid var(--line);
}

/* ---------- rail ---------- */
.rail { grid-area: rail; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 10px; }
.rail a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; margin-bottom: 2px;
  border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: 13px;
}
.rail a svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.rail a:hover { background: var(--paper); color: var(--ink); }
.rail a.active { background: var(--blue-soft); color: var(--navy); font-weight: 600; }
.rail .rail-note { margin-top: 22px; padding: 0 12px; font-size: 10.5px; color: var(--faint); line-height: 1.6; }

/* ---------- main ---------- */
.main { grid-area: main; overflow-y: auto; padding: 22px 26px 40px; }
.view-title { font-family: var(--display); font-weight: 600; font-size: 19px; margin-bottom: 3px; }
.view-sub { color: var(--muted); margin-bottom: 18px; }
.eyebrow { font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--faint); font-weight: 600; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 14px; align-items: center; }
.filters input, .filters select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px;
}
.filters input:focus, .filters select:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: transparent; }
.filters .grow { flex: 1; min-width: 180px; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 7px; padding: 7px 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--blue); border-color: var(--blue); color: #fff; }

/* KPI strip */
.kpis { display: flex; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 11px 16px; min-width: 150px; }
.kpi b { display: block; font-family: var(--display); font-size: 19px; font-weight: 700; color: var(--navy); }
.kpi span { font-size: 10.5px; letter-spacing: .7px; text-transform: uppercase; color: var(--faint); }

/* table */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
/* Cards whose containers have a hard width cap scroll sideways instead of
   clipping columns. (Explorer/Lab keep overflow hidden so sticky headers
   survive; they get scroll only at narrow widths below.) */
.panel .card, .two-col .card, #wlTable { overflow-x: auto; }
.cell-clip { max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
.panel .cell-clip { max-width: 145px; }
.panel td, .panel th { padding-left: 9px; padding-right: 9px; }
.panel .fund-name { max-width: none; white-space: normal; }
.table-note { padding: 8px 14px; font-size: 11px; color: var(--faint); border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 10.5px; letter-spacing: .7px; text-transform: uppercase;
  color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line);
  background: #fcfdfe; white-space: nowrap; cursor: pointer; user-select: none; position: sticky; top: 0;
}
thead th.sorted { color: var(--navy); }
thead th .arr { font-size: 9px; }
tbody td { padding: 8px 12px; border-bottom: 1px solid #eef2f6; white-space: nowrap; }
tbody tr:hover { background: var(--blue-soft); cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }
td.r, th.r { text-align: right; }
.fund-name { font-weight: 600; color: var(--ink); max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--faint); font-size: 11.5px; }
.trend-rising { color: var(--rise); font-weight: 600; }
.trend-falling { color: var(--fall); font-weight: 600; }
.trend-steady, .trend-na { color: var(--faint); }
.pct-bar { display: inline-block; vertical-align: middle; width: 52px; height: 5px; border-radius: 3px; background: var(--line); margin-left: 8px; overflow: hidden; }
.pct-bar i { display: block; height: 100%; background: var(--blue); border-radius: 3px; }
.pager { display: flex; align-items: center; gap: 12px; padding: 10px 14px; color: var(--muted); }
.pager button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 4px 11px; cursor: pointer; color: var(--ink); }
.pager button:disabled { opacity: .35; cursor: default; }

/* slide-over profile */
.overlay { position: fixed; inset: 0; background: rgba(16, 32, 46, .28); opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 40; }
.overlay.open { opacity: 1; pointer-events: auto; }
.panel {
  position: fixed; top: 0; right: -720px; width: 700px; max-width: 92vw; height: 100vh;
  background: var(--surface); box-shadow: -12px 0 40px rgba(16,32,46,.14);
  transition: right .22s ease; z-index: 50; overflow-y: auto; padding: 26px 28px;
}
.panel.open { right: 0; }
.panel h2 { font-family: var(--display); font-size: 20px; font-weight: 700; margin: 2px 0 2px; padding-right: 36px; overflow-wrap: break-word; }
.panel .close { position: absolute; top: 18px; right: 20px; border: none; background: none; font-size: 20px; color: var(--faint); cursor: pointer; }
.contact { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0 6px; }
.contact div { background: var(--paper); border-radius: 8px; padding: 9px 12px; }
.contact b { display: block; font-size: 12.5px; font-weight: 600; }
.contact span { font-size: 10px; text-transform: uppercase; letter-spacing: .7px; color: var(--faint); }
.chart { width: 100%; height: 230px; margin: 10px 0; }
.chart-sm { width: 100%; height: 170px; margin: 6px 0; }
.section-h { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 0 8px; }

/* lookup */
.search-hero { max-width: 620px; margin: 0 auto 20px; text-align: center; }
.search-hero input {
  width: 100%; font: inherit; font-size: 15px; padding: 13px 18px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
}
.search-hero input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.hits { text-align: left; margin-top: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.hit { padding: 10px 14px; display: flex; gap: 12px; align-items: baseline; cursor: pointer; border-bottom: 1px solid #eef2f6; }
.hit:hover { background: var(--blue-soft); }
.hit .tk { font-family: var(--mono); font-weight: 700; color: var(--navy); min-width: 56px; }
.tag { font-size: 10px; letter-spacing: .5px; text-transform: uppercase; background: var(--paper); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; color: var(--muted); }

/* sectors */
.sector-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.sector-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; cursor: pointer; }
.sector-card:hover { border-color: var(--blue); }
.sector-card.active { border-color: var(--navy); background: var(--blue-soft); }
.sector-card b { font-family: var(--display); font-size: 14.5px; font-weight: 600; display: block; margin-bottom: 6px; }
.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

/* lab */
.lab-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .lab-grid { grid-template-columns: 1fr; } }
.lab-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }

/* ---------- narrow screens ---------- */
@media (max-width: 1240px) {
  .top-meta { display: none; }
  /* Wide tables scroll sideways here; the sticky-header nicety loses to cut-off columns. */
  #tableWrap, #labTable { overflow-x: auto; }
}
@media (max-width: 960px) {
  #app { grid-template: "top top" 56px "rail main" 1fr / 54px 1fr; }
  .rail { padding: 14px 5px; }
  .rail a { justify-content: center; padding: 10px 0; position: relative; }
  .rail a .rail-label, .rail-note, .brand .name, .brand .sub, .ruler-label { display: none; }
  .wl-count { position: absolute; top: 2px; right: 2px; margin-left: 0; }
  .idx-thr { display: none; }
  .main { padding: 16px 14px 32px; }
  .topbar { gap: 16px; }
}
@media (max-width: 720px) {
  .idx-ctl { display: none; }
  .ruler-value { min-width: 72px; font-size: 16px; }
}

.loading { opacity: .45; pointer-events: none; transition: opacity .15s; }
.empty { padding: 40px; text-align: center; color: var(--faint); }
a { color: var(--blue); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
