@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap');

:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --accent: #06b6d4;
  --danger: #ef4444;
  --background: #f6f8fa;
  --card-bg: #fff;
  --text: #222;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 10px;
  --shadow: 0 2px 8px 0 rgba(30, 64, 175, 0.06);
  --sidebar-bg: #1e293b;
  --sidebar-text: #e2e8f0;
  --sidebar-active-bg: #e0e7ff;
  --sidebar-active-text: #2563eb;
  --sidebar-hover-bg: #f1f5f9;
  --bubble-user: #2563eb;
  --bubble-user-text: #fff;
  --bubble-user-border: #1e40af;
  --bubble-ai: #fff;
  --bubble-ai-text: #222;
  --bubble-ai-border: #e5e7eb;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Inter', Arial, sans-serif;
  background: var(--background);
  color: var(--text);
  width: 100vw;
  max-width: 100vw;
  overflow-x: hidden;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.5rem 1.2rem 1.5rem;
  max-width: 380px;
  margin: 2.5rem auto 0 auto;
  width: 100%;
  box-sizing: border-box;
}

h1, h2 {
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 1rem;
  letter-spacing: -0.5px;
}

label {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 0.2rem;
  display: block;
}

input, textarea, select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.2px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  margin-bottom: 0.8rem;
  background: #f9fafb;
  transition: border 0.2s;
  box-sizing: border-box;
  line-height: 1.5;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  outline: none;
}

button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.7rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 4px 0 rgba(37, 99, 235, 0.07);
  margin-bottom: 0.2rem;
}
button:hover, button:focus {
  background: var(--primary-dark);
}
button.danger {
  background: var(--danger);
}
button.danger:hover, button.danger:focus {
  background: #b91c1c;
}

.error {
  color: var(--danger);
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  margin-bottom: 0.8rem;
  text-align: center;
  font-size: 0.98rem;
}

.app-shell, .flex {
  display: flex;
  height: 100vh;
  width: 100vw;
  max-width: 100vw;
  min-width: 0;
  overflow-x: hidden;
}
.sidebar, .sidebar-app {
  min-width: 220px;
  max-width: 240px;
  width: 220px;
  height: 100vh;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
}
.main-content, .main-app-content {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chat-messages::-webkit-scrollbar {
  display: none;
}
.conversation-list {
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
}
.sidebar h2 {
  font-size: 1.05rem;
  margin-bottom: 0.7rem;
  font-weight: 600;
}
.conversation-item {
  background: transparent;
  color: var(--sidebar-text);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.2rem;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  font-size: 1.05rem;
}
.conversation-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-color: var(--primary);
}
.conversation-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--primary);
}
.message-timestamp {
  font-size: 0.92rem;
  color: #b6c2d1;
  margin-top: 0.1rem;
}

/* WhatsApp-style chat */
.message {
  display: flex;
  align-items: flex-end;
  max-width: 70%;
  min-width: 80px;
  margin-bottom: 0.2rem;
  font-size: 1.08rem;
  line-height: 1.6;
  position: relative;
  word-break: break-word;
}
.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.message.ai {
  gap: 0;
  align-items: flex-end;
}
.bubble {
  padding: 0.7rem 1.1rem 0.7rem 1.1rem;
  border-radius: 0.9em;
  position: relative;
  background: var(--bubble-ai);
  color: var(--bubble-ai-text);
  border: 1px solid var(--bubble-ai-border);
  box-shadow: 0 1px 2px 0 rgba(0,0,0,0.03);
  min-width: 60px;
  max-width: 100%;
  font-size: 1.08rem;
  word-break: break-word;
}
.message.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border: 1px solid var(--bubble-user-border);
}
.message.ai .bubble {
  margin-left: 0;
}
/* Bubble tails */
.message.ai .bubble:after {
  content: '';
  position: absolute;
  left: -10px;
  bottom: 0.7em;
  width: 0;
  height: 0;
  border-top: 10px solid var(--bubble-ai);
  border-left: 10px solid transparent;
  filter: drop-shadow(0 1px 1px #e5e7eb);
}
.message.user .bubble:after {
  content: '';
  position: absolute;
  right: -10px;
  bottom: 0.7em;
  width: 0;
  height: 0;
  border-top: 10px solid var(--bubble-user);
  border-right: 10px solid transparent;
  filter: drop-shadow(0 1px 1px #1e40af);
}
.bubble .message-type-icon {
  margin-right: 0.5rem;
  font-size: 1.1rem;
  vertical-align: middle;
}
.bubble .message-timestamp {
  display: inline-block;
  font-size: 0.92rem;
  color: #888;
  margin-left: 0.7em;
  float: right;
  vertical-align: bottom;
}
.message img[alt="avatar"] {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  margin: 0 0.5rem 0 0;
  align-self: flex-end;
}
.message.user img[alt="avatar"] {
  margin: 0 0 0 0.5rem;
}
.message.ai img[alt="robot"], .message.user img[alt="avatar"] {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 0.5rem;
  margin-left: 0;
  background: #fff;
}

/* Chat header and input */
.chat-header {
  padding: 0.7rem 1.2rem 0.7rem 1.2rem;
  background: #f7f7f7;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
  min-height: 56px;
}
.chat-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #222;
  margin: 0;
}

.chat-input {
  padding: 0.7rem 1.2rem;
  border-top: 1px solid #e5e7eb;
  background: #f7f7f7;
  position: sticky;
  bottom: 0;
  z-index: 2;
}
.input-container {
  display: flex;
  gap: 0.5rem;
}
textarea {
  flex: 1;
  min-height: 36px;
  max-height: 90px;
  resize: vertical;
  font-size: 1.05rem;
  line-height: 1.5;
  border-radius: 1.2em;
  border: 1.2px solid #d1d5db;
  background: #fff;
  padding: 0.7rem 1.1rem;
}

/* Animations */
.thinking-animation, .error-animation, .success-animation {
  text-align: center;
  padding: 0.7rem;
  margin: 0 auto 0.7rem auto;
  display: none;
}
.thinking-animation.active, .error-animation.active, .success-animation.active {
  display: block;
}
.thinking-creature {
  font-size: 1.7rem;
  animation: bounce 1s infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
.error-animation {
  color: var(--danger);
  border: 2px solid var(--danger);
  border-radius: 6px;
  animation: shake 0.5s;
  background: #fee2e2;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.success-animation {
  color: #0f9d58;
}
@keyframes sparkle {
  0% { transform: scale(1); }
  50% { transform: scale(1.13); }
  100% { transform: scale(1); }
}
.sparkle {
  animation: sparkle 0.5s;
}

/* Admin Table */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.7rem;
  font-size: 1.05rem;
}
th, td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  background: #f3f4f6;
  font-weight: 600;
  font-size: 1.08rem;
}
tr:last-child td {
  border-bottom: none;
}
td select {
  margin-bottom: 0 !important;
}

/* Responsive */
@media (max-width: 900px) {
  .app-shell, .flex {
    flex-direction: column;
    height: auto;
    width: 100vw;
    max-width: 100vw;
    min-width: 0;
    overflow-x: hidden;
  }
  .sidebar, .sidebar-app {
    min-width: 100vw;
    max-width: 100vw;
    width: 100vw;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.7rem 0.5rem;
    overflow-x: hidden;
  }
  .main-content, .main-app-content {
    min-height: 0;
    padding: 0.5rem !important;
    width: 100vw;
    max-width: 100vw;
    min-width: 0;
    overflow-x: hidden;
  }
  .chat-header, .chat-messages, .chat-input {
    padding-left: 0.7rem;
    padding-right: 0.7rem;
    width: 100vw;
    max-width: 100vw;
    min-width: 0;
    overflow-x: hidden;
  }
  .chat-messages {
    max-width: 100vw;
    overflow-x: hidden;
  }
}

@media (max-width: 600px) {
  .card {
    padding: 0.7rem 0.3rem 0.7rem 0.3rem;
    max-width: 99vw;
  }
  .sidebar, .sidebar-app, .chat-header, .chat-messages, .chat-input {
    padding-left: 0.2rem;
    padding-right: 0.2rem;
    width: 100vw;
    max-width: 100vw;
    min-width: 0;
    overflow-x: hidden;
  }
  th, td {
    padding: 0.3rem 0.3rem;
  }
  .chat-messages {
    padding: 0.5rem 0.1rem;
    gap: 0.2rem;
    max-width: 100vw;
    overflow-x: hidden;
  }
  .bubble {
    font-size: 1rem;
    padding: 0.5rem 0.7rem;
  }
  .chat-header h2 {
    font-size: 1rem;
  }
}

.topbar {
  width: 100%;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 2.2rem 0.7rem 2.2rem;
  min-height: 56px;
  box-sizing: border-box;
}
.topbar > div:last-child, .topbar > a, .topbar > button {
  margin-left: 0.7rem;
}
@media (max-width: 900px) {
  .topbar {
    padding-left: 0.7rem;
    padding-right: 0.7rem;
  }
} 