:root{
  --bg:#000000;
  --panel:#0b0f14;
  --panel2:#0a0d12;
  --line: rgba(255,255,255,.08);
  --text:#ffffff;
  --muted: rgba(255,255,255,.65);
  --green:#00FF80;
  --accent:#00FF80;
  --accent2:#2D7DFF;
  --shadow: 0 18px 48px rgba(0,0,0,.6);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

body.ensure-dark{
  margin:0;
  color:var(--text);
  background:
    radial-gradient(1200px 650px at 18% 0%, rgba(45,125,255,.16), transparent 62%),
    radial-gradient(900px 520px at 85% 10%, rgba(0,255,128,.12), transparent 60%),
    radial-gradient(900px 520px at 40% 90%, rgba(0,255,128,.06), transparent 60%),
    var(--bg);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

/* Shell */
.ensure-shell{
  width:100%;
  display:flex;
  justify-content:center;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
}

/* Card */
.chat-card{
  width:min(980px, 100%);
  height: calc(100svh - 64px - 20px - env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.015));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

/* Messages */
.messages{
  flex:1;
  overflow-y:auto;
  padding: 14px 14px;
  scroll-behavior:smooth;

  /* hide scrollbar */
  scrollbar-width: none;
}
.messages::-webkit-scrollbar{ width:0; height:0; }

.msg{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin: 10px 0;
  max-width: 86%;
}

.msg.bot{ align-self:flex-start; }
.msg.user{ align-self:flex-end; }

.msg-name{
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  padding-left: 6px;
}

/* Bubbles (no blue borders) */
.bubble{
  font-size: 17px;
  line-height: 1.45;
  border-radius: 16px;
  padding: 12px 12px;
  border: 1px solid var(--line);
  background: rgba(12,16,22,.85);
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.bot{
  /* Assistant content is rendered inside an inner "card" for a cleaner
     ChatGPT/Grok-style layout. */
  background: transparent;
  border: none;
  padding: 0;
}

/* Report link under assistant messages */
.msg-actions{
  display:flex;
  gap:10px;
  margin-top:10px;
}
.link-btn{
  appearance:none;
  border:0;
  background:transparent;
  color: rgba(255,255,255,0.72);
  font-size:12px;
  padding:0;
  cursor:pointer;
  text-decoration: underline;
}
.link-btn:hover{ color: rgba(255,255,255,0.92); }

/* Optional lightweight toast */
#toast{
  position:fixed;
  left:50%;
  bottom:84px;
  transform:translateX(-50%);
  background: rgba(0,0,0,0.80);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.92);
  padding:10px 12px;
  border-radius:12px;
  font-size:13px;
  opacity:0;
  pointer-events:none;
  transition: opacity 160ms ease;
  z-index:9999;
}
#toast.show{ opacity:1; }

.bubble.bot .rich-card{
  background: rgba(10,13,18,.88);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 12px 14px;
}

.bubble.bot .rich-card h1,
.bubble.bot .rich-card h2,
.bubble.bot .rich-card h3{
  margin: 0.2em 0 0.4em;
  letter-spacing: .01em;
}

.bubble.bot .rich-card ul,
.bubble.bot .rich-card ol{
  margin: 0.35em 0 0.35em 1.15em;
}

.bubble.bot .rich-card table{
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08);
}

.bubble.bot .rich-card th,
.bubble.bot .rich-card td{
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.bubble.bot .rich-card tr:last-child td{
  border-bottom: none;
}

.bubble.user{
  border-color: rgba(50,255,90,.22);
  background: rgba(50,255,90,.12);
}

/* Links */
.bot-link{
  color: var(--green);
  text-decoration: none;
  font-weight: 800;
}
.bot-link:hover{ text-decoration: underline; }

/* Chips */
.chips{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin-top:12px;
}

/* Lead capture card (inside chat) */
.lead-card{
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
}

.lead-card.lead-done .lead-grid,
.lead-card.lead-done .lead-notes,
.lead-card.lead-done .lead-submit{
  display:none;
}

.lead-title{
  font-weight: 900;
  margin-bottom: 10px;
  color: rgba(255,255,255,.92);
}

.lead-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}

.lead-field{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size: 12px;
  color: var(--muted);
}

.lead-field input,
.lead-field textarea{
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.45);
  color: #fff;
  padding: 10px 10px;
  outline:none;
}

.lead-notes{ margin-top: 10px; }
.lead-notes textarea{ resize: vertical; }

.lead-actions{
  display:flex;
  gap:10px;
  align-items:center;
  margin-top: 12px;
}

.lead-submit{
  border: 1px solid rgba(50,255,90,.35);
  background: rgba(50,255,90,.18);
  color: #fff;
  font-weight: 900;
  border-radius: 12px;
  padding: 10px 12px;
  cursor:pointer;
}

.lead-status{
  font-size: 12px;
  color: rgba(255,255,255,.65);
}

.chip{
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 999px;
  cursor:pointer;
  font-weight:800;
}
.chip:active{ transform: scale(.98); }

/* Typing dots */
.typing-row{
  display:flex;
  align-items:center;
  gap:8px;
}

.typing{
  display:flex;
  gap:6px;
  padding: 10px 12px;
  width: fit-content;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.05);
}
.typing span{
  width:7px; height:7px;
  border-radius:50%;
  background: rgba(255,255,255,.55);
  animation: bounce 1s infinite;
}
.typing span:nth-child(2){ animation-delay:.12s; }
.typing span:nth-child(3){ animation-delay:.24s; }

@keyframes bounce{
  0%, 80%, 100% { transform: translateY(0); opacity:.6; }
  40% { transform: translateY(-5px); opacity:1; }
}

/* Composer: INPUT + + + SEND */
.composer{
  padding: 12px;
  border-top: 1px solid var(--line);
  background: rgba(0,0,0,.55);
  display:grid;
  grid-template-columns: 1fr 52px 56px;
  gap:10px;
  align-items:center;
}

.chat-input{
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(15,22,34,.55);
  color: #fff;
  padding: 0 12px;
  outline:none;
}
.chat-input::placeholder{ color: rgba(255,255,255,.55); }

.menu-btn,
.send-btn{
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  font-weight: 900;
}

.menu-btn{
  background: rgba(255,255,255,.06);
  color: var(--text);
  font-size: 20px;
}

.send-btn{
  background: radial-gradient(circle at 30% 30%, rgba(50,255,90,.95), rgba(20,199,103,.85));
  color: #04110a;
  border-color: rgba(50,255,90,.35);
  font-size: 18px;
}

/* Footer */
.footer{
  padding: 10px 12px 12px;
  text-align:center;
  font-size: 12px;
  color: rgba(255,255,255,.45);
  border-top: 1px solid rgba(255,255,255,.06);
  background: rgba(0,0,0,.35);
}

/* Menu overlay + sheet */
.menu-overlay{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.65);
  opacity:0;
  pointer-events:none;
  transition: opacity .18s ease;
  z-index:40;
}
.menu-overlay.show{
  opacity:1;
  pointer-events:auto;
}

.menu-sheet{
  position:fixed;
  left:50%;
  transform: translateX(-50%) translateY(120%);
  bottom: 10px;
  width:min(680px, calc(100% - 18px));
  background: rgba(12,16,22,.95);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 10px 10px 12px;
  transition: transform .18s ease;
  z-index:50;
}
.menu-sheet.show{
  transform: translateX(-50%) translateY(0);
}

.menu-grabber{
  width:64px; height:6px;
  border-radius:999px;
  background: rgba(255,255,255,.18);
  margin: 6px auto 10px;
}

.menu-title{
  font-weight: 900;
  margin: 0 8px 10px;
  color: var(--text);
}

.menu-item{
  width:100%;
  text-align:left;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  padding: 12px 12px;
  margin: 8px 0;
  color: var(--text);
  cursor:pointer;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.menu-item:hover{ background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.18); transform: translateY(-1px); }
.menu-item-title{ font-weight: 900; }
.menu-item-sub{ color: var(--muted); font-size: 12px; margin-top:4px; }

.menu-close{
  width:100%;
  margin-top:8px;
  height:44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: var(--text);
  font-weight:900;
  cursor:pointer;
}


/* ---- Lead form (embedded in chat) ---- */
.lead-form{
  margin-top: 12px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.03);
  border-radius: 14px;
  padding: 12px;
}
.lead-form-title{
  font-weight: 900;
  margin-bottom: 4px;
}
.lead-form-sub{
  color: rgba(255,255,255,.65);
  font-size: 12px;
  margin-bottom: 10px;
}
.lead-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}
.lead-grid label{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size: 12px;
  color: rgba(255,255,255,.75);
}
.lead-grid input{
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.35);
  color:#fff;
  padding: 0 10px;
  outline:none;
}
.lead-grid input[readonly]{
  opacity:.8;
}
@media (max-width: 520px){
  .lead-grid{ grid-template-columns: 1fr; }
}
.lead-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin-top: 10px;
}
.lead-status{
  margin-top: 10px;
  font-size: 12px;
  color: rgba(255,255,255,.75);
}


/* Inline SVG chart rendering */
.chart-wrap{margin-top:8px;margin-bottom:8px;border:1px solid rgba(255,255,255,0.08);border-radius:12px;padding:10px;background:rgba(255,255,255,0.03)}
.chart-link{display:inline-block;margin-bottom:8px;font-size:12px;color:#9fb0c6;text-decoration:underline}
.chart-img img{width:100%;height:auto;max-width:720px;display:block;border-radius:10px;background:#0b0f14}


/* Chips (CHOICES) */
.chips{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}

@media (max-width: 520px){
  .chips{flex-wrap:nowrap;overflow-x:auto;-webkit-overflow-scrolling:touch}
  .chips::-webkit-scrollbar{height:6px}
}
.chip{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;padding:8px 12px;border-radius:999px;border:1px solid rgba(255,255,255,.18);background:rgba(255,255,255,.06);color:#eaf2ff;font-size:14px;cursor:pointer;user-select:none;white-space:normal;word-break:normal;overflow-wrap:normal;hyphens:none;min-width:160px;max-width:78vw;text-align:center;writing-mode:horizontal-tb;text-orientation:mixed}
.chip:hover{background:rgba(255,255,255,.10)}

/*
  Mobile Safari sometimes inherits aggressive word-breaking from container styles,
  causing choice buttons to wrap letter-by-letter (tall vertical pills).
  Force sane wrapping + a usable minimum width for all chip buttons.
*/
.chips .chip{
  word-break: normal !important;
  overflow-wrap: normal !important;
  white-space: normal !important;
  min-width: 140px !important;
}

@media (max-width: 520px){
  .chips{flex-wrap:nowrap !important; overflow-x:auto !important; -webkit-overflow-scrolling:touch}
  .chips::-webkit-scrollbar{display:none}
  .chips .chip{flex:0 0 auto !important; max-width:78vw !important;}
}

/* State picker chips */
.state-chips{margin-top:10px;display:flex;gap:8px;flex-wrap:wrap}
.state-chip{gap:6px;justify-content:flex-start;align-items:flex-start;padding:10px 12px;min-width:150px;max-width:78vw;flex-direction:column}
.state-chip b{font-weight:900}
.state-chip .state-name{font-size:12px;opacity:.8}

@media (max-width: 520px){
  .state-chips{flex-wrap:nowrap;overflow-x:auto;-webkit-overflow-scrolling:touch}
  .state-chips::-webkit-scrollbar{display:none}
  .state-chip{min-width:130px}
}

/* Message spacing */
.bubble{line-height:1.45}
.bubble p{margin:0 0 10px 0}
.bubble p:last-child{margin-bottom:0}
.bubble ul{margin:0 0 10px 18px}
.bubble li{margin:4px 0}

/* Consent modal */
.consent-modal{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.65);z-index:9999;padding:16px}
.consent-card{max-width:520px;width:100%;border:1px solid rgba(255,255,255,.10);background:#0b0f14;border-radius:16px;padding:16px;color:#e6eef6}
.consent-title{font-weight:900;font-size:16px;margin-bottom:8px}
.consent-body{font-size:13px;color:rgba(230,238,246,.82);line-height:1.45;white-space:pre-line}
.consent-actions{display:flex;gap:10px;margin-top:12px;flex-wrap:wrap}
.consent-btn{flex:1;min-width:140px;height:44px;border-radius:14px;border:1px solid rgba(255,255,255,.14);background:rgba(255,255,255,.08);color:#e6eef6;font-weight:900;cursor:pointer}
.consent-btn.primary{background:rgba(120,255,167,.14);border-color:rgba(120,255,167,.25)}

/* Generic modal (used for Talk-to-Agent Terms) */
.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.72);opacity:0;pointer-events:none;transition:opacity .18s ease;z-index:9998}
.modal-overlay.show{opacity:1;pointer-events:auto}
.modal-card{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);width:min(720px,92vw);max-height:80vh;overflow:auto;background:#0b0f14;border:1px solid rgba(255,255,255,.10);border-radius:16px;padding:16px;color:#e6eef6;box-shadow:0 22px 60px rgba(0,0,0,.75);opacity:0;pointer-events:none;transition:opacity .18s ease;z-index:9999}
.modal-card.show{opacity:1;pointer-events:auto}
.modal-title{font-weight:900;font-size:16px;margin-bottom:10px}
.modal-text{font-size:13px;line-height:1.45;color:rgba(230,238,246,.86)}
.modal-check{display:flex;gap:10px;align-items:flex-start;margin:12px 0}
.modal-check input{margin-top:3px}
.modal-actions{display:flex;gap:10px;justify-content:flex-end;flex-wrap:wrap}
.btn-secondary{background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.14);color:#e6eef6;border-radius:14px;padding:10px 12px;cursor:pointer;font-weight:900}
.btn-primary{background:rgba(120,255,167,.14);border:1px solid rgba(120,255,167,.25);color:#e6eef6;border-radius:14px;padding:10px 12px;cursor:pointer;font-weight:900}


/* Quote & Apply modal */
.qa-overlay{
  position:fixed; inset:0;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(6px);
  display:none;
  z-index: 50;
}
.qa-modal{
  position:fixed;
  top: 6vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(980px, calc(100vw - 24px));
  height: 88vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display:none;
  z-index: 60;
  overflow:hidden;
}
.qa-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,0));
}
.qa-title{
  font-weight: 650;
  letter-spacing: .2px;
}
.qa-close{
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  cursor:pointer;
}
.qa-body{
  position:relative;
  height: calc(88vh - 54px);
  padding: 10px;
  overflow:auto;
}
.qa-widget{
  width:100%;
  height:100%;
  min-height: 620px;
}
.qa-loading{
  display:flex;
  gap:10px;
  align-items:center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.02);
  margin-bottom: 10px;
}
.spinner{
  width:14px;
  height:14px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.18);
  border-top-color: rgba(255,255,255,.8);
  animation: spin 1s linear infinite;
}
@keyframes spin{ to { transform: rotate(360deg); } }



/* Readability improvements (mobile-first) */
.bubble { font-size: 17px; line-height: 1.45; }
.msg-name { font-size: 12px; }
#chatInput { font-size: 17px; line-height: 1.35; }
#sendBtn { font-size: 17px; }

@media (max-width: 520px){
  .bubble { font-size: 16.5px; }
  #chatInput { font-size: 16.5px; }
}


.card-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:10px}
.btn-secondary{background:transparent;border:1px solid rgba(255,255,255,.25);color:#fff}
.btn-secondary:hover{border-color:rgba(255,255,255,.4)}


.ensure-room-banner{padding:10px 12px;margin:10px 0;border:1px solid rgba(255,255,255,0.12);border-radius:14px;color:rgba(255,255,255,0.85);font-size:13px;text-align:center;background:rgba(255,255,255,0.04)}


@media(max-width:520px){
  .ensure-shell{ padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .messages{ padding: 10px 10px; }
  .bubble{ font-size: 15.5px; padding: 11px 11px; }
  .chat-input{ font-size: 16px; }
  .footer{ padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}
