* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: #f4f5f7;
  color: #1a1a1a;
}
.hidden { display: none !important; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand.center { justify-content: center; margin-bottom: 20px; }
.logo { width: 26px; height: 26px; border-radius: 6px; }
.link-btn {
  background: none; border: none; color: #4338ca; cursor: pointer;
  font-size: 13px; text-decoration: none; padding: 0;
}

/* ---- App shell ---- */
.app-wrap { display: flex; height: 100vh; }
.sidebar {
  width: 260px; background: #fff; border-right: 1px solid #eee;
  display: flex; flex-direction: column; padding: 16px;
}
.new-chat-btn {
  margin: 14px 0; padding: 10px; border: 1px dashed #c7c9ff; border-radius: 8px;
  background: #f5f5ff; color: #4338ca; cursor: pointer; font-size: 14px;
}
.conversation-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conv-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.conv-item:hover { background: #f1f2f6; }
.conv-item.active { background: #eef2ff; color: #4338ca; }
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-delete { background: none; border: none; cursor: pointer; color: #999; font-size: 16px; }
.sidebar-footer {
  border-top: 1px solid #eee; padding-top: 12px; display: flex;
  flex-direction: column; gap: 8px; font-size: 13px;
}
.username { color: #555; }

.chat-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
header {
  padding: 16px 20px; border-bottom: 1px solid #eee;
  display: flex; align-items: center; justify-content: space-between;
  background: #fff;
}
.badge {
  font-size: 12px; background: #eef2ff; color: #4338ca;
  padding: 4px 10px; border-radius: 999px;
}
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; line-height: 1.5; font-size: 14px; }
.msg.user { align-self: flex-end; background: #4338ca; color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: #f1f2f6; color: #1a1a1a; border-bottom-left-radius: 4px; }
.msg.error { align-self: center; background: #fee2e2; color: #991b1b; }
.msg img.attached { max-width: 220px; border-radius: 8px; margin-top: 6px; display: block; }
.msg .msg-actions { margin-top: 6px; display: flex; gap: 10px; }
.msg .msg-actions button {
  font-size: 11px; background: none; border: none; color: #888; cursor: pointer; padding: 0;
}
.msg.assistant pre { background: #1e1e2e; color: #eee; padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg.assistant code { font-family: Consolas, Monaco, monospace; font-size: 13px; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }

#chat-form { padding: 14px; border-top: 1px solid #eee; background: #fff; }
.input-row { display: flex; gap: 8px; align-items: center; }
.attach-btn { cursor: pointer; font-size: 18px; padding: 6px; }
#user-input { flex: 1; padding: 10px 14px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; }
button { padding: 10px 16px; border: none; border-radius: 8px; background: #4338ca; color: #fff; font-size: 14px; cursor: pointer; }
#stop-btn { background: #991b1b; }
.image-preview { display: flex; gap: 8px; margin-bottom: 8px; }
.image-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-card { background: #fff; border-radius: 12px; padding: 20px; width: 90%; max-width: 480px; }
.modal-card h2 { margin-top: 0; font-size: 16px; }
.modal-card textarea {
  width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; resize: vertical;
}
.modal-actions { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }
button.secondary { background: #e5e7eb; color: #333; }

/* ---- Auth pages ---- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: #fff; padding: 32px; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); width: 100%; max-width: 360px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; }
.auth-card label { font-size: 13px; color: #555; }
.auth-card input { padding: 10px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; }
.auth-switch { text-align: center; font-size: 13px; margin-top: 16px; }
.error-text { color: #991b1b; font-size: 13px; text-align: center; }

/* ---- Admin ---- */
.admin-wrap { max-width: 800px; margin: 0 auto; padding: 24px; }
.admin-wrap section { background: #fff; padding: 16px 20px; border-radius: 10px; margin-bottom: 20px; }
.admin-wrap table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-wrap th, .admin-wrap td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #eee; }
