:root {
  --sidebar-width: 260px;
  --bg: #fff;
  --bg-sidebar: #f0f4f8;
  --bg-bubble-user: #b22234;
  --bg-bubble-bot: #3c3b6e;
  --text: #1a1a2e;
  --text-muted: #5c5c7a;
  --border: #c4c8cc;
  --input-bg: #e8ecf0;
  --danger: #b22234;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100%;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.btn-new-chat,
.btn-about {
  flex-shrink: 0;
  padding: 12px 16px;
  margin: 8px;
  border: none;
  border-radius: 8px;
  background: var(--bg-bubble-user);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s;
}

.btn-new-chat:hover,
.btn-about:hover {
  opacity: 0.9;
}

.btn-about {
  margin-top: auto;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 8px 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-item:hover {
  background: var(--input-bg);
}

.chat-item.active {
  background: var(--input-bg);
}

.chat-item-date {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.chat-item-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}

.chat-item-input:focus {
  border-color: var(--bg-bubble-user);
}

.chat-item-edit {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: color 0.15s, background 0.15s;
}

.chat-item-edit:hover {
  color: var(--text);
  background: var(--input-bg);
}

.chat-item-delete {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: color 0.15s, background 0.15s;
}

.chat-item-delete:hover {
  color: var(--danger);
  background: rgba(229, 68, 68, 0.15);
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.message {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 85%;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
}

.message.bot .message-bubble {
  background: var(--bg-bubble-bot);
  color: #fff;
  border-bottom-left-radius: 4px;
}

.message.user .message-bubble {
  background: var(--bg-bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-avatar svg {
  width: 100%;
  height: 100%;
}

.message.user .message-avatar {
  color: var(--bg-bubble-user);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 85%;
  padding: 12px 16px;
  background: var(--input-bg);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  font-size: 14px;
  color: var(--text);
}

.typing-dots {
  display: flex;
  gap: 4px;
  margin-left: 6px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: typing-bounce 0.6s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.1s; }
.typing-dots span:nth-child(3) { animation-delay: 0.2s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Input row */
.input-row {
  flex-shrink: 0;
  padding: 16px 24px 24px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

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

.input:focus {
  border-color: var(--bg-bubble-user);
}

.btn-send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--bg-bubble-user);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-send:hover {
  opacity: 0.9;
}

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

.btn-send-icon {
  font-size: 18px;
  line-height: 1;
}

/* Empty state */
.messages-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
  padding: 24px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

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

.modal {
  background: var(--bg-sidebar);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.modal p {
  margin: 0 0 20px;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  text-align: center;
}

.modal a {
  color: var(--bg-bubble-user);
  text-decoration: none;
  font-weight: 600;
}

.modal a:hover {
  text-decoration: underline;
}

.btn-close-modal {
  display: block;
  margin: 0 auto;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background: var(--bg-bubble-user);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-close-modal:hover {
  opacity: 0.9;
}

/* Main header (mobile menu button) */
.main-header {
  display: none;
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.btn-menu {
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-menu:hover {
  background: var(--input-bg);
}

.btn-menu-icon {
  font-size: 22px;
  line-height: 1;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 98;
  transition: opacity 0.2s;
}

/* Mobile */
@media (max-width: 768px) {
  .main-header {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 99;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    box-shadow: none;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  body.sidebar-open .sidebar-backdrop:not(.hidden) {
    display: block;
  }

  .main {
    min-width: 0;
  }

  .messages {
    padding: 16px;
  }

  .input-row {
    padding: 12px 16px 16px;
  }

  .message {
    max-width: 92%;
  }

  .typing-indicator {
    max-width: 92%;
  }
}
