/**
 * Ask Boyd's — dedicated /ask page styles.
 * Loaded via $extra_css only on the /ask view.
 *
 * Note: home-page Ask panel no longer uses .ask-msgs (it redirects to /ask).
 * Full conversation styles live under body[data-page="ask"] below.
 */

:root {
  --ask-chrome: var(--header-h, 72px);
}

/* ─── Immersive /ask: edge-to-edge below fixed header ─── */
body[data-page="ask"] {
  height: 100dvh;
  overflow: hidden;
  background: var(--bg, #f4f6f8);
}

body[data-page="ask"] .site-footer,
body[data-page="ask"] .ask-fab,
body[data-page="ask"] .breadcrumbs {
  display: none !important;
}

body[data-page="ask"] main.page-offset--ask {
  position: fixed;
  top: var(--ask-chrome);
  left: 0;
  right: 0;
  bottom: var(--mobile-call-bar-h, 0px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
  box-sizing: border-box;
}

/* Two-column grid — fills fixed main */
body[data-page="ask"] .ask-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 10px 20px 14px;
  box-sizing: border-box;
}

/* ─── Conversation column ─── */
body[data-page="ask"] .ask-conv {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow, 0 1px 3px rgba(0,0,0,0.06));
  overflow: hidden;
}

.ask-conv__head {
  flex: 0 0 auto;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
}
.ask-conv__title {
  font-size: 17px;
  font-weight: 800;
  margin: 0;
  color: var(--ink);
}
.ask-conv__subtitle {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 0;
}
.ask-history-btn {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-blue);
  padding: 6px 10px;
  border: 1px solid var(--brand-blue);
  border-radius: var(--radius);
  white-space: nowrap;
}
.ask-history-btn:hover { background: var(--brand-blue-light); }

/* History drawer overlay */
.ask-history {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  max-height: 60vh;
  overflow-y: auto;
  display: none;
}
.ask-history.is-open { display: block; }
.ask-history__head {
  padding: 12px 16px;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.ask-history__close {
  font-size: 20px;
  color: var(--muted);
  padding: 2px 6px;
}
.ask-history__list { list-style: none; margin: 0; padding: 0; }
.ask-history__item { border-bottom: 1px solid var(--border); }
.ask-history__item button {
  width: 100%;
  text-align: left;
  padding: 11px 16px;
  font-size: 13px;
  line-height: 1.4;
}
.ask-history__item button:hover { background: var(--surface-alt); }
.ask-history__item-title {
  font-weight: 700;
  color: var(--ink);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.ask-history__item-meta { font-size: 11px; color: var(--muted); }
.ask-history__empty { padding: 20px 16px; font-size: 13px; color: var(--muted); text-align: center; }
.ask-history-outer { position: relative; }

/* Messages — grows to fill; composer stays at bottom */
body[data-page="ask"] .ask-msgs {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-content: flex-start;
  background: transparent;
  border-radius: 0;
  font-size: inherit;
  -webkit-overflow-scrolling: touch;
  scroll-padding-top: 12px;
  overscroll-behavior: contain;
}

.ask-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  max-width: 340px;
}
.ask-empty__icon { font-size: 42px; margin-bottom: 12px; opacity: 0.4; }
.ask-empty__head { font-size: 18px; font-weight: 800; margin: 0 0 8px; color: var(--ink); }
.ask-empty__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}
.ask-empty__chip {
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
}
.ask-empty__chip:hover { border-color: var(--brand-blue); color: var(--brand-blue); background: var(--brand-blue-light); }

/* Individual messages */
.ask-msg { display: flex; flex-direction: column; gap: 4px; max-width: 92%; flex-shrink: 0; }
.ask-msg--user { align-self: flex-end; align-items: flex-end; }
.ask-msg--bot  { align-self: flex-start; align-items: flex-start; }
.ask-msg__role { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.ask-msg__bubble {
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 16px;
  line-height: 1.65;
  word-break: break-word;
}
.ask-msg--user .ask-msg__bubble {
  background: var(--brand-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ask-msg--bot .ask-msg__bubble {
  background: var(--surface-alt);
  color: var(--ink);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.ask-msg--thinking .ask-msg__bubble { color: var(--muted); font-style: italic; }
.ask-msg--error .ask-msg__bubble { background: #fff5f5; border-color: #fecaca; color: #b91c1c; }

.ask-msg__bubble p { margin: 0 0 8px; }
.ask-msg__bubble p:last-child { margin: 0; }
.ask-msg__bubble ul { margin: 8px 0; padding-left: 20px; }
.ask-msg__bubble li { margin-bottom: 4px; }
.ask-msg__bubble strong { font-weight: 700; }

.ask-table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  -webkit-overflow-scrolling: touch;
}
.ask-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.4;
}
.ask-table th,
.ask-table td {
  border: 1px solid var(--border, #d8dee6);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.ask-table th {
  background: var(--bg, #f4f6f8);
  font-weight: 700;
}
.ask-table tr:nth-child(even) td { background: rgba(0, 0, 0, 0.02); }

/* Composer — pinned to bottom of card */
body[data-page="ask"] .ask-composer {
  flex: 0 0 auto;
  margin-top: auto;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.ask-composer__textarea {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
.ask-composer__textarea:focus { border-color: var(--brand-blue); outline: none; }
.ask-composer__send {
  flex-shrink: 0;
  padding: 10px 18px;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  background: var(--brand-blue);
  border-radius: 12px;
  height: 44px;
  white-space: nowrap;
}
.ask-composer__send:disabled { opacity: 0.5; cursor: not-allowed; }
.ask-composer__send:not(:disabled):hover { background: var(--brand-blue-dark, #005ba4); }

/* ─── Rail ─── */
body[data-page="ask"] .ask-rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}
.ask-rail__head {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  width: 100%;
  font-family: inherit;
  cursor: default;
}
.ask-rail__body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}
.ask-rail__section { display: flex; flex-direction: column; gap: 8px; }
.ask-rail__section-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-blue);
}
.ask-rail__empty { font-size: 13px; color: var(--muted); text-align: center; padding: 20px 0; }

.ask-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
}
.ask-card:hover { border-color: var(--brand-blue); box-shadow: 0 2px 8px rgba(0,114,206,0.12); }
.ask-card__swatch {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.08);
}
.ask-card__img {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 6px;
  background: var(--surface-alt);
}
.ask-card__icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--brand-blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.ask-card__body { min-width: 0; flex: 1; }
.ask-card__label {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  color: var(--ink);
}
.ask-card__sub { font-size: 11px; color: var(--muted); margin-top: 1px; display: block; }
.ask-card__arrow { flex-shrink: 0; font-size: 13px; color: var(--muted); }
.ask-card--store { border-color: var(--brand-red); }
.ask-card--store .ask-card__icon { background: #fff5f5; }
.ask-card--store .ask-card__label { color: var(--brand-red); }

.ask-banner {
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 16px;
  font-size: 13px;
  border-radius: 0;
  border-bottom: 1px solid #fecaca;
  background: #fff5f5;
  color: #b91c1c;
}
.ask-banner[hidden] { display: none !important; }

/* Hide energy picker on /ask — overlaps composer on mobile */
body[data-page="ask"] .energy-picker { display: none; }

@media (max-width: 900px) {
  body[data-page="ask"] .ask-page {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 16px 10px;
    overflow: hidden;
  }
  /* Conversation fills leftover viewport; Related stays a compact strip */
  body[data-page="ask"] .ask-conv {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
  }
  body[data-page="ask"].ask-has-reply .ask-conv {
    flex: 1 1 auto;
    min-height: 0;
  }
  body[data-page="ask"] .ask-rail {
    flex: 0 0 auto;
    max-height: 28vh;
    height: auto;
  }
  body[data-page="ask"].ask-has-reply .ask-rail {
    max-height: none;
    overflow: hidden;
    padding: 10px 14px;
    flex: 0 0 auto;
  }
  body[data-page="ask"].ask-has-reply .ask-rail:not(.ask-rail--open) .ask-rail__body {
    display: none;
  }
  body[data-page="ask"].ask-has-reply .ask-rail__head {
    cursor: pointer;
    color: var(--brand-blue);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  body[data-page="ask"].ask-has-reply .ask-rail__head::after {
    content: 'Show';
    font-size: 12px;
    letter-spacing: 0;
    text-transform: none;
    font-weight: 700;
  }
  body[data-page="ask"].ask-has-reply .ask-rail--open .ask-rail__head::after {
    content: 'Hide';
  }
  /* Cap Related so the chat pane stays the main reading area */
  body[data-page="ask"].ask-has-reply .ask-rail--open {
    max-height: min(30vh, 220px);
    overflow-y: auto;
    flex: 0 0 auto;
  }
  body[data-page="ask"] .ask-msgs {
    flex: 1 1 auto;
    min-height: 120px;
  }
  .ask-msg__bubble { font-size: 15px; }
}
@media (max-width: 560px) {
  body[data-page="ask"] .ask-page { padding: 8px 12px 10px; }
  body[data-page="ask"] .ask-msgs { padding: 12px 14px 16px; gap: 14px; }
  body[data-page="ask"] .ask-composer { padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
  .ask-conv__head { padding: 10px 14px; }
}
