:root {
  --bg: #131722;
  --panel: #1e222d;
  --hover: #2a2e39;
  --border: #2a2e39;
  --text: #d1d4dc;
  --text-dim: #787b86;
  --accent: #2962ff;
  --up: #089981;
  --down: #f23645;  /* keep in sync with UP/DOWN in js/theme.js */
  --top-h: 44px;
  --tab-h: 52px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }

button {
  background: none;
  border: 0;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { color: var(--text-dim); cursor: default; opacity: .5; }
button.on { color: var(--accent); }

.up { color: var(--up); }
.down { color: var(--down); }
.dim { color: var(--text-dim); }
[hidden] { display: none !important; }

/* ---------- app shell ---------- */
body.app {
  display: grid;
  grid-template-rows: calc(var(--top-h) + env(safe-area-inset-top)) 1fr;
  overflow: hidden;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: env(safe-area-inset-top) calc(8px + env(safe-area-inset-right)) 0 calc(8px + env(safe-area-inset-left));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.sep { width: 1px; height: 22px; background: var(--border); flex: none; }

#search { position: relative; flex: none; }
#search input {
  width: 180px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  outline: none;
}
#search input:focus { border-color: var(--accent); }
#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 300px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  z-index: 20;
  margin: 0;
  padding: 4px 0;
  list-style: none;
}
#search-results li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 7px 10px;
  cursor: pointer;
}
#search-results li:hover, #search-results li.sel { background: var(--hover); }
#search-results .code { color: var(--text-dim); width: 56px; flex: none; }
#search-results .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search-results .market { color: var(--text-dim); font-size: 12px; }
#search-results .empty { color: var(--text-dim); cursor: default; }

#symbol { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; min-width: 0; overflow: hidden; }
#sym-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
#sym-price { font-variant-numeric: tabular-nums; }

#periods { display: flex; gap: 2px; flex: none; }
#periods button { padding: 4px 7px; }

.spacer { flex: 1; }

#menu {
  position: absolute;
  top: calc(var(--top-h) + env(safe-area-inset-top));
  right: 8px;
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  padding: 8px;
  z-index: 20;
}
#menu h3 { margin: 4px 4px 6px; font-size: 12px; font-weight: 600; color: var(--text-dim); }
#menu label { display: flex; align-items: center; gap: 8px; padding: 6px 4px; cursor: pointer; border-radius: 4px; }
#menu label:hover { background: var(--hover); }
#menu hr { border: 0; border-top: 1px solid var(--border); margin: 8px 0; }
#menu button { width: 100%; text-align: left; padding: 6px 4px; }

#main {
  display: grid;
  grid-template-columns: 44px 1fr 300px;
  min-height: 0;
}

#tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 8px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: none;
}
#tools button { display: flex; align-items: center; justify-content: center; flex: none; width: 32px; height: 32px; padding: 0; font-size: 16px; }
#tools button.on { background: var(--hover); }
#tools hr { flex: none; width: 24px; margin: 4px 0; border: 0; border-top: 1px solid var(--border); }
#tools button { position: relative; color: var(--text); }
#tools button:disabled { opacity: .35; }
#tools button.strong { color: var(--accent); }
#tools .more { position: absolute; right: 0; bottom: 0; width: 10px; height: 12px; font-size: 8px; line-height: 12px; color: var(--dim, #787b86); }
#tools .more:hover { color: var(--text); }

/* drawing tool flyout, style bar, colour popover, menu, settings dialog, inline text */
.dfly, .dmenu, .dpop {
  position: fixed; z-index: 40;
  padding: 4px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
}
.dfly { display: grid; min-width: 190px; }
.dfly button { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; color: var(--text); text-align: left; font-size: 13px; }
.dfly button span { flex: 1; }
.dfly kbd { font: 11px/1 inherit; color: #787b86; }
.dfly button.on, .dfly button:hover, .dmenu button:hover { background: var(--hover); }
.dmenu { display: grid; min-width: 140px; }
.dmenu button { height: 32px; padding: 0 12px; text-align: left; color: var(--text); font-size: 13px; }
.dmenu .danger { color: var(--down); }
.dpop { display: grid; gap: 8px; padding: 8px; }
.dpal { display: grid; grid-template-columns: repeat(7, 22px); gap: 4px; }
.dpal button { width: 22px; height: 22px; padding: 0; border: 1px solid var(--border); border-radius: 3px; }
.dpal button.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.dpop input[type=color] { width: 100%; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; cursor: pointer; }
.dalpha { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #b2b5be; }
.dbar {
  position: absolute; z-index: 12; top: 8px; left: 50%;
  display: flex; align-items: center; gap: 2px; padding: 3px 4px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4); font-size: 13px; white-space: nowrap;
}
.dbar[hidden] { display: none; }
.dbar .grip { cursor: grab; padding: 0 4px; color: #787b86; letter-spacing: -2px; user-select: none; touch-action: none; }
.dbar button { min-width: 28px; height: 28px; padding: 0 4px; color: var(--text); border-radius: 4px; }
.dbar button:hover, .dbar button.on { background: var(--hover); }
.dbar .sw { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.dbar .sw i { display: block; width: 16px; height: 16px; border: 1px solid var(--border); border-radius: 3px; }
.dbar .sw b { font-size: 11px; line-height: 1; }
.dbar .sw b + i { height: 4px; }
.dbar select { height: 28px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.dbar [data-a=del] { color: var(--down); }
.ddlg { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(0, 0, 0, .45); }
.ddlg[hidden] { display: none; }
.dd-box { width: min(380px, calc(100vw - 24px)); max-height: calc(100vh - 24px); display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.dd-box header { padding: 12px 16px 4px; font-weight: 600; }
.dd-box nav { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.dd-box nav button { padding: 8px 10px; color: #b2b5be; border-bottom: 2px solid transparent; border-radius: 0; }
.dd-box nav button[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
.dd-body { display: grid; gap: 10px; padding: 14px 16px; overflow: auto; }
.dd-row { display: grid; grid-template-columns: 72px 1fr; align-items: center; gap: 6px 8px; font-size: 13px; }
.dd-row > :nth-child(n+3) { grid-column: 2; }
.dd-row input, .dd-row select, .dd-row textarea { min-width: 0; height: 30px; padding: 0 6px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.dd-row textarea { height: auto; padding: 6px; resize: vertical; }
.dd-row input[type=color] { width: 48px; padding: 0 2px; cursor: pointer; }
.dd-row input[type=range] { padding: 0; border: 0; background: none; }
.dd-check { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.dd-note { margin: 0; color: #b2b5be; font-size: 13px; }
.dd-box footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px 14px; }
.dd-box footer button { height: 32px; padding: 0 16px; border: 1px solid var(--border); border-radius: 4px; color: var(--text); }
.dd-box footer .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.dtext { position: absolute; z-index: 12; width: 180px; height: 28px; padding: 0 6px; background: var(--bg); color: var(--text); border: 1px solid var(--accent); border-radius: 4px; font: inherit; }

/* drawing style bar and the clear-all question, over the top of the chart */
.chart-pop {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: flex; align-items: center; gap: 6px;
  max-width: calc(100% - 16px);
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
  font-size: 13px;
  white-space: nowrap;
}
.chart-pop select { height: 28px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; font: inherit; }
#da-yes { color: var(--accent); }

#chart-wrap { position: relative; min-width: 0; min-height: 0; }
#chart { position: absolute; inset: 0; }
#ind-list { max-height: 50vh; overflow-y: auto; }

/* indicator legend over the chart; only the indicator rows take pointer events */
#legend { position: absolute; inset: 0; z-index: 10; pointer-events: none; overflow: hidden; } /* above the engine canvases (z 2) */
.legend-pane { position: absolute; left: 8px; right: 64px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.legend-head, .legend-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 6px;
  max-width: 100%; padding: 0 4px; border-radius: 4px;
  font-size: 12px; line-height: 20px; color: var(--text);
}
.legend-row { pointer-events: auto; cursor: default; }
.legend-row:hover { background: rgba(19, 23, 34, .8); }
.legend-close { display: none; font-variant-numeric: tabular-nums; }
.legend-row.off .legend-label { color: var(--text-dim); }
.legend-vals { display: flex; flex-wrap: wrap; gap: 0 6px; font-variant-numeric: tabular-nums; }
.legend-btns { display: flex; }
.legend-btns button { padding: 0 4px; line-height: 20px; font-size: 12px; }
.legend-warn { padding: 0 4px; line-height: 20px; font-size: 12px; color: #f23645; pointer-events: auto; }

#note {
  position: fixed;
  top: calc(var(--top-h) + env(safe-area-inset-top) + 34px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 16;
  display: flex; align-items: center; gap: 6px;
  max-width: calc(100vw - 16px);
  padding: 4px 6px 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
  font-size: 13px;
}
#note button { padding: 2px 6px; }
#note-retry { color: var(--accent); }
@media (max-width: 767px) {
  /* compact until tapped: header = symbol + close, rows = title + params on one line */
  .legend-head, .legend-row { pointer-events: auto; cursor: pointer; }
  #legend:not(.full) .legend-btns, #legend:not(.full) .legend-vals { display: none; }
  #legend:not(.full) .legend-close { display: inline; }
  #legend:not(.full) .legend-head, #legend:not(.full) .legend-row { flex-wrap: nowrap; white-space: nowrap; }
  #legend:not(.full) .legend-title, #legend:not(.full) .legend-label { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  #legend.full .legend-head, #legend.full .legend-row { background: rgba(19, 23, 34, .8); }
}
#chart-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  pointer-events: none;
  font-size: 15px;
}

#side {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  min-height: 0;
}
#side header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
#watch-head, .watch-row {
  display: grid;
  grid-template-columns: 1fr 76px 62px 24px;
  align-items: center;
  gap: 4px;
  padding: 0 6px 0 10px;
}
#watch-head { height: 28px; font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--border); }
#watch-head span:nth-child(n+2), .watch-row .num { text-align: right; }
#watch-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.watch-row { height: 40px; cursor: pointer; }
.watch-row:hover { background: var(--hover); }
.watch-row.cur { background: rgba(41, 98, 255, .15); }
.watch-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-row .nm small { color: var(--text-dim); margin-left: 4px; }
.watch-row .num { font-variant-numeric: tabular-nums; }
.watch-row .del { padding: 0; width: 22px; height: 22px; color: var(--text-dim); visibility: hidden; }
.watch-row:hover .del { visibility: visible; }
#watch-empty { padding: 16px 10px; color: var(--text-dim); }

#tabbar { display: none; }

#fake-banner {
  position: fixed;
  top: calc(var(--top-h) + env(safe-area-inset-top) + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 2px 10px;
  border-radius: 4px;
  background: #f7a600;
  color: #131722;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}

/* ---------- phone ---------- */
@media (max-width: 767px) {
  :root { --top-h: 84px; }
  body.app { grid-template-rows: calc(var(--top-h) + env(safe-area-inset-top)) 1fr calc(var(--tab-h) + env(safe-area-inset-bottom)); }
  /* two rows: search + name/price + star, then periods (scrollable) + 지표 */
  #topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "search symbol star" "periods periods ind";
    grid-template-rows: 42px 42px;
    column-gap: 6px;
  }
  #search { grid-area: search; }
  #symbol { grid-area: symbol; flex-direction: column; gap: 0; line-height: 1.25; font-size: 13px; }
  #star { grid-area: star; }
  #periods { grid-area: periods; overflow-x: auto; scrollbar-width: none; }
  #periods::-webkit-scrollbar { display: none; }
  #ind-btn { grid-area: ind; }
  #search input { width: 120px; }
  #search-results { position: fixed; left: 8px; right: 8px; width: auto; top: calc(var(--top-h) + env(safe-area-inset-top)); }
  #topbar .sep, #topbar .spacer, .desk { display: none; }
  /* drawing tools: a horizontally scrolling strip under the chart, above the tab bar */
  #main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  #tools {
    grid-row: 2;
    flex-direction: row;
    padding: 4px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-top: 1px solid var(--border);
  }
  #tools button { width: 36px; height: 36px; }
  #tools hr { width: 0; height: 24px; margin: 0 4px; border-top: 0; border-left: 1px solid var(--border); }
  #tools .more, .dfly kbd { display: none; }
  .dbar { position: fixed; top: auto !important; left: 8px !important; right: 8px; bottom: calc(var(--tab-h, 56px) + 52px + env(safe-area-inset-bottom)); overflow-x: auto; scrollbar-width: none; }
  .dbar .grip { display: none; }
  .dbar button { min-width: 34px; height: 34px; }
  body.tab-watch #tools, body.tab-more #tools { display: none; }
  #side { display: none; }
  body.tab-watch #chart-wrap, body.tab-more #chart-wrap { display: none; }
  body.tab-watch #side { display: flex; border-left: 0; }
  body.tab-more #menu {
    display: block !important;
    position: static;
    width: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: var(--bg);
    padding: 12px calc(12px + env(safe-area-inset-right)) 12px calc(12px + env(safe-area-inset-left));
  }
  .watch-row .del { visibility: visible; }
  #tabbar {
    display: flex;
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  #tabbar button { flex: 1; border-radius: 0; color: var(--text-dim); font-size: 13px; }
  #tabbar button.on { color: var(--text); }
}

/* ---------- login ---------- */
body.login { display: flex; align-items: center; justify-content: center; padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); }
.login form {
  width: 100%;
  max-width: 320px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  font-size: 16px; /* 16px stops iOS from zooming in */
  outline: none;
}
.login input:focus { border-color: var(--accent); }
.login button[type=submit] { background: var(--accent); color: #fff; padding: 10px; font-weight: 600; }
.login button[type=submit]:hover { background: #1e53e5; }
.login .err { color: var(--down); min-height: 1.4em; margin: 0; font-size: 13px; }

/* ---------- indicator settings dialog ---------- */
.settings-back { position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; }
.settings-dlg {
  width: min(420px, calc(100vw - 32px)); max-height: 80vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.settings-dlg h2 { margin: 0; font-size: 16px; }
.settings-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.settings-tabs button { border-radius: 4px 4px 0 0; color: var(--text-dim); }
.settings-tabs button.on { color: var(--text); border-bottom: 2px solid var(--accent); }
.settings-body { display: flex; flex-direction: column; gap: 10px; }
.settings-row { display: flex; flex-direction: column; gap: 4px; }
.settings-row > label { color: var(--text-dim); font-size: 13px; }
.settings-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.settings-dlg input:not([type=checkbox]):not([type=color]), .settings-dlg select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; font-size: 16px; outline: none; min-width: 0;
}
.settings-dlg input:focus, .settings-dlg select:focus { border-color: var(--accent); }
.settings-dlg input.bad { border-color: var(--down); }
.settings-dlg input[type=color] { width: 36px; height: 30px; padding: 0; border: 1px solid var(--border); background: none; }
.settings-ctl > input:not([type]), .settings-ctl > input[inputmode] { width: 100px; }
.settings-list { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.settings-li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.settings-li input { width: 100px; }
.settings-err { color: var(--down); font-size: 12px; width: 100%; }
.settings-err:empty { display: none; }
.settings-note { color: var(--text-dim); margin: 0; }
.settings-foot { display: flex; gap: 8px; align-items: center; }
.settings-foot .grow { flex: 1; }
.settings-ok { background: var(--accent); color: #fff; font-weight: 600; }
.settings-ok:hover:not(:disabled) { background: #1e53e5; }

/* Pane separators: the engine's 7px hit strip is too thin for a finger; widen it on touch screens.
   (width:100% picks the separator, not the 52px price-axis widget that shares the ns-resize cursor) */
@media (pointer: coarse) {
  #chart div[style*="cursor: ns-resize"][style*="width: 100%"] { height: 26px !important; top: -22px !important; /* mostly upward: the lower pane's legend row sits just below */ }
}

/* "내 지표" rows in the indicator menu: name (add) + small ✎ 🗑 buttons */
#my-list { max-height: 30vh; overflow-y: auto; }
.my-row { display: flex; align-items: center; gap: 2px; }
#menu .my-row button { flex: none; width: auto; padding: 6px; }
#menu .my-row button.my-add { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu .my-row button.my-yes { color: var(--down); }
.my-ask { flex: 1; font-size: 12px; color: var(--text-dim); padding: 0 4px; }
.my-empty { padding: 4px; font-size: 12px; color: var(--text-dim); }

/* script editor (PC only): a panel on the right, over the watchlist */
#editor {
  position: fixed;
  top: calc(var(--top-h) + env(safe-area-inset-top));
  right: 0; bottom: 0;
  width: min(480px, 100vw);
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, .4);
  z-index: 30;
}
.ed-head, .ed-foot { display: flex; align-items: center; gap: 6px; }
#ed-name { flex: 1; min-width: 0; }
#ed-name, #ed-tpl { height: 30px; padding: 0 6px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.ed-code { flex: 1; min-height: 0; display: flex; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); overflow: hidden; }
#ed-lines, #ed-text { font: 13px/1.5 ui-monospace, Consolas, 'D2Coding', monospace; padding: 6px 0; }
#ed-lines { flex: none; min-width: 36px; padding-right: 6px; text-align: right; color: var(--text-dim); overflow: hidden; user-select: none; border-right: 1px solid var(--border); }
#ed-lines div { padding-left: 6px; }
#ed-lines .err { background: var(--down); color: #fff; }
#ed-text { flex: 1; min-width: 0; padding-left: 8px; border: 0; outline: 0; resize: none; background: transparent; color: var(--text); tab-size: 2; white-space: pre; }
#ed-err { color: var(--down); font-size: 13px; white-space: pre-wrap; }
#ed-apply { padding: 6px 16px; background: var(--accent); color: #fff; border-radius: 4px; }
#ed-apply:disabled { opacity: .6; }
#ed-msg { font-size: 12px; color: var(--text-dim); }
#ed-help { font-size: 12px; color: var(--text-dim); max-height: 35vh; overflow-y: auto; }
#ed-help summary { cursor: pointer; padding: 2px 0; }
#ed-help ul { margin: 4px 0; padding-left: 16px; }
#ed-help code { color: var(--text); }

/* ETF calculator + news (side panel, under the watchlist) */
.side-sec { border-top: 1px solid var(--border); flex: none; }
.side-sec > summary { padding: 8px 10px; font-weight: 600; cursor: pointer; }
.side-sec > .body { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.side-sec small { color: var(--text-dim); }
.side-sec .link { background: none; border: 0; color: var(--accent, #2962ff); cursor: pointer; padding: 0 2px; font: inherit; }
.etf-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; color: var(--text-dim); }
.etf-row { display: grid; grid-template-columns: minmax(0, 1fr) 72px auto; align-items: center; column-gap: 4px; }
.etf-row small { grid-column: 1 / -1; }
.etf-row .link { grid-column: 1 / -1; justify-self: start; }
.etf-row input { width: 72px; text-align: right; font-variant-numeric: tabular-nums; }
.etf-row.dim { opacity: .45; }
.etf-est b { font-size: 16px; font-variant-numeric: tabular-nums; }
.etf-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.etf-table th, .etf-table td { text-align: right; padding: 2px 4px; }
.etf-table th { color: var(--text-dim); font-weight: 400; }
.etf-set { display: flex; flex-direction: column; gap: 6px; }
.etf-set input[type=number] { width: 72px; }
.etf-btns { display: flex; gap: 6px; flex-wrap: wrap; }
#news .body { list-style: none; margin: 0; max-height: 40vh; overflow-y: auto; }
#news li { display: flex; flex-direction: column; gap: 2px; }
#news li a { color: inherit; text-decoration: none; }
#news li a:hover { text-decoration: underline; }
#news li.muted { color: var(--text-dim); }

/* Alerts (side section, bell form) */
#alert-form { position: fixed; top: 56px; right: 12px; z-index: 40; width: min(340px, calc(100vw - 24px)); display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .4); }
#alert-form[hidden] { display: none; }
#alert-form label { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#alert-form input[type=number], #alert-form input[type=text] { min-width: 0; flex: 1; }
#alert-form h4, #alerts h4 { margin: 4px 0 0; font-size: 13px; }
.al-warn { color: #f0b429 !important; }
.al-list, .al-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.al-row, .al-log li { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 6px; }
.al-row small, .al-log small { grid-column: 1; }
.al-row .al-btns { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.al-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.al-fired span:first-child { color: var(--accent); }
.al-off { opacity: .6; }
.al-nodata small { color: #f0b429; }
.al-push { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
@media (max-width: 767px) {
  #alert-form { top: calc(var(--top-h) + env(safe-area-inset-top) + 4px); }
  body.tab-alerts #tools { display: none; }
  body.tab-alerts #chart-wrap { display: none; }
  body.tab-alerts #side { display: flex; border-left: 0; overflow-y: auto; }
}
