/* ── ITS Geomatika Theme ── */
:root {
  --primary: #013880;
  --primary-hover: #012a60;
  --primary-light: rgba(1, 56, 128, 0.08);
  --accent-yellow: #ffbd07;
  --bg-primary: #e3eaee;
  --bg-secondary: #ffffff;
  --bg-chat: #f0f4f7;
  --text-main: #162030;
  --text-muted: #475569;
  --text-inverse: #ffffff;
  --border-color: #d0d9e0;
  --user-bubble: #013880;
  --bot-bubble: #ffffff;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

/* ── Dark Mode ── */
[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: rgba(59, 130, 246, 0.15);
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-chat: #1a2332;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --text-inverse: #f8fafc;
  --border-color: #334155;
  --user-bubble: #2563eb;
  --bot-bubble: #1e293b;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  letter-spacing: -0.01em;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, #013880 0%, #014a9e 55%, #0157b4 100%);
  color: var(--text-inverse);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  border-bottom: 3px solid var(--accent-yellow);
}
.header-logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.header-logo-img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: contain;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  background: #ffffff;
  padding: 3px;
}
.header-logo-img:hover {
  opacity: 0.9;
  transform: scale(1.05);
}
.header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  flex: 1;
}
.header h1 small {
  font-weight: 400;
  font-size: 0.75rem;
  opacity: 0.85;
  display: block;
}
.header-actions {
  display: flex;
  gap: 6px;
}
.header-actions button {
  background: rgba(255,255,255,0.12);
  border: none;
  color: var(--text-inverse);
  padding: 6px;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
  transition: background 0.2s;
}
.header-actions button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.header-actions button:hover {
  background: rgba(255,255,255,0.25);
}

.visitor-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  opacity: 0.7;
  color: var(--text-inverse);
  padding: 4px 8px;
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
}
.visitor-icon {
  font-size: 0.8rem;
}

/* ── Container Layout ── */
html, body { height: 100%; }
.main-container {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Messages ── */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  background: var(--bg-chat);
  scroll-behavior: smooth;
}

#messages {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg.bot {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.msg.user .msg-avatar {
  background: var(--primary);
  color: white;
}
.msg.bot .msg-avatar {
  background: var(--accent-yellow);
  color: var(--text-main);
}
/* Source references */
.source-refs {
  color: white;
}

/* ── Responsive (Mobile) ── */
@media (max-width: 640px) {
  .header {
    padding: 10px 12px;
    gap: 8px;
  }
  .header h1 {
    font-size: 0.95rem;
  }
  .header h1 small {
    font-size: 0.65rem;
  }
  .header-logo-img {
    width: 30px;
  }
  .header-actions button {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
  }
  .main-container {
    padding: 0;
  }
  .chat-area {
    padding: 8px;
  }
  .msg-list {
    padding: 4px;
  }
  .msg {
    max-width: 92%;
  }
  .msg-content {
    padding: 10px 12px;
    font-size: 0.9rem;
  }
  .input-container {
    padding: 8px 10px 10px;
    gap: 6px;
  }
  .input-container textarea {
    padding: 10px 12px;
    font-size: 0.9rem;
    max-height: 100px;
  }
  .input-container button.send-btn {
    width: 42px;
    height: 42px;
    font-size: 1rem;
  }
  .welcome {
    padding: 24px 12px;
  }
  .welcome .icon {
    font-size: 2.2rem;
  }
  .welcome h2 {
    font-size: 1.1rem;
  }
  .typing-indicator {
    padding: 8px;
  }
  .header-actions {
    gap: 2px;
  }
}

/* ── Scrollbar styling ── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
svg.feather {
  width: 1em;
  height: 1em;
  vertical-align: middle;
}

.msg-content {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.92rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.user .msg-content {
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg.bot .msg-content {
  background: var(--bot-bubble);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}
.msg.bot .msg-content code {
  background: rgba(128, 128, 128, 0.15);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.83rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}
.msg.bot .msg-content pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.82rem;
}
.msg.bot .msg-content pre code {
  background: none;
  color: inherit;
  padding: 0;
}

/* Typing indicator */
.typing {
  align-self: flex-start;
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}
.typing .msg-avatar {
  background: var(--accent-yellow);
  color: var(--text-main);
}
.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bot-bubble);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}
.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Welcome screen */
.welcome {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  animation: fadeIn 0.4s ease;
}
.welcome .icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  border-radius: 22px;
  background: linear-gradient(135deg, #013880 0%, #0157b4 70%);
  color: #fff;
  box-shadow: 0 8px 20px rgba(1, 56, 128, 0.3);
  position: relative;
}
.welcome .icon::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 26px;
  border: 2px solid var(--accent-yellow);
  opacity: 0.55;
}
.welcome h2 {
  color: var(--text-main);
  margin-bottom: 10px;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.welcome p {
  font-size: 0.92rem;
  line-height: 1.7;
  max-width: 520px;
  margin: 0 auto;
}
.welcome .hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
}
.welcome .hints .hint {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  animation: hintPopIn 0.35s ease-out both;
}
.welcome .hints .hint:nth-child(2) { animation-delay: 0.05s; }
.welcome .hints .hint:nth-child(3) { animation-delay: 0.10s; }
.welcome .hints .hint:nth-child(4) { animation-delay: 0.15s; }

@keyframes hintPopIn {
  from { opacity: 0; transform: translateY(8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.welcome .hints .hint:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Input Bar ── */
.input-bar {
  flex-shrink: 0;
  padding: 16px 24px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
}
.input-wrap {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.input-wrap textarea {
  flex: 1;
  border: 2px solid var(--border-color);
  border-radius: 16px;
  padding: 14px 18px;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 52px;
  max-height: 140px;
  line-height: 1.5;
  transition: border-color 0.2s;
}
.input-wrap textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.input-wrap button {
  background: linear-gradient(135deg, #013880 0%, #0157b4 100%);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 14px 22px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  height: 52px;
  min-width: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(1, 56, 128, 0.35);
}
.input-wrap button svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.input-wrap button:hover:not(:disabled) {
  background: linear-gradient(135deg, #014a9e 0%, #0166cc 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(1, 56, 128, 0.45);
}
.input-wrap button:active:not(:disabled) {
  transform: translateY(0);
}
.input-wrap button:disabled {
  background: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
}

.input-clear-btn {
  background: transparent !important;
  color: var(--text-secondary, #94a3b8) !important;
  background-image: none !important;
  border: none;
  border-radius: 12px;
  padding: 10px 14px !important;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
  height: 52px;
  min-width: 48px;
  flex-shrink: 0;
}
.input-clear-btn:hover {
  color: #ef4444 !important;
  background: rgba(239,68,68,0.1) !important;
  background-image: none !important;
}
.input-clear-btn svg {
  width: 20px;
  height: 20px;
}

/* ── Toast notifications ── */
.toast {
  position: fixed;
  bottom: 80px;
  right: 20px;
  background: var(--text-main);
  color: white;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  z-index: 200;
  animation: slideIn 0.3s ease;
  max-width: 300px;
}
@keyframes slideIn {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.toast.success { border-left: 4px solid #22c55e; }
.toast.error { border-left: 4px solid #ef4444; }
.toast.info { border-left: 4px solid var(--primary); }

/* ── Suggestion chips ── */
.suggestions {
  align-self: flex-start;
  max-width: 85%;
  padding: 8px 12px;
  background: var(--bot-bubble);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}
.sugg-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.sugg-chip {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  margin: 3px 4px 3px 0;
  transition: all 0.2s;
  max-width: 100%;
  line-height: 1.3;
}
.sugg-chip:hover {
  background: var(--primary);
  color: white;
}
