/* Council / Lattice charcoal zinc palette (not deep navy) */
:root {
  --bg: #181818;          /* Council bar chrome */
  --panel: #242424;       /* Council chat surface */
  --ink: #e4e4e7;         /* zinc-200 */
  --muted: #a1a1aa;       /* zinc-400 */
  --accent: #c4a35a;      /* brand gold */
  --accent-2: #d4d4d8;    /* zinc-300 links / secondary */
  --danger: #e07070;
  --line: #2a2a2a;        /* Council border */
  --input: #121212;
  --chip: #1c1c1c;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, sans-serif;
}

.img-fluid {
  max-width: 100%;
  height: auto;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
}
body { line-height: 1.45; }

.app {
  /* Phone → tablet → laptop → large desktop readable shell */
  width: 100%;
  max-width: min(100%, 56rem);
  margin: 0 auto;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0.85rem 0.5rem;
}
@media (min-width: 768px) {
  .app {
    max-width: min(100%, 64rem);
    padding: 1rem 1.15rem 0.55rem;
  }
}
@media (min-width: 1280px) {
  .app {
    max-width: min(100%, 72rem);
    padding: 1.1rem 1.5rem 0.6rem;
  }
}
@media (min-width: 1600px) {
  .app { max-width: min(100%, 80rem); }
}

.trust-strip {
  display: flex;
  justify-content: space-between;
  gap: 0.85rem;
  align-items: flex-start;
  padding: 0.75rem 1rem;
  background: linear-gradient(145deg, #222222, #181818);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

/* Headwater brand (Council logo for this room) */
.trust-brand {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  min-width: 0;
  flex: 1 1 auto;
  width: 100%;
}
.brand-logo {
  width: 5.5rem;
  height: 5.5rem;
  object-fit: contain;
  border-radius: 0;
  background: transparent;
  border: none;
  flex-shrink: 0;
}
.brand-logo.hidden { display: none !important; }
.trust-brand-text {
  min-width: 0;
  flex: 1 1 auto;
}
/* Eyebrow left · version + Sign in/out flush right on the same row */
.brand-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 1.6rem;
}
.brand-label {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  letter-spacing: 0.01em;
}
.brand-label.hidden { display: none !important; }
.eyebrow {
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
h1 { margin: 0.15rem 0 0; font-size: 1.55rem; font-weight: 600; }
/* "N items for Name" sits under the room title (e.g. Ask HRSC) */
.session-meta {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-for[hidden],
.auth-for.hidden {
  display: none !important;
}
.app-version {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
  line-height: 1;
}
.session-action,
#btnLogout.session-action {
  margin: 0;
  flex-shrink: 0;
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
  white-space: nowrap;
  line-height: 1.2;
}
/* Actions on the eyebrow row, flush right */
.header-aside {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
}
/* Legacy meta stack (unused in asker header; keep for other pages) */
.meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
}
/* Shared site nav — horizontal pill chips */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.site-nav a {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.site-nav a:hover,
.site-nav a:focus-visible {
  border-color: #5a8f6a;
  background: #152018;
  color: #e8fff0;
  outline: none;
}
.site-nav a[aria-current="page"] {
  border-color: #2ecc71;
  background: linear-gradient(145deg, #1a3d28, #152a1c);
  color: #e8fff0;
  box-shadow: 0 0 0 1px rgba(46, 204, 113, 0.35);
}
/* Narrow form column under a full-width header (host claim, etc.) */
.hero-panel {
  max-width: 28rem;
  margin: 0 auto;
  width: 100%;
}
/* Guest gateway / longer copy — ~30% wider; near downloads lead (40rem) */
.hero-panel-wide {
  max-width: 36.5rem;
  margin: 0 auto;
  width: 100%;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
}
.panel h2 { margin-top: 0; }
label {
  display: block;
  margin: 0.65rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}
/* Gate: invite only when expanded (no clutter on every login) */
.invite-details {
  margin-top: 1rem;
  padding: 0.55rem 0.75rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1a1a1a;
}
.invite-details.hidden {
  display: none !important;
}
.invite-details > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  list-style: none;
  user-select: none;
}
.invite-details > summary::-webkit-details-marker {
  display: none;
}
.invite-details > summary::before {
  content: "▸ ";
  color: #71717a;
  font-size: 0.75rem;
}
.invite-details[open] > summary::before {
  content: "▾ ";
}
.invite-details > summary:hover {
  color: var(--ink);
}
.invite-details-help {
  margin: 0.5rem 0 0.25rem;
  font-size: 0.78rem;
  line-height: 1.35;
}
.invite-details label {
  margin-top: 0.5rem;
}
input, textarea {
  width: 100%;
  margin-top: 0.3rem;
  background: var(--input);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
}
/* Kill OS white focus glow; fields that need a ring set their own blue stroke */
input:focus,
input:focus-visible,
textarea:focus,
textarea:focus-visible {
  outline: none;
}
textarea { resize: vertical; min-height: 3rem; }
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.75rem; }
button {
  background: var(--accent);
  color: #1a1408;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
}
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
button:disabled { opacity: 0.5; cursor: wait; }
.muted { color: var(--muted); }
/* PRIVATE closed-door note panel — grows with HTML (text, images, lists) */
.private-door-note {
  color: var(--ink);
  font-weight: 600;
  font-size: 1.05em;
  line-height: 1.45;
  margin: 0.25rem 0 1rem;
  min-height: 0;
}
.private-door-note p {
  margin: 0 0 0.75rem;
}
.private-door-note p:last-child {
  margin-bottom: 0;
}
.private-door-note .private-owner-note,
.private-door-note strong.private-owner-note {
  color: var(--ink);
  font-weight: 600;
}
.private-door-note img.private-door-img,
.private-door-note img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.75rem 0;
  border-radius: 0.5rem;
}
#gateHelp .private-owner-note {
  color: var(--ink);
  font-weight: 600;
  font-size: 1.05em;
}
#gateHelp .private-local-hint {
  color: var(--muted);
  font-weight: 400;
}
.error { color: var(--danger); min-height: 1.2em; font-size: 0.9rem; }
.hidden { display: none !important; }

.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-height: min(52vh, 36rem);
}
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.25rem 0 1rem;
  display: flex;
  flex-direction: column;
  /* ~40px between user ↔ assistant turns (Council-style breathing room) */
  gap: 40px;
  min-height: 32vh;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 92%;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
/* authorized questions — compact chip (sans), right side */
.bubble.user {
  align-self: flex-end;
  max-width: min(36rem, 92%);
  padding: 0.75rem 0.95rem;
  border-radius: 16px;
  background: #2e2e2e;
  border: 1px solid #3f3f46;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.55;
}
/*
 * Agent replies — Lattice / Council Anthropic-style:
 * Source Serif 4, no bubble chrome, sits on chat surface.
 */
.bubble.assistant {
  align-self: flex-start;
  max-width: 100%;
  padding: 0.15rem 8% 0.35rem 0;
  border-radius: 0;
  background: transparent;
  border: none;
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  font-weight: 300;
  line-height: 1.85;
  letter-spacing: 0.012em;
  color: #e4e4e7;
  white-space: normal; /* block markdown structure */
}
.bubble.assistant .bubble-body.md-body {
  white-space: normal;
}
.bubble.assistant strong {
  font-weight: 600;
  color: #f4f4f5;
}
.bubble.assistant em {
  font-style: italic;
}

/* Display-only markdown (Council chat parity) */
.bubble.assistant .md-h {
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 600;
  font-size: 1.3em;
  color: #c0c0c0;
  line-height: 1.35;
  letter-spacing: 0.01em;
  margin: 1.1rem 0 0.45rem;
}
.bubble.assistant .md-h:first-child { margin-top: 0.15rem; }
.bubble.assistant .md-h1,
.bubble.assistant .md-h2,
.bubble.assistant .md-h3,
.bubble.assistant .md-h4 {
  font-size: 1.3em;
  color: #c0c0c0;
  font-weight: 600;
}
.bubble.assistant .md-p {
  margin: 0 0 0.4rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}
.bubble.assistant .md-blank { height: 0.55rem; }
.bubble.assistant .md-hr {
  border: none;
  border-top: 1px solid #3f3f46;
  margin: 0.85rem 0;
}
.bubble.assistant .md-ul {
  margin: 0.35rem 0 0.65rem 1.15rem;
  padding: 0;
  list-style: disc;
}
.bubble.assistant .md-ul li {
  margin: 0.15rem 0;
  padding-left: 0.15rem;
}
.bubble.assistant .md-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.65rem 0 1rem;
  max-width: 100%;
  border-radius: 0.4rem;
  border: 1px solid #3f3f46;
}
.bubble.assistant table.md-table {
  width: 100%;
  min-width: 20rem;
  border-collapse: collapse;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
}
.bubble.assistant table.md-table th,
.bubble.assistant table.md-table td {
  border-bottom: 1px solid #3f3f46;
  border-right: 1px solid #2e2e33;
  padding: 0.5rem 0.65rem;
  text-align: left;
  vertical-align: top;
}
.bubble.assistant table.md-table th:last-child,
.bubble.assistant table.md-table td:last-child {
  border-right: none;
}
.bubble.assistant table.md-table th {
  background: #1a1a1d;
  color: #fafafa;
  font-weight: 600;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.bubble.assistant table.md-table td {
  color: #d4d4d8;
  background: rgba(0, 0, 0, 0.12);
}
.bubble.assistant table.md-table tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.025);
}
.bubble.assistant table.md-table tbody tr:last-child td {
  border-bottom: none;
}
.bubble.assistant code.md-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid #3f3f46;
  border-radius: 0.25rem;
  padding: 0.05rem 0.3rem;
  color: #e4e4e7;
}
.bubble.assistant a.md-link {
  color: #c4a35a;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.bubble.assistant a.md-link:hover {
  color: #e0c98a;
}

/* Sources line stays UI-chrome (sans), under the serif body */
.bubble .cite {
  margin-top: 0.55rem;
  padding-top: 0.35rem;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  color: var(--muted);
  white-space: normal;
}
/* In-flight reply: modern “thinking” indicator (sans, light) */
.bubble.thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  max-width: min(18rem, 92%);
  padding: 0.5rem 0.25rem;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
}
.bubble.thinking .thinking-label {
  letter-spacing: 0.01em;
}
.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  flex-shrink: 0;
}
.thinking-dots span {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 999px;
  background: #a1a1aa;
  opacity: 0.35;
  animation: thinking-bounce 1.05s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinking-bounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  40% {
    transform: translateY(-0.28rem);
    opacity: 1;
  }
}
/* Composer shell + centered top grip (Council / Lattice pill) */
.composer-area {
  position: relative;
  margin-top: 0.35rem;
}
.resize-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.resize-grip {
  pointer-events: none;
  border-radius: 9999px;
  background: #52525b;
  box-shadow: 0 0 0 1px #27272a;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.resize-handle:hover .resize-grip,
.resize-handle.dragging .resize-grip {
  background: #71717a;
  box-shadow: 0 0 0 1px #6366f1;
}
#composer-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 16px;
  transform: translateY(-50%);
  cursor: row-resize;
  z-index: 10;
  /* Critical on Android: stop page scroll from stealing the drag */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#composer-resize-handle:hover,
#composer-resize-handle.dragging {
  background: linear-gradient(to top, rgba(99, 102, 241, 0.12), transparent);
}
#composer-resize-handle .resize-grip {
  width: 40px;
  height: 6px;
}
/* Phone: fat finger hit target (visual grip stays the small pill) */
@media (max-width: 640px), (pointer: coarse) {
  #composer-resize-handle {
    height: 36px;
    /* Sit a bit higher so the strip is easier to grab above the field */
    transform: translateY(calc(-50% - 4px));
  }
  #composer-resize-handle .resize-grip {
    width: 56px;
    height: 8px;
    background: #71717a;
  }
  #composer-resize-handle.dragging .resize-grip {
    background: #a5b4fc;
    box-shadow: 0 0 0 1px #6366f1;
  }
  .composer-area {
    /* Room for the taller touch strip without covering chat text */
    margin-top: 0.65rem;
    padding-top: 0.15rem;
  }
}
.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: center; /* Send stays vertical middle as textarea grows */
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.composer textarea {
  margin-top: 0;
  min-height: 3.25rem;
  height: 3.25rem;
  max-height: min(70vh, 28rem);
  width: 100%;
  min-width: 0;
  resize: none; /* custom top pill grip only */
  overflow-y: auto;
  line-height: 1.4;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  box-shadow: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
/* Council-parity: blue stroke only — no white / soft glow */
.composer textarea:focus,
.composer textarea:focus-visible {
  outline: none;
  border-color: #3b5bdb; /* brand blue stroke */
  box-shadow: 0 0 0 1px rgba(59, 91, 219, 0.4);
}
#btnSend {
  background: #ffffff;
  color: #121212;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2), 0 4px 12px rgba(0, 0, 0, 0.22);
  align-self: center;
  min-height: 2.65rem;
  padding: 0.55rem 1.2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: filter 0.12s ease, transform 0.12s ease, opacity 0.12s ease;
}
#btnSend:hover:not(:disabled) {
  filter: brightness(0.96);
}
#btnSend:active:not(:disabled) {
  transform: translateY(1px);
}
#btnSend:disabled {
  opacity: 0.55;
  cursor: wait;
}
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 0.2rem;
  color: var(--muted);
  font-size: 0.75rem;
}
.footer a { color: var(--accent-2); }
.footer-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex-shrink: 0;
}
.footer-tagline {
  margin-left: auto;
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.2;
  max-width: min(100%, 36rem);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Bottom-left History dock (Council sidebar History affordance) */
.history-dock-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #1c1c1c;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.history-dock-btn:hover {
  background: #2a2a2a;
  border-color: #3f3f46;
  color: #fafafa;
}
.history-dock-btn .history-icon {
  opacity: 0.9;
  flex-shrink: 0;
}
.history-dock-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}
/* Longer dock label next to History */
#btnAsk .history-dock-label {
  letter-spacing: 0.04em;
}
.history-dock-btn:hover .history-dock-label {
  color: var(--ink);
}

/* Modal shell */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.modal-backdrop.hidden {
  display: none !important;
}
.modal-panel {
  width: 100%;
  max-width: 52rem;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 1rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  position: relative;
}
/* History + Ask: tall default (75vh) + bottom grab to resize */
.history-modal-panel,
.ask-modal-panel {
  height: 75vh;
  max-height: 92vh;
  min-height: min(40vh, 22rem);
  max-width: min(52rem, 96vw);
}
.history-modal-panel .modal-body,
.ask-modal-panel .modal-body {
  flex: 1 1 auto;
  min-height: 12rem;
}
.modal-resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  cursor: ns-resize;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.22), transparent);
}
.modal-resize-handle::after {
  content: "";
  width: 2.25rem;
  height: 3px;
  border-radius: 999px;
  background: #52525b;
  box-shadow: 0 5px 0 #3f3f46;
}
.modal-resize-handle:hover::after,
.modal-resize-handle:focus-visible::after {
  background: #a1a1aa;
  box-shadow: 0 5px 0 #71717a;
}
.history-modal-panel.is-resizing,
.ask-modal-panel.is-resizing {
  user-select: none;
}
.history-modal-panel.is-resizing .modal-resize-handle::after,
.ask-modal-panel.is-resizing .modal-resize-handle::after {
  background: #d4d4d8;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #27272a;
}
.modal-title-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  color: #e4e4e7;
}
.modal-title-row h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}
.modal-x {
  background: transparent;
  border: none;
  color: #71717a;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 0.4rem;
}
.modal-x:hover { color: #e4e4e7; background: #27272a; }
.modal-search {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid #27272a;
}
.modal-search input {
  width: 100%;
  padding: 0.55rem 0.8rem;
  border-radius: 0.75rem;
  border: 1px solid #3f3f46;
  background: #09090b;
  color: #e4e4e7;
  font-size: 0.9rem;
}
.modal-search input:focus {
  outline: none;
  border-color: #71717a;
}
.modal-body {
  /* flex:1 alone + min-height:auto clips list on phones (only top row visible) */
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.75rem 1rem 1rem;
}
/* Room for bottom resize grip so footer buttons aren't covered */
.history-modal-panel .modal-footer,
.ask-modal-panel .modal-footer {
  padding-bottom: 1.15rem;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid #27272a;
}
.modal-footer button {
  padding: 0.45rem 0.95rem;
  border-radius: 0.75rem;
  border: 1px solid #3f3f46;
  background: #27272a;
  color: #d4d4d8;
  font-size: 0.85rem;
  cursor: pointer;
}
.modal-footer button:hover {
  background: #3f3f46;
  color: #fafafa;
}
.modal-footer button.ghost {
  background: transparent;
  color: var(--muted);
}
.modal-footer button.ghost:hover {
  background: #27272a;
  color: #e4e4e7;
}

/* History rows (Lattice / Council pattern) */
.history-session-header,
.history-session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  text-align: left;
  padding: 0.75rem 0.85rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
  background: transparent;
  color: #e4e4e7;
}
.history-session-header {
  padding: 0.35rem 0.85rem 0.5rem;
  border-radius: 0;
  color: #71717a;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.65rem;
  user-select: none;
  border-bottom: 1px solid #27272a;
  margin-bottom: 0.25rem;
  position: sticky;
  top: 0;
  z-index: 2;
  background: #18181b;
}
.history-session-header .hist-title-block,
.history-session-row .hist-title-block {
  flex: 1;
  min-width: 0;
}
.history-session-header .hist-meta,
.history-session-row .hist-meta {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.history-session-header .hist-turns,
.history-session-row .hist-turns {
  min-width: 3.5rem;
  text-align: right;
}
.history-session-header .hist-when,
.history-session-row .hist-when {
  min-width: 8.5rem;
  text-align: right;
}
.history-session-header .hist-menu-spacer {
  width: 1.35rem;
  flex-shrink: 0;
}
.history-session-header .sortable {
  cursor: pointer;
  white-space: nowrap;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.history-session-header .sortable:hover {
  color: #d4d4d8;
}
.history-session-header .sortable.is-sorted {
  color: #e4e4e7;
}
.history-session-header .sort-ind {
  font-size: 0.6rem;
  opacity: 0.75;
}
.history-session-row {
  cursor: pointer;
}
.history-session-row:hover {
  background: #242424;
  border-color: #2a2a2a;
}
.history-session-row.is-active {
  border-color: #52525b;
  background: #1f1f23;
}
.history-session-row .session-title-display {
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Ask list: wrap so long authorized questions are readable on phone */
.ask-row .session-title-display {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
.history-session-row .session-preview {
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: #71717a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-session-row .hist-when,
.history-session-row .hist-turns {
  font-size: 0.78rem;
  color: #a1a1aa;
}
.history-session-row .session-menu-btn {
  width: 1.35rem;
  height: 1.35rem;
  border: none;
  background: transparent;
  color: #71717a;
  border-radius: 0.35rem;
  cursor: pointer;
  padding: 0;
  font-size: 0.95rem;
  line-height: 1;
}
.history-session-row .session-menu-btn:hover {
  color: #e4e4e7;
  background: #2a2a2a;
}
.history-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #71717a;
  font-size: 0.9rem;
}
.history-empty .history-empty-icon {
  font-size: 1.75rem;
  margin-bottom: 0.65rem;
  opacity: 0.45;
}
.history-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  color: #71717a;
  font-size: 0.9rem;
}
.history-error {
  text-align: center;
  padding: 2rem 1rem;
  color: #e07070;
  font-size: 0.9rem;
}
.history-rows {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

/* Lightweight context menu for history row actions */
.history-ctx {
  position: fixed;
  z-index: 100;
  min-width: 9rem;
  padding: 0.3rem;
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 0.6rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.history-ctx.hidden { display: none !important; }
.history-ctx button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.7rem;
  border: none;
  background: transparent;
  color: #e4e4e7;
  font-size: 0.85rem;
  border-radius: 0.4rem;
  cursor: pointer;
}
.history-ctx button:hover {
  background: #27272a;
}
.history-ctx button.danger {
  color: #e07070;
}

@media (max-width: 640px) {
  .trust-strip {
    flex-direction: column;
    align-items: stretch;
    padding: 0.55rem 0.75rem;
    gap: 0.45rem;
    margin-bottom: 0.5rem;
  }
  .brand-top-row {
    gap: 0.5rem;
    min-height: 1.45rem;
  }
  .header-aside {
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 0.4rem;
    margin-left: auto;
  }
  .site-nav { justify-content: flex-start; }
  .meta {
    align-items: flex-start;
    text-align: left;
    width: 100%;
  }
  /* Hide product version on narrow phones */
  .app-version { display: none; }
  h1 { font-size: 1.15rem; }
  .eyebrow { font-size: 0.68rem; letter-spacing: 0.06em; }
  .bubble.assistant {
    padding-right: 0;
    font-size: 1rem;
    line-height: 1.75;
  }
  .bubble.user {
    max-width: 95%;
    font-size: 0.9rem;
  }
  .messages { gap: 40px; }
  .composer {
    grid-template-columns: 1fr auto;
    align-items: center;
  }
  #btnSend {
    min-height: 2.75rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .footer {
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
  }
  .footer-tagline {
    white-space: normal;
    max-width: 100%;
    flex: 1 1 100%;
    order: 2;
    text-align: left;
  }
  .footer-left { order: 1; }
  .history-session-header .hist-turns,
  .history-session-row .hist-turns {
    display: none;
  }
  .history-session-header .hist-when,
  .history-session-row .hist-when {
    min-width: 4.25rem;
    max-width: 4.75rem;
    font-variant-numeric: tabular-nums;
  }
  .history-session-header .hist-meta,
  .history-session-row .hist-meta {
    gap: 0.45rem;
  }
  /* Keep History / Ask labels visible on phone (icon alone was too opaque) */
  .history-dock-label {
    display: inline;
    font-size: 0.62rem;
  }
  .history-dock-btn {
    min-height: 2.5rem;
    padding: 0.4rem 0.55rem;
    gap: 0.3rem;
  }
  .modal-panel {
    max-height: 88dvh;
    max-width: 100%;
  }
  .bubble.assistant table.md-table {
    min-width: 16rem;
    font-size: 0.78rem;
  }
}

/* Ask the owner modal — compact chrome so the list stays above the fold */
.ask-composer-wrap {
  padding: 0.5rem 1rem 0.4rem;
  border-bottom: 1px solid #27272a;
  flex: 0 0 auto;
}
.ask-help {
  margin: 0 0 0.3rem;
  font-size: 0.74rem;
  line-height: 1.25;
  max-width: 40rem;
}
.ask-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  align-items: end;
}
.ask-composer textarea {
  width: 100%;
  min-height: 2.75rem;
  max-height: 8rem;
  resize: vertical;
  padding: 0.45rem 0.65rem;
  border-radius: 0.65rem;
  border: 1px solid #3f3f46;
  background: #09090b;
  color: #e4e4e7;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.35;
}
.ask-composer textarea:focus,
.ask-composer textarea:focus-visible {
  outline: none;
  border-color: #3b5bdb;
  box-shadow: 0 0 0 1px rgba(59, 91, 219, 0.4);
}
.ask-composer #btnAskSubmit {
  align-self: stretch;
  min-height: 2.5rem;
  padding: 0.45rem 0.85rem;
  border-radius: 0.65rem;
  border: 1px solid #3f3f46;
  background: #2a3f32;
  color: #e8fff0;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.ask-composer #btnAskSubmit:hover:not(:disabled) {
  background: #355a42;
}
.ask-composer #btnAskSubmit:disabled {
  opacity: 0.55;
  cursor: wait;
}
#askFormError {
  margin: 0.3rem 0 0;
  min-height: 0.95em;
  font-size: 0.76rem;
}
#askFormError.is-ok {
  color: #6ee7b7;
}
.ask-modal-panel .modal-search {
  padding: 0.4rem 1rem 0.35rem;
  flex: 0 0 auto;
}
.ask-modal-panel .modal-search input {
  padding: 0.4rem 0.7rem;
  font-size: 0.84rem;
  border-radius: 0.6rem;
}
.ask-modal-panel .modal-body {
  /* Prefer list space over empty chrome; less top pad under search */
  min-height: 8rem;
  padding: 0.35rem 0.75rem 0.75rem;
}
.ask-list-header {
  padding: 0.2rem 0.55rem 0.3rem !important;
  margin-bottom: 0.1rem !important;
  gap: 0.5rem !important;
  align-items: center !important;
}
.ask-list-header .ask-col-label {
  white-space: nowrap;
}
.ask-list-header .ask-col-yours {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ask-list-header .hist-title-block {
  min-width: 0;
  flex: 1 1 auto;
}
.ask-list-header .hist-meta {
  flex: 0 0 auto;
  gap: 0.65rem;
}
.ask-col-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #71717a;
  white-space: nowrap;
}
.history-session-header .hist-status,
.history-session-row .hist-status {
  min-width: 7.5rem;
  text-align: right;
}
.ask-status-pill {
  display: inline-block;
  max-width: 100%;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ask-status-pill.pending {
  background: #3f2e12;
  color: #fbbf24;
  border: 1px solid #78520f;
}
.ask-status-pill.answered {
  background: #14301f;
  color: #6ee7a8;
  border: 1px solid #2a6b45;
}
.ask-row.is-answered .session-title-display {
  color: #d4d4d8;
}
.ask-row.is-linked .session-title-display,
.ask-row .ask-title-link {
  color: #86efac;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  text-align: left;
  width: 100%;
}
.ask-row .ask-title-link:hover {
  color: #bbf7d0;
}
.ask-row .ask-title-soft {
  color: #d4d4d8;
  text-decoration: none;
}
.ask-row.is-linked {
  cursor: pointer;
}
.ask-row.is-linked:hover {
  border-color: #2a6b45;
  background: #0f1f17;
}
.ask-answer-panel {
  margin: 0 0.75rem 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid #2a6b45;
  background: #0c1612;
  max-height: 40vh;
  overflow: auto;
}
.ask-answer-panel.hidden {
  display: none;
}
.ask-answer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.ask-answer-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #e4e4e7;
  line-height: 1.35;
}
.ask-answer-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6ee7a8;
  margin-bottom: 0.25rem;
}
.ask-answer-q,
.ask-answer-a {
  margin-bottom: 0.75rem;
}
.ask-answer-path {
  font-size: 0.72rem;
  word-break: break-all;
  margin: 0.35rem 0 0;
}
.ask-answer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.ask-answer-actions button {
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  .ask-composer {
    grid-template-columns: 1fr auto;
  }
  .ask-composer #btnAskSubmit {
    width: auto;
    min-width: 4.5rem;
  }
  .history-session-header .hist-status,
  .history-session-row .hist-status {
    min-width: 4.25rem;
    max-width: 5.25rem;
  }
  .ask-status-pill {
    font-size: 0.62rem;
    padding: 0.12rem 0.35rem;
  }
  /* Phone: list must claim most of the panel height */
  .ask-modal-panel,
  .history-modal-panel {
    max-height: 92dvh;
  }
  .ask-modal-panel .modal-body {
    min-height: 10rem;
    flex: 1 1 auto;
  }
  .ask-help {
    font-size: 0.72rem;
    margin-bottom: 0.25rem;
  }
  .ask-composer textarea {
    min-height: 2.5rem;
  }
  .ask-composer-wrap {
    padding: 0.4rem 0.75rem 0.3rem;
  }
  .ask-modal-panel .modal-search {
    padding: 0.3rem 0.75rem 0.25rem;
  }
  .ask-modal-panel .modal-body {
    padding: 0.25rem 0.55rem 0.65rem;
  }
}

/* Tablet landscape / small laptop */
@media (min-width: 641px) and (max-width: 1024px) {
  .bubble.assistant { padding-right: 5%; }
  .messages { gap: 40px; }
}
