:root {
  --navy: #0f2a5c;
  --navy-light: #1b3a6b;
  --navy-border: #23407a;
  --orange: #ee7203;
  --bg: #f7f8fa;
  --border: #e2e5ea;
  --text: #1c2530;
  --text-muted: #6b7686;
  --text-faint: #9aa4b2;
  --sidebar-text: #cdd9ec;
  --sidebar-text-muted: #8ba0c4;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button {
  font-family: inherit;
  cursor: pointer;
}

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

/* Sidebar */

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 18px 16px 8px;
  color: #ffffff;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.brand-tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--orange);
  border: 1px solid var(--orange);
  border-radius: 4px;
  padding: 1px 5px;
}

.btn-new-chat {
  margin: 8px 12px 10px;
  background: var(--orange);
  border: none;
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: filter 0.15s ease;
}

.btn-new-chat:hover {
  filter: brightness(1.08);
}

.btn-new-chat:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.search-box {
  margin: 0 12px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--navy-light);
  border-radius: 6px;
  padding: 7px 10px;
}

.search-box i {
  color: var(--sidebar-text-muted);
  font-size: 14px;
}

.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  color: #ffffff;
  font-size: 12px;
}

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

.search-box input:focus {
  outline: none;
}

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

.chat-group-label {
  font-size: 11px;
  color: var(--sidebar-text-muted);
  letter-spacing: 0.04em;
  margin: 12px 8px 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--sidebar-text);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
}

.chat-item:hover {
  background: var(--navy-light);
}

.chat-item.active {
  background: var(--navy-light);
  color: #ffffff;
}

.chat-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-menu-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  font-size: 14px;
  padding: 2px;
  border-radius: 4px;
  opacity: 0;
}

.chat-item:hover .chat-item-menu-btn,
.chat-item-menu-btn.open {
  opacity: 1;
}

.chat-item-menu-btn:hover {
  color: #ffffff;
}

.chat-item-dropdown {
  position: absolute;
  right: 4px;
  top: 100%;
  margin-top: 2px;
  background: #ffffff;
  border: 0.5px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  min-width: 140px;
  z-index: 10;
  overflow: hidden;
}

.chat-item-dropdown button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.chat-item-dropdown button.danger {
  color: #a32d2d;
}

.rename-input {
  flex: 1;
  background: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 13px;
  color: var(--text);
}

.rename-input:focus {
  outline: 2px solid var(--orange);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 0.5px solid var(--navy-border);
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--orange);
  color: #ffffff;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-name {
  font-size: 12px;
  color: var(--sidebar-text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 6px;
}

.icon-btn:hover {
  color: #ffffff;
}

/* Chat panel */

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 14px 24px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
}

.chat-title {
  font-size: 14px;
  font-weight: 500;
  margin: 0;
  color: var(--text);
}

.model-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.model-badge i {
  color: var(--orange);
  font-size: 14px;
}

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

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-faint);
}

.empty-icon {
  font-size: 32px;
  color: var(--text-faint);
}

.empty-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  margin: 10px 0 4px;
}

.empty-sub {
  font-size: 13px;
  margin: 0;
}

.msg-row {
  display: flex;
  max-width: 720px;
}

.msg-row.user {
  justify-content: flex-end;
  align-self: flex-end;
}

.msg-row.assistant {
  align-self: flex-start;
  gap: 10px;
}

.msg-bubble-user {
  background: var(--navy);
  color: #ffffff;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 12px 12px 2px 12px;
  max-width: 100%;
}

.msg-avatar-assistant {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--orange);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-avatar-assistant i {
  color: #ffffff;
  font-size: 13px;
}

.msg-text-assistant {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.msg-text-assistant .cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--text-muted);
  margin-left: 2px;
  vertical-align: middle;
  animation: blink 1s step-start infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.source-tag {
  display: inline-block;
  font-size: 12px;
  background: #eaf3fa;
  color: var(--navy);
  padding: 5px 10px;
  border-radius: 6px;
  margin-top: 10px;
}

.composer {
  padding: 14px 24px 20px;
  border-top: 0.5px solid var(--border);
  background: #ffffff;
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer > .icon-btn {
  color: var(--text-faint);
  font-size: 16px;
}

.composer > .icon-btn:hover {
  color: var(--text-muted);
}

.composer {
  border: 0.5px solid var(--border);
  border-radius: 10px;
  margin: 14px 24px 20px;
  padding: 8px 10px 8px 14px;
}

#messageInput {
  flex: 1;
  border: none;
  font-size: 14px;
  background: transparent;
  color: var(--text);
}

#messageInput:focus {
  outline: none;
}

.send-btn {
  background: var(--orange);
  border: none;
  color: #ffffff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.send-btn:disabled {
  background: var(--border);
  color: var(--text-faint);
  cursor: default;
}

.send-btn:focus-visible,
.icon-btn:focus-visible,
.chat-item:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    z-index: 20;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
}
