/* ============================================================
   Sertrus2 — SERA Chatbot UI
   Floating bubble + chat panel + ticket modal
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --s2-blue: #1a56db;
  --s2-blue-dark: #1341a8;
  --s2-purple: #7c3aed;
  --s2-green: #059669;
  --s2-red: #dc2626;
  --s2-orange: #d97706;
  --s2-bg: #f8fafc;
  --s2-surface: #ffffff;
  --s2-border: #e2e8f0;
  --s2-text: #1e293b;
  --s2-text-muted: #64748b;
  --s2-radius: 16px;
  --s2-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

/* ── Floating Bubble ────────────────────────────────────── */
#sera-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#sera-bubble-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--s2-blue), var(--s2-purple));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(26, 86, 219, 0.45);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}

#sera-bubble-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(26, 86, 219, 0.55);
}

#sera-bubble-btn svg {
  width: 28px;
  height: 28px;
  color: white;
  fill: white;
}

#sera-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--s2-red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  display: none;
}

#sera-tooltip {
  background: var(--s2-text);
  color: white;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#sera-bubble:hover #sera-tooltip {
  opacity: 1;
}

/* ── Chat Panel ─────────────────────────────────────────── */
#sera-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 380px;
  max-height: 580px;
  background: var(--s2-surface);
  border-radius: var(--s2-radius);
  box-shadow: var(--s2-shadow);
  display: none;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  border: 1px solid var(--s2-border);
  animation: seraSlideUp 0.25s ease;
}

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

#sera-panel.open { display: flex; }

/* Header */
#sera-header {
  background: linear-gradient(135deg, var(--s2-blue), var(--s2-purple));
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
}

#sera-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

#sera-header-info { flex: 1; }
#sera-header-name { font-weight: 700; font-size: 15px; }
#sera-header-status { font-size: 12px; opacity: 0.85; display: flex; align-items: center; gap: 5px; }
#sera-header-status::before {
  content: '';
  width: 7px; height: 7px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
}

#sera-close-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
#sera-close-btn:hover { background: rgba(255,255,255,0.3); }

/* Messages */
#sera-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--s2-bg);
}

#sera-messages::-webkit-scrollbar { width: 4px; }
#sera-messages::-webkit-scrollbar-track { background: transparent; }
#sera-messages::-webkit-scrollbar-thumb { background: var(--s2-border); border-radius: 2px; }

.sera-msg {
  display: flex;
  gap: 8px;
  max-width: 100%;
  animation: seraFadeIn 0.2s ease;
}

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

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

.sera-msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.sera-msg.assistant .sera-msg-avatar {
  background: linear-gradient(135deg, var(--s2-blue), var(--s2-purple));
  color: white;
}
.sera-msg.user .sera-msg-avatar {
  background: var(--s2-blue);
  color: white;
}

.sera-msg-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
}

.sera-msg.assistant .sera-msg-bubble {
  background: var(--s2-surface);
  color: var(--s2-text);
  border: 1px solid var(--s2-border);
  border-bottom-left-radius: 4px;
}

.sera-msg.user .sera-msg-bubble {
  background: var(--s2-blue);
  color: white;
  border-bottom-right-radius: 4px;
}

.sera-msg-bubble strong { font-weight: 600; }
.sera-msg-bubble ul { margin: 6px 0 0 16px; padding: 0; }
.sera-msg-bubble li { margin-bottom: 3px; }

/* Typing indicator */
#sera-typing {
  display: none;
  padding: 0 16px 8px;
  background: var(--s2-bg);
}
#sera-typing.show { display: flex; }

.sera-typing-dots {
  background: var(--s2-surface);
  border: 1px solid var(--s2-border);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.sera-typing-dots span {
  width: 7px; height: 7px;
  background: var(--s2-blue);
  border-radius: 50%;
  animation: seraDot 1.2s infinite;
}
.sera-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.sera-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes seraDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Quick replies */
#sera-quick-replies {
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--s2-bg);
  border-top: 1px solid var(--s2-border);
}

.sera-quick-btn {
  background: white;
  border: 1px solid var(--s2-blue);
  color: var(--s2-blue);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.sera-quick-btn:hover {
  background: var(--s2-blue);
  color: white;
}

/* Input */
#sera-input-row {
  padding: 12px 14px;
  background: var(--s2-surface);
  border-top: 1px solid var(--s2-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#sera-input {
  flex: 1;
  border: 1px solid var(--s2-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 100px;
  line-height: 1.4;
  background: var(--s2-bg);
  color: var(--s2-text);
}
#sera-input:focus { border-color: var(--s2-blue); }
#sera-input::placeholder { color: var(--s2-text-muted); }

#sera-send-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--s2-blue);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
#sera-send-btn:hover { background: var(--s2-blue-dark); }
#sera-send-btn:disabled { background: var(--s2-border); cursor: not-allowed; }

/* ── Ticket Modal ────────────────────────────────────────── */
#sera-ticket-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#sera-ticket-modal.open { display: flex; }

#sera-ticket-box {
  background: white;
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--s2-shadow);
  animation: seraSlideUp 0.25s ease;
}

#sera-ticket-box h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--s2-text);
  margin: 0 0 6px;
}

#sera-ticket-box p {
  font-size: 13px;
  color: var(--s2-text-muted);
  margin: 0 0 20px;
}

.sera-field {
  margin-bottom: 14px;
}

.sera-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--s2-text);
  margin-bottom: 5px;
}

.sera-field input,
.sera-field select,
.sera-field textarea {
  width: 100%;
  border: 1px solid var(--s2-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  color: var(--s2-text);
  background: var(--s2-bg);
  box-sizing: border-box;
}

.sera-field input:focus,
.sera-field select:focus,
.sera-field textarea:focus {
  border-color: var(--s2-blue);
}

.sera-field textarea { resize: vertical; min-height: 80px; }

.sera-ticket-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.sera-btn {
  flex: 1;
  padding: 11px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.sera-btn-primary {
  background: var(--s2-blue);
  color: white;
}
.sera-btn-primary:hover { background: var(--s2-blue-dark); }

.sera-btn-ghost {
  background: var(--s2-bg);
  color: var(--s2-text-muted);
  border: 1px solid var(--s2-border);
}
.sera-btn-ghost:hover { background: var(--s2-border); }

/* ── Urgency badges ─────────────────────────────────────── */
.urgency-critical { color: var(--s2-red); font-weight: 700; }
.urgency-high     { color: var(--s2-orange); font-weight: 600; }
.urgency-normal   { color: var(--s2-blue); }
.urgency-low      { color: var(--s2-text-muted); }

.status-open        { background: #dbeafe; color: #1e40af; }
.status-in_progress { background: #fef3c7; color: #92400e; }
.status-resolved    { background: #d1fae5; color: #065f46; }
.status-closed      { background: #f1f5f9; color: #64748b; }

.ticket-badge {
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  #sera-panel {
    width: calc(100vw - 20px);
    right: 10px;
    bottom: 90px;
    max-height: calc(100vh - 120px);
  }
  #sera-bubble { bottom: 20px; right: 14px; }
}
