/* ============================================================
   DIZ Chatbot v2.3 – Toggle button + bottom-right modal
   Brand: #422F84
   ============================================================ */

:root {
  --diz-primary:       #422F84;
  --diz-primary-dark:  #321f6a;
  --diz-primary-light: #5a44a0;
  --diz-white:         #ffffff;
  --diz-bg:            #f5f3fb;
  --diz-border:        #e2ddf2;
  --diz-text:          #1a1530;
  --diz-muted:         #7c6fa0;
  --diz-shadow:        0 12px 48px rgba(66,47,132,0.22), 0 2px 8px rgba(66,47,132,0.10);
  --diz-shadow-btn:    0 4px 20px rgba(66,47,132,0.50);
  --diz-radius:        20px;
  --diz-radius-sm:     12px;
}

/* ── Toggle Button ─────────────────────────────────────────── */
#diz-toggle-btn {
  position:        fixed;
  bottom:          28px;
  right:           28px;
  z-index:         99999;
  width:           58px;
  height:          58px;
  border-radius:   50%;
  background:      var(--diz-primary);
  border:          none;
  cursor:          pointer;
  box-shadow:      var(--diz-shadow-btn);
  display:         flex;
  align-items:     center;
  justify-content: center;
  transition:      transform 0.25s cubic-bezier(.34,1.56,.64,1),
                   background 0.2s ease,
                   box-shadow 0.2s ease;
  outline:         none;
  -webkit-tap-highlight-color: transparent;
}

#diz-toggle-btn:hover {
  background:  var(--diz-primary-light);
  transform:   scale(1.08);
  box-shadow:  0 6px 28px rgba(66,47,132,0.60);
}

#diz-toggle-btn:active {
  transform: scale(0.94);
}

/* Pulse ring when chat is closed */
#diz-toggle-btn::after {
  content:       '';
  position:      absolute;
  inset:         -6px;
  border-radius: 50%;
  border:        2px solid rgba(66,47,132,0.40);
  animation:     diz-pulse 2.5s ease-out infinite;
  pointer-events: none;
}

@keyframes diz-pulse {
  0%   { opacity: 1;   transform: scale(1); }
  70%  { opacity: 0;   transform: scale(1.45); }
  100% { opacity: 0;   transform: scale(1.45); }
}

#diz-toggle-btn.diz-open::after {
  animation: none;
  opacity:   0;
}

/* Icon swap */
.diz-icon-chat,
.diz-icon-close {
  position:  absolute;
  width:     24px;
  height:    24px;
  fill:      none;
  stroke:    var(--diz-white);
  stroke-width: 2;
  stroke-linecap:  round;
  stroke-linejoin: round;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(.34,1.56,.64,1);
}

.diz-icon-close {
  opacity:   0;
  transform: rotate(-90deg) scale(0.5);
}

#diz-toggle-btn.diz-open .diz-icon-chat {
  opacity:   0;
  transform: rotate(90deg) scale(0.5);
}

#diz-toggle-btn.diz-open .diz-icon-close {
  opacity:   1;
  transform: rotate(0deg) scale(1);
}

/* ── Chat Modal ─────────────────────────────────────────────── */
#diz-chat-modal {
  position:       fixed;
  bottom:         98px;
  right:          28px;
  z-index:        99998;
  width:          380px;
  max-width:      calc(100vw - 44px);
  height:         560px;
  max-height:     calc(100vh - 130px);
  background:     var(--diz-white);
  border-radius:  var(--diz-radius);
  box-shadow:     var(--diz-shadow);
  display:        flex;
  flex-direction: column;
  overflow:       hidden;
  border:         1px solid var(--diz-border);
  /* hidden by default */
  opacity:        0;
  transform:      translateY(16px) scale(0.96);
  pointer-events: none;
  transition:     opacity 0.28s cubic-bezier(.4,0,.2,1),
                  transform 0.28s cubic-bezier(.4,0,.2,1);
  transform-origin: bottom right;
}

#diz-chat-modal.diz-open {
  opacity:        1;
  transform:      translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────────── */
.diz-header {
  background:   var(--diz-primary);
  padding:      14px 18px;
  display:      flex;
  align-items:  center;
  gap:          12px;
  flex-shrink:  0;
}

.diz-header-avatar {
  width:           38px;
  height:          38px;
  border-radius:   50%;
  background:      rgba(255,255,255,0.15);
  display:         flex;
  align-items:     center;
  justify-content: center;
  flex-shrink:     0;
}

.diz-header-avatar svg {
  width:  20px;
  height: 20px;
  fill:   none;
  stroke: var(--diz-white);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.diz-header-info { flex: 1; min-width: 0; }

.diz-header-title {
  font-family:   system-ui, -apple-system, sans-serif;
  font-size:     15px;
  font-weight:   700;
  color:         var(--diz-white);
  line-height:   1.2;
  white-space:   nowrap;
  overflow:      hidden;
  text-overflow: ellipsis;
}

.diz-header-sub {
  font-family:  system-ui, -apple-system, sans-serif;
  font-size:    12px;
  color:        rgba(255,255,255,0.72);
  margin-top:   3px;
  display:      flex;
  align-items:  center;
  gap:          5px;
}

.diz-dot-online {
  width:         6px;
  height:        6px;
  border-radius: 50%;
  background:    #4ade80;
  flex-shrink:   0;
  animation:     diz-blink 2s ease-in-out infinite;
}

@keyframes diz-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.diz-btn-clear {
  background:    transparent;
  border:        none;
  cursor:        pointer;
  padding:       6px;
  border-radius: 8px;
  display:       flex;
  align-items:   center;
  justify-content: center;
  transition:    background 0.15s;
  flex-shrink:   0;
}

.diz-btn-clear:hover { background: rgba(255,255,255,0.18); }

.diz-btn-clear svg {
  width:  17px;
  height: 17px;
  stroke: rgba(255,255,255,0.85);
  fill:   none;
  stroke-width:    2;
  stroke-linecap:  round;
  stroke-linejoin: round;
}

/* ── Messages area ──────────────────────────────────────────── */
.diz-messages {
  flex:           1;
  overflow-y:     auto;
  padding:        14px 12px;
  background:     var(--diz-bg);
  display:        flex;
  flex-direction: column;
  gap:            10px;
  scroll-behavior: smooth;
}

.diz-messages::-webkit-scrollbar { width: 4px; }
.diz-messages::-webkit-scrollbar-track { background: transparent; }
.diz-messages::-webkit-scrollbar-thumb {
  background:    rgba(66,47,132,0.22);
  border-radius: 4px;
}

/* ── Message bubble ─────────────────────────────────────────── */
.diz-msg {
  display:        flex;
  flex-direction: column;
  max-width:      83%;
  animation:      diz-msg-in 0.2s ease;
}

@keyframes diz-msg-in {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

.diz-bubble {
  padding:       10px 14px;
  border-radius: 16px;
  font-family:   system-ui, -apple-system, sans-serif;
  font-size:     14px;
  line-height:   1.58;
  word-break:    break-word;
}

.diz-user .diz-bubble {
  background:               var(--diz-primary);
  color:                    var(--diz-white);
  border-bottom-right-radius: 4px;
}

.diz-bot .diz-bubble {
  background:              var(--diz-white);
  color:                   var(--diz-text);
  border-bottom-left-radius: 4px;
  box-shadow:              0 1px 4px rgba(66,47,132,0.10);
  border:                  1px solid var(--diz-border);
}

.diz-bot .diz-bubble strong { color: var(--diz-primary); }

.diz-time {
  font-size:  11px;
  color:      var(--diz-muted);
  margin-top: 4px;
  padding:    0 4px;
}

/* Sources */
.diz-sources {
  margin-top:    8px;
  padding:       8px 12px;
  background:    rgba(66,47,132,0.06);
  border-radius: 10px;
  border-left:   3px solid var(--diz-primary);
  max-width:     100%;
}

.diz-sources-label {
  font-size:      11px;
  font-weight:    700;
  color:          var(--diz-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom:  4px;
  font-family:    system-ui, -apple-system, sans-serif;
}

.diz-sources ul {
  margin:  0;
  padding: 0 0 0 14px;
}

.diz-sources li {
  font-size:  12px;
  color:      var(--diz-muted);
  margin:     2px 0;
  font-family: system-ui, -apple-system, sans-serif;
}

/* Typing dots */
.diz-typing {
  display:       flex;
  gap:           5px;
  padding:       12px 14px;
  background:    var(--diz-white);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  border:        1px solid var(--diz-border);
  box-shadow:    0 1px 4px rgba(66,47,132,0.08);
  align-self:    flex-start;
  width:         fit-content;
}

.diz-typing span {
  width:         7px;
  height:        7px;
  border-radius: 50%;
  background:    var(--diz-primary);
  opacity:       0.45;
  animation:     diz-bounce 1.1s ease-in-out infinite;
}

.diz-typing span:nth-child(2) { animation-delay: 0.18s; }
.diz-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes diz-bounce {
  0%, 100% { transform: translateY(0);    opacity: 0.45; }
  50%       { transform: translateY(-5px); opacity: 1;   }
}

/* Long-wait label */
.diz-wait-label {
  font-size:   12px;
  color:       var(--diz-muted);
  font-style:  italic;
  text-align:  center;
  padding:     3px 0;
  animation:   diz-fadein 0.4s ease;
  font-family: system-ui, -apple-system, sans-serif;
}

@keyframes diz-fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Input area ─────────────────────────────────────────────── */
.diz-input-area {
  padding:      10px 12px 12px;
  background:   var(--diz-white);
  border-top:   1px solid var(--diz-border);
  display:      flex;
  gap:          8px;
  align-items:  flex-end;
  flex-shrink:  0;
}

#diz-input {
  flex:         1;
  min-height:   40px;
  max-height:   96px;
  padding:      10px 13px;
  border:       1.5px solid var(--diz-border);
  border-radius: var(--diz-radius-sm);
  font-family:  system-ui, -apple-system, sans-serif;
  font-size:    14px;
  color:        var(--diz-text);
  background:   var(--diz-bg);
  resize:       none;
  outline:      none;
  line-height:  1.45;
  overflow-y:   auto;
  transition:   border-color 0.15s, background 0.15s;
}

#diz-input:focus {
  border-color: var(--diz-primary);
  background:   var(--diz-white);
}

#diz-input::placeholder { color: var(--diz-muted); }

#diz-send-btn {
  width:          42px;
  height:         42px;
  border-radius:  var(--diz-radius-sm);
  background:     var(--diz-primary);
  border:         none;
  cursor:         pointer;
  display:        flex;
  align-items:    center;
  justify-content: center;
  flex-shrink:    0;
  transition:     background 0.15s, transform 0.15s;
}

#diz-send-btn:hover:not(:disabled) {
  background: var(--diz-primary-light);
  transform:  translateY(-1px);
}

#diz-send-btn:active:not(:disabled) { transform: scale(0.94); }

#diz-send-btn:disabled {
  background: #c5bede;
  cursor:     not-allowed;
}

#diz-send-btn svg {
  width:  20px;
  height: 20px;
  stroke: var(--diz-white);
  fill:   none;
  stroke-width:    2.2;
  stroke-linecap:  round;
  stroke-linejoin: round;
}

/* ── Footer branding ────────────────────────────────────────── */
.diz-footer {
  padding:    5px 12px 9px;
  text-align: center;
  background: var(--diz-white);
  flex-shrink: 0;
}

.diz-footer a {
  font-family: system-ui, -apple-system, sans-serif;
  font-size:   11px;
  color:       var(--diz-muted);
  text-decoration: none;
  transition:  color 0.15s;
}

.diz-footer a:hover { color: var(--diz-primary); }

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #diz-toggle-btn { right: 16px; bottom: 18px; }
  #diz-chat-modal {
    right:  10px;
    bottom: 88px;
    width:  calc(100vw - 20px);
    height: calc(100dvh - 115px);
  }
}
