:root {
  --mv-purple: #6C5CE7;
  --mv-purple-dark: #5A4BD1;
  --mv-purple-pale: #EFEBFB;
  --mv-gold: #C99A4A;
  --mv-brown: #7A5C3E;
  --mv-bg: #FFFFFF;
  --mv-bot-bubble: #F1F1F4;
  --mv-text: #2D2A3E;
  --mv-text-muted: #8A8798;
  --mv-border: #ECEAF3;
  --mv-error: #D64545;
  --mv-radius-card: 24px;
  --mv-radius-bubble: 18px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--mv-text);
}

.mv-widget {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 680px;
  height: 640px;
  max-height: 100vh;
  margin: 0 auto;
  background: var(--mv-bg);
  border: 1px solid var(--mv-border);
  border-radius: var(--mv-radius-card);
  box-shadow: 0 20px 40px -12px rgba(45, 42, 62, 0.12);
  overflow: hidden;
}

/* ===== PERSONA CAROUSEL ===== */
.persona-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 18px 12px;
  flex-shrink: 0;
}

.persona-track {
  display: flex;
  gap: 22px;
  overflow-x: hidden;
  scroll-behavior: smooth;
  flex: 1;
  padding: 0 6px;
}

.persona-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  width: 84px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
}

.persona-item.is-primary {
  width: auto;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.persona-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.persona-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--mv-purple-pale);
  display: block;
  transition: width 0.2s ease, height 0.2s ease, opacity 0.2s ease;
  animation: mv-avatar-pop 0.25s ease;
}

@keyframes mv-avatar-pop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.persona-item.is-secondary .persona-avatar {
  width: 44px;
  height: 44px;
  opacity: 0.85;
}

.persona-check {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--mv-brown);
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.persona-check svg { width: 11px; height: 11px; }

.persona-name-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  min-width: 0;
}

.persona-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--mv-text);
  white-space: nowrap;
}

.persona-signature {
  font-size: 12px;
  color: var(--mv-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.persona-arrow {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--mv-purple);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.persona-arrow:hover { background: var(--mv-purple-dark); }
.persona-arrow:active { transform: scale(0.92); }
.persona-arrow[hidden] { display: none; }

.mv-divider {
  height: 1px;
  background: var(--mv-border);
  flex-shrink: 0;
  margin: 0 20px;
}

/* ===== CHAT AREA ===== */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-scroll::-webkit-scrollbar { width: 6px; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--mv-border); border-radius: 4px; }

.bubble-row {
  display: flex;
  animation: mv-fade-in 0.25s ease;
}
.bubble-row--bot { justify-content: flex-start; }
.bubble-row--user { justify-content: flex-end; }

@keyframes mv-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble {
  max-width: 78%;
  padding: 14px 16px;
  border-radius: var(--mv-radius-bubble);
  font-size: 15px;
  line-height: 1.45;
  position: relative;
}

.bubble-row--bot .bubble {
  background: var(--mv-bot-bubble);
  color: var(--mv-text);
  border-bottom-left-radius: 4px;
}

.bubble-row--user .bubble {
  background: var(--mv-purple-pale);
  color: var(--mv-text);
  border-bottom-right-radius: 4px;
}

.bubble-time {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--mv-text-muted);
  text-align: right;
}

.bubble-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: #FBEFDD;
  color: var(--mv-gold);
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s ease;
}
.bubble-play:hover { background: #F5E3C4; }
.bubble-play svg { width: 12px; height: 12px; margin-left: 1px; }

.bubble-play.is-loading svg { visibility: hidden; }
.bubble-play.is-loading {
  position: relative;
}
.bubble-play.is-loading::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(201,154,74,0.35);
  border-top-color: var(--mv-gold);
  animation: mv-spin 0.7s linear infinite;
}
@keyframes mv-spin { to { transform: rotate(360deg); } }

.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 2px;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #B9B6C6;
  animation: mv-bounce 1.1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes mv-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ===== INPUT BAR ===== */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--mv-border);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: var(--mv-bg);
  font-size: 15px;
  color: var(--mv-text);
  padding: 8px 4px;
  font-family: inherit;
}
#chat-input::placeholder { color: var(--mv-text-muted); }
#chat-input:disabled { opacity: 0.5; }

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--mv-purple);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}
.send-btn:hover:not(:disabled) { background: var(--mv-purple-dark); }
.send-btn:active:not(:disabled) { transform: scale(0.92); }
.send-btn:disabled {
  background: #DAD7E8;
  cursor: not-allowed;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(45, 42, 62, 0.45);
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-overlay:not([hidden]) {
  display: flex;
}

.modal {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 20px;
  padding: 32px 28px 28px;
  box-shadow: 0 24px 48px -16px rgba(45, 42, 62, 0.3);
  animation: mv-modal-in 0.2s ease;
  /* smanjeno za 20% na zahtev testera */
  transform: scale(0.8);
  transform-origin: center center;
}

@keyframes mv-modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--mv-text-muted);
  cursor: pointer;
}
.modal-close:hover { color: var(--mv-text); }

.modal-title {
  margin: 0 0 20px;
  font-size: 19px;
  font-weight: 700;
  color: var(--mv-text);
  padding-right: 20px;
}

.modal-form {
  display: flex;
  flex-direction: column;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--mv-text-muted);
  margin: 12px 0 6px;
}
.field-label:first-child { margin-top: 0; }

.field-input {
  border: 1px solid var(--mv-border);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  color: var(--mv-text);
  outline: none;
  transition: border-color 0.15s ease;
}
.field-input:focus { border-color: var(--mv-purple); }
.field-input.is-invalid { border-color: var(--mv-error); }

.field-error {
  display: block;
  min-height: 16px;
  font-size: 12px;
  color: var(--mv-error);
  margin-top: 4px;
}

.field-error--general {
  min-height: 0;
  margin-top: 8px;
  text-align: center;
}

.btn-primary {
  margin-top: 18px;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: var(--mv-purple);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--mv-purple-dark); }
.btn-primary:disabled {
  background: #DAD7E8;
  cursor: not-allowed;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .mv-widget { height: 100vh; border-radius: 0; max-width: 100%; }
  .persona-item.is-primary { min-width: 170px; }
  .persona-signature { max-width: 110px; }
  .bubble { max-width: 86%; }
}
