/* ================================================================
   APP SHELL
================================================================ */
#app { display: none; min-height: 100dvh; }
#app.visible { display: flex; }

/* ── Main content ────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-width: 0;
}

/* ── Top bar ────────────────────────────────────────────────── */
/* Warm-paper surface matching the page background — per
   lex-design-system primitive A. Wordmark + breadcrumb live in
   .topbar-left (see css/home.css for the wordmark styles). */
.topbar {
  height: var(--topbar-h, 3.25rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--paper-edge);
  background: var(--paper);
  position: sticky; top: 0; z-index: 50;
  gap: 1rem;
}
.topbar-left { display: flex; align-items: center; gap: 0.5rem; }
.topbar-title {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: 0.005em;
}
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

/* ── Module screens ─────────────────────────────────────────── */
/* Content cap at --content-max (80rem) per the design system —
   stops content sprawling on wide displays. Modules that already
   cap their inner content (analyse-doc, library) compose harmlessly
   with this outer cap. */
.module {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: 1.5rem;
  min-height: 0;
  width: 100%;
  max-width: var(--content-max);
  margin-left: auto;
  margin-right: auto;
}
.module.active { display: flex; }
.module-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.module-title { font-family: var(--font-serif); font-size: 1.5rem; font-weight: 500; color: var(--ink); }
.module-sub { font-size: 0.875rem; color: var(--muted); margin-top: 0.2rem; }
.module-actions { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }

/* ── Lex Widget (floating, context-aware) ───────────────────── */
#lex-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
}

.lex-fab {
  width: 3.25rem; height: 3.25rem;
  background: var(--gold);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(201,168,76,0.4);
  border: none;
  transition: transform var(--t), box-shadow var(--t);
}
.lex-fab:hover { transform: scale(1.05); box-shadow: 0 6px 28px rgba(201,168,76,0.5); }

.lex-panel {
  position: absolute;
  bottom: 4rem;
  right: 0;
  width: 22rem;
  max-height: 75dvh;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: 0 16px 48px rgba(0,0,0,0.16);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  display: none;
}
.lex-panel.open { display: flex; }

.lex-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--ink);
}
.lex-panel-title {
  display: flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-serif); font-size: 1rem;
  color: var(--white);
}
.lex-panel-ctx {
  font-size: 0.7rem; color: rgba(255,255,255,0.4);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-left: 0.5rem;
}
.lex-panel-close { background: none; border: none; color: rgba(255,255,255,0.4); cursor: pointer; padding: 0.25rem; border-radius: var(--r-sm); }
.lex-panel-close:hover { color: var(--white); }

.lex-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.lex-msg-user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--white);
  padding: 0.6rem 0.85rem;
  border-radius: var(--r-lg) var(--r-lg) var(--r-sm) var(--r-lg);
  font-size: 0.875rem;
  max-width: 85%;
}
.lex-msg-ai {
  align-self: flex-start;
  max-width: 90%;
}
.lex-msg-ai-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.7rem 0.9rem;
  border-radius: var(--r-sm) var(--r-lg) var(--r-lg) var(--r-lg);
  font-size: 0.875rem;
  line-height: 1.55;
}
.lex-msg-ai-actions {
  display: flex; gap: 0.4rem; margin-top: 0.4rem; flex-wrap: wrap;
}
.lex-action-btn {
  font-size: 0.7rem; padding: 0.2rem 0.6rem;
  background: none; border: 1px solid var(--border);
  border-radius: 9999px; cursor: pointer; color: var(--mid);
  transition: all var(--t);
}
.lex-action-btn:hover { border-color: var(--gold); color: var(--gold); }

/* Chat session threads */
.lex-thread {
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.lex-thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  gap: 0.5rem;
}
.lex-thread-header:hover { background: var(--border); }
.lex-thread-preview {
  font-size: 0.8rem;
  color: var(--ink);
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lex-thread-meta {
  font-size: 0.7rem;
  color: var(--muted);
  flex-shrink: 0;
}
.lex-thread-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--white);
  max-height: 20rem;
  overflow-y: auto;
}
.lex-thread.collapsed .lex-thread-body { display: none; }
.lex-session-divider {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.lex-thinking {
  align-self: flex-start;
  display: flex; align-items: center; gap: 0.3rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 0.75rem;
  color: var(--muted);
}
.lex-dot { width: 0.3rem; height: 0.3rem; background: var(--muted); border-radius: 50%; animation: lex-pulse 1s ease-in-out infinite; }
.lex-dot:nth-child(2) { animation-delay: 0.2s; }
.lex-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes lex-pulse { 0%,100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1); } }
.speaker-block { margin-bottom: 0.85rem; }
.speaker-label {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; margin-bottom: 0.2rem;
}
.speaker-A .speaker-label { color: #1A5276; }
.speaker-B .speaker-label { color: #2E7D52; }
.speaker-C .speaker-label { color: #B5651D; }
.speaker-D .speaker-label { color: #6B2D8B; }
.speaker-text { font-size: 0.875rem; color: var(--ink); line-height: 1.7; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.lex-input-row {
  display: flex; gap: 0.5rem; align-items: flex-end;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}
.lex-textarea {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.55rem 0.75rem;
  resize: none;
  max-height: 7rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  transition: border-color var(--t);
}
.lex-textarea:focus { outline: none; border-color: var(--gold); }
.lex-send {
  width: 2.25rem; height: 2.25rem;
  background: var(--gold); border: none; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: opacity var(--t);
}
.lex-send:hover { opacity: 0.85; }

/* TTS button on Lex messages */
.tts-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); padding: 0.15rem 0.3rem;
  border-radius: var(--r-sm); transition: color var(--t);
  font-size: 0.7rem;
}
.tts-btn:hover { color: var(--gold); }

