/* Shas Radar — mobile-first RTL stylesheet.
   A distinct identity from פסוק לשם's green: deep indigo/navy with a gold
   accent, evoking ink on an old page rather than the Tanakh app's look. */

:root {
  color-scheme: light dark;

  --bg: #f3f1ea;
  --surface: #fffdf8;
  --surface-2: #ece8dc;
  --text: #211f1a;
  --text-soft: #5c574a;
  --text-faint: #8a8372;
  --line: #ddd6c4;

  --accent: #2b3a55;
  --accent-soft: #e3e6ee;
  --accent-text: #1f2c42;
  --gold: #a3792f;
  --gold-soft: #f3e6cc;

  --exact-bg: #f3e6cc;
  --exact: #8a5a15;
  --prefix-bg: #e3e6ee;
  --prefix: #2b3a55;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(33, 31, 26, .06), 0 4px 16px rgba(33, 31, 26, .05);

  --font: "Heebo", system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", Arial, sans-serif;
  --font-verse: "Frank Ruhl Libre", "Times New Roman", var(--font);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151f;
    --surface: #1a1f2c;
    --surface-2: #232a3a;
    --text: #ecebe5;
    --text-soft: #aba894;
    --text-faint: #7c7968;
    --line: #303748;

    --accent: #7c93c4;
    --accent-soft: #1e2536;
    --accent-text: #a9bce0;
    --gold: #d4ac66;
    --gold-soft: #3a2f1a;

    --exact-bg: #3a2f1a;
    --exact: #d4ac66;
    --prefix-bg: #1e2536;
    --prefix: #7c93c4;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

.wrap {
  width: 100%;
  max-width: 44rem;
  margin-inline: auto;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

/* --- Header --- */

.header {
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-text) 100%);
  color: #fff;
  padding: calc(1.5rem + env(safe-area-inset-top)) 0 1.5rem;
  text-align: center;
}
.header-wrap { display: flex; flex-direction: column; align-items: center; }
.title {
  font-family: var(--font-verse);
  font-size: clamp(1.9rem, 7vw, 2.5rem);
  font-weight: 700;
  margin: 0 0 .25rem;
  letter-spacing: -.01em;
  direction: ltr;
}
/* pre-line: header.subtitle carries a literal newline (see i18n.js) to
   force a two-line break at a fixed point, rather than wrapping wherever
   the viewport happens to run out of room. */
.subtitle { margin: 0; opacity: .88; font-size: .95rem; white-space: pre-line; }

/* --- Header icon + settings button ---
   icon+title+gear, matching KanDOne's header (AppBrandMark + title + a
   Settings entry point). The settings button is absolutely positioned so
   the icon+title pair still centers as a group. */

.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  position: relative;
  width: 100%;
}
.app-icon {
  flex: 0 0 auto;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 10px;
  object-fit: cover;
  background: rgba(255, 255, 255, .18);
}
.settings-btn {
  position: absolute;
  inset-inline-end: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .4);
  background: rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
  transition: background .15s;
}
.settings-btn:hover { background: rgba(255, 255, 255, .24); }
.settings-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* --- Language switch ---
   Now rendered only inside the settings dialog (see the
   .ai-settings-dialog .lang-switch override further down), not in the
   header banner. */

.lang-switch {
  display: flex;
  gap: .3rem;
  background: rgba(255, 255, 255, .14);
  border-radius: 999px;
  padding: .25rem;
}
.lang-btn {
  font: 500 .8rem var(--font);
  color: #fff;
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: .35rem .75rem;
  min-height: 32px;
  opacity: .75;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.lang-btn:hover { opacity: 1; }
.lang-btn.active {
  background: #fff;
  color: var(--accent-text);
  opacity: 1;
  font-weight: 700;
}

/* --- Search --- */

.search {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-top: -1.25rem;
  position: relative;
  z-index: 1;
}
.label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-soft);
  margin-bottom: .5rem;
}
.label-inline { margin-bottom: .35rem; }
/* :not([hidden]) so the book picker's `hidden` attribute still hides it (see the
   note on .connections-btn below). */
.field:not([hidden]) { display: flex; gap: .5rem; }
.field-filter { flex-direction: column; margin-top: .9rem; }
.input {
  flex: 1;
  min-width: 0;
  font: 500 1.05rem var(--font);
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .75rem .85rem;
  min-height: 48px;
  max-height: 8.5rem;
  text-align: right;
  resize: none;
  overflow-y: auto;
  line-height: 1.3;
}
.input::placeholder { color: var(--text-faint); font-weight: 400; font-size: .85rem; }
.select {
  font: 500 .95rem var(--font);
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .65rem .75rem;
  min-height: 44px;
}
.input:focus-visible,
.submit:focus-visible,
.clear:focus-visible,
.chip:focus-visible,
.copy:focus-visible,
.more:focus-visible,
.stepper-btn:focus-visible,
.select:focus-visible,
.settings-btn:focus-visible,
.settings-install-btn:focus-visible,
.dialog-close:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}
/* Clear: resets the search and drops the query from the URL. A quiet
   companion to Search rather than a second primary action -- same height so
   the row stays level, but outlined and square, and only shown when there is
   something to clear (see syncClearButton in app.js). */
.clear {
  flex: 0 0 auto;
  min-height: 48px;
  min-width: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 500 1.05rem var(--font);
  color: var(--text-soft);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.clear:hover {
  color: var(--text);
  border-color: var(--text-soft);
}

.submit {
  flex: 0 0 auto;
  min-height: 48px;
  padding-inline: 1.35rem;
  font: 700 1rem var(--font);
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform .08s ease, opacity .15s ease;
}
.submit:active { transform: scale(.97); }
.submit[disabled] { opacity: .6; cursor: progress; }

/* --- Stepper controls (before/after word count) --- */

.controls {
  display: flex;
  gap: .6rem;
  margin-top: .9rem;
}
.stepper { flex: 1; }
.stepper-label {
  display: block;
  font-size: .78rem;
  color: var(--text-soft);
  margin-bottom: .3rem;
}
.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .3rem;
}
.stepper-btn {
  width: 36px;
  height: 36px;
  font: 700 1.1rem var(--font);
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
}
.stepper-btn:active { transform: scale(.93); }
.stepper-value {
  font: 700 1.05rem var(--font);
  font-variant-numeric: tabular-nums;
  min-width: 1.6rem;
  text-align: center;
}

/* --- How it works / hint --- */

.how-it-works {
  margin-top: .9rem;
  font-size: .85rem;
  color: var(--text-soft);
}
.how-it-works summary { cursor: pointer; color: var(--accent-text); font-weight: 500; padding: .3rem 0; }
.how-it-works p { margin: .4rem 0 0; }
.how-it-works p + p { margin-top: .3rem; }

/* --- Example chips --- */

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; }
.chip {
  font: 500 .85rem var(--font);
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: .45rem .8rem;
  min-height: 36px;
  cursor: pointer;
}
.chip:active { transform: scale(.97); }

/* --- Waking notice --- */

/* :not([hidden]) so the notice's `hidden` attribute still hides it (see the
   note on .connections-btn below). */
.waking:not([hidden]) {
  display: flex;
}
.waking {
  align-items: center;
  gap: .55rem;
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  padding: .65rem .9rem;
  margin-top: 1rem;
}
.waking-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .35; transform: scale(.85); }
  50%      { opacity: 1;   transform: scale(1); }
}

/* --- Results --- */

.results { margin-top: 1.5rem; }

.group { margin-bottom: 2rem; }
.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .1rem;
}
.group-title {
  font-family: var(--font-verse);
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0;
}
.group-count {
  font-size: .8rem;
  color: var(--text-faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.group-breakdown {
  font-size: .82rem;
  color: var(--text-soft);
  margin: .2rem 0 .9rem;
}
.tag-exact, .tag-prefix {
  display: inline-block;
  border-radius: 999px;
  padding: .05rem .5rem;
  font-weight: 600;
}
.tag-exact { background: var(--exact-bg); color: var(--exact); }
.tag-prefix { background: var(--prefix-bg); color: var(--prefix); }

.group-subheading {
  margin: 1.25rem 0 .6rem;
  padding-top: .9rem;
  border-top: 1px dashed var(--line);
  font: 700 .8rem var(--font);
  color: var(--prefix);
  text-align: center;
}
.group-subheading:first-child { margin-top: 0; padding-top: 0; border-top: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .9rem 1rem 1rem;
  margin-bottom: .75rem;
}
.card-head {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  margin-bottom: .55rem;
}
.badge {
  font-size: .78rem;
  font-weight: 500;
  border-radius: 999px;
  padding: .18rem .6rem;
  background: var(--surface-2);
  color: var(--text-soft);
  white-space: nowrap;
}
.badge-tractate { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.badge a { color: inherit; text-decoration: underline; }

.kwic {
  font-family: var(--font-verse);
  font-size: 1.15rem;
  line-height: 2;
  margin: 0;
  direction: rtl;
  unicode-bidi: isolate;
}
.kwic .context { color: var(--text-soft); }
.kwic .match {
  font-weight: 700;
  background: var(--gold-soft);
  color: var(--gold);
  border-radius: 4px;
  padding: 0 .25em;
}

.paragraph {
  margin: .6rem 0 0;
  font-size: .85rem;
}
.paragraph summary { cursor: pointer; color: var(--accent-text); font-weight: 500; }
.paragraph-text {
  margin: .5rem 0 0;
  padding: .65rem .8rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-verse);
  font-size: 1.05rem;
  line-height: 1.9;
  direction: rtl;
}

/* Row of per-result actions (copy/share/Sefaria/select-for-AI). Sized to
   fit one row without scrolling on an ordinary phone width; overflow-x
   stays as a safety net for a genuinely narrow viewport rather than the
   normal path. */
.card-foot {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: flex-start;
  gap: .35rem;
  margin-top: .6rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.card-foot::-webkit-scrollbar { display: none; }
.copy {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font: 500 .78rem var(--font);
  color: var(--text-soft);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .3rem .55rem;
  min-height: 34px;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.copy:active { transform: scale(.97); }
.copy.done { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* .select-ai is a `.copy` too -- same pill, same 34px row, same spot in
   card-foot as the copy/Sefaria buttons (moved here from a separate label
   above the card, which read as unrelated to this card's other actions). */
.select-ai {
  user-select: none;
}
.select-ai .select-ai-checkbox {
  width: 15px;
  height: 15px;
  accent-color: var(--gold);
  cursor: pointer;
  flex-shrink: 0;
}
.select-ai.checked { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }

.more-wrap { margin-top: .25rem; }
.more {
  display: block;
  width: 100%;
  min-height: 44px;
  font: 500 .9rem var(--font);
  color: var(--accent-text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.more:disabled { opacity: .6; cursor: default; }

.empty, .error {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  color: var(--text-soft);
}
.empty strong, .error strong { color: var(--text); display: block; margin-bottom: .4rem; }
.error { border-color: var(--gold); }

.connections { margin-top: .5rem; margin-bottom: 2rem; }
/* :not([hidden]) rather than an unconditional `display`: an author rule
   that sets `display` unconditionally beats the UA stylesheet's own
   `[hidden] { display: none }` (author styles always outrank UA styles,
   regardless of selector specificity), so setting el.hidden = true from JS
   silently did nothing and the button was stuck showing "מחפש קשר…" long
   after the request had actually finished. */
.connections-btn:not([hidden]) { display: block; }
.connections-btn {
  width: 100%;
  min-height: 44px;
  font: 500 .9rem var(--font);
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.connections-btn:disabled { opacity: .6; cursor: default; }
.connections-hint:not([hidden]) { display: block; }
.connections-hint {
  margin: 0 0 .5rem;
  font-size: .82rem;
  color: var(--text-soft);
  text-align: center;
}
.connections-body { margin-top: .75rem; }
.connections.answered .connections-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .9rem 1rem 1rem;
}
.connections-answer-label {
  margin: 0 0 .35rem;
  font-size: .78rem;
  font-weight: 700;
  color: var(--gold);
}
.connections-text { margin: 0; line-height: 1.7; color: var(--text); }
.connections-chat-btn { margin-top: .7rem; }

.connections-links:not([hidden]) { display: flex; }
.connections-links {
  flex-wrap: wrap;
  gap: .5rem 1rem;
  margin-top: .5rem;
  justify-content: center;
}
.connections-settings-link {
  background: none;
  border: none;
  padding: 0;
  font: 500 .8rem var(--font);
  color: var(--text-soft);
  text-decoration: underline;
  cursor: pointer;
}
.connections-settings-link:hover { color: var(--accent-text); }
.connections-external-wrap { margin-top: .6rem; }

/* The "find connections" no-key state (see noProviderNotice in app.js) --
   one box, not an error notice followed by a separately-styled paragraph:
   that read as "the message ended" and the actual next steps underneath it
   went unread. */
.connections-noprovider {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.1rem;
}
.connections-noprovider-reason { margin: 0 0 .3rem; font-weight: 700; color: var(--text); }
.connections-noprovider-cta { margin: 0 0 .7rem; font-size: .82rem; color: var(--text-soft); }
.connections-noprovider-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem 1rem;
  margin-bottom: .5rem;
}
.connections-ask-favorite-btn {
  min-height: 40px;
  padding: 0 1rem;
  font: 600 .85rem var(--font);
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}
.connections-ask-favorite-btn:hover { opacity: .9; }

/* One line rather than wrapping: nowrap + horizontal scroll, same treatment
   as .card-foot above -- with Groq/Google AI Mode added, five labeled links
   don't reliably fit a narrow phone's width otherwise. */
.external-links {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: .4rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.external-links::-webkit-scrollbar { display: none; }
.external-link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  font: 500 .78rem var(--font);
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: .25rem .65rem;
  white-space: nowrap;
  text-decoration: none;
}
.external-link:hover { opacity: .85; }

.skeleton .line {
  height: 1rem;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  margin-bottom: .6rem;
}
.skeleton .line:nth-child(1) { width: 35%; }
.skeleton .line:nth-child(3) { width: 80%; }
.skeleton .line:last-child { margin-bottom: 0; }
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* --- Toast --- */

.toast {
  position: fixed;
  inset-inline: 0;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  margin-inline: auto;
  width: max-content;
  max-width: 90vw;
  background: var(--text);
  color: var(--bg);
  font-size: .9rem;
  font-weight: 500;
  padding: .65rem 1.1rem;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(.75rem);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* --- Footer --- */

.footer {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-size: .8rem;
  color: var(--text-faint);
  text-align: center;
}
.footer a { color: var(--accent-text); }
#footer-attribution { margin-bottom: .2rem; }
.footer-credit {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .9rem;
  margin-bottom: 0;
  font-size: .75rem;
  color: var(--text-faint);
}
.footer-credit a { display: inline-flex; color: var(--text-faint); }
.footer-credit a:hover { color: var(--accent-text); }
.footer-links {
  display: inline-flex;
  align-items: center;
  gap: .1rem;
  margin-inline-start: .25rem;
}
.footer-links a {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .15rem;
  text-decoration: none;
  padding: .4rem .5rem;
  border-radius: .5rem;
  transition: background-color .15s ease, transform .1s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(128, 128, 128, .35);
}
.footer-link-label {
  font-size: .62rem;
  line-height: 1;
  color: var(--text-faint);
}
.footer-links a:hover { background-color: var(--surface-2); }
.footer-links a:active { background-color: var(--surface-2); transform: scale(.88); }
.footer-links svg { display: block; }
.settings-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-inline-start: 0;
}

/* --- AI settings dialog ---
   Also holds the install action and the language switcher, each as its own
   .settings-section above the AI one (see index.html) -- the header banner
   above only carries the icon, title, and the gear button that opens this
   dialog. */

.ai-settings-dialog {
  width: min(92vw, 30rem);
  max-height: min(88vh, 40rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
  color: var(--text);
  /* A browser too old for showModal()'s top-layer placement (app.js falls
     back to a plain `open` attribute there) still needs to render above
     everything else on the page. */
  z-index: 100;
}
.ai-settings-dialog::backdrop { background: rgba(20, 16, 8, .5); }
.ai-settings-form { padding: 1.25rem; overflow-y: auto; }

.ai-settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .6rem;
}
.ai-settings-head h2 { margin: 0; font-family: var(--font-verse); font-size: 1.2rem; }
.dialog-close {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  min-height: 32px;
  font-size: .9rem;
  color: var(--text-soft);
  cursor: pointer;
}

.settings-section + .settings-section {
  margin-top: 1.1rem;
  padding-top: 1.1rem;
  border-top: 1px dashed var(--line);
}
.settings-section-title {
  margin: 0 0 .6rem;
  font-size: .85rem;
  font-weight: 700;
  color: var(--text-soft);
}
/* Inside the dialog the lang switch sits on a light surface, not the
   header's colored background, so it needs its own readable palette rather
   than the white-on-color one further up this file. */
.ai-settings-dialog .lang-switch { background: var(--surface-2); }
.ai-settings-dialog .lang-btn { color: var(--text-soft); }
.ai-settings-dialog .lang-btn:hover { opacity: 1; color: var(--text); }
.ai-settings-dialog .lang-btn.active { background: var(--accent); color: #fff; }

/* Install: a full-width row, same shell as .connections-btn below --
   moved here from a fixed corner FAB (see the HTML comment above it in
   index.html) so the header stays icon + title + the one settings entry
   point. Hidden by default; app.js reveals it once the page isn't already
   running standalone. */
.settings-install-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  width: 100%;
  min-height: 44px;
  font: 600 .9rem var(--font);
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-install-btn:hover { opacity: .92; }
.settings-install-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.ai-settings-desc, .ai-settings-trust {
  font-size: .82rem;
  line-height: 1.6;
  color: var(--text-soft);
  margin: 0 0 .6rem;
}
.ai-settings-trust { font-size: .75rem; color: var(--text-faint); }

.ai-settings-server-note {
  font-size: .8rem;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: .5rem .7rem;
  margin: 0 0 .8rem;
}

/* The mounted <ModelPicker> island (frontend/src/main.tsx) styles its own
   contents via modeldispatcher-react-ui's stylesheet -- this just gives it
   dialog-appropriate vertical spacing on either side. */
#ai-model-picker-root { margin-bottom: .8rem; }

/* modeldispatcher-react-ui/styles.css (vendored, generated -- see
   frontend/README.md -- never hand-edit static/vendor/model-picker/main.css
   itself) hardcodes a single light palette on its own --md-* custom
   properties with no dark variant, so in this app's dark theme its near-
   black --md-text/--md-surface render almost invisibly on this dialog's
   dark background. Re-declared here instead: every selector below matches
   one in that stylesheet that sets these vars (or, for .md-conversation-
   intro, a literal color with no var at all) -- an ID-scoped selector
   always outranks its plain-class one on specificity, so this wins
   regardless of which stylesheet loads second (main.css is injected into
   <head> on first dialog open, after this file). */
@media (prefers-color-scheme: dark) {
  #ai-model-picker-root .md-picker {
    --md-accent: var(--accent);
    --md-accent-ink: #fff;
    --md-accent-soft: var(--accent-soft);
    --md-border: var(--line);
    --md-text: var(--text);
    --md-text-muted: var(--text-soft);
    --md-danger: #f87171;
    --md-success: #4ade80;
    --md-surface: var(--surface-2);
    --md-surface-muted: var(--surface-2);
  }
  #ai-model-picker-root .md-ask-externally,
  #ai-model-picker-root .md-no-provider {
    --md-accent: var(--accent);
    --md-accent-ink: #fff;
    --md-border: var(--line);
    --md-text-muted: var(--text-soft);
  }
  #ai-model-picker-root .md-paste-reply {
    --md-accent: var(--accent);
    --md-accent-ink: #fff;
    --md-border: var(--line);
    --md-text: var(--text);
    --md-text-muted: var(--text-soft);
    --md-surface: var(--surface-2);
  }
  #ai-model-picker-root .md-conversation-intro {
    background: var(--surface-2);
    color: var(--text-soft);
  }
}

.ai-settings-note { font-size: .75rem; color: var(--text-faint); line-height: 1.5; margin: 0; }

.install-help-dialog { width: min(92vw, 22rem); }
.install-help-steps {
  margin: .9rem 0 0;
  padding-inline-start: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  font-size: .95rem;
  line-height: 1.5;
  color: var(--text);
}
.install-help-steps li { padding-inline-start: .3rem; }

/* --- AI chat dialog ---
   Same shell as .ai-settings-dialog above (native <dialog>, showModal()),
   just laid out as a column so the message list can grow/scroll between a
   fixed header and composer -- see openAiChat/sendChatMessage in app.js. */

/* [open] guard matters here: an unconditional `display: flex` is an author
   rule, which always outranks the UA stylesheet's own
   `dialog:not([open]) { display: none }` regardless of specificity -- so
   without it this dialog would render inline in the page flow even while
   closed (see .connections-btn's own such note above for the same
   author-vs-UA-stylesheet reasoning). */
.ai-chat-dialog[open] { display: flex; flex-direction: column; }
.ai-chat-form { display: flex; flex-direction: column; min-height: 0; }

.ai-chat-messages {
  flex: 1;
  min-height: 8rem;
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  padding-inline-end: .1rem; /* room for the scrollbar, not under the text */
}
.ai-chat-bubble {
  margin: 0;
  max-width: 88%;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  line-height: 1.6;
}
.ai-chat-bubble-assistant { align-self: flex-start; background: var(--surface-2); color: var(--text); }
.ai-chat-bubble-user { align-self: flex-end; background: var(--accent-soft); color: var(--accent-text); }
.ai-chat-bubble-pending { opacity: .65; }
.ai-chat-bubble-error {
  align-self: stretch;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}
.ai-chat-bubble-error .connections-settings-link { display: block; margin-top: .4rem; }

.ai-chat-composer { display: flex; gap: .5rem; margin-top: .75rem; }
.ai-chat-composer .ai-chat-input { flex: 1; }

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