/* ─── RESET & BASE ─────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #212121;
  color: #ececec;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

input, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

/* ─── APP LAYOUT ───────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  width: 100%;
  position: relative;
}

/* ─── TOP BAR ──────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: #212121;
  min-height: 52px;
  flex-shrink: 0;
  z-index: 10;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.icon-btn:active {
  background: rgba(255,255,255,0.08);
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 700;
  color: #ececec;
}

.model-selector:active {
  background: rgba(255,255,255,0.08);
}

/* ─── MESSAGES ─────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 16px;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  padding: 40px 24px;
}

.welcome-icon {
  width: 40px;
  height: 40px;
}

.welcome-title {
  font-size: 22px;
  font-weight: 700;
  color: #ececec;
  text-align: center;
}

/* Message rows */
.message-row {
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: fadeIn 0.2s ease;
}

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

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

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

/* User message */
.user-bubble {
  max-width: 85%;
  background: #303030;
  color: #ececec;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 16px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

/* Assistant message */
.assistant-content {
  display: flex;
  gap: 10px;
  max-width: 100%;
  padding-right: 40px;
}

.assistant-avatar {
  width: 28px;
  height: 28px;
  border-radius: 14px;
  background: #10a37f;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.assistant-avatar svg {
  width: 18px;
  height: 18px;
}

.assistant-text {
  font-size: 16px;
  line-height: 1.6;
  color: #d1d5db;
  word-wrap: break-word;
  white-space: pre-wrap;
  flex: 1;
  min-width: 0;
}

.assistant-text p {
  margin-bottom: 12px;
}

.assistant-text p:last-child {
  margin-bottom: 0;
}

.assistant-text code {
  background: #1a1a2e;
  color: #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 14px;
}

.assistant-text pre {
  background: #1e1e2e;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 8px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.assistant-text pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b6b6b;
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── INPUT AREA ───────────────────────────────────────────── */
.input-area {
  padding: 0 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  background: #212121;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: #303030;
  border-radius: 24px;
  padding: 4px 4px 4px 4px;
  min-height: 48px;
  border: 1px solid #424242;
  transition: border-color 0.15s;
}

.input-container:focus-within {
  border-color: #565656;
}

.attach-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: 4px;
}

.attach-btn:active {
  background: rgba(255,255,255,0.08);
}

#messageInput {
  flex: 1;
  resize: none;
  font-size: 16px;
  line-height: 1.4;
  padding: 8px 4px 8px 8px;
  max-height: 120px;
  color: #ececec;
  overflow-y: auto;
}

#messageInput::placeholder {
  color: #8e8ea0;
}

.send-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #676767;
  color: #212121;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.send-btn:not(:disabled) {
  background: #ececec;
  color: #212121;
}

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

.send-btn:not(:disabled):active {
  background: #d1d1d1;
}

.input-footer {
  text-align: center;
  font-size: 12px;
  color: #8e8ea0;
  padding: 6px 0 2px;
}

/* ─── SIDEBAR ──────────────────────────────────────────────── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: #171717;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-top: env(safe-area-inset-top);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  min-height: 52px;
}

.sidebar-close-btn,
.sidebar-new-chat {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.sidebar-close-btn:active,
.sidebar-new-chat:active {
  background: rgba(255,255,255,0.08);
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 8px;
  background: #2f2f2f;
  border-radius: 12px;
  padding: 8px 12px;
}

.sidebar-search input {
  flex: 1;
  font-size: 15px;
  color: #ececec;
}

.sidebar-search input::placeholder {
  color: #8e8ea0;
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 8px;
}

.conversation-item {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: #ececec;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.conversation-item:active,
.conversation-item.active {
  background: rgba(255,255,255,0.08);
}

.conversation-group-label {
  font-size: 12px;
  font-weight: 600;
  color: #8e8ea0;
  padding: 16px 12px 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ─── SCROLLBAR ────────────────────────────────────────────── */
.messages::-webkit-scrollbar,
.sidebar-conversations::-webkit-scrollbar {
  width: 0;
}

/* ─── STOP BUTTON ──────────────────────────────────────────── */
.stop-btn {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  background: #212121;
  border: 1px solid #424242;
  color: #ececec;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 20;
  margin-bottom: 8px;
}

.stop-btn:active {
  background: #303030;
}

.stop-btn svg {
  width: 16px;
  height: 16px;
}
