:root {
  color-scheme: light dark;
  --bg: #f6f6f3; --surface: #ffffff; --fg: #1c1c1a; --muted: #6b6b66; --line: #e2e2dc;
  --accent: #2557a7; --up: #1d7a46; --down: #b3261e; --star: #b07a00; --warn-bg: #fff4d6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413; --surface: #1d1d1b; --fg: #ececea; --muted: #9a9a94; --line: #33332f;
    --accent: #7aa7ff; --up: #4cc38a; --down: #ff7a70; --star: #f2c14e; --warn-bg: #3a3220;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, -apple-system, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.bar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; padding: 12px 16px;
       border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { font-weight: 700; color: var(--fg); }
nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
main { max-width: 1500px; margin: 0 auto; padding: 20px 16px 40px; }
footer { max-width: 1500px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: 13px;
         border-top: 1px solid var(--line); }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.narrow { max-width: 420px; margin: 40px auto; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--down); }
.ok { color: var(--up); }
label { display: block; margin: 8px 0; }
input, select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
                background: var(--bg); color: var(--fg); max-width: 100%; }
button { font: inherit; padding: 6px 14px; border: 1px solid var(--accent); border-radius: 6px;
         background: var(--accent); color: #fff; cursor: pointer; }
button.link { background: none; color: var(--accent); border: none; padding: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bull { color: var(--up); }
.bear { color: var(--down); }
.star { color: var(--star); }
.star-form { display: inline; }
button.star { background: none; border: none; padding: 0 4px; font-size: 1.1em; cursor: pointer; color: var(--muted); }
button.star.on, button.star:hover { color: var(--star); }
.grade { font-weight: 700; white-space: nowrap; }
.chips span { display: inline-block; padding: 1px 7px; margin: 1px 2px 1px 0; border: 1px solid var(--line);
              border-radius: 10px; font-size: 12px; white-space: nowrap; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; margin-bottom: 12px; }
.filters label { margin: 0; }
.note { background: var(--warn-bg); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.light { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.light-green { background: #2e9d5b; }
.light-amber { background: #e0a200; }
.light-red { background: #d1453b; }
.light-grey { background: #9a9a94; }

/* Funnel main page */
.tabs { margin: 0 0 10px; }
.tabs a { display: inline-block; margin-right: 12px; padding: 4px 10px; border-bottom: 2px solid transparent; }
.tabs a.on { border-color: currentColor; font-weight: 600; }
.chips a.on { font-weight: 600; text-decoration: underline; }
.tag { font-size: .75em; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
tr.good td:first-child { box-shadow: inset 3px 0 0 #2e9d5b; }
details summary { cursor: pointer; white-space: nowrap; }
details[open] { min-width: 14em; }

/* Charts */
.chart { width: 100%; height: 60vh; min-height: 320px; }
.chart-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.chart-bar .layers label { display: inline-flex; align-items: center; gap: 3px; margin: 0 10px 0 0; white-space: nowrap; font-size: .9em; }
.chart-bar .layers input { margin: 0; width: auto; }
.chart-bar button.tf.on, #ranges button.on { font-weight: 700; text-decoration: underline; }
.chart-bar button.draw-tool.on { font-weight: 700; outline: 2px solid #2962ff; }
.chart.draw-hover, .chart.draw-hover * { cursor: move !important; }  /* over a drawing of the viewer's: it can be dragged */
/* drawing hints float over the top of the chart, so showing one never moves the chart down */
.chart-wrap { position: relative; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0 .9em; margin: .2em 0; min-height: 1.4em; font-variant-numeric: tabular-nums; }
/* the currency on top of the price axis, as TradingView shows it */
.chart-unit { position: absolute; top: 2px; right: 4px; z-index: 3; pointer-events: none; font-size: 36px; line-height: 1.1; font-weight: 600;
  color: var(--muted); background: var(--surface); padding: 0 4px; border-radius: 3px; }
.draw-note { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); z-index: 5; max-width: 90%;
             padding: 2px 8px; border-radius: 4px; background: rgba(41,98,255,.9); color: #fff; pointer-events: none; }
.draw-note:empty { display: none; }
.chart-bar #live-btn.on { background: var(--up); color: #fff; border-color: var(--up); }
#search { flex: 1 1 260px; padding: 6px; }
.results { list-style: none; padding: 0; margin: 0 0 6px; }
#items span { border-left: 4px solid; padding-left: 6px; }

.chart-sub { width: 100%; height: 180px; }
#sentiment { position: relative; }
.fg-tip { position: absolute; z-index: 3; pointer-events: none; padding: 0 4px; border-radius: 3px; font-weight: 600; white-space: nowrap;
          background: var(--surface); opacity: .92; }
.chart-osc { height: 140px; margin-top: 4px; }
#osc-main { height: 200px; }
#sentiment-note { margin: 4px 0 0; }

/* Macro monthly tables: row names stay visible while scrolling sideways */
.macro-history th:first-child, .macro-history td:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--line);
}
.split { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.split > * { min-width: 0; }  /* wide tables scroll inside the card instead of widening the page */
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }
ul.plain { list-style: none; padding: 0; margin: 0 0 10px; }
ul.plain li { padding: 4px 0; border-bottom: 1px solid var(--line); }
ul.plain li.on a { font-weight: 700; }
tr.past td { color: var(--muted); }
.chart-bar .layer-group { border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px 6px; margin: 0; }
.chart-bar .layer-group legend { font-size: .85em; font-weight: 600; padding: 0 4px; }
tr.group th { text-align: left; padding-top: 10px; border-bottom: 1px solid var(--line, #ccc); }
.subtabs { font-size: 0.92em; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.subtabs a { margin-right: 6px; }
.fav-add .filters { align-items: center; }
.fav-add input[type=search] { flex: 1 1 220px; max-width: 420px; }
.fav-found { list-style: none; padding: 0; margin: 0 0 12px; }
.fav-found li { padding: 4px 0; border-bottom: 1px solid var(--line); }
form.inline { display: inline; margin-left: 8px; }
button.star.pin { opacity: 0.3; filter: grayscale(1); font-size: 0.9em; padding: 0 2px; }
button.star.pin.on, button.star.pin:hover { opacity: 1; filter: none; }

td.rsi { white-space: nowrap; }
/* funnel and favourites: one line per row; the sector and industry side by side, cut short with "…" */
table.one-line td { white-space: nowrap; }
table.one-line td details > div { white-space: normal; min-width: 16em; }
table.one-line td.sector { max-width: 16em; overflow: hidden; text-overflow: ellipsis; }
table.one-line td.sector br { display: none; }
table.one-line td.sector .muted::before { content: " · "; }
td.rsi .tag { margin-left: 4px; }
/* Portfolios → My portfolio */
.pf-donut { width: 160px; height: 160px; display: block; margin: 0 auto 8px; }
.pf-legend li { display: inline-block; margin: 0 10px 4px 0; }
.pf-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.pf-bar { display: grid; grid-template-columns: 7em 1fr auto; gap: 8px; align-items: center; margin: 4px 0; }
.pf-bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-bar-track { position: relative; height: 12px; background: var(--surface); border-left: 0; }
.pf-bar-track::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; border-left: 1px solid var(--muted); }
.pf-bar-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.pf-bar-fill.bull { background: #26a69a; } .pf-bar-fill.bear { background: #ef5350; }
.pf-bar-val { white-space: nowrap; }
.pf-history { width: 100%; height: 220px; }
.pf-fill input[size] { width: auto; }
/* the Draw bar: tools grouped in dropdown menus */
.draw-box { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.draw-menu { position: relative; }
.draw-menu > summary { list-style: none; cursor: pointer; padding: 6px 12px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--accent); color: #fff; white-space: nowrap; user-select: none; }
.draw-menu > summary::-webkit-details-marker { display: none; }
.draw-menu > summary::after { content: " ▾"; }
.draw-menu > summary.on { font-weight: 700; outline: 2px solid #2962ff; }
.draw-menu[open] > summary { filter: brightness(.85); }
.draw-items { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; min-width: 190px; display: flex; flex-direction: column;
  gap: 4px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.draw-items button { text-align: left; white-space: nowrap; }
.order-dialog { background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; max-width: min(92vw, 380px); }
.order-dialog::backdrop { background: rgba(0, 0, 0, .35); }
.order-dialog h3 { margin: 0 0 8px; }
.order-dialog label { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 6px 0; }
.order-dialog select { max-width: 230px; }
.order-dialog .od-buttons { display: flex; gap: 8px; margin: 10px 0 0; }
.chart-bar .draw-items label { margin: 2px 4px; }

/* a spinning wheel before a "loading" note */
.spinner { display: inline-block; width: 1em; height: 1em; margin-right: 6px; vertical-align: -0.15em;
  border: 2px solid var(--line); border-top-color: currentColor; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* trades in any currency: the rate boxes hide for the chart's own currency */
.order-dialog label[hidden], .trade-form label[hidden] { display: none; }
.trade-add { margin-top: 8px; }
.trade-form label { display: inline-flex; align-items: center; gap: 4px; }
