/* ============================================================
   Contract Assistant — Collapsible Chat Widget
   ============================================================ */

.chat-widget {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  font-family: var(--font-sans, 'Poppins', system-ui, sans-serif);
}

/* Toggle button */
.chat-widget-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--gold, #2563EB);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37, 99, 235, .35), 0 2px 4px rgba(0,0,0,.1);
  transition: transform .2s, box-shadow .2s;
  position: relative;
}

.chat-widget-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(37, 99, 235, .45), 0 2px 8px rgba(0,0,0,.15);
}

.chat-widget-label {
  position: absolute;
  right: 68px;
  background: var(--text-primary, #0a0a0a);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  padding: .35rem .65rem;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.chat-widget-toggle:hover .chat-widget-label {
  opacity: 1;
}

.chat-widget.open .chat-widget-label { display: none; }

/* Panel */
.chat-widget-panel {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 380px;
  max-height: 520px;
  background: var(--white, #fff);
  border: 1px solid var(--border, #DDE2EA);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.15), 0 4px 12px rgba(0,0,0,.08);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: widgetSlideUp .25s ease;
}

.chat-widget.open .chat-widget-panel {
  display: flex;
}

.chat-widget.open .chat-widget-icon-open { display: none; }
.chat-widget.open .chat-widget-icon-close { display: block !important; }

@keyframes widgetSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
.chat-widget-header {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border, #DDE2EA);
  background: var(--surface, #F5F7FA);
}

.chat-widget-header-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--gold, #2563EB);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-widget-title {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text-primary, #0a0a0a);
}

.chat-widget-sub {
  font-size: .72rem;
  color: var(--text-muted, #94A3B8);
}

/* Access gate */
.chat-widget-gate {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.5rem;
  flex: 1;
}

.chat-widget-gate h3 {
  font-family: var(--font-display, 'Poppins', system-ui, sans-serif);
  font-size: 1.1rem;
  font-weight: 700;
  margin: .5rem 0 .35rem;
  color: var(--text-primary);
}

.chat-widget-gate p {
  font-size: .82rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.chat-widget-gate .btn {
  display: inline-block;
  padding: .55rem 1.5rem;
  background: var(--gold);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: .85rem;
  transition: background .2s;
}

.chat-widget-gate .btn:hover {
  background: var(--gold-dark, #1d4ed8);
}

/* Suggestions */
.chat-widget-suggestions {
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.chat-widget-suggestion {
  padding: .55rem .75rem;
  background: var(--surface, #F5F7FA);
  border: 1px solid var(--border, #DDE2EA);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  transition: border-color .2s, background .2s;
}

.chat-widget-suggestion:hover {
  border-color: var(--gold);
  background: var(--white, #fff);
}

/* Messages */
.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  max-height: 280px;
}

.wgt-msg {
  display: flex;
  gap: .5rem;
  animation: widgetFadeIn .25s ease;
}

@keyframes widgetFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.wgt-msg--user { flex-direction: row-reverse; }

.wgt-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .65rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.wgt-msg--assistant .wgt-avatar { background: var(--gold); color: #fff; }
.wgt-msg--user .wgt-avatar { background: var(--text-primary); color: #fff; }

.wgt-bubble {
  padding: .6rem .8rem;
  border-radius: 10px;
  font-size: .82rem;
  line-height: 1.55;
  max-width: 78%;
  word-wrap: break-word;
}

.wgt-msg--user .wgt-bubble {
  background: var(--gold);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.wgt-msg--assistant .wgt-bubble {
  background: var(--surface, #F5F7FA);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.wgt-bubble p { margin: 0 0 .35rem; }
.wgt-bubble p:last-child { margin-bottom: 0; }
.wgt-bubble ul, .wgt-bubble ol { margin: .3rem 0; padding-left: 1.1rem; }
.wgt-bubble li { margin-bottom: .15rem; }
.wgt-bubble strong { font-weight: 600; }
.wgt-bubble code { background: rgba(0,0,0,.06); padding: .1rem .25rem; border-radius: 3px; font-size: .78rem; }

/* Typing */
.wgt-typing {
  display: flex;
  gap: 4px;
  padding: .6rem .8rem;
  align-items: center;
}

.wgt-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: wgtBounce 1.4s infinite;
}

.wgt-typing-dot:nth-child(2) { animation-delay: .2s; }
.wgt-typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes wgtBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Input */
.chat-widget-input-area {
  padding: .5rem .75rem .65rem;
  border-top: 1px solid var(--border, #DDE2EA);
}

.chat-widget-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: .4rem;
  background: var(--surface, #F5F7FA);
  border: 1.5px solid var(--border, #DDE2EA);
  border-radius: 10px;
  padding: .35rem .4rem .35rem .7rem;
  transition: border-color .2s;
}

.chat-widget-input-wrap:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .1);
}

.chat-widget-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: .82rem;
  color: var(--text-primary);
  background: transparent;
  resize: none;
  max-height: 80px;
  line-height: 1.5;
  padding: .25rem 0;
}

.chat-widget-input::placeholder { color: var(--text-muted); }

.chat-widget-send {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--gold);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s, transform .15s;
}

.chat-widget-send:hover:not(:disabled) {
  background: var(--gold-dark, #1d4ed8);
  transform: scale(1.05);
}

.chat-widget-send:disabled { opacity: .4; cursor: not-allowed; }

/* ═══════════ DARK MODE ═══════════ */

[data-theme="dark"] .chat-widget-panel {
  background: #141414;
  border-color: #2a2a2a;
  box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 4px 12px rgba(0,0,0,.3);
}

[data-theme="dark"] .chat-widget-header {
  background: #1a1a1a;
  border-bottom-color: #2a2a2a;
}

[data-theme="dark"] .chat-widget-suggestion {
  background: #1a1a1a;
  border-color: #2a2a2a;
  color: #e0e0e0;
}

[data-theme="dark"] .chat-widget-suggestion:hover {
  background: #222;
  border-color: var(--gold);
}

[data-theme="dark"] .wgt-msg--assistant .wgt-bubble {
  background: #1a1a1a;
  border-color: #2a2a2a;
  color: #e0e0e0;
}

[data-theme="dark"] .wgt-bubble code {
  background: rgba(255,255,255,.08);
}

[data-theme="dark"] .chat-widget-input-area {
  border-top-color: #2a2a2a;
}

[data-theme="dark"] .chat-widget-input-wrap {
  background: #1a1a1a;
  border-color: #2a2a2a;
}

[data-theme="dark"] .chat-widget-input {
  color: #e0e0e0;
}

[data-theme="dark"] .chat-widget-title { color: #e0e0e0; }

[data-theme="dark"] .chat-widget-toggle {
  box-shadow: 0 4px 16px rgba(37, 99, 235, .4), 0 2px 6px rgba(0,0,0,.3);
}

[data-theme="dark"] .chat-widget-label {
  background: #e0e0e0;
  color: #0a0a0a;
}

[data-theme="dark"] .chat-widget-gate h3 { color: #e0e0e0; }
[data-theme="dark"] .chat-widget-gate p { color: #999; }

/* ═══════════ RESPONSIVE ═══════════ */

@media (max-width: 480px) {
  .chat-widget-panel {
    width: calc(100vw - 1.5rem);
    right: -0.5rem;
    max-height: 70vh;
  }

  .chat-widget-toggle {
    width: 50px;
    height: 50px;
  }
}
