* { box-sizing: border-box; }

:root {
  color-scheme: dark;
  --bg-main: #212121;
  --bg-sidebar: #171717;
  --bg-bubble-assistant: #2f2f2f;
  --bg-bubble-assistant-alt: #1f2530;
  --bg-bubble-user: #303030;
  --text-primary: #ececec;
  --text-secondary: #b4b4b4;
  --border-color: #3a3a3a;
  --accent: #ececec;
}

html {
  height: 100vh;
}

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  overscroll-behavior: none;
  touch-action: none;
}

/* ---------- Login ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
}

.login-card {
  background: var(--bg-main);
  padding: 32px 24px;
  border-radius: 12px;
  text-align: center;
}

.login-logo {
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 32px;
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 16px;
}

.field span {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: #2a2a2a;
  color: var(--text-primary);
  font-size: 16px;
}

.field input:focus {
  outline: none;
  border-color: #6e6e6e;
}

.password-wrap {
  position: relative;
}

.password-wrap input {
  padding-right: 44px;
}

.toggle-password {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  line-height: 1;
}

.toggle-password.active {
  color: var(--text-primary);
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #111;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

.login-card button[type="submit"]:disabled {
  opacity: 0.6;
}

.error {
  color: #f87171;
  font-size: 13px;
  min-height: 18px;
  margin-top: 12px;
}

/* ---------- App shell ---------- */

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease;
  z-index: 20;
}

.sidebar-header {
  display: flex;
  justify-content: flex-end;
  padding: 12px;
}

.sidebar-header .new-chat-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  display: none;
}

.sidebar-section-title {
  color: var(--text-secondary);
  font-size: 12px;
  padding: 8px 16px;
}

.conversation-item {
  padding: 10px 16px;
  margin: 0 8px;
  border-radius: 8px;
  background: #2a2a2a;
  font-size: 14px;
  cursor: default;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border-color);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  font-size: 14px;
}

.user-pill .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #444;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.logout-btn {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  margin-top: 6px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 15;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.topbar-title {
  font-weight: 600;
  margin-left: 8px;
}

.topbar-spacer {
  flex: 1;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  line-height: 1;
}

.icon-btn:hover {
  background: #2a2a2a;
}

/* ---------- Messages ---------- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.msg-row {
  display: flex;
  max-width: 100%;
  margin: 6px 0;
}

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

.msg-row.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
}

.bubble > div:not(.markdown-content) {
  white-space: pre-wrap;
}

.markdown-content p {
  margin: 0 0 8px;
}

.markdown-content p:last-child {
  margin-bottom: 0;
}

.markdown-content h3,
.markdown-content h4,
.markdown-content h5 {
  margin: 12px 0 6px;
  font-weight: 600;
  line-height: 1.3;
}

.markdown-content h3:first-child,
.markdown-content h4:first-child,
.markdown-content h5:first-child {
  margin-top: 0;
}

.markdown-content h3 { font-size: 17px; }
.markdown-content h4 { font-size: 16px; }
.markdown-content h5 { font-size: 15px; }

.markdown-content ul {
  margin: 4px 0 8px;
  padding-left: 20px;
}

.markdown-content li {
  margin: 2px 0;
}

.markdown-content strong {
  font-weight: 600;
}

.markdown-content code {
  background: rgba(255,255,255,0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.markdown-content pre {
  background: rgba(0,0,0,0.3);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
}

.markdown-content pre code {
  background: none;
  padding: 0;
}

.msg-row.user .bubble {
  background: var(--bg-bubble-user);
  border-bottom-right-radius: 4px;
}

.msg-row.assistant .bubble {
  background: var(--bg-bubble-assistant);
  border-bottom-left-radius: 4px;
}

/* subtle marker distinguishing the two "assistant-looking" senders (friend vs Claude) - noticeable on close look, unremarkable at a glance */
.bubble.marker-b {
  background: var(--bg-bubble-assistant-alt);
}

.bubble.marker-b::after {
  content: '';
  position: absolute;
  bottom: 6px;
  right: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  opacity: 0.9;
}

.bubble .msg-image {
  max-width: 100%;
  border-radius: 12px;
  display: block;
  cursor: pointer;
  margin-bottom: 4px;
}

.bubble .msg-time {
  font-size: 10.5px;
  color: var(--text-secondary);
  margin-top: 4px;
  opacity: 0.7;
}

.bubble .delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #444;
  border: none;
  color: #ccc;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.msg-row.deletable.show-delete .delete-btn {
  display: flex;
}

/* ---------- Install hint ---------- */

.install-hint[hidden] {
  display: none;
}

.install-hint {
  background: #2a2a2a;
  border-top: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.install-hint button {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------- Composer ---------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-color);
  background: var(--bg-main);
}


.composer-input-wrap {
  flex: 1;
  background: #2f2f2f;
  border-radius: 20px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
}

#messageInput {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 16px;
  resize: none;
  max-height: 140px;
  font-family: inherit;
}

#messageInput:focus {
  outline: none;
}

.image-preview[hidden] {
  display: none;
}

.image-preview {
  position: relative;
  display: inline-block;
  margin-bottom: 8px;
  width: fit-content;
}

.image-preview img {
  max-height: 80px;
  border-radius: 8px;
  display: block;
}

.image-preview button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #444;
  border: none;
  color: #ccc;
  font-size: 11px;
  cursor: pointer;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #111;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:disabled {
  opacity: 0.4;
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar.open ~ .sidebar-backdrop,
  .sidebar-backdrop.visible {
    display: block;
  }
  .sidebar-header .new-chat-btn {
    display: block;
  }
  .bubble {
    max-width: 88%;
  }
}

@media (min-width: 769px) {
  #openSidebarBtn {
    display: none;
  }
}
