/* NewsDesk - mobile-first, dark by default, no external assets. */

:root {
  --bg: #0b0f14;
  --bg-elev: #111821;
  --bg-elev-2: #16202b;
  --line: #22303d;
  --line-soft: #1a2531;
  --text: #e6edf3;
  --text-dim: #93a4b5;
  --text-faint: #6b7d8f;
  --accent: #4ade80;
  --accent-ink: #052e16;
  --accent-soft: rgba(74, 222, 128, 0.12);
  --blue: #38bdf8;
  --blue-soft: rgba(56, 189, 248, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.38);
  --topbar-h: 54px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  --bg: #f4f6f8;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef2f5;
  --line: #d7dee5;
  --line-soft: #e6ebf0;
  --text: #101820;
  --text-dim: #56636f;
  --text-faint: #7b8894;
  --accent: #128a4a;
  --accent-ink: #ffffff;
  --accent-soft: rgba(18, 138, 74, 0.12);
  --blue: #0369a1;
  --blue-soft: rgba(3, 105, 161, 0.12);
  --red: #b91c1c;
  --red-soft: rgba(185, 28, 28, 0.1);
  --amber: #92400e;
  --amber-soft: rgba(146, 64, 14, 0.12);
  --shadow: 0 10px 26px rgba(16, 24, 32, 0.12);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* No global smooth scrolling: it turns every programmatic scroll restore
     (list refresh, sheet open) into an animation, which reads as jank. */
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--bg-elev);
  padding: 10px 14px;
  z-index: 100;
}
.skip:focus { left: 8px; top: 8px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.error { color: var(--red); font-size: 14px; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}

/* Sticky bars stay fully opaque on purpose. A backdrop-filter here has to be
   re-blurred on every scroll frame and, worse, it gets nested inside the sheet
   overlay blur, which makes the article modal scroll and the chat input lag. */

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand-name { font-size: 17px; }

.badge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.top-actions { display: flex; gap: 2px; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-dim);
  font-size: 19px;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.icon-btn.is-spinning { animation: spin 0.9s linear infinite; }

/* ------------------------------------------------------------------ tabs */

.tabs {
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  z-index: 29;
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tab.is-active {
  background: var(--bg-elev-2);
  border-color: var(--line);
  color: var(--text);
}

.tab-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* ------------------------------------------------------------------ views */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 12px calc(80px + env(safe-area-inset-bottom));
}

.view { display: none; }
.view.is-active { display: block; }

.filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.search-row { display: flex; gap: 8px; }

.search-row input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  -webkit-appearance: none;
}
.search-row input::placeholder { color: var(--text-faint); }
.search-row input:focus { border-color: var(--accent); outline: none; }

.search-row select,
.chip-select select {
  min-height: var(--tap);
  padding: 0 30px 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background-color: var(--bg-elev);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2393a4b5' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  -webkit-appearance: none;
  appearance: none;
  color: var(--text);
  font-size: 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.chips-scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 3px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips-scroll::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.chip:hover { color: var(--text); }
.chip.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.chip .chip-count { font-size: 11px; opacity: 0.75; }

.chip-select { display: inline-flex; }
.chip-select select {
  min-height: 32px;
  border-radius: 999px;
  font-size: 13px;
  padding-left: 12px;
}

/* ------------------------------------------------------------ story cards */

.cards { display: flex; flex-direction: column; gap: 9px; }

.card {
  position: relative;
  padding: 13px 14px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.card.is-unread { border-left: 3px solid var(--accent); padding-left: 12px; }
.card.is-read { opacity: 0.72; }
.card.is-read:hover { opacity: 1; }

.card-title {
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: -0.005em;
  margin-bottom: 5px;
}
.card.is-read .card-title { font-weight: 550; }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.card-meta .dot { opacity: 0.45; }

.card-snippet {
  font-size: 14px;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 9px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag[data-kind="ticker"] {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: transparent;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.tag[data-kind="section"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
}
.tag[data-kind="user"] {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: transparent;
}

.stock-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 9px;
}
.stock-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-family: var(--mono);
}
.stock-chip .up { color: var(--accent); }
.stock-chip .down { color: var(--red); }
.stock-chip .flat { color: var(--text-faint); }

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-faint);
}

.card-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.card-actions .mini {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
}
.card-actions .mini:hover { background: var(--bg-elev-2); color: var(--text); }
.card-actions .mini.is-on { color: var(--amber); border-color: var(--amber); }
.card-actions .mini[data-action="read"].is-on {
  color: var(--text-dim);
  border-color: var(--line);
}

.list-footer { padding: 16px 0 0; text-align: center; }

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
}

.spinner {
  width: 22px;
  height: 22px;
  margin: 24px auto;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}


/* ------------------------------------------------------------- stock list */

.stock-list { display: flex; flex-direction: column; gap: 9px; }

.stock-row {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "ident price"
    "range range"
    "metrics metrics"
    "votes votes";
  gap: 9px 12px;
}

.stock-ident { grid-area: ident; min-width: 0; }
.stock-ticker {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--blue);
}
.stock-name {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-price { grid-area: price; text-align: right; }
.stock-last { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stock-change { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.up { color: var(--accent); }
.down { color: var(--red); }
.flat { color: var(--text-faint); }

.stock-range { grid-area: range; }
.range-bar {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
}
.range-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--red), var(--amber), var(--accent));
  opacity: 0.45;
}
.range-marker {
  position: absolute;
  top: 50%;
  width: 3px;
  height: 14px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: var(--text);
  transform: translateY(-50%);
  box-shadow: 0 0 0 2px var(--bg-elev);
}
.range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.stock-metrics {
  grid-area: metrics;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 14px;
}
.metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px dashed var(--line-soft);
}
.metric .label { color: var(--text-faint); }
.metric .value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.stock-votes {
  grid-area: votes;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
}
.vote-pills { display: inline-flex; gap: 5px; }
.vote-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.vote-pill.up { background: var(--accent-soft); color: var(--accent); }
.vote-pill.down { background: var(--red-soft); color: var(--red); }
.vote-pill.flat { background: var(--bg-elev-2); color: var(--text-faint); }


/* ------------------------------------------------------------------ sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  /* Solid-ish scrim instead of a backdrop-filter blur: blurring the whole
     viewport behind a scrolling panel forces the compositor to re-blur on
     every repaint (scroll frames, keystrokes), which is the main source of
     the laggy modal on laptops without a strong GPU. */
  background: rgba(2, 6, 12, 0.74);
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  animation: slide-up 0.22s ease-out;
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  border-radius: 20px 20px 0 0;
}
.sheet-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Keep the modal's own scrolling from chaining to the page behind it. */
  overscroll-behavior: contain;
  padding: 16px 16px calc(36px + env(safe-area-inset-bottom));
}

.detail-kicker {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 6px;
}
.detail-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.detail-meta {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.detail-tags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }

.detail-section { margin-top: 22px; }
.detail-section h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 9px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
}

.prose { font-size: 15px; line-height: 1.62; color: var(--text); }
.prose > * + * { margin-top: 0.75em; }
.prose h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin-top: 1.4em;
  padding-top: 0.9em;
  border-top: 1px solid var(--line-soft);
}
.prose h3 { font-size: 15.5px; margin-top: 1.1em; }
.prose p { color: var(--text); }
.prose ul, .prose ol { padding-left: 1.2em; }
.prose li + li { margin-top: 0.3em; }
.prose strong { color: var(--text); }
.prose em { color: var(--text-dim); }
.prose code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--bg-elev-2);
}
.prose pre {
  overflow-x: auto;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-elev-2);
}
.prose pre code { padding: 0; background: none; }
.prose blockquote {
  margin: 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
}
.prose a { text-decoration: underline; text-underline-offset: 2px; }
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  display: block;
  overflow-x: auto;
}
.prose th, .prose td {
  padding: 5px 7px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
}
.prose th {
  color: var(--text-faint);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.prose td { font-variant-numeric: tabular-nums; }
.prose hr { border: 0; border-top: 1px solid var(--line-soft); }

.article-text { font-size: 15.5px; line-height: 1.68; color: var(--text); }
.article-text p + p { margin-top: 0.85em; }

.related-list { display: flex; flex-direction: column; gap: 6px; }
.related-item {
  display: block;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 13.5px;
}
.related-item:hover { border-color: var(--accent); text-decoration: none; }
.related-item .muted { font-size: 11.5px; }


/* ---------------------------------------------------------------- buttons */

.btn {
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.btn:hover { border-color: var(--text-faint); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-danger { color: var(--red); border-color: var(--red); background: var(--red-soft); }
.btn-wide { width: 100%; }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

/* ---------------------------------------------------------------- panels */

.panel {
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  margin-bottom: 10px;
}
.panel h2 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 8px;
}

.facts {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 5px 14px;
  margin: 8px 0 0;
  font-size: 13px;
}
.facts dt { color: var(--text-faint); }
.facts dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.hint {
  margin: 10px 0 0;
  padding-left: 1.2em;
  font-size: 13px;
  color: var(--text-dim);
}
.hint li + li { margin-top: 5px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 14px;
}

.tag-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.tag-form input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
}
.tag-form input:focus { border-color: var(--accent); outline: none; }

.tag-remove {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
  margin-left: -4px;
}
.tag-remove:hover { color: var(--red); }

@media (min-width: 720px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 460px);
  padding: 11px 16px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}
.toast[hidden] { display: none; }
.toast.is-error { border-color: var(--red); }

/* ----------------------------------------------------------------- login */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 15% 0%, rgba(74, 222, 128, 0.09), transparent 42%),
    radial-gradient(circle at 90% 10%, rgba(56, 189, 248, 0.08), transparent 40%),
    var(--bg);
}

.login-wrap { width: 100%; max-width: 380px; }

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 30px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 { font-size: 23px; font-weight: 750; letter-spacing: -0.01em; }
.login-card > p { font-size: 13.5px; }

.field {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.field span { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.field input {
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
.field input:focus { border-color: var(--accent); outline: none; }

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  font-size: 13px;
  color: var(--text-dim);
  text-align: left;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ------------------------------------------------------------- responsive */

@media (min-width: 720px) {
  main { padding: 18px 20px 90px; }
  .search-row input { max-width: 420px; }
  .cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { margin: 0; }
  .stock-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sheet { align-items: center; }
  .sheet-panel {
    max-width: 860px;
    max-height: 86dvh;
    border-radius: 20px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0;
  }
  .sheet-head { border-radius: 20px 20px 0 0; }
  .sheet-body { padding: 22px 26px 32px; }
  .detail-title { font-size: 26px; }
  .stock-row {
    grid-template-columns: minmax(150px, 1.1fr) auto minmax(180px, 1.2fr) minmax(210px, 1.5fr);
    grid-template-areas:
      "ident price range metrics"
      "votes votes votes votes";
    align-items: center;
  }
  .stock-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ------------------------------------------------------------- animations */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide-up {
  from { transform: translateY(18px); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toast-in {
  from { transform: translate(-50%, 8px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}


/* ------------------------------------------------- summaries and model */

.summary-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 2px 0 7px;
}

.summary-action { display: inline-flex; align-items: center; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.busy { background: var(--blue-soft); color: var(--blue); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.idle { background: var(--bg-elev-2); color: var(--text-faint); }

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 3px var(--bg-elev-2);
}
.status-dot.ok { background: var(--accent); }
.status-dot.busy { background: var(--blue); animation: pulse 1.2s ease-in-out infinite; }
.status-dot.warn { background: var(--amber); }
.status-dot.bad { background: var(--red); }
.status-dot.idle { background: var(--text-faint); }

.model-line {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 8px 0 10px;
}
.model-line .status-dot { margin-top: 5px; }
.model-state { font-size: 14.5px; font-weight: 650; }

.summary-panel { padding: 12px 14px; }
.summary-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.missing-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.missing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-elev);
  font-size: 12.5px;
}
.missing-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.missing-row b {
  color: var(--blue);
  font-family: var(--mono);
  margin-right: 4px;
}
.missing-row .mini { flex: 0 0 auto; }

.article-row { display: block; }
.article-row a { font-weight: 600; }
.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.row-actions .mini { min-height: 28px; font-size: 11.5px; }

/* ------------------------------------------------------------------ chat */

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 0 10px;
  -webkit-overflow-scrolling: touch;
}
.chat-bubble {
  max-width: 92%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  /* Isolate layout/paint so a streaming bubble does not invalidate the
     whole modal on every token. */
  contain: content;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.chat-bubble.typing { color: var(--text-dim); font-style: italic; }
.chat-bubble.streaming { border-color: var(--accent); }
.chat-bubble p { margin: 0; }
.chat-bubble p + p { margin-top: 0.6em; }
.chat-bubble ul, .chat-bubble ol { margin: 0.4em 0; padding-left: 1.1em; }
.chat-bubble table { font-size: 11.5px; }
.chat-pending { color: var(--text-dim); font-style: italic; }
.chat-model {
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--text-dim);
  opacity: 0.8;
  overflow-wrap: anywhere;
}

.chat-reasoning {
  margin-bottom: 8px;
  padding: 6px 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.chat-reasoning summary {
  cursor: pointer;
  font-size: 11.5px;
  color: var(--text-dim);
  user-select: none;
}
.chat-reasoning-text {
  margin-top: 6px;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
}

.chat-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 7px;
}
.chat-tool {
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.chat-tool.is-error { border-color: #b3261e66; color: #d95c5c; }
.chat-sources {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 8px;
}
.chat-sources a {
  color: var(--accent);
  font-size: 11.5px;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.chat-sources a:hover { text-decoration: underline; }
.chat-notice {
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 11.5px;
  font-style: italic;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-form textarea {
  flex: 1 1 auto;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  resize: vertical;
}
.chat-form textarea:focus { border-color: var(--accent); outline: none; }
.chat-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}
.chat-meta .btn { min-height: 32px; padding: 0 10px; font-size: 12px; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

