:root {
  --bg: #0a0a0a;
  --bg-elevated: #161410;
  --bubble-user: #e1ba65;
  --bubble-user-text: #1a1408;
  --bubble-ai: #1c1a15;
  --text: #f2ead9;
  --text-dim: #9c9483;
  --accent: #e1ba65;
  --accent-text: #1a1408;
  --danger: #e2574c;
  --border: #2c2820;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header .title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.04em;
}

header .logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
}

header .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
header .status-dot.ok { background: #34d399; }
header .status-dot.err { background: var(--danger); }

header button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#drawerOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 20;
}
#drawerOverlay[hidden] { display: none; }

#drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(80vw, 300px);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  z-index: 21;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 14px) 10px 14px;
  gap: 10px;
  overflow-y: auto;
}
#drawer[hidden] { display: none; }

#drawerNewChatBtn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

#convoList {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.convo-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
  padding: 2px;
}
.convo-item:hover, .convo-item.active {
  background: var(--bubble-ai);
}

.convo-item button.convo-select {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 10px 8px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo-item button.convo-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 6px 8px;
  flex-shrink: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.bubble-text p { margin: 0 0 8px 0; }
.bubble-text p:last-child { margin-bottom: 0; }
.bubble-text ul { margin: 2px 0 8px 20px; padding: 0; }
.bubble-text ul:last-child { margin-bottom: 0; }
.bubble-text li { margin: 2px 0; }
.bubble-text strong { font-weight: 700; }

.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.bubble.ai {
  align-self: flex-start;
  background: var(--bubble-ai);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.bubble.error {
  align-self: center;
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 13px;
}

.empty-hint {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 0 30px;
}

#previewStrip {
  display: flex;
  gap: 8px;
  padding: 10px 12px 0;
  background: var(--bg-elevated);
  overflow-x: auto;
  flex-shrink: 0;
}
#previewStrip[hidden] { display: none; }

.preview-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.preview-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-thumb .remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bubble .attached-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.bubble .attached-images img {
  max-width: 160px;
  max-height: 160px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}

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

#attachBtn, #imageModeBtn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#imageModeBtn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

#attachBtn[hidden] { display: none; }

#composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
}
#composer textarea:focus { outline: none; border-color: var(--accent); }

#composer button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#composer button:disabled { opacity: 0.4; }

.search-note {
  font-size: 12px;
  color: var(--text-dim);
  border-left: 2px solid var(--accent);
  padding-left: 8px;
  margin-bottom: 6px;
}

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
