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

body {
  font-family: Georgia, serif;
  background: #f7f7f5;
  color: #1a1a1a;
  height: 100vh;
  overflow: hidden;
}

/* ── Three-column layout ───────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 240px 1fr 280px;
  height: 100vh;
  overflow: hidden;
}

/* ── Left sidebar ──────────────────────────────────────────────────────────── */

.sidebar-left {
  background: #ececea;
  border-right: 1px solid #d8d8d5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #d8d8d5;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}

.app-name {
  font-size: 1rem;
  font-weight: bold;
  letter-spacing: 0.02em;
}

.sidebar-title {
  font-size: 0.9rem;
  font-weight: bold;
}

.sidebar-actions {
  display: flex;
  gap: 0.4rem;
}

.sidebar-actions button {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-size: 0.78rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: #4a90e2;
  color: white;
}

.sidebar-actions button:hover {
  background: #357abd;
}

/* New project form */
.new-project-form {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #d8d8d5;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}

.new-project-form input,
.new-project-form textarea {
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-family: inherit;
  resize: vertical;
  background: white;
}

.new-project-form input:focus,
.new-project-form textarea:focus {
  outline: none;
  border-color: #4a90e2;
}

.form-actions {
  display: flex;
  gap: 0.4rem;
}

.form-actions button {
  flex: 1;
  padding: 0.35rem;
  font-size: 0.8rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#createProjectBtn { background: #4a90e2; color: white; }
#createProjectBtn:hover { background: #357abd; }
#cancelProjectBtn { background: #ddd; color: #333; }
#cancelProjectBtn:hover { background: #ccc; }

/* Sidebar list */
#sidebarList {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 1rem;
}

.sidebar-section {
  padding-top: 0.5rem;
}

.sidebar-section-label {
  padding: 0.3rem 1rem 0.2rem;
  font-size: 0.68rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #888;
}

.sidebar-empty {
  padding: 0.3rem 1rem;
  font-size: 0.78rem;
  color: #aaa;
  font-style: italic;
}

/* Session items (standalone + in-project) */
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 1rem;
  cursor: pointer;
  gap: 0.4rem;
}

.session-item:hover {
  background: #e2e2df;
}

.session-item.active {
  background: #d2e4f8;
}

.session-label {
  font-size: 0.8rem;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.session-item.active .session-label {
  color: #111;
  font-weight: bold;
}

/* "Add to project" dropdown on standalone sessions */
.move-select {
  font-size: 0.68rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 0.1rem 0.2rem;
  background: white;
  color: #555;
  cursor: pointer;
  max-width: 60px;
  flex-shrink: 0;
}

/* Project items */
.project-item {
  border-bottom: 1px solid #e0e0de;
}

.project-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  user-select: none;
}

.project-header:hover {
  background: #e2e2df;
}

.project-chevron {
  font-size: 0.6rem;
  color: #888;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.project-item.expanded .project-chevron {
  transform: rotate(90deg);
}

.project-title {
  font-size: 0.83rem;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.project-sessions {
  padding: 0.2rem 0;
}

.new-chat-btn {
  display: block;
  width: calc(100% - 2.5rem);
  margin: 0.25rem 1.25rem;
  padding: 0.28rem 0.5rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px dashed #bbb;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  color: #666;
  font-family: inherit;
}

.new-chat-btn:hover {
  background: #e2e2df;
}

/* ── Main content ──────────────────────────────────────────────────────────── */

.main-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fafaf8;
}

/* Feed — scrollable message area */
#feed {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

/* Welcome state */
.feed-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #999;
  gap: 0.5rem;
  padding: 2rem;
}

.feed-welcome p {
  font-size: 1rem;
}

.feed-welcome-sub {
  font-size: 0.8rem !important;
  color: #bbb !important;
}

/* ── Chat messages ─────────────────────────────────────────────────────────── */

.message {
  animation: msgIn 0.15s ease;
}

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

/* User message — right-aligned bubble */
.message-user {
  display: flex;
  justify-content: flex-end;
}

.message-user .message-bubble {
  background: #4a90e2;
  color: white;
  padding: 0.65rem 1rem;
  border-radius: 18px 18px 4px 18px;
  max-width: 72%;
  font-size: 0.93rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Assistant message — left-aligned card */
.message-assistant {
  display: flex;
  flex-direction: column;
  max-width: 90%;
  align-self: flex-start;
}

.message-label {
  font-size: 0.68rem;
  font-weight: bold;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.3rem;
  padding-left: 0.25rem;
}

.message-body {
  background: white;
  border: 1px solid #e0e0de;
  border-radius: 4px 18px 18px 18px;
  padding: 0.85rem 1.1rem;
  font-size: 0.92rem;
  line-height: 1.7;
}

/* Error message */
.message-error {
  display: flex;
  justify-content: center;
}

.message-error .message-bubble {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-style: italic;
}

/* Summary text inside assistant message */
.summary {
  white-space: pre-wrap;
  margin-bottom: 0.75rem;
}

/* Papers grouped by source */
.papers-by-source {
  border-top: 1px solid #eee;
  margin-top: 0.25rem;
}

.papers-group {
  margin-top: 0.6rem;
}

.papers-group-label {
  font-size: 0.68rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #888;
  padding: 0.2rem 0 0.3rem;
  border-bottom: 1px solid #eee;
  margin-bottom: 0.1rem;
}

.papers-list {
  list-style: none;
  padding: 0;
}

.papers-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid #f0f0ee;
  font-size: 0.83rem;
  line-height: 1.6;
}

.papers-list li:last-child {
  border-bottom: none;
}

.paper-summary {
  margin-top: 0.4rem;
  color: #555;
  font-style: italic;
  line-height: 1.55;
}

.papers-list a {
  color: #4a90e2;
  text-decoration: none;
  word-break: break-all;
}

.papers-list a:hover {
  text-decoration: underline;
}

.cited-by {
  font-size: 0.75rem;
  color: #999;
  margin-left: 0.4rem;
}

.oa-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.68rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #d1fae5;
  color: #065f46;
  border-radius: 3px;
  vertical-align: middle;
}

/* Thinking / loading dots */
.thinking-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 0.15rem 0;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  background: #bbb;
  border-radius: 50%;
  animation: bounce 1.3s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.18s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30%            { transform: translateY(-7px); opacity: 1; }
}

/* ── Search / prompt area ──────────────────────────────────────────────────── */

.search-area {
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid #ddd;
  background: #f7f7f5;
  flex-shrink: 0;
}

.search-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
}

.search-row textarea {
  flex: 1;
  min-height: 70px;
  max-height: 200px;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1px solid #ccc;
  border-radius: 10px;
  outline: none;
  resize: none;
  line-height: 1.5;
  background: white;
  overflow-y: auto;
}

.search-row textarea:focus {
  border-color: #4a90e2;
}

.search-row button {
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 1px;
}

.search-row button:hover {
  background: #357abd;
}

/* ── Right sidebar ─────────────────────────────────────────────────────────── */

.sidebar-right {
  background: #ececea;
  border-left: 1px solid #d8d8d5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-right .sidebar-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #d8d8d5;
}

.sidebar-placeholder {
  padding: 1rem;
  font-size: 0.82rem;
  color: #aaa;
  font-style: italic;
  line-height: 1.6;
}

/* ── Utility ───────────────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}
