* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: #0b141a;
}

body {
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  background: #111b21;
  direction: ltr;
}

/* Sidebar */
.sidebar {
  width: 34%;
  min-width: 320px;
  max-width: 430px;
  background: #111b21;
  border-right: 1px solid #222d34;
  display: flex;
  flex-direction: column;
}

.sidebar-top {
  height: 60px;
  background: #202c33;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid #222d34;
}

.sidebar-title {
  color: #e9edef;
  font-size: 20px;
  font-weight: 700;
}

.search-box {
  padding: 10px 12px;
  background: #111b21;
  border-bottom: 1px solid #222d34;
}

.search-box input {
  width: 100%;
  height: 40px;
  border: none;
  outline: none;
  border-radius: 8px;
  background: #202c33;
  color: #e9edef;
  padding: 0 14px;
  font-size: 14px;
}

.search-box input::placeholder {
  color: #8696a0;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  background: #111b21;
}

.conversation-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid #222d34;
  transition: background 0.15s ease;
}

.conversation-item:hover {
  background: #202c33;
}

.conversation-item.active {
  background: #2a3942;
}

.session-id {
  color: #e9edef;
  font-size: 17px;
  font-weight: 600;
  direction: ltr;
  text-align: left;
}

.preview {
  color: #8696a0;
  font-size: 14px;
  line-height: 1.5;
  direction: rtl;
  text-align: right;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Chat */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0b141a;
  direction: rtl;
}

.chat-header {
  height: 60px;
  background: #202c33;
  border-bottom: 1px solid #222d34;
  display: flex;
  align-items: center;
  padding: 0 18px;
}

.chat-title {
  color: #e9edef;
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 2px;
}

.chat-subtitle {
  color: #8696a0;
  font-size: 13px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 34px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background:
    linear-gradient(rgba(11, 20, 26, 0.92), rgba(11, 20, 26, 0.92)),
    radial-gradient(circle at center, #111b21 1px, transparent 1px);
  background-size: auto, 24px 24px;
}

.message-wrap {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.message-wrap.user {
  align-self: flex-start;
}

.message-wrap.ai {
  align-self: flex-end;
}

.message {
  width: fit-content;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.message.user {
  background: #005c4b;
  color: #e9edef;
  border-top-left-radius: 0;
}

.message.ai {
  background: #202c33;
  color: #e9edef;
  border-top-right-radius: 0;
}

.message.user::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 0;
  border-top: 8px solid #005c4b;
  border-left: 8px solid transparent;
}

.message.ai::after {
  content: "";
  position: absolute;
  left: -6px;
  top: 0;
  border-top: 8px solid #202c33;
  border-right: 8px solid transparent;
}

.message-text {
  overflow: hidden;
}

.message-text.collapsed {
  display: -webkit-box;
  -webkit-line-clamp: 6;
  line-clamp: 6;
  -webkit-box-orient: vertical;
}

.expand-btn {
  margin-top: 6px;
  background: transparent;
  border: none;
  color: #53bdeb;
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  align-self: flex-start;
}

.expand-btn:hover {
  text-decoration: underline;
}

.empty-state,
.error-state,
.loading-state {
  color: #8696a0;
  font-size: 16px;
  margin: auto;
  text-align: center;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #374248;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4a5c66;
}

@media (max-width: 900px) {
  .sidebar {
    width: 38%;
    min-width: 280px;
  }

  .messages {
    padding: 18px;
  }

  .message-wrap {
    max-width: 88%;
  }
}
