:root {
  --bg: #ffffff;
  --panel: #f7f9fb;
  --border: #dde3ea;
  --text: #1c2430;
  --muted: #6b7480;
  --accent: #0a8f3c;
  --up: #1763b8;
  --down: #e2418f;
  --red: #e03131;
  --link: #1c66c2;
}

/* Dynamic type scale: everything is in rem, so the whole UI grows with the
   window. ~13px at 1100px wide → ~17px at 2400px wide. */
html { font-size: clamp(12.5px, 0.45vw + 8.4px, 18px); }

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 1rem; color: var(--text); background: var(--bg);
  overflow: hidden;
}
body { display: flex; flex-direction: column; }

/* ---------- top toolbar ---------- */
#topbar {
  display: flex; align-items: center; gap: 0.8rem;
  height: 3.1rem; padding: 0 1rem; flex: none;
  border-bottom: 1px solid var(--border); background: #fff;
}
.logo { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.3px; white-space: nowrap; }
.logo span { color: var(--accent); }
.spacer { flex: 1; }

#searchBox { position: relative; }
#searchInput {
  width: 15rem; padding: 0.42rem 0.7rem;
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 1rem; outline: none; background: var(--panel);
}
#searchInput:focus { border-color: var(--accent); background: #fff; }
#searchResults {
  position: absolute; top: 2.4rem; left: 0; width: 24rem; z-index: 50;
  background: #fff; border: 1px solid var(--border); border-radius: 4px;
  box-shadow: 0 6px 20px rgba(20,30,40,.12); max-height: 22rem; overflow-y: auto;
}
#searchResults .row {
  display: flex; gap: 0.7rem; padding: 0.5rem 0.7rem; cursor: pointer; align-items: baseline;
}
#searchResults .row:hover, #searchResults .row.sel { background: #eef4fb; }
#searchResults .sym { font-weight: 700; min-width: 4rem; }
#searchResults .name { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#searchResults .exch { color: #98a1ad; font-size: 0.85rem; }

.btn-group { display: flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; flex: none; }
.btn-group button {
  border: none; background: #fff; padding: 0.42rem 0.85rem; cursor: pointer;
  font-size: 0.95rem; color: var(--text); border-right: 1px solid var(--border);
  font-family: inherit;
}
.btn-group button:last-child { border-right: none; }
.btn-group button:hover { background: #f0f3f7; }
.btn-group button.active { background: var(--accent); color: #fff; }

#intradayGroup select, #dayNav input[type="date"] {
  border: none; background: #fff; padding: 0.4rem 0.55rem; font-size: 0.95rem;
  color: var(--text); cursor: pointer; outline: none; font-family: inherit;
}
#intradayGroup.active select { background: var(--accent); color: #fff; }
#dayNav button { padding: 0.42rem 0.6rem; font-size: 1.05rem; line-height: 1; }
#dayNav input[type="date"] { width: 9.2rem; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }

#utilButtons button { font-size: 1.1rem; padding: 0.35rem 0.7rem; }

#liveStatus { display: flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
#liveStatus .dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: #b9c1cc; }
#liveStatus.on .dot { background: var(--accent); box-shadow: 0 0 5px rgba(10,143,60,.7); }

/* ---------- fat company bar (MS-style) ---------- */
#companyBar {
  display: flex; align-items: center; gap: 1.4rem; flex: none;
  padding: 0.55rem 1.1rem; min-height: 4.6rem;
  border-bottom: 1px solid var(--border); background: #fff;
}
.cb-left { flex: none; max-width: 30rem; }
.cb-title { display: flex; align-items: baseline; gap: 0.6rem; }
#qhSymbol { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.5px; }
#qhName { font-size: 1.15rem; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16rem; }
.cb-sub { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.25rem; }
#qhIndustry { color: var(--link); font-size: 0.9rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 24rem; }
.cb-sub button {
  border: 1px solid var(--border); background: #fff; border-radius: 4px;
  padding: 0.25rem 0.6rem; font-size: 0.85rem; cursor: pointer; white-space: nowrap;
  font-family: inherit; color: var(--text);
}
.cb-sub button:hover { background: #f0f3f7; }
#listAddWrap { position: relative; }

.cb-blurb {
  flex: 1 1 auto; min-width: 8rem; color: var(--muted); font-size: 0.88rem;
  line-height: 1.25; max-height: 3.4rem; overflow: hidden;
}
#qhWebsite { color: var(--link); margin-left: 0.4rem; }

.cb-stats {
  flex: none; display: grid; grid-auto-flow: column;
  grid-template-rows: 1fr 1fr 1fr; gap: 0.12rem 1.6rem;
  font-size: 0.92rem; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.cb-stats .pair { display: flex; justify-content: space-between; gap: 0.8rem; }
.cb-stats .k { color: var(--muted); }
.cb-stats .v { font-weight: 700; }

.cb-price { flex: none; text-align: right; min-width: 11rem; }
#qhPrice { font-size: 1.85rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
#qhChange { font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums; }
#qhVolume { color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }

.pos { color: var(--accent); }
.neg { color: var(--red); }

/* ---------- popovers ---------- */
.pop {
  position: absolute; z-index: 60; background: #fff; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 26px rgba(20,30,40,.18); padding: 0.7rem;
  font-size: 0.92rem; min-width: 16rem;
}
.pop-title { font-weight: 700; margin-bottom: 0.5rem; }
.pop-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.pop-row input {
  flex: 1; border: 1px solid var(--border); border-radius: 4px; padding: 0.3rem 0.5rem;
  font-size: 0.92rem; font-family: inherit; outline: none;
}
.pop-row input:focus { border-color: var(--accent); }
.pop-row button, .pop .item button {
  border: 1px solid var(--border); background: var(--accent); color: #fff;
  border-radius: 4px; padding: 0.3rem 0.8rem; cursor: pointer; font-family: inherit;
}
.pop .item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.3rem 0.2rem; border-bottom: 1px solid #f0f3f6;
}
.pop .item button { background: #fff; color: var(--red); border: none; padding: 0 0.4rem; }
.pop-note { color: var(--muted); font-size: 0.8rem; margin-top: 0.4rem; }
#listAddPop { top: 2rem; left: 0; }
#listAddPop .choice { padding: 0.4rem 0.6rem; cursor: pointer; border-radius: 4px; }
#listAddPop .choice:hover { background: #eef4fb; }
#listAddPop .choice.inlist { color: var(--accent); font-weight: 600; }
#alertPop { top: 7.2rem; left: 14rem; }

/* ---------- layout ---------- */
main { display: flex; flex: 1; min-height: 0; }

aside {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
#watchlistPanel { width: 13.5rem; flex: none; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.4rem;
  padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border);
}
#listSelect {
  flex: 1; border: 1px solid var(--border); border-radius: 4px; background: #fff;
  font-size: 0.92rem; font-weight: 700; padding: 0.25rem 0.3rem; font-family: inherit;
  text-transform: uppercase; letter-spacing: .3px; color: var(--muted); outline: none;
}
.panel-head-btns { display: flex; gap: 0.3rem; }
.panel-head button {
  border: 1px solid var(--border); background: #fff; border-radius: 4px;
  width: 1.7rem; height: 1.7rem; cursor: pointer; font-size: 0.95rem; line-height: 1;
  color: var(--accent); font-family: inherit;
}
.panel-head button:hover { background: #eef4ee; }
.panel-foot { border-top: 1px solid var(--border); padding: 0.4rem; }
.panel-foot button {
  width: 100%; border: 1px dashed var(--border); background: #fff; border-radius: 4px;
  padding: 0.35rem; cursor: pointer; color: var(--accent); font-size: 0.88rem; font-family: inherit;
}
.panel-foot button:hover { background: #eef4ee; }

/* ---------- watchlist ---------- */
#watchlist { overflow-y: auto; flex: 1; }
.wl-row {
  display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.6rem;
  padding: 0.5rem 0.7rem; cursor: pointer; border-bottom: 1px solid #edf0f4; position: relative;
  font-size: 0.95rem;
}
.wl-row:hover { background: #eef2f7; }
.wl-row.active { background: #e3eefb; border-left: 3px solid var(--up); padding-left: calc(0.7rem - 3px); }
.wl-row .sym { font-weight: 700; }
.wl-row .px { text-align: right; font-variant-numeric: tabular-nums; }
.wl-row .chg { grid-column: 2; text-align: right; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.wl-row .rm {
  position: absolute; right: 0.25rem; top: 0.25rem; display: none;
  border: none; background: none; color: #aab; cursor: pointer; font-size: 0.9rem; padding: 0 0.2rem;
}
.wl-row:hover .rm { display: block; }
.wl-row .rm:hover { color: var(--red); }

/* ---------- chart ---------- */
#chartSection { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#chartWrap { position: relative; flex: 1; min-height: 0; background: #fff; }
#chartWrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#overlay { cursor: crosshair; }
#chartMsg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; color: var(--muted); background: rgba(255,255,255,.85); z-index: 5;
}
#toast {
  position: absolute; top: 0.8rem; right: 0.8rem; z-index: 70;
  background: #1c2430; color: #fff; border-radius: 6px; padding: 0.6rem 1rem;
  font-size: 0.95rem; box-shadow: 0 8px 26px rgba(20,30,40,.3); max-width: 22rem;
}

#replayBanner {
  padding: 0.3rem 1rem; background: #fff7e0; border-bottom: 1px solid #eadfb8;
  color: #7a5c00; font-size: 0.9rem; flex: none;
}
#replayBanner button {
  margin-left: 0.7rem; border: 1px solid #d8c787; background: #fff; border-radius: 3px;
  cursor: pointer; font-size: 0.82rem; padding: 0.05rem 0.5rem; font-family: inherit;
}

.hint {
  padding: 0.28rem 1rem; color: #9aa3ae; font-size: 0.8rem; flex: none;
  border-top: 1px solid var(--border); background: var(--panel); white-space: nowrap; overflow: hidden;
}

/* ---------- floating stats panel (landscape) ---------- */
#floatPanel {
  position: absolute; top: 0.7rem; left: 0.7rem; z-index: 10;
  display: flex; align-items: flex-start;
  max-width: calc(100% - 8rem);
}
#fpBody {
  display: flex; gap: 1rem; align-items: flex-start;
  overflow: auto; max-height: 23rem;
  background: rgba(255,255,255,0.96); border: 1px solid var(--border);
  border-radius: 5px; box-shadow: 0 4px 18px rgba(20,30,40,.13);
  padding: 0.6rem 0.8rem;
}
#fpToggle {
  order: 2; margin-left: -1px; margin-top: 1rem; flex: none;
  width: 1.3rem; height: 3.2rem; border: 1px solid var(--border); border-left: none;
  border-radius: 0 5px 5px 0; background: var(--accent); color: #fff;
  cursor: pointer; font-size: 1rem; line-height: 1; padding: 0;
}
#fpToggle:hover { filter: brightness(1.1); }
#floatPanel.collapsed #fpBody { display: none; }
#floatPanel.collapsed #fpToggle { border-left: 1px solid var(--border); border-radius: 5px; }

table.annual {
  border-collapse: collapse; font-size: 0.88rem;
  font-variant-numeric: tabular-nums; flex: none;
}
table.annual th {
  text-align: right; color: var(--text); font-weight: 700; font-size: 0.84rem;
  padding: 0.1rem 0.4rem 0.25rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.annual th:first-child { text-align: left; }
table.annual td { text-align: right; padding: 0.16rem 0.4rem; white-space: nowrap; }
table.annual td:first-child { text-align: left; font-weight: 600; }
table.annual tr:nth-child(even) td { background: #f3f6f9; }
table.annual .est td { color: #1a2028; } /* MS: estimates upright, marked by " e" + arrow only */
.tr-up { color: #007942; }
.tr-down { color: var(--red); }

.fp-stats {
  padding-left: 1.2rem; flex: none;
  display: grid; grid-template-rows: repeat(9, auto); grid-auto-flow: column;
  gap: 0.12rem 1.4rem; align-content: start;
}
.fp-stats .stat-row {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: 0.88rem; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.stat-row .k { color: var(--muted); }
.stat-row .v { font-weight: 700; }
.rs-badge {
  display: inline-block; background: var(--up); color: #fff; border-radius: 3px;
  padding: 0 0.4rem; font-weight: 800;
}

/* ---------- floating tools bar ---------- */
#toolsBar {
  position: absolute; top: 0.7rem; right: 4.2rem; z-index: 12;
  display: flex; align-items: center;
  background: rgba(255,255,255,0.97); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 4px 14px rgba(20,30,40,.12);
}
#toolsBar button.tool {
  border: none; background: none; cursor: pointer; font-size: 1.05rem;
  padding: 0.4rem 0.55rem; border-right: 1px solid #eef1f5; color: #3c4654;
  font-family: inherit; line-height: 1;
}
#toolsBar button.tool:last-of-type { border-right: none; }
#toolsBar button.tool:hover { background: #f0f3f7; }
#toolsBar button.tool.on { background: var(--accent); color: #fff; }
#toolsBar .tool-pop {
  position: absolute; top: 2.4rem; right: 0; min-width: 15rem;
}

#toolsBar button.tool.on { background: #f4f9f6; color: #027d42; }
#toolsBar .caret { font-size: 0.6rem; margin-left: 0.15rem; vertical-align: middle; }

.trow {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.42rem 0.2rem; cursor: pointer; border-bottom: 1px solid #f0f3f6;
  gap: 1.2rem; white-space: nowrap;
}
.trow:hover { background: #f7faf8; }
.pill {
  width: 2rem; height: 1.1rem; border-radius: 0.55rem; background: #cdd4dc;
  position: relative; transition: background .15s; flex: none;
}
.pill::after {
  content: ""; position: absolute; top: 0.12rem; left: 0.12rem;
  width: 0.86rem; height: 0.86rem; border-radius: 50%; background: #fff;
  transition: left .15s;
}
.pill.on { background: #027d42; }
.pill.on::after { left: 1.02rem; }

.rrow {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.42rem 0.2rem; cursor: pointer; border-bottom: 1px solid #f0f3f6; gap: 1.2rem;
}
.rrow:hover { background: #f7faf8; }
.radio {
  width: 1rem; height: 1rem; border-radius: 50%; border: 2px solid #cdd4dc; flex: none;
}
.radio.sel { border-color: #027d42; background: radial-gradient(#027d42 45%, #fff 50%); }

.tool-pop .choice { padding: 0.35rem 0.5rem; cursor: pointer; border-radius: 4px; font-weight: 600; }
.tool-pop .choice:hover { background: #eef4fb; }

/* markup palette docked at chart left edge */
#mkPalette {
  position: absolute; top: 0.7rem; left: 0.7rem; z-index: 14;
  width: 5.4rem; background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 14px rgba(20,30,40,.12); padding: 0.35rem;
  display: flex; flex-direction: column; gap: 0.3rem;
}
#mkPalette .mk-row { display: flex; gap: 0.25rem; justify-content: center; }
#mkPalette .mk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem; }
#mkPalette button {
  border: 1px solid var(--border); background: #fff; border-radius: 4px;
  font-size: 1rem; cursor: pointer; padding: 0.25rem 0; width: 100%; line-height: 1.2;
  font-family: inherit; color: #394859;
}
#mkPalette button:hover { background: #f0f3f7; }
#mkPalette button.on { background: #f4f9f6; color: #027d42; border-color: #027d42; }
#mkPalette input[type="color"] { width: 100%; height: 1.6rem; border: 1px solid var(--border); border-radius: 4px; background: #fff; padding: 0.1rem; }
#mkPalette .mk-foot { border-top: 1px solid var(--border); padding-top: 0.3rem; }

/* When markup mode is on, the floating panel may overlap the palette — shift it */
#mkPalette ~ #floatPanel, #chartWrap:has(#mkPalette:not(.hidden)) #floatPanel { left: 6.6rem; }

/* PiP mode: chart only */
body.pip #topbar, body.pip #companyBar, body.pip #watchlistPanel, body.pip .hint { display: none; }

.hidden { display: none !important; }
