:root {
  --bg: #14161c;
  --panel: #1c1f27;
  --panel2: #232733;
  --border: #2c3140;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --c1: #4f8cff; /* categorical series 1 */
  --c2: #d96f24;
  --c3: #11a394;
  --c4: #9a6dff;
  --c5: #d84f92;
  --c6: #9d8400;
  --up: #1e9e7e;   /* status: gains / long */
  --down: #e05260; /* status: losses / short */
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  /* extend into display-cutout areas (Samsung punch-hole in landscape) without
     content hiding under them */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand span { color: var(--c1); }
.controls { display: flex; gap: 8px; align-items: center; flex: 1; }
.right { display: flex; gap: 12px; align-items: center; }
.live { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c3); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
#status { color: var(--muted); font-size: 12px; }

select, input[type="number"], input[type="text"] {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; font-size: 13px;
}
select[multiple] { width: 100%; }
.btn {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 14px; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--c1); }
.btn.primary { background: var(--c1); border-color: var(--c1); color: #0b1020; font-weight: 600; width: 100%; margin-top: 12px; }
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: wait; }

#tabs { display: flex; gap: 2px; background: var(--panel); padding: 0 16px; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; color: var(--muted);
  padding: 10px 16px; font-size: 13.5px; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--c1); }

main { flex: 1; overflow: auto; padding: 14px 16px; }
.tabpane { display: none; }
.tabpane.active { display: block; }

.chart-toolbar { display: flex; gap: 16px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.chk { color: var(--muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.sep { width: 1px; height: 18px; background: var(--border); }
.chart-main { height: calc(100vh - 220px); min-height: 420px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.chk.ma { gap: 5px; }
.ma-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--mac, #4f8cff); display: inline-block; flex: 0 0 auto; }
.ma-per { width: 54px; padding: 3px 5px; }
.legend { font-size: 12.5px; color: var(--muted); min-height: 20px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.legend b { color: var(--text); }

.bt-layout { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0;
}
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-top: 8px; }
.panel h3:first-child { margin-top: 0; }
.params { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.params label, .row label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.params input, .params select { width: 100%; }
.row { display: flex; gap: 8px; }
.row label { flex: 1; }
.row input, .row select { width: 100%; }
.checklist { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow: auto; }
.checklist label { font-size: 13px; display: flex; gap: 7px; align-items: center; cursor: pointer; }
.checklist .fam { color: var(--muted); font-size: 11px; margin-left: auto; }
.wf-quick { font-size: 11px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.wf-quick a { color: var(--c1); cursor: pointer; }
.wf-quick a:hover { text-decoration: underline; }
.wf-symlist { max-height: 260px; }
.wf-cathead { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 8px 0 2px; position: sticky; top: 0; background: var(--panel); padding: 1px 0; }
.wf-symrow { font-size: 12.5px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px;
}
.tile .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.tile .v { font-size: 20px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .v.pos { color: var(--up); }
.tile .v.neg { color: var(--down); }

.chart-eq { height: 320px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px; overflow: hidden; }

table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--bg); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel2); }
tr.selected td { background: var(--panel2); }
td.pos { color: var(--up); }
td.neg { color: var(--down); }
.tablewrap { overflow-x: auto; max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; } /* must beat .login-overlay's display:flex (same specificity, later in file) */
h3 { font-size: 14px; margin: 10px 0; }

.etoro-info {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--c2);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; font-size: 12.5px; color: var(--muted);
}
.etoro-info b { color: var(--text); }
.tile .v.small-text { font-size: 13px; font-weight: 500; line-height: 1.35; }

.pf-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 12px; flex-wrap: wrap; }
.pf-slider { display: flex; align-items: center; gap: 14px; }
.slider-wrap { width: 260px; }
.slider-wrap input[type="range"] { width: 100%; accent-color: var(--c1); }
.slider-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }
.slider-val { color: var(--text); font-weight: 600; }
.pf-slider { display: flex; flex-direction: column; gap: 2px; }
.slider-wrap { width: 200px; }
.pf-hz { font-size: 13px; color: var(--text); font-weight: 600; min-width: 120px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.new { background: rgba(79,140,255,.18); color: var(--c1); }
.badge.long { background: rgba(30,158,126,.18); color: var(--up); }
.badge.short { background: rgba(224,82,96,.18); color: var(--down); }

/* ---------- asset research ---------- */
.rs-head h2 { font-size: 20px; }
.rs-tiles { margin-top: 12px; }
.rs-sec { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-top: 12px; }
.rs-sec h3 { margin: 0 0 8px; font-size: 14px; color: var(--c1); }
.rs-about { color: var(--text); line-height: 1.55; max-width: 900px; }
.rs-reco { font-size: 15px; font-weight: 600; text-transform: capitalize; margin-bottom: 8px; }
.rs-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--panel2); }
.rs-bar span { display: block; height: 100%; }
.rs-barleg { display: flex; gap: 16px; margin-top: 6px; font-size: 12px; }
.rs-barleg span:nth-child(2) { color: var(--muted); }
.rs-target { margin-top: 10px; font-size: 13px; }
.rs-news { display: flex; flex-direction: column; }
.rs-newsrow { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.rs-newsrow:last-child { border-bottom: none; }
a.rs-newsrow:hover .rs-newst { color: var(--c1); }
.rs-newst { flex: 1; }

/* ---------- research ticker search ---------- */
.rs-search { position: relative; flex: 1; max-width: 440px; }
.rs-search input { width: 100%; }
.rs-suggest { position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  margin-top: 4px; max-height: 340px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.rs-sug { padding: 8px 12px; cursor: pointer; display: flex; align-items: baseline; gap: 8px; border-bottom: 1px solid var(--border); }
.rs-sug:last-child { border-bottom: none; }
.rs-sug:hover { background: var(--panel); }
.rs-sug b { color: var(--text); }
.rs-sug-name { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rs-sug-meta { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ---------- sentiment gauge ---------- */
.sent-gauge { margin: 6px 0 12px; }
.sent-score { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sent-max { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 1px; }
.sent-label { font-size: 15px; margin-left: 10px; color: var(--text); }
.sent-meter { position: relative; height: 10px; border-radius: 5px; margin: 10px 0 4px;
  background: linear-gradient(90deg, var(--down), var(--c2) 50%, var(--up)); }
.sent-marker { position: absolute; top: -3px; width: 4px; height: 16px; border-radius: 2px;
  background: var(--text); transform: translateX(-50%); box-shadow: 0 0 0 2px var(--panel); }
.sent-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.sent-comps { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 22px; margin-top: 12px; }
.sent-comp { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sent-comp .muted { margin-left: auto; }
.sent-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.sent-dot.bull { background: var(--up); }
.sent-dot.bear { background: var(--down); }
.sent-dot.neut { background: var(--muted); }
.sent-extra { margin-top: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 5px; }
@media (max-width: 640px) { .sent-comps { grid-template-columns: 1fr; } }

.guide { max-width: 860px; margin: 0 auto; }
.guide h2 { font-size: 20px; margin-bottom: 4px; }
.gsub { color: var(--muted); margin-bottom: 18px; }
.gsec { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; margin-bottom: 12px; }
.gsec h3 { margin: 0 0 8px; font-size: 15px; color: var(--c1); }
.gsec.warn h3 { color: var(--down); }
.gsec ul, .gsec ol { margin: 6px 0 6px 20px; }
.gsec li { margin-bottom: 5px; }
.gsec p { margin: 6px 0; }
.gsec code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 17, 22, 0.96);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; width: 340px; max-width: 92vw;
  display: flex; flex-direction: column; gap: 10px;
}
.login-box input { width: 100%; padding: 9px 10px; }

.toast {
  position: fixed; bottom: 18px; right: 18px; max-width: 440px;
  background: #3a2530; border: 1px solid var(--down); color: var(--text);
  padding: 10px 14px; border-radius: 8px; font-size: 13px; z-index: 50;
  white-space: pre-wrap;
}
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--c1); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .bt-layout { grid-template-columns: 1fr; }
  .panel { position: static; }
}

/* ---------- landscape phone (short viewport, any width) ---------- */
@media (max-height: 520px) {
  header { padding: 5px 10px; gap: 8px; }
  .brand { font-size: 14px; }
  /* landscape: header must fit one row — drop decorations, let selects shrink */
  #who, .live { display: none; }
  .controls { min-width: 0; } /* lift the flex auto-min so the row can compress */
  .right { flex-shrink: 0; }  /* bar count + Log out never get squeezed out */
  .controls select { min-width: 0; }
  #symbol { flex: 0 10 auto; } /* the wide one absorbs the squeeze */
  #status { white-space: nowrap; }
  .right { gap: 8px; }
  #tabs { overflow-x: auto; scrollbar-width: none; }
  #tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
  main { padding: 6px 10px; }
  .chart-toolbar { margin-bottom: 4px; gap: 10px; font-size: 12px; }
  .legend { min-height: 14px; margin-bottom: 2px; font-size: 11px; }
  #levels-info { display: none; } /* landscape: every vertical pixel goes to the chart */
  .chart-toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .chart-toolbar::-webkit-scrollbar { display: none; }
  .chk, .chart-toolbar label { white-space: nowrap; }
  .chart-main { height: calc(100vh - 118px); height: calc(100dvh - 118px); min-height: 220px; }
  .chart-eq { height: 180px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
  .tile { padding: 6px 10px; }
  .tile .v { font-size: 15px; }
  .panel { position: static; }
}

/* ---------- phone layout ---------- */
@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .controls { flex-wrap: wrap; width: 100%; order: 3; }
  .controls select { flex: 1; min-width: 90px; }
  #tabs { overflow-x: auto; padding: 0 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 10px 10px; font-size: 12.5px; white-space: nowrap; }
  main { padding: 10px 8px; }
  .chart-main { height: 52vh; height: 52dvh; min-height: 300px; }
  .chart-eq { height: 220px; }
  .chart-toolbar { gap: 10px; font-size: 12px; }
  .legend { font-size: 11px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .tile .v { font-size: 16px; }
  .pf-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .pf-slider { width: 100%; }
  .slider-wrap { width: 100%; }
  .btn.primary { width: 100%; }
  table { font-size: 11.5px; }
  th, td { padding: 5px 6px; }
  .guide { padding: 0 2px; }
}
