/* ── MPS Monitor design tokens ─────────────────────────────────── */
:root {
  --bg:            #f0f4f8;
  --surface:       #ffffff;
  --surface2:      #f5f7fa;
  --border:        #d5dce4;
  --border-light:  #e8edf2;
  --text:          #1c2b3a;
  --muted:         #5f7282;
  --accent:        #0055a5;
  --accent-dark:   #003e7e;
  --accent-light:  #ebf3fb;
  --accent-soft:   rgba(0,85,165,.08);
  --green:         #107c41;
  --green-light:   #e5f4ed;
  --green-border:  rgba(16,124,65,.2);
  --orange:        #d97706;
  --shadow-sm:     0 1px 3px rgba(0,40,100,.08);
  --shadow-md:     0 4px 16px rgba(0,40,100,.10);
  --shadow-lg:     0 12px 40px rgba(0,40,100,.14);
  --radius:        10px;
  --radius-lg:     16px;
  --font:          'Segoe UI', system-ui, -apple-system, sans-serif;
  /* Branding overrides (set via JS from /branding endpoint) */
  --nav-bg:        var(--surface);
  --bubble-user-bg: var(--accent);
  --bubble-ai-bg:  #ffffff;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Topnav ──────────────────────────────────────────────────────── */
.topnav {
  background: var(--nav-bg); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-sm);
}
.topnav-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 28px;
  height: 76px; display: flex; align-items: center;
}
.topnav-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; flex-shrink: 0; }
.topnav-logo  { height: 50px; max-width: 200px; object-fit: contain; }
.topnav-divider { width: 1px; height: 36px; background: var(--border); margin: 0 22px; }
.topnav-app {
  font-size: 1.05rem; font-weight: 600; color: #0055a5;
  letter-spacing: .2em; text-transform: uppercase;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
.topnav-spacer { flex: 1; }
.topnav-actions { display: flex; align-items: center; gap: 8px; }

/* ── Language switcher ───────────────────────────────────────────── */
.lang-switcher { display: flex; align-items: center; gap: 2px; margin-right: 4px; }
.lang-btn {
  padding: 4px 7px; border-radius: 5px; font-size: .72rem; font-weight: 700;
  cursor: pointer; border: 1px solid transparent; background: transparent;
  color: var(--muted); font-family: var(--font); letter-spacing: .03em;
  transition: background .12s, color .12s, border-color .12s;
}
.lang-btn:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent-light); }
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.nav-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 16px; border-radius: var(--radius);
  font-size: .85rem; font-weight: 600; cursor: pointer;
  border: none; font-family: var(--font); transition: background .15s, color .15s, border-color .15s;
}
.btn-ghost   { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-light); }
.btn-primary { background: var(--accent); color: #fff; border: 1px solid transparent; }
.btn-primary:hover { background: var(--accent-dark); }
/* Admin gear icon — no text, compact */
.admin-icon-btn { padding: 5px 9px; font-size: 1.05rem; line-height: 1; letter-spacing: 0; }

.auth-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px; font-size: .78rem; font-weight: 600;
}
.auth-badge.public   { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.auth-badge.basic    { background: #dbeeff; color: #0a66c2; border: 1px solid rgba(10,102,194,.22); }
.auth-badge.auth     { background: var(--green-light); color: var(--green); border: 1px solid var(--green-border); }
.auth-badge .dot     { width: 7px; height: 7px; border-radius: 50%; }
.auth-badge.public .dot { background: var(--muted); }
.auth-badge.basic  .dot { background: #0a66c2; }
.auth-badge.auth   .dot { background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* Card tier indicators */
.card-tag.tier-free { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.card-tag.tier-li   { background: #dbeeff; color: #0a66c2; border: 1px solid rgba(10,102,194,.22); display: inline-flex; align-items: center; gap: 4px; }
.card-tag.tier-mps  { background: var(--green-light); color: var(--green); border: 1px solid var(--green-border); display: inline-flex; align-items: center; gap: 4px; }
/* Auth icon in navbar badge */
#auth-icon { display: none; align-items: center; flex-shrink: 0; }

/* ── Page wrapper ────────────────────────────────────────────────── */
.page {
  max-width: 1200px; margin: 0 auto;
  padding: 40px 24px 60px; flex: 1;
  display: flex; flex-direction: column; gap: 56px;
}

/* ── Hero ────────────────────────────────────────────────────────── */
.hero {
  display: grid;
  grid-template-columns: minmax(0,4fr) minmax(0,8fr);
  gap: 40px; align-items: stretch;
}
@media(max-width:900px){ .hero { grid-template-columns: 1fr; } }

.hero-copy { display: flex; flex-direction: column; gap: 20px; padding-top: 12px; }
.eyebrow   { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); }
.hero-title { font-size: clamp(1.6rem,2.4vw,2.2rem); line-height: 1.18; font-weight: 800; }
.hero-title .hi { color: var(--accent); }
.hero-sub { font-size: .93rem; color: var(--muted); max-width: 28rem; line-height: 1.65; }
.btn-row  { display: flex; flex-wrap: wrap; gap: 10px; }

.cta-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 24px; border-radius: var(--radius);
  background: var(--accent); color: #fff;
  font-size: .9rem; font-weight: 700; border: none; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,85,165,.3); font-family: var(--font);
  transition: background .15s, box-shadow .15s;
}
.cta-btn:hover { background: var(--accent-dark); box-shadow: 0 6px 20px rgba(0,85,165,.4); }
.cta-ghost {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 24px; border-radius: var(--radius);
  background: var(--surface); color: var(--muted);
  font-size: .9rem; font-weight: 600; border: 1px solid var(--border); cursor: pointer;
  font-family: var(--font); transition: border-color .15s, color .15s;
}
.cta-ghost:hover { border-color: var(--accent); color: var(--accent); }

.trust-row { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px; align-items: center; }
.trust-badge-img {
  height: 52px; width: auto; object-fit: contain;
  display: block; opacity: .88; transition: opacity .2s;
}
.trust-badge-img:hover { opacity: 1; }

/* ── Chat card ───────────────────────────────────────────────────── */
.chat-card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid rgba(0,85,165,.18);
  border-top: 3px solid var(--accent);
  box-shadow: 0 8px 40px rgba(0,85,165,.18), 0 2px 10px rgba(0,40,100,.10);
  display: flex; flex-direction: column; overflow: hidden; min-height: 480px;
}

.chat-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid rgba(0,85,165,.12);
  background: linear-gradient(135deg, #d6eafb 0%, var(--accent-light) 100%);
}
.chat-topbar-left { display: flex; align-items: center; gap: 10px; font-size: .8rem; font-weight: 700; color: var(--text); }
.chat-topbar-actions { display: flex; align-items: center; gap: 6px; }
.topbar-action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 7px; font-size: .74rem; font-weight: 600;
  background: rgba(255,255,255,.7); border: 1px solid rgba(0,85,165,.2);
  color: var(--accent-dark); cursor: pointer; font-family: var(--font);
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.topbar-action-btn:hover:not(:disabled) { background: #fff; border-color: var(--accent); color: var(--accent); }
.topbar-action-btn:disabled { opacity: .45; cursor: default; }
.topbar-action-btn.copied { color: var(--green); border-color: var(--green-border); background: var(--green-light); }
.topbar-action-btn svg { flex-shrink: 0; }
.topbar-chip {
  padding: 2px 10px; border-radius: 999px; font-size: .72rem; font-weight: 500;
  background: rgba(255,255,255,.7); border: 1px solid rgba(0,85,165,.18); color: var(--accent-dark);
}

.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  background: #f7fafd;
  display: flex; flex-direction: column; gap: 14px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }

.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .65rem; font-weight: 700;
}
.avatar.ai   { background: var(--accent); color: #fff; }
.avatar.user { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }

.bubble {
  padding: 10px 14px; border-radius: 12px;
  font-size: .875rem; line-height: 1.6;
  max-width: calc(100% - 44px);
  position: relative;
}
.bubble.user { background: var(--bubble-user-bg); color: #fff; border-bottom-right-radius: 4px; }
.bubble.ai   { background: var(--bubble-ai-bg); border: 1px solid rgba(0,85,165,.12); color: var(--text); border-bottom-left-radius: 4px; box-shadow: 0 1px 4px rgba(0,40,100,.07); }

/* Markdown in AI bubble */
.bubble.ai p               { margin: 0 0 8px; }
.bubble.ai p:last-child    { margin-bottom: 0; }
.bubble.ai ul, .bubble.ai ol { padding-left: 20px; margin: 4px 0 8px; }
.bubble.ai li              { margin-bottom: 3px; }
.bubble.ai strong          { color: var(--text); }
.bubble.ai table           { border-collapse: collapse; font-size: .83rem; width: 100%; margin: 8px 0; }
.bubble.ai th, .bubble.ai td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.bubble.ai th              { background: var(--accent-light); color: var(--accent-dark); font-weight: 600; }
.bubble.ai code            { background: var(--border-light); padding: 1px 6px; border-radius: 4px; font-size: .82rem; font-family: monospace; }
.bubble.ai h1, .bubble.ai h2, .bubble.ai h3 { font-size: .9rem; font-weight: 700; margin: 8px 0 4px; }

/* Source pills */
.msg-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.source-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 500;
}
.source-pill.kb   { background: var(--accent-light); color: var(--accent); border: 1px solid rgba(0,85,165,.18); }
.source-pill.live { background: var(--green-light);  color: var(--green);  border: 1px solid var(--green-border); }

/* Follow-up suggestions */
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sug-chip {
  padding: 5px 12px; border-radius: 999px; font-size: .78rem; font-weight: 500;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  cursor: pointer; font-family: var(--font); transition: border-color .15s, color .15s, background .15s;
}
.sug-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* Per-message hover toolbar (copy / Word / Excel) — sits BELOW the bubble so it
   never overlaps the message text. Revealed on hover of the message row. */
.msg-actions {
  display: flex; gap: 4px; margin-top: 5px;
  opacity: 0; transition: opacity .15s;
}
.msg.user .msg-actions { justify-content: flex-end; }
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
/* Touch devices have no hover — keep the toolbar faintly visible. */
@media (hover: none) { .msg-actions { opacity: .55; } }

.msg-action-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted);
  cursor: pointer; font-size: .72rem; font-weight: 800; font-family: var(--font);
  transition: color .15s, border-color .15s, background .15s, opacity .15s;
}
.msg-action-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); background: var(--accent-light); }
.msg-action-btn:disabled { cursor: default; opacity: .5; }
.msg-action-btn.busy { opacity: .5; cursor: progress; }
.msg-action-btn.copied { color: var(--green); border-color: var(--green-border); background: var(--green-light); }
.msg-action-btn.act-word  { color: #2b579a; }
.msg-action-btn.act-excel { color: #217346; }
.msg-action-btn.act-word:hover:not(:disabled)  { border-color: #2b579a; background: #eef2fb; color: #2b579a; }
.msg-action-btn.act-excel:hover:not(:disabled) { border-color: #217346; background: #e8f5ee; color: #217346; }
/* On the blue user bubble */
.bubble.user .msg-action-btn { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.4); color: #fff; }
.bubble.user .msg-action-btn:hover:not(:disabled) { background: rgba(255,255,255,.32); border-color: #fff; color: #fff; }

/* Word/Excel letter badges (topbar export buttons) */
.file-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 3px; color: #fff;
  font-size: .62rem; font-weight: 800; flex-shrink: 0;
}
.file-badge.word  { background: #2b579a; }
.file-badge.excel { background: #217346; }
.file-badge.ppt   { background: #c43e1c; }

/* Deck-template picker (MPS users only) */
.deck-template-wrap {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 10px; border-radius: 7px; font-size: .74rem; font-weight: 600;
  background: rgba(255,255,255,.7); border: 1px solid rgba(0,85,165,.2);
  color: var(--accent-dark); font-family: var(--font); cursor: pointer;
}
.deck-template-wrap:hover { background: #fff; border-color: var(--accent); }
.deck-template-label { white-space: nowrap; }
.deck-template-wrap select {
  border: none; background: transparent; font-family: var(--font);
  font-size: .74rem; font-weight: 600; color: var(--accent-dark);
  cursor: pointer; padding: 2px 2px; max-width: 150px;
}
.deck-template-wrap select:focus { outline: none; }

/* Feedback buttons */
.feedback-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.feedback-label { font-size: .75rem; color: var(--muted); }
.fb-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 2px 9px; cursor: pointer; font-size: .85rem; line-height: 1.6;
  transition: all .15s; font-family: var(--font);
}
.fb-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-light); }
.fb-btn:disabled { cursor: default; opacity: .45; }
.fb-btn.fb-selected { border-color: var(--accent); background: var(--accent-light); opacity: 1 !important; }

/* Upgrade inline banner */
.upgrade-inline {
  background: linear-gradient(135deg, var(--accent-light), #dbeafe);
  border: 1px solid rgba(0,85,165,.2); border-radius: var(--radius);
  padding: 10px 14px; margin-top: 10px;
  font-size: .82rem; color: var(--accent-dark);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.upgrade-inline .upgrade-btns { display: flex; gap: 6px; flex-wrap: wrap; flex-shrink: 0; }
.upgrade-inline button {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 5px 14px; font-size: .8rem; font-weight: 600; cursor: pointer;
  font-family: var(--font); white-space: nowrap; transition: background .15s;
}
.upgrade-inline button:hover { background: var(--accent-dark); }
.upgrade-inline button.btn-secondary {
  background: rgba(0,85,165,.1); color: var(--accent-dark);
  border: 1px solid rgba(0,85,165,.25);
}
.upgrade-inline button.btn-secondary:hover { background: rgba(0,85,165,.2); }
/* Soft CTA for LinkedIn users */
.upgrade-soft {
  background: #f0f7ff; border-color: rgba(0,85,165,.12);
  justify-content: flex-start; font-size: .8rem; color: var(--muted);
}
.upgrade-soft a { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Typing indicator */
.typing { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--muted); font-size: .85rem; }
.typing-dots { display: flex; align-items: center; gap: 4px; }
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .5; display: block; animation: bounce .9s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes bounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-6px)} }

/* Input row */
.chat-input-row {
  padding: 12px 14px; border-top: 1px solid var(--border-light);
  display: flex; align-items: flex-end; gap: 8px; background: var(--surface);
}
#chat-input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 14px;
  color: var(--text); font-size: .875rem; outline: none;
  font-family: var(--font); resize: none; min-height: 38px; max-height: 120px;
  line-height: 1.5; overflow-y: auto; transition: border-color .15s;
}
#chat-input:focus { border-color: var(--accent); }
#chat-input::placeholder { color: var(--muted); }
#send-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .88rem; flex-shrink: 0; align-self: flex-end;
  transition: background .15s, opacity .15s;
}
#send-btn:hover { background: var(--accent-dark); }
#send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Topic tiles ─────────────────────────────────────────────────── */
.tile-grid {
  display: flex; flex-direction: column; gap: 12px;
}

.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  transition: border-color .15s, box-shadow .15s;
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
}
.tile:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }

/* Header: icon + title on one line */
.tile-header { display: flex; align-items: center; gap: 8px; }
.tile-icon   { font-size: 1.4rem; line-height: 1; flex-shrink: 0; display: flex; align-items: center; }
.tile-icon-img { width: 22px; height: 22px; object-fit: contain; display: block; }
.tile-title  { font-size: .88rem; font-weight: 700; flex: 1; }
.tile-desc   { font-size: .8rem; color: var(--muted); line-height: 1.5; }

/* Questions — always visible, normal flow */
.tile-questions {
  display: flex; flex-direction: column; gap: 5px;
  margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px;
}
.tile-q {
  font-size: .73rem; color: var(--accent); background: var(--accent-light);
  border: none; border-radius: 5px; padding: 5px 8px; cursor: pointer;
  text-align: left; line-height: 1.4; transition: background .12s;
}
.tile-q:hover { background: #d0e6f7; }
.tile-q-open {
  font-size: .73rem; color: var(--muted); background: transparent;
  border: 1px dashed var(--border); border-radius: 5px; padding: 5px 8px;
  cursor: pointer; text-align: left; line-height: 1.4; font-style: italic;
  transition: background .12s, border-color .12s, color .12s; margin-top: 2px;
}
.tile-q-open:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }

/* Admin controls */
.admin-edit-btn {
  margin-left: auto; background: none; border: 1px solid var(--border);
  border-radius: 5px; padding: 2px 6px; font-size: .7rem; cursor: pointer;
  color: var(--muted); flex-shrink: 0;
  transition: border-color .12s, color .12s;
}
.admin-edit-btn:hover { border-color: var(--accent); color: var(--accent); }

.admin-panel {
  grid-column: 1 / -1;
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 18px 20px;
}
.admin-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.admin-panel-title { font-size: .9rem; font-weight: 700; }
.admin-panel-close {
  background: none; border: none; font-size: 1.2rem; cursor: pointer;
  color: var(--muted); line-height: 1;
}
.admin-q-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.admin-q-input {
  flex: 1; border: 1px solid var(--border); border-radius: 5px;
  padding: 5px 8px; font-size: .8rem; font-family: inherit;
}
.admin-q-input:focus { outline: none; border-color: var(--accent); }
.admin-icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 7px; cursor: pointer; font-size: .8rem; color: var(--muted);
  transition: border-color .12s, color .12s;
}
.admin-icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.admin-icon-btn.del:hover { border-color: #d93025; color: #d93025; }
.admin-add-row {
  display: flex; align-items: center; gap: 6px; margin-top: 12px;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.admin-oe-label { font-size: .75rem; color: var(--muted); white-space: nowrap; }

/* ── Sections ────────────────────────────────────────────────────── */
.section-head { font-size: 1.2rem; font-weight: 800; margin-bottom: 6px; }
.section-sub  { font-size: .93rem; color: var(--muted); max-width: 44rem; line-height: 1.65; margin-bottom: 24px; }

.grid-3 { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; }
@media(max-width:760px){ .grid-3 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card-tag {
  display: inline-block; margin-bottom: 10px;
  padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 600;
  background: var(--accent-light); color: var(--accent); border: 1px solid rgba(0,85,165,.18);
}
.card h3 { font-size: .95rem; font-weight: 700; margin-bottom: 8px; }
.card p  { font-size: .87rem; color: var(--muted); line-height: 1.6; }

/* ── Upgrade CTA section ─────────────────────────────────────────── */
.upgrade-section {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: var(--radius-lg); padding: 36px 40px;
}
#upgrade-public,
#upgrade-basic {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
}
.upgrade-text { flex: 1; min-width: 0; }
.upgrade-section h2 { font-size: 1.3rem; font-weight: 800; color: #fff; margin-bottom: 6px; }
.upgrade-section p  { font-size: .92rem; color: rgba(255,255,255,.82); max-width: 36rem; line-height: 1.6; }
.cta-white {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 28px; border-radius: var(--radius);
  background: #fff; color: var(--accent-dark);
  font-size: .92rem; font-weight: 700; border: none; cursor: pointer;
  flex-shrink: 0; font-family: var(--font); transition: opacity .15s;
}
.cta-white:hover { opacity: .9; }

/* ── Sign-in modal ───────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 200;
  align-items: center; justify-content: center;
  overflow-y: auto; padding: 24px 16px;   /* scroll the overlay if a modal is taller than the viewport */
}
.modal-overlay.open { display: flex; }
/* When any modal/drawer is open, lock the page behind so the wheel scrolls the
   modal's own content, not the page. Toggled in JS via a MutationObserver. */
body.modal-open { overflow: hidden; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 28px 32px 32px; width: min(460px, calc(100vw - 40px));
  box-shadow: var(--shadow-lg);
  margin: auto;   /* center when it fits, allow overlay scroll when taller than viewport */
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
/* Enlarge the click/touch target: the bare "×" glyph was only ~13px wide, so
   clicks landing just off it hit dead space and seemed to do nothing. Padding +
   min size give a comfortable 36px target; the negative right margin keeps the
   glyph visually flush with the modal edge. */
.modal-close {
  background: none; border: none; font-size: 1.4rem; cursor: pointer;
  color: var(--muted); line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; min-height: 36px; padding: 6px; margin: -6px -8px -6px 0;
  border-radius: 6px; position: relative; z-index: 1;
}
.modal-close:hover { color: var(--text); background: var(--surface); }
.modal-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 22px; }
.modal-tab {
  flex: 1; padding: 8px 4px; border: none; background: none;
  font-size: .84rem; font-weight: 600; color: var(--muted);
  cursor: pointer; font-family: var(--font); border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: color .15s, border-color .15s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.modal-tab:hover:not(.active) { color: var(--text); }
.modal-panel { display: none; }
.modal-panel.active { display: block; }
.modal label { font-size: .85rem; font-weight: 600; display: block; margin-bottom: 6px; margin-top: 14px; }
.modal label:first-child { margin-top: 0; }
.modal-input {
  width: 100%; padding: 9px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .87rem; font-family: var(--font);
  color: var(--text); background: var(--surface2); outline: none;
  box-sizing: border-box; transition: border-color .15s;
}
.modal-input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .cta-btn { flex: 1; justify-content: center; }
.modal-cancel {
  flex: 1; padding: 10px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  font-size: .88rem; font-weight: 600; color: var(--muted);
  cursor: pointer; font-family: var(--font); transition: border-color .15s, color .15s;
}
.modal-cancel:hover { border-color: var(--accent); color: var(--accent); }
.modal-err { color: #c0392b; font-size: .82rem; margin-top: 8px; display: none; }
.modal-ok  { color: var(--green); font-size: .82rem; margin-top: 8px; display: none; }

/* Dealer picker */
.dealer-list {
  margin-top: 12px; max-height: 320px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface2);
}
.dealer-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 10px 14px; border: none; border-bottom: 1px solid var(--border);
  background: transparent; cursor: pointer; font-family: var(--font); text-align: left;
  transition: background .12s;
}
.dealer-item:last-child { border-bottom: none; }
.dealer-item:hover { background: var(--surface); }
.dealer-item-name { font-size: .87rem; font-weight: 600; color: var(--text); }
.dealer-item-code { font-size: .76rem; color: var(--muted); white-space: nowrap; }
.dealer-loading, .dealer-empty { padding: 18px; text-align: center; color: var(--muted); font-size: .85rem; }
.dealer-list.dealer-selecting { pointer-events: none; opacity: .7; }
.dealer-item--selecting { background: var(--surface) !important; }
.dealer-item-spinner {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline spinner for buttons in a loading state (e.g. MPS login while the
   staging pool wakes up). White-on-accent to match .cta-btn. */
.btn-spinner {
  display: inline-block; width: 14px; height: 14px; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.cta-btn.is-loading { opacity: .85; cursor: progress; }
.dealer-pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.dealer-pager .modal-cancel { flex: 0 0 auto; padding: 7px 16px; }
.dealer-pager .modal-cancel:disabled { opacity: .4; cursor: default; border-color: var(--border); color: var(--muted); }
.dealer-count { font-size: .78rem; color: var(--muted); }
.modal-divider { text-align: center; font-size: .8rem; color: var(--muted); margin: 16px 0; position: relative; }
.modal-divider::before, .modal-divider::after {
  content:''; position: absolute; top: 50%; width: 42%; height: 1px; background: var(--border);
}
.modal-divider::before { left: 0; } .modal-divider::after { right: 0; }
.btn-ms {
  width: 100%; padding: 11px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  font-size: .9rem; font-weight: 600; color: var(--text);
  cursor: pointer; font-family: var(--font);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: border-color .15s, background .15s;
}
.btn-ms:hover { border-color: var(--accent); background: var(--accent-light); }
.ms-remember-row {
  display: flex; align-items: center; gap: 7px;
  margin-top: 10px; font-size: .82rem; color: var(--muted);
}
.ms-remember-row input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); width: 14px; height: 14px; flex-shrink: 0; }
.ms-remember-row label { cursor: pointer; margin: 0; font-weight: 400; font-size: .82rem; }
.toggle-form-link { font-size: .82rem; color: var(--accent); cursor: pointer; text-decoration: underline; margin-top: 10px; display: inline-block; }
.toggle-form-link:hover { color: var(--accent-dark); }
.btn-li { background: #0a66c2; border-color: #0a66c2; color: #fff; }
.btn-li:hover { background: #004182; border-color: #004182; color: #fff; }

/* ── Footer ──────────────────────────────────────────────────────── */
footer { background: var(--surface); border-top: 1px solid var(--border); padding: 14px 24px; }
.footer-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; font-size: .78rem; color: var(--muted);
}
.footer-links { display: flex; gap: 16px; }
.footer-links a { color: var(--muted); }
.footer-links a:hover { color: var(--accent); text-decoration: none; }

@media(max-width:600px){
  .page { padding: 24px 16px 48px; gap: 40px; }
  .upgrade-section { padding: 28px 24px; }
  .topnav-inner { padding: 0 16px; }
}

/* ── Utility classes (replace inline styles) ─────────────────────── */
.flex-shrink-0   { flex-shrink: 0; }
.d-none          { display: none !important; }
.invisible       { visibility: hidden; }

/* Inline icon sizes */
.icon-sm  { width: 11px; height: 11px; object-fit: contain; flex-shrink: 0; }
.icon-tab { height: 14px; width: 14px; object-fit: contain; flex-shrink: 0; }
.icon-xs  { width: 13px; height: 13px; object-fit: contain; }

/* Modal text variants */
.modal-desc     { font-size: .87rem; color: var(--muted); margin-bottom: 6px;  line-height: 1.6; }
.modal-desc-sub { font-size: .8rem;  color: var(--muted); margin-bottom: 16px; }
.modal-note     { font-size: .82rem; color: var(--muted); margin-top: 14px; text-align: center; }
.modal-desc-ms  { font-size: .87rem; color: var(--muted); margin-bottom: 14px; line-height: 1.6; }

/* Label variants */
.label-no-top { margin-top: 0; }
.label-sm     { font-size: .85rem; font-weight: 600; display: block; margin-bottom: 4px; }

/* Layout helpers */
.mt-16            { margin-top: 16px; }
.upgrade-btns-row { display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.btn-stretch      { flex: 1; justify-content: center; }
.modal-input-mb   { margin-bottom: 10px; }
.modal-narrow     { max-width: 400px; }

/* Upgrade ghost white button */
.cta-white-ghost {
  background: rgba(255,255,255,.15); color: #fff;
  border: 1px solid rgba(255,255,255,.45);
}

/* Tab: Microsoft subtle styling */
.tab-ms-style { color: var(--muted); font-size: .8rem; }

/* Link: accent color, no-wrap */
.link-accent-nowrap { color: var(--accent); white-space: nowrap; }

/* Inline chat link (upgrade-soft) */
.link-muted-inline { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Error/warning colours in chat bubbles */
.err-critical  { color: #c0392b; }
.err-ratelimit { color: var(--orange); }

/* Inline context notice shown atop a recalled conversation (dealer switch) */
.context-notice {
  align-self: center; max-width: 100%;
  font-size: .78rem; color: var(--accent-dark);
  background: var(--accent-light); border: 1px solid rgba(0,85,165,.2);
  border-radius: 8px; padding: 7px 12px; margin: 2px 0 4px;
}
.context-notice-warn { color: #8a5300; background: #fdf3e3; border-color: rgba(217,119,6,.3); }

/* ── Chat history drawer (MPS customers/admins only) ─────────────────────── */
.history-overlay {
  position: fixed; inset: 0; background: rgba(15,30,50,.35);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 200;
}
.history-overlay.open { opacity: 1; pointer-events: auto; }
.history-drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 340px; max-width: 88vw;
  background: var(--surface); box-shadow: -8px 0 32px rgba(0,40,100,.18);
  transform: translateX(100%); transition: transform .22s ease; z-index: 201;
  display: flex; flex-direction: column; padding: 16px;
}
.history-drawer.open { transform: translateX(0); }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.history-head h3 { font-size: 1rem; font-weight: 700; }
.history-new { width: 100%; justify-content: center; margin-bottom: 10px; }
.history-search { width: 100%; margin-bottom: 6px; }
.history-list {
  flex: 1; overflow-y: auto; margin-top: 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.history-item {
  position: relative; cursor: pointer;
  padding: 9px 30px 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  transition: border-color .15s, background .15s;
}
.history-item:hover { border-color: var(--accent); background: var(--accent-light); }
.history-item.active { border-color: var(--accent); background: var(--accent-light); }
.history-item-title { font-size: .84rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item-date { font-size: .7rem; color: var(--muted); margin-top: 2px; }
.history-item-dealer { color: var(--accent); font-weight: 600; }
.history-item-del {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; padding: 0; border: none; background: none;
  color: var(--muted); cursor: pointer; border-radius: 5px; font-size: .95rem; line-height: 1;
  opacity: 0; transition: opacity .15s, color .15s, background .15s;
}
.history-item:hover .history-item-del { opacity: 1; }
.history-item-del:hover { color: #c0392b; background: rgba(192,57,43,.1); }
.history-empty { color: var(--muted); font-size: .82rem; text-align: center; padding: 24px 8px; }
@media (hover: none) { .history-item-del { opacity: .7; } }
