:root {
  --bg: #0f1419;
  --panel: #1a2129;
  --border: #2c3640;
  --text: #d7dde4;
  --muted: #8a97a5;
  --accent: #4da3ff;
  --green: #3ddc84;
  --red: #ff5c5c;
  --amber: #ffb454;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topnav {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 1.2rem; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topnav .brand { font-weight: 700; color: var(--text); font-size: 1.1rem; margin-right: .2rem; }
.nav-toggle {
  display: none; margin-left: auto; background: none; border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; font-size: 1.1rem; line-height: 1;
  padding: .35rem .6rem; cursor: pointer;
}
.nav-collapse { display: flex; align-items: center; gap: 1rem; flex: 1; }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-collapse a:not(.brand) { color: var(--muted); }
.nav-collapse a:hover { color: var(--text); text-decoration: none; }
.nav-search { margin-left: auto; }

/* user dropdown menu (native <details>) */
.user-menu { position: relative; }
.user-menu > summary {
  list-style: none; cursor: pointer; color: var(--muted);
  padding: .25rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary::after { content: " ▾"; color: var(--muted); }
.user-menu > summary:hover { color: var(--text); border-color: var(--accent); }
.user-menu[open] > summary { color: var(--text); }
.user-menu-items {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
  display: flex; flex-direction: column; min-width: 160px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: .3rem; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.user-menu-items a { color: var(--muted); padding: .4rem .6rem; border-radius: 6px; }
.user-menu-items a:hover { background: #232c36; color: var(--text); text-decoration: none; }

/* left-nav dropdown (Screens → Schedules/Results), styled like a plain nav link */
.nav-menu { position: relative; }
.nav-menu > summary {
  list-style: none; cursor: pointer; color: var(--muted);
}
.nav-menu > summary::-webkit-details-marker { display: none; }
.nav-menu > summary::after { content: " ▾"; }
.nav-menu > summary:hover, .nav-menu[open] > summary { color: var(--text); }
.nav-menu-items {
  position: absolute; left: 0; top: calc(100% + 8px); z-index: 20;
  display: flex; flex-direction: column; min-width: 150px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: .3rem; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.nav-menu-items a { color: var(--muted); padding: .4rem .6rem; border-radius: 6px; }
.nav-menu-items a:hover { background: #232c36; color: var(--text); text-decoration: none; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; margin-top: 2rem; }

.cards { display: flex; gap: 1rem; flex-wrap: wrap; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 1rem 1.4rem; min-width: 180px;
}
.card h3 { margin: 0 0 .3rem; font-size: .85rem; color: var(--muted); text-transform: uppercase; }
.card .big { font-size: 1.6rem; font-weight: 700; margin: 0; }
.card p { margin: .2rem 0; color: var(--muted); }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 8px; }
th, td { text-align: left; padding: .5rem .8rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .8rem; text-transform: uppercase; }
tr.status-failed td:nth-child(2) { color: var(--red); }
tr.status-done td:nth-child(2) { color: var(--green); }
tr.status-running td:nth-child(2), tr.status-pending td:nth-child(2) { color: var(--amber); }

pre {
  background: #11161c; border: 1px solid var(--border); border-radius: 6px;
  padding: .8rem; overflow-x: auto; font-size: .8rem; max-height: 320px;
}
details summary { cursor: pointer; color: var(--red); }

/* ticker data-flag: one quiet blue link below the chart */
.flag-box { margin-top: .8rem; }
.flag-box > summary { color: var(--accent); font-size: .85rem; }
.flag-box > summary:hover { text-decoration: underline; }
.flag-box .form-card { max-width: 460px; }

button, .btn {
  background: var(--accent); color: #08233f; border: 0; border-radius: 6px;
  padding: .5rem 1rem; font-weight: 600; cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.1); }
input, select, textarea {
  background: #11161c; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: .45rem .6rem; width: 100%;
}
label { display: block; margin-bottom: .8rem; color: var(--muted); }
/* checkboxes/radios shouldn't inherit the full-width text-input sizing above */
input[type="checkbox"], input[type="radio"] {
  width: auto; padding: 0; margin: 0 .45rem 0 0; vertical-align: middle;
}
.error { color: var(--red); }

.btn-small {
  display: inline-block; background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: .25rem .6rem; margin: 0 .15rem .3rem 0; color: var(--accent);
}
.btn-small:hover { text-decoration: none; border-color: var(--accent); }
button.danger { background: var(--red); color: #2b0707; }
.actions form { margin-right: .3rem; }
.form-card { max-width: 560px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 1.2rem 1.5rem; }
.form-card h2 { margin-top: 1.2rem; font-size: 1rem; color: var(--muted); }
.form-card small { display: block; color: var(--muted); font-weight: 400; }
.inline-form { margin-bottom: 1rem; max-width: 320px; }
.muted { color: var(--muted); }
.price-header { display: flex; align-items: baseline; gap: .7rem; flex-wrap: wrap; margin: .2rem 0 .6rem; }
.price-now { font-size: 1.7rem; font-weight: 700; }
.price-change { font-size: 1rem; font-weight: 600; }
.price-change.up { color: var(--green); }
.price-change.down { color: var(--red); }
.price-asof { color: var(--muted); font-size: .85rem; }
.price-asof .badge {
  display: inline-block; padding: .05rem .4rem; border: 1px solid var(--border);
  border-radius: 4px; font-size: .75rem; margin-right: .25rem;
}
.price-asof .badge.stale { color: var(--amber); border-color: var(--amber); }

.chart-controls .tf-btn { background: var(--panel); color: var(--muted); border: 1px solid var(--border); }
.chart-controls .tf-btn.active { background: var(--accent); color: #08233f; }

/* review mode: filmstrip + dot progress */
.filmstrip {
  display: flex; gap: .35rem; overflow-x: auto; padding: .4rem .2rem;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.chip {
  display: inline-flex; gap: .4rem; align-items: baseline; flex-shrink: 0;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: .25rem .7rem; cursor: pointer; font-weight: 400;
}
.chip:hover { border-color: var(--accent); filter: none; }
.chip.viewed { color: var(--muted); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #08233f; }
.chip.active .chip-score { color: #08233f; }
.chip-symbol { font-weight: 700; }
.chip-score { font-size: .8rem; color: var(--muted); }

.review-bar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .25rem .2rem; border-bottom: 1px solid var(--border);
}
.dot-rail { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; max-width: 50%; }
.dot {
  width: 10px; height: 10px; border-radius: 50%; padding: 0; border: 0;
  cursor: pointer; background: var(--muted); opacity: .9;
}
.dot:hover { transform: scale(1.5); filter: none; }
.dot.viewed { opacity: .35; }
.dot.active { outline: 2px solid #fff; outline-offset: 1px; opacity: 1; transform: scale(1.25); }
.dot.tier-elite { background: var(--green); }
.dot.tier-strong { background: var(--accent); }
.dot.tier-moderate { background: var(--amber); }
.dot.tier-weak { background: var(--red); }
/* wrap rather than overflow the viewport on narrow screens (stopgap; a fuller
   control redesign is coming) */
.review-controls { display: inline-flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-left: auto; }
.review-controls label { margin: 0; display: inline-flex; gap: .25rem; align-items: center; color: var(--muted); }
.chart-pane { height: calc(100vh - 320px); min-height: 340px; margin-top: .3rem; overflow: hidden; }
/* prev/next under the chart: hidden on desktop (j/k + chips do the job), shown on mobile */
.viewer-nav { display: none; gap: .5rem; margin-top: .6rem; }
.vnav-btn { flex: 1 1 50%; padding: .85rem; font-size: 1rem; }
.vnav-btn:disabled { opacity: .4; }

.chart-header { padding: .45rem .2rem 0; font-size: 1.05rem; }
.chart-header strong { font-size: 1.15rem; }
.chart-header .ch-name { color: var(--text); }
.chart-header .ch-score { float: right; color: var(--amber); font-weight: 600; }
.nav-search input { width: 110px; padding: .25rem .5rem; }
progress { accent-color: var(--accent); height: 14px; }

/* ticker chat */
.chat-card {
  margin-top: 1.4rem; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 1rem 1.2rem;
}
.chat-suggest { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .7rem; }
.chat-log { display: flex; flex-direction: column; gap: .6rem; max-height: 460px; overflow-y: auto; }
.chat-log:empty { display: none; }
.msg {
  max-width: 90%; padding: .55rem .8rem; border-radius: 10px;
  line-height: 1.5; word-wrap: break-word;
}
.msg.user { align-self: flex-end; background: var(--accent); color: #08233f; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: #11161c; border: 1px solid var(--border); }
/* rendered markdown inside assistant bubbles */
.msg.assistant > :first-child { margin-top: 0; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg.assistant p { margin: 0 0 .5em; }
.msg.assistant ul, .msg.assistant ol { margin: .3em 0 .5em; padding-left: 1.3em; }
.msg.assistant li { margin: .15em 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3, .msg.assistant h4 { margin: .4em 0 .3em; font-size: 1rem; }
.msg.assistant a { color: var(--accent); }
.msg.assistant code { background: #0b0f14; padding: .05em .35em; border-radius: 4px; font-size: .9em; }
.msg.assistant pre { background: #0b0f14; padding: .6rem; border-radius: 6px; overflow-x: auto; }
.msg.assistant pre code { background: none; padding: 0; }

/* animated "thinking" state */
.msg.assistant.thinking { display: flex; align-items: center; gap: .6rem; color: var(--muted); }
.thinking-label { font-size: .9rem; }
.dots { display: inline-flex; gap: 4px; }
.dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: dot-pulse 1.2s infinite ease-in-out both;
}
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dot-pulse { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.chat-form { display: flex; gap: .5rem; margin-top: .7rem; align-items: flex-end; }
.chat-form textarea { flex: 1; resize: vertical; min-height: 2.4rem; font: inherit; }
.chat-form textarea:disabled { opacity: .5; cursor: not-allowed; }
.chat-form button { white-space: nowrap; }
.chat-form button:disabled { opacity: .5; cursor: not-allowed; }

.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 2rem; width: 320px;
}
.login-card h1 { margin-top: 0; text-align: center; }
.login-card .brand-mark { margin-bottom: .2rem; letter-spacing: .02em; }
.login-card .brand-tagline {
  margin: 0 0 1.4rem; text-align: center; color: var(--muted);
  font-size: .8rem; letter-spacing: .08em; text-transform: uppercase;
}
.login-card button { width: 100%; margin-top: .5rem; }
.login-divider {
  display: flex; align-items: center; gap: .6rem; margin: 1rem 0;
  color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em;
}
.login-divider::before, .login-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.btn-oauth {
  display: block; width: 100%; box-sizing: border-box; text-align: center;
  padding: .55rem 1rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); color: var(--text); text-decoration: none;
}
.btn-oauth:hover { filter: brightness(1.15); }

/* ---- dashboard boards + watchlists ---- */
.dash-head, .section-head { display: flex; align-items: baseline; gap: .8rem; }
.section-head { justify-content: space-between; margin: 1.6rem 0 .6rem; border-bottom: 1px solid var(--border); padding-bottom: .3rem; }
.section-head h2 { margin: 0; }
.boards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; align-items: start; }
.board { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem; }
.board-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: .4rem; }
.board-head h3 { margin: 0; font-size: 1rem; }
.board-head .muted { font-size: .78rem; }
/* fixed layout: columns honor the widths below and the name truncates, so the
   table can never exceed its board card (was overflowing without this). */
.board-table { width: 100%; table-layout: fixed; }
.board-table th { font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  font-weight: 600; text-align: left; padding: 0 .3rem .25rem; border-bottom: 1px solid var(--border); }
.board-table th.b-px, .board-table th.b-chg { text-align: right; }
.board-table td { padding: .25rem .3rem; border: none; border-bottom: 1px solid var(--border); font-size: .9rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-table tr:last-child td { border-bottom: none; }
.b-sym { font-weight: 700; width: 4.5rem; }
.b-name { font-size: .8rem; }   /* takes the remaining width; truncates with ellipsis */
.b-px { width: 5rem; text-align: right; font-variant-numeric: tabular-nums; }
.b-chg { width: 4.5rem; text-align: right; font-variant-numeric: tabular-nums; font-size: .82rem; }
.b-chg.up { color: var(--green); }
.b-chg.down { color: var(--red); }
.board-empty { font-size: .85rem; margin: .3rem 0; }
.board-foot { margin: -.4rem 0 .4rem; }

/* ---- dashboard watchlist carousel (one list at a time; chips + ‹ › / arrows) ---- */
.wl-tabs { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .5rem; scrollbar-width: thin; }
.wl-tab { flex: 0 0 auto; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: .3rem .85rem; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.wl-tab:hover { border-color: var(--accent); }
.wl-tab.active { background: var(--accent); color: #08233f; border-color: var(--accent); font-weight: 600; }
.wl-stage { display: flex; align-items: stretch; gap: .5rem; }
.wl-slides { flex: 1; min-width: 0; }          /* min-width:0 lets the fixed table shrink, never overflow */
.wl-slide { display: none; }
.wl-slide.active { display: block; }
.wl-nav { flex: 0 0 auto; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; cursor: pointer; font-size: 1.4rem; line-height: 1; padding: 0 .65rem; }
.wl-nav:hover { background: var(--accent); color: #08233f; border-color: var(--accent); }
.wl-counter { text-align: center; font-size: .8rem; margin-top: .4rem; }

/* ---- /digests history ---- */
.digest-entry { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .8rem; margin: .6rem 0; }
.digest-entry > summary { cursor: pointer; }
.digest-body { margin-top: .6rem; }
.digest-body table { border-collapse: collapse; margin: .4rem 0; font-size: .9rem; }
.digest-body th, .digest-body td { padding: .25rem .5rem; }

/* ---- site-wide disclaimer footer ---- */
.site-disclaimer { margin-top: 2rem; padding-top: .8rem; border-top: 1px solid var(--border); }
.site-disclaimer p { font-size: .75rem; line-height: 1.4; margin: 0 0 1rem; }

/* ---- ticker page header actions ---- */
.ticker-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.ticker-head h1 { margin: 0; }
.ticker-actions { display: flex; align-items: flex-start; gap: .5rem; }
.star-btn { background: var(--panel); color: var(--muted); border: 1px solid var(--border); }
.star-btn.on { color: var(--amber); border-color: var(--amber); }
.addlist > summary { color: var(--accent); list-style: none; cursor: pointer; padding: .45rem .7rem; border: 1px solid var(--border); border-radius: 6px; font-size: .9rem; }
.addlist[open] > summary { border-color: var(--accent); }
.addlist .form-card { position: absolute; z-index: 5; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .8rem; min-width: 240px; }

/* ---- watchlist management chips ---- */
.chip-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.chip-list .chip { display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .5rem; }
.chip-x { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 .2rem; font-size: 1rem; line-height: 1; }
.chip-x:hover { color: var(--red); }
.inline-create { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.inline-create label { margin-bottom: 0; }

/* ---- composite screen builder ---- */
.conditions { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .6rem; }
.condition-row { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; padding: .5rem; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.condition-row select, .condition-row input { margin: 0; }
.condition-row .len-input, .rank-row .len-input { width: 5rem; }
.rank-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.rank-row select { margin: 0; }
#add-condition { margin-bottom: 1rem; }

/* ---- screen-builder help modal ---- */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-header h1 { margin: 0; }
dialog.help-modal { max-width: 640px; width: 92%; padding: 0; border: 1px solid var(--border);
  border-radius: 12px; background: var(--panel); color: var(--text); }
dialog.help-modal::backdrop { background: rgba(0, 0, 0, .6); }
.help-modal-head { display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); }
.help-modal-head h2 { margin: 0; }
.help-close { background: none; border: none; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.help-close:hover { color: var(--text); }
.help-body { padding: 1rem 1.2rem; max-height: 70vh; overflow-y: auto; }
.help-body h3 { margin: 1.2rem 0 .4rem; }
.help-list { padding-left: 1.1rem; }
.help-list > li { margin-bottom: .5rem; }
.help-example { border: 1px solid var(--border); border-radius: 8px; margin: .4rem 0; padding: .1rem .7rem; }
.help-example > summary { cursor: pointer; color: var(--text); padding: .5rem 0; font-weight: 600; }
.help-example ol { margin: .3rem 0 .5rem 1.1rem; }
.help-example li { margin-bottom: .25rem; }
.help-body code { background: #232c36; padding: .05rem .35rem; border-radius: 4px; font-size: .85em; }

/* Save / view saved-chat dialogs — match the app's dark theme (default <dialog> is white). */
.chat-dialog { max-width: 480px; width: 92%; padding: 1.25rem; background: var(--panel);
  color: var(--text); border: 1px solid var(--border); border-radius: 12px; }
.chat-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.chat-dialog h3 { margin: 0 0 .9rem; color: var(--text); }
.chat-dialog label { color: var(--muted); }
.chat-dialog #save-summary { min-height: 6rem; resize: vertical; }
.chat-dialog fieldset { border: 1px solid var(--border); border-radius: 6px;
  padding: .5rem .8rem .7rem; margin: 0 0 .8rem; }
.chat-dialog fieldset legend { color: var(--muted); padding: 0 .35rem; }
.chat-dialog .visibility-options { display: flex; flex-wrap: wrap; gap: 1.25rem; }
.chat-dialog .visibility-options label { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
.chat-dialog .visibility-options input { width: auto; }
.chat-dialog menu { display: flex; gap: .5rem; justify-content: flex-end; padding: 0; margin: .2rem 0 0; }

/* Link-styled buttons (default <button> is a solid pill in this app). */
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit;
  cursor: pointer; text-decoration: underline; border-radius: 0; }
button.link:hover { text-decoration: none; }
button.link.danger { background: none; color: var(--red); }

/* Separator between the Ask box / save bar and the saved conversations. */
.section-sep { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

/* Saved-conversation list: only the title is a link; clicking it expands the transcript inline. */
.saved-chats h3 { margin: .8rem 0 .4rem; }
.saved-chat-list { list-style: none; padding: 0; margin: 0; }
.saved-chat { position: relative; padding: .55rem 4.5rem .55rem 0; border-top: 1px solid var(--border); }
.saved-chat:first-child { border-top: 0; }
.saved-chat-toggle { font-weight: 600; }   /* button.link supplies the blue underline */
.saved-chat-toggle::before { content: "\25B8"; display: inline-block; width: 1em; color: var(--muted);
  transition: transform .12s ease; }
.saved-chat.open .saved-chat-toggle::before { transform: rotate(90deg); }
.saved-chat-vis { font-size: .85rem; }
/* Collapsed: one truncated line (full text on hover via title=). Expanded: full text. */
.saved-chat-summary { margin: .2rem 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-chat.open .saved-chat-summary { white-space: normal; overflow: visible; }
.saved-chat-delete { position: absolute; top: .55rem; right: 0; }
.saved-chat-body { margin-top: .6rem; }
/* .chat-log sets display:flex, which beats the UA [hidden] rule — restore it explicitly. */
.saved-chat-body[hidden] { display: none; }
.saved-chat-collapse { align-self: flex-end; margin-top: .2rem; font-size: .8rem;
  color: var(--muted); text-decoration: none; }
.saved-chat-collapse:hover { color: var(--text); text-decoration: underline; }

/* ---- Settings hub (sidebar + content) -------------------------------------- */
.settings-hub { display: flex; gap: 1.5rem; align-items: flex-start; }
.settings-nav {
  flex: 0 0 180px; display: flex; flex-direction: column; gap: .15rem;
  position: sticky; top: 1rem;
}
.settings-nav a {
  color: var(--muted); padding: .45rem .6rem; border-radius: 6px;
  border-left: 2px solid transparent;
}
.settings-nav a:hover { background: #232c36; color: var(--text); text-decoration: none; }
.settings-nav a.active { color: var(--text); background: #232c36; border-left-color: var(--accent); }
.settings-nav-group {
  color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  margin: .7rem .6rem .2rem;
}
.settings-content { flex: 1; min-width: 0; }
.settings-content h1 { margin-top: 0; }

/* ---- Patterns browser ------------------------------------------------------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: .8rem 1rem; align-items: flex-end; margin: 1rem 0; }
.filter-bar label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
.badge { padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; border: 1px solid var(--border); }
.badge-confirmed { color: var(--green); border-color: var(--green); }
.badge-forming { color: var(--amber); border-color: var(--amber); }
.badge-new { color: var(--accent); border-color: var(--accent); margin-left: .25rem; }
.filter-bar label.check { flex-direction: row; align-items: center; gap: .4rem; }
.ep-closed { opacity: .55; }
.tier-note { border: 1px solid var(--amber); border-radius: 6px; padding: .5rem .8rem; }

/* ---- Unified viewer (list + chart) ------------------------------------------ */
/* timeframe buttons are used in the viewer too (not just .chart-controls), so style
   the base + the selected-period highlight here (issue #31). */
.tf-btn { background: var(--panel); color: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: .25rem .6rem; cursor: pointer; }
.tf-btn:hover { color: var(--text); }
.tf-btn.active { background: var(--accent); color: #08233f; border-color: var(--accent); }
.viewer-actions { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: .4rem 0 .2rem; }
/* every action control shares one size/look (matching the Star button) */
.viewer-actions .star-btn,
.viewer-actions .btn-small {
  margin: 0; padding: .35rem .7rem; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font-size: .85rem; line-height: 1.3;
}
.viewer-actions .star-btn.on { color: var(--amber); border-color: var(--amber); }

/* Add-to-watchlist modal (matches the dark chat dialog) */
.wl-dialog { max-width: 420px; width: 92%; padding: 1.25rem; background: var(--panel);
  color: var(--text); border: 1px solid var(--border); border-radius: 10px; }
.wl-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.wl-dialog h3 { margin: 0 0 .9rem; }
.wl-dialog label { color: var(--muted); }
.wl-dialog menu { display: flex; gap: .5rem; justify-content: flex-end; padding: 0; margin: .6rem 0 0; }

/* ---- Responsive (phones) ---------------------------------------------------- */
/* Wrap any wide table in <div class="table-scroll"> to get horizontal scroll on narrow screens. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 720px) {
  .container { padding: 1rem; }

  /* collapsible nav: brand + ☰ stay; everything else drops into a panel */
  .topnav { padding: .5rem .8rem; }
  .nav-toggle { display: block; }
  .nav-collapse {
    display: none; flex-basis: 100%; flex-direction: column;
    align-items: stretch; gap: .25rem; margin-top: .5rem;
  }
  .topnav.nav-open .nav-collapse { display: flex; }
  .nav-links { flex-direction: column; align-items: stretch; gap: .25rem; }
  /* ≥44px touch targets */
  .nav-links a, .nav-menu > summary, .user-menu > summary { padding: .6rem .4rem; }
  /* nested dropdowns expand inline (not absolute) inside the panel */
  .nav-menu, .user-menu { position: static; }
  .nav-menu-items, .user-menu-items {
    position: static; box-shadow: none; border: none; padding-left: .8rem;
  }
  .user-menu > summary { max-width: none; }
  .nav-search { margin-left: 0; width: 100%; }
  .nav-search input { width: 100%; }

  /* layout: cards/forms go full-width, tables get a bit tighter */
  .cards { gap: .6rem; }
  .card { min-width: 0; flex: 1 1 100%; }
  .form-card { max-width: none; }
  table { font-size: .9rem; }
  th, td { padding: .4rem .5rem; }

  /* settings hub: sidebar becomes a horizontal strip above the content */
  .settings-hub { flex-direction: column; gap: 1rem; }
  .settings-nav {
    flex: none; flex-direction: row; flex-wrap: wrap; position: static; gap: .25rem;
    border-bottom: 1px solid var(--border); padding-bottom: .5rem;
  }
  .settings-nav a { border-left: none; border-bottom: 2px solid transparent; }
  .settings-nav a.active { border-left: none; border-bottom-color: var(--accent); }
  .settings-nav-group { width: 100%; margin: .3rem .3rem 0; }

  /* viewer: dots and the keyboard hint are desktop-only; navigate with the
     full-width prev/next buttons under the chart (or by tapping a chip). */
  .dot-rail { display: none; }
  .nav-hint-kbd { display: none; }
  .viewer-nav { display: flex; }
  /* bound the chart with the small (toolbar-collapsed) viewport so it can't lap
     over the prev/next buttons; dvh tracks the real visible height on mobile. */
  .chart-pane { height: 52svh; min-height: 260px; }
  /* the floated header score splits the narrow layout; it's already shown on the
     chips and the review-current line, so drop it here on mobile. */
  .chart-header .ch-score { display: none; }

  /* viewer title eats valuable space on mobile — shrink it and tighten line height */
  .viewer-title { font-size: 1.15rem; line-height: 1.2; }
  .viewer-title small { font-size: .75rem; }
}
