:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.1);
  --bg-main: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-chat: #f1f5f9;
  --bg-message-user: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --bg-message-bot: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-message-user: #ffffff;
  --text-message-bot: #1e293b;
  --border-color: #e2e8f0;
  --input-bg: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --online: #22c55e;
}

[data-theme="dark"] {
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-light: rgba(129, 140, 248, 0.15);
  --bg-main: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-chat: #0f172a;
  --bg-message-user: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --bg-message-bot: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-message-user: #ffffff;
  --text-message-bot: #f1f5f9;
  --border-color: #334155;
  --input-bg: #334155;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.2);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.3), 0 8px 10px -6px rgb(0 0 0 / 0.2);
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

.hidden {
  display: none !important;
}

/* Login */
.login-container {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
}

.theme-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
  width: 44px;
  height: 44px;
}

.theme-toggle svg {
  width: 22px;
  height: 22px;
  fill: var(--text-primary);
}

.theme-toggle:hover {
  transform: scale(1.05);
}

.login-card {
  background: var(--bg-sidebar);
  border-radius: 24px;
  padding: 40px 36px;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-color);
  width: 100%;
}

.logo-section {
  text-align: center;
  margin-bottom: 30px;
}

.logo {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--primary) 0%, #a78bfa 100%);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 8px 16px rgba(99, 102, 241, 0.3);
}

.logo svg {
  width: 32px;
  height: 32px;
  fill: white;
}

.title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 15px;
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: 22px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}

.input-wrapper {
  position: relative;
}

.form-input {
  width: 100%;
  padding: 14px 16px 14px 48px;
  background: var(--input-bg);
  border: 2px solid transparent;
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  transition: all 0.3s ease;
  outline: none;
}

.form-input.with-action {
  padding-right: 52px;
}

.form-input:focus {
  background: var(--bg-sidebar);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.input-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  fill: var(--text-secondary);
}

.password-toggle {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
}

.password-toggle svg {
  width: 20px;
  height: 20px;
  fill: var(--text-secondary);
}

.btn-primary {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  transform: translateY(-2px);
}

.error {
  min-height: 22px;
  margin-top: 10px;
  color: #ef4444;
  font-size: 14px;
}

/* Chat */
.chat-container {
  display: flex;
  height: 100vh;
  width: 100%;
}

.sidebar {
  width: 320px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary) 0%, #a78bfa 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
}

.user-details h3 {
  font-size: 16px;
  margin-bottom: 2px;
}

.user-status,
.contact-status {
  font-size: 13px;
  color: var(--online);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--online);
  border-radius: 50%;
}

.sidebar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: transparent;
  border: none;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--primary-light);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: var(--text-secondary);
}

.search-container {
  padding: 16px 20px;
}

.search-wrapper {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-secondary);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  fill: var(--text-secondary);
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.conversation-item {
  display: flex;
  gap: 12px;
  padding: 14px 12px;
  border-radius: 14px;
  background: var(--primary-light);
}

.conversation-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  position: relative;
}

.conversation-avatar.bot {
  background: linear-gradient(135deg, var(--primary) 0%, #a78bfa 100%);
}

.avatar-online {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background: var(--online);
  border: 2px solid var(--bg-sidebar);
  border-radius: 50%;
}

.conversation-info {
  flex: 1;
}

.conversation-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.conversation-name {
  font-size: 15px;
  font-weight: 600;
}

.conversation-time,
.conversation-preview {
  font-size: 13px;
  color: var(--text-secondary);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
}

.chat-header {
  background: var(--bg-sidebar);
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-contact-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  margin-right: 8px;
}

.menu-toggle svg {
  width: 24px;
  height: 24px;
}

.contact-avatar {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary) 0%, #a78bfa 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
}

.contact-details h2 {
  font-size: 17px;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bubble {
  max-width: 72%;
  padding: 14px 18px;
  border-radius: 18px;
  line-height: 1.5;
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
  animation: messageSlide 0.2s ease-out;
}

.bubble.user {
  align-self: flex-end;
  background: var(--bg-message-user);
  color: var(--text-message-user);
  border-bottom-right-radius: 6px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bg-message-bot);
  color: var(--text-message-bot);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border-color);
}

.bubble.error {
  align-self: flex-start;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

.bubble.loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.spinner {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.input-area {
  padding: 20px 24px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-color);
}

.input-area .input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  padding: 8px 8px 8px 20px;
}

.input-area .input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.message-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 24px;
  line-height: 1.5;
  padding: 8px 0;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn svg {
  width: 22px;
  height: 22px;
}

/* Result card */
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--border-color);
}

.badge.ok {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.12);
}

.badge.no {
  border-color: rgba(244, 63, 94, 0.35);
  background: rgba(244, 63, 94, 0.12);
}

.chip {
  font-size: 11px;
  color: var(--text-secondary);
}

.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 10px;
  font-size: 14px;
}

.k {
  color: var(--text-secondary);
}

details {
  margin-top: 10px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
}

summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
}

.json-wrap {
  padding: 0 12px 12px;
}

.json-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 8px 0;
}

.copy-btn {
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}

.mono {
  margin: 0;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.meta {
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 12px;
}

/* Toast */
.toasts {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1200;
}

.app-toast {
  width: min(420px, calc(100vw - 28px));
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.app-toast p {
  margin: 0;
  font-size: 14px;
}

.app-toast .x {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

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

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.overlay {
  display: none;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -320px;
    top: 0;
    bottom: 0;
    z-index: 1000;
  }

  .sidebar.open {
    left: 0;
  }

  .overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  .overlay.active {
    display: block;
  }

  .menu-toggle {
    display: block;
  }

  .messages-container {
    padding: 16px;
  }

  .bubble {
    max-width: 88%;
  }

  .input-area {
    padding: 14px;
  }

  .kv {
    grid-template-columns: 1fr;
  }
}
