:root {
  --bg: #faf8f4;
  --panel: #f3efe8;
  --ink: #1a1a1a;
  --ink-soft: #5a5a5a;
  --line: #e3ddd0;
  --accent: #c1432a;
  --accent-soft: #f0d9d2;
  --user-bg: #ebe6db;
  --buddy-bg: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: grid;
  grid-template-columns: 280px 1fr;
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }
textarea { font: inherit; }

/* SIDEBAR ---------------------------------------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  padding: 18px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.2px;
  margin-bottom: 14px;
}
.brand svg { color: var(--accent); }

.btn-new {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--ink);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-new:hover { background: #2c2c2c; }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}
.session-item {
  position: relative;
  padding: 9px 30px 9px 12px;
  margin-bottom: 2px;
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}
.session-item:hover { background: rgba(0,0,0,0.04); }
.session-item.active { background: rgba(193,67,42,0.1); color: var(--accent); font-weight: 500; }
.session-delete {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  border-radius: 4px;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  display: flex;
}
.session-item:hover .session-delete { opacity: 1; }
.session-delete:hover { background: rgba(0,0,0,0.08); color: var(--accent); }

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-soft);
  font-style: italic;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sidebar-foot .attribution {
  font-style: normal;
  font-size: 10.5px;
  color: var(--ink-soft);
  text-decoration: none;
  opacity: 0.7;
}
.sidebar-foot .attribution:hover { opacity: 1; color: var(--accent); }

/* CHAT ------------------------------------------- */
.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100vh;
}
.chat-bg {
  position: absolute;
  inset: 0;
  background: url("/img/sutherland.jpg") center 30% / cover no-repeat;
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
}
.messages, .composer {
  position: relative;
  z-index: 1;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0;
  min-height: 0;
}

.empty-state {
  max-width: 640px;
  margin: 50px auto 0;
  padding: 0 24px;
  text-align: left;
}
.empty-state h1 {
  font-size: 32px;
  font-weight: 600;
  margin: 0 0 8px;
  text-shadow: 0 1px 2px var(--bg), 0 0 10px var(--bg);
}
.empty-state .lede {
  font-size: 16px;
  color: var(--ink);
  font-weight: 500;
  margin: 0 0 20px;
  line-height: 1.5;
  text-shadow: 0 1px 2px var(--bg), 0 0 10px var(--bg);
}
.empty-state p {
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.65;
  margin: 0 0 16px;
  text-shadow: 0 1px 2px var(--bg), 0 0 8px var(--bg);
}
.empty-state .kicker {
  font-style: italic;
  color: var(--accent);
  margin-top: 24px;
  font-size: 15px;
}

.message-row {
  max-width: 760px;
  margin: 0 auto 18px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
}
.message-row.user { align-items: flex-end; }
.message-row.assistant { align-items: flex-start; }

.message-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.message-row.user .message-bubble {
  background: var(--user-bg);
  border-bottom-right-radius: 4px;
}
.message-row.assistant .message-bubble {
  background: var(--buddy-bg);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.message-bubble strong { font-weight: 600; }
.message-bubble em { font-style: italic; }
.message-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.message-bubble ul, .message-bubble ol { margin: 6px 0; padding-left: 22px; }
.message-bubble li { margin: 3px 0; }
.message-bubble p { margin: 0 0 8px; }
.message-bubble p:last-child { margin-bottom: 0; }

.thinking {
  display: inline-flex;
  gap: 4px;
  padding: 14px 18px;
}
.thinking span {
  width: 7px; height: 7px;
  background: var(--ink-soft);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.error-message {
  max-width: 760px;
  margin: 0 auto 18px;
  padding: 0 24px;
  color: var(--accent);
  font-size: 13.5px;
}
.error-message div {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
}

/* COMPOSER --------------------------------------- */
.composer {
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding: 12px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14.5px;
  background: var(--buddy-bg);
  color: var(--ink);
  outline: none;
  max-height: 200px;
  line-height: 1.5;
  transition: border-color 0.15s;
}
.composer textarea:focus { border-color: var(--accent); }
.btn-send,
.btn-attach {
  border: none;
  border-radius: 12px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s, color 0.15s, border-color 0.15s;
}
.btn-send {
  background: var(--accent);
  color: white;
}
.btn-send:hover { background: #a8351f; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-attach {
  background: var(--buddy-bg);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn-attach:hover { color: var(--accent); border-color: var(--accent); }

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 10px;
  background: var(--user-bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  font-size: 12.5px;
  color: var(--ink);
  max-width: 240px;
}
.attachment-chip .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-chip .size { color: var(--ink-soft); font-size: 11.5px; flex-shrink: 0; }
.attachment-chip .remove {
  background: none;
  border: none;
  padding: 2px;
  border-radius: 4px;
  color: var(--ink-soft);
  display: flex;
  cursor: pointer;
}
.attachment-chip .remove:hover { color: var(--accent); background: rgba(0,0,0,0.05); }

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.message-attachments a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-decoration: none;
  color: var(--ink);
  font-size: 12.5px;
  max-width: 240px;
}
.message-attachments a:hover { border-color: var(--accent); color: var(--accent); }
.message-attachments a .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-attachments .image-thumb {
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  background: none;
}
.message-attachments .image-thumb img {
  display: block;
  max-width: 200px;
  max-height: 200px;
  object-fit: cover;
}

.composer.dragging {
  background: var(--accent-soft);
  border-top-color: var(--accent);
}
.composer.dragging textarea {
  border-color: var(--accent);
  border-style: dashed;
}
.composer.dragging .btn-attach {
  border-color: var(--accent);
  color: var(--accent);
}
.drop-hint {
  display: none;
  text-align: center;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 500;
  padding-bottom: 4px;
  pointer-events: none;
}
.composer.dragging .drop-hint { display: block; }

/* SCROLLBARS -------------------------------------- */
.session-list::-webkit-scrollbar,
.messages::-webkit-scrollbar { width: 8px; }
.session-list::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track { background: transparent; }
.session-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 4px;
}

/* MOBILE ------------------------------------------ */
@media (max-width: 720px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 30% 0 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: 2px 0 12px rgba(0,0,0,0.1);
  }
  .sidebar.open { transform: translateX(0); }
}
