/* ══════════════════════════════════════════════════════════════════════
   MUP RS Chatbot — CSS Design System
   Tamna tema · Glassmorphism · Profesionalni vladini tonovi
   ══════════════════════════════════════════════════════════════════════ */

/* ── Google Font import (fallback if offline) ────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Tokens — Boje zastave Republike Srpske: crvena, plava, bijela ───── */
:root {
  /* Palette — RS flag colors */
  --color-bg:          #07090f;
  --color-bg-surface:  #0c1020;
  --color-bg-card:     #101828;
  --color-bg-elevated: #162035;

  /* Plava — RS zastava */
  --color-primary:     #003DA5;
  --color-primary-h:   #0047c2;
  --color-primary-glow:rgba(0, 61, 165, 0.4);

  /* Crvena — RS zastava */
  --color-red:         #CC1121;
  --color-red-h:       #e01325;
  --color-red-glow:    rgba(204, 17, 33, 0.35);

  /* Bijela — akcent */
  --color-white-accent: #f0f4ff;

  --color-user-bubble: #CC1121;
  --color-asst-glass:  rgba(255, 255, 255, 0.05);
  --color-asst-border: rgba(255, 255, 255, 0.09);

  --color-text-1:      #eef0f8;
  --color-text-2:      #8da3c8;
  --color-text-3:      #5a7299;

  --color-success:     #22c55e;
  --color-warning:     #f59e0b;
  --color-error:       #ef4444;

  --color-border:      rgba(255, 255, 255, 0.07);
  --color-divider:     rgba(255, 255, 255, 0.05);

  /* Header */
  --header-h: 68px;

  /* Radii */
  --r-sm:   6px;
  --r-md:   12px;
  --r-lg:   18px;
  --r-xl:   24px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-card: 0 4px 24px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 32px rgba(0, 61, 165, 0.25);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;

  /* Sidebar */
  --sidebar-w: 240px;
}

/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text-1);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar        { width: 4px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: rgba(255,255,255,0.12); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ══════════════════════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════════════════════ */
.app-header {
  height: var(--header-h);
  background: rgba(8, 13, 26, 0.9);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid var(--color-border);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  box-shadow: 0 2px 24px rgba(0,0,0,0.4);
}

.header-inner {
  max-width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  object-fit: contain;
  flex-shrink: 0;
}

.header-titles { display: flex; flex-direction: column; }

.header-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text-1);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.72rem;
  color: var(--color-gold-light);
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Status badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--color-border);
  border-radius: var(--r-full);
  padding: 4px 12px;
  font-size: 0.72rem;
  color: var(--color-text-2);
  cursor: default;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-3);
  transition: background var(--transition-base);
  flex-shrink: 0;
}

.status-dot.active  { background: var(--color-success); box-shadow: 0 0 6px rgba(34,197,94,0.6); }
.status-dot.error   { background: var(--color-error);   box-shadow: 0 0 6px rgba(239,68,68,0.6); }
.status-dot.loading { background: var(--color-warning); }

/* Icon button */
.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--color-border);
  color: var(--color-text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon:hover {
  background: rgba(255,255,255,0.1);
  color: var(--color-text-1);
}

/* ══════════════════════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════════════════════ */
.app-main {
  display: flex;
  height: 100dvh;
  padding-top: var(--header-h);
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-bg-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 14px;
  overflow-y: auto;
}

.sidebar-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-3);
  padding: 0 4px;
  margin-bottom: 4px;
}

.quick-topics {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topic-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-text-2);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 400;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.topic-chip svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.topic-chip:hover {
  background: rgba(0, 61, 165, 0.18);
  border-color: rgba(0, 61, 165, 0.4);
  color: var(--color-text-1);
}

.topic-chip:hover svg { opacity: 1; }

.sidebar-divider {
  height: 1px;
  background: var(--color-divider);
  margin: 8px 0;
}

.sidebar-disclaimer {
  font-size: 0.68rem;
  color: var(--color-text-3);
  line-height: 1.5;
  padding: 0 4px;
}

/* ── Chat section ─────────────────────────────────────────────────────── */
.chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(ellipse 60% 40% at 70% 20%, rgba(0,61,165,0.08) 0%, transparent 60%),
    radial-gradient(ellipse 40% 30% at 30% 80%, rgba(204,17,33,0.05) 0%, transparent 60%),
    var(--color-bg);
}

/* ── Messages ─────────────────────────────────────────────────────────── */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

/* Welcome screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  text-align: center;
  padding: 60px 40px;
  animation: fadeInUp 0.5s ease both;
}

.welcome-logo {
  width: 80px;
  height: 80px;
  border-radius: 10px;
  object-fit: contain;
}

.welcome-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-text-1);
  margin-top: 8px;
}

.welcome-text {
  font-size: 0.9rem;
  color: var(--color-text-2);
  max-width: 480px;
  line-height: 1.7;
}

/* ══════════════════════════════════════════════════════════════════════
   GATE — obavezni podaci (ime, email, telefon) prije početka razgovora
   ══════════════════════════════════════════════════════════════════════ */
.gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 6, 12, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

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

.gate-card {
  width: 100%;
  max-width: 380px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--r-lg, 16px);
  padding: 28px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: fadeInUp 0.4s ease both;
}

.gate-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  align-self: center;
  margin-bottom: 4px;
}

.gate-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text-1);
  text-align: center;
}

.gate-text {
  font-size: 0.8rem;
  color: var(--color-text-2);
  text-align: center;
  line-height: 1.5;
  margin-bottom: 6px;
}

.gate-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-2);
  margin-top: 4px;
}

.gate-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--color-text-1);
  transition: border-color var(--transition-fast);
}

.gate-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.gate-input:invalid:not(:placeholder-shown) {
  border-color: var(--color-red);
}

.gate-error {
  font-size: 0.78rem;
  color: var(--color-error);
  text-align: center;
}

.gate-submit {
  margin-top: 8px;
  padding: 12px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--color-primary);
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.gate-submit:hover:not(:disabled) { background: var(--color-primary-h); }
.gate-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.gate-disclaimer {
  font-size: 0.68rem;
  color: var(--color-text-3);
  text-align: center;
  line-height: 1.5;
  margin-top: 4px;
}

body.embed-mode .gate-card {
  max-width: 320px;
  padding: 22px 18px;
}

/* Message row */
.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fadeInUp 0.3s ease both;
  max-width: 820px;
  width: 100%;
}

.message-user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message-assistant { margin-right: auto; }

/* Avatar */
.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.message-avatar-user {
  background: var(--color-primary);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 0 12px var(--color-primary-glow);
}

.message-avatar-assistant {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.avatar-logo {
  width: 76%;
  height: 76%;
  object-fit: contain;
}

/* Bubble */
.message-bubble {
  padding: 12px 16px;
  border-radius: var(--r-lg);
  max-width: 680px;
  line-height: 1.65;
  font-size: 0.88rem;
}

.message-user .message-bubble {
  background: linear-gradient(135deg, var(--color-red) 0%, #a50e1c 100%);
  color: #fff;
  border-bottom-right-radius: var(--r-sm);
  box-shadow: 0 4px 20px var(--color-red-glow);
}

.message-assistant .message-bubble {
  background: var(--color-asst-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-asst-border);
  color: var(--color-text-1);
  border-bottom-left-radius: var(--r-sm);
  box-shadow: var(--shadow-card);
}

/* Message content */
.message-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 680px;
}

/* Message text formatting */
.message-text h1, .message-text h2, .message-text h3 {
  font-weight: 600;
  margin: 12px 0 6px;
  color: var(--color-text-1);
}

.message-text h3 { font-size: 0.95rem; }

.message-text p { margin: 6px 0; }

.message-text ul, .message-text ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-text li { margin: 4px 0; }

.message-text strong { color: #c8d8f8; font-weight: 600; }

.message-text code {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 0.85em;
}

.message-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 0.82rem;
}

.message-text th, .message-text td {
  border: 1px solid var(--color-border);
  padding: 6px 10px;
  text-align: left;
}

.message-text th {
  background: rgba(0,61,165,0.18);
  color: var(--color-text-1);
}

.message-text tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}

/* Sources panel */
.message-sources {
  border-top: 1px solid var(--color-divider);
  padding-top: 10px;
}

.sources-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--color-text-3);
  font-family: inherit;
  font-size: 0.74rem;
  cursor: pointer;
  transition: color var(--transition-fast);
  padding: 0;
}

.sources-toggle:hover { color: var(--color-text-2); }

.sources-toggle svg { transition: transform var(--transition-fast); }
.sources-toggle.open svg { transform: rotate(90deg); }

.sources-list {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.sources-list.open { display: flex; }

.source-item {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  padding: 8px 12px;
}

.source-title {
  font-size: 0.76rem;
  font-weight: 600;
  color: #e06b77;
  margin-bottom: 3px;
}

.source-excerpt {
  font-size: 0.72rem;
  color: var(--color-text-3);
  line-height: 1.5;
}

/* Typing indicator */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  width: fit-content;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-3);
  animation: bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

/* Error bubble */
.error-bubble {
  background: rgba(239,68,68,0.1) !important;
  border-color: rgba(239,68,68,0.25) !important;
  color: #fca5a5 !important;
}

/* ── Input area ───────────────────────────────────────────────────────── */
.input-area {
  padding: 16px 32px 20px;
  border-top: 1px solid var(--color-border);
  background: rgba(8,13,26,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--color-bg-card);
  border: 1.5px solid var(--color-border);
  border-radius: var(--r-lg);
  padding: 10px 10px 10px 16px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-wrapper:focus-within {
  border-color: rgba(0,61,165,0.7);
  box-shadow: 0 0 0 3px rgba(0,61,165,0.15);
}

.message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--color-text-1);
  font-family: inherit;
  font-size: 0.88rem;
  resize: none;
  max-height: 140px;
  line-height: 1.5;
  overflow-y: auto;
}

.message-input::placeholder { color: var(--color-text-3); }

.btn-send {
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  background: var(--color-red);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast);
  opacity: 0.5;
}

.btn-send:not(:disabled) {
  opacity: 1;
  box-shadow: 0 4px 16px var(--color-red-glow);
}

.btn-send:not(:disabled):hover {
  background: var(--color-red-h);
  transform: scale(1.06);
}

.btn-send:not(:disabled):active { transform: scale(0.96); }

.btn-send:disabled { cursor: not-allowed; }

.input-hint {
  margin-top: 8px;
  font-size: 0.68rem;
  color: var(--color-text-3);
  text-align: center;
  user-select: none;
}

/* ══════════════════════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════════════════════ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* Streaming cursor */
.cursor-blink::after {
  content: '▍';
  display: inline-block;
  color: var(--color-red);
  animation: pulse 0.8s ease-in-out infinite;
  margin-left: 1px;
  font-size: 0.9em;
  vertical-align: baseline;
}

/* ══════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { display: none; }

  .messages-container { padding: 16px; }
  .input-area          { padding: 12px 16px 16px; }

  .header-subtitle { display: none; }

  .message { max-width: 100%; }
  .message-bubble { max-width: 85vw; }
}

@media (max-width: 480px) {
  :root { --header-h: 56px; }
  .header-logo { width: 34px; height: 34px; }
  .header-title { font-size: 0.95rem; }
}

/* ══════════════════════════════════════════════════════════════════════
   EMBED MODE — kompaktan prikaz unutar widget iframe-a na drugim sajtovima
   ══════════════════════════════════════════════════════════════════════ */
body.embed-mode {
  --header-h: 52px;
}

body.embed-mode .sidebar {
  display: none;
}

body.embed-mode .app-header {
  padding: 0;
}

body.embed-mode .header-inner {
  padding: 0 14px;
}

body.embed-mode .header-subtitle {
  display: none;
}

body.embed-mode .status-badge {
  display: none;
}

body.embed-mode .header-logo {
  width: 30px;
  height: 30px;
}

body.embed-mode .welcome-screen {
  padding: 32px 20px;
}

body.embed-mode .messages-container {
  padding: 12px;
}

body.embed-mode .input-area {
  padding: 10px 12px 12px;
}
