/* === Reset & Base === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #212121;
  --bg-input: #2f2f2f;
  --text: #ececec;
  --text-dim: #b4b4b4;
  --user-bg: #2f2f2f;
  --input-focus: #ececec;
}

html, body {
  height: 100%; height: 100dvh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* === App Shell === */
.app {
  display: flex; flex-direction: column;
  height: 100%; height: 100dvh;
  max-width: 800px; margin: 0 auto;
  position: relative;
  background: var(--bg);
}

/* === Auth Overlay === */
.auth-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.auth-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.auth-input {
  background: transparent; border: none; outline: none;
  border-bottom: 2px solid #333; color: var(--text);
  font-size: 32px; text-align: center; width: 120px;
  padding: 5px; font-family: monospace; letter-spacing: 4px;
}

/* === Chat Area === */
.chat-area {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 24px 16px; display: flex; flex-direction: column; gap: 24px;
  scroll-behavior: smooth;
}
.chat-area::-webkit-scrollbar { width: 8px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: #424242; border-radius: 4px; }

/* === Messages === */
.message { display: flex; animation: fade 0.15s ease; width: 100%; justify-content: center; }
.user-message { justify-content: flex-end; }
.ai-message { justify-content: flex-start; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.message-bubble {
  max-width: 80%; padding: 12px 16px; border-radius: 12px;
  font-size: 16px; line-height: 1.6; word-break: break-word; white-space: pre-wrap;
}
.user-message .message-bubble { background: var(--user-bg); color: var(--text); }
.ai-message .message-bubble { background: transparent; color: var(--text); }
.message-content { direction: auto; unicode-bidi: plaintext; }

/* === Thinking Badge === */
.think-badge {
  display: inline-block;
  font-size: 14px; color: var(--text-dim);
  font-style: italic; margin-bottom: 8px;
}

/* === Error Message === */
.error-text { color: #f297a2; }

/* === Input Area === */
.input-area {
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--bg);
  flex-shrink: 0;
}
.input-container {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input);
  border-radius: 20px; padding: 8px 8px 8px 16px;
}

#msg-input {
  flex: 1; background: transparent; border: none; color: var(--text);
  font-size: 16px; font-family: inherit; font-weight: 400;
  resize: none; outline: none; padding: 8px 0;
  max-height: 200px; line-height: 1.5;
}
#msg-input::placeholder { color: var(--text-dim); }

.controls-right {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.model-select {
  appearance: none; -webkit-appearance: none;
  background: transparent; color: var(--text-dim);
  border: 1px solid transparent; border-radius: 6px;
  padding: 4px 8px; font-size: 13px; font-family: inherit;
  cursor: pointer; transition: all 0.1s;
}
.model-select:hover {
  background: rgba(255,255,255,0.05); color: var(--text);
}
.model-select:focus { outline: none; }
.model-select option { background: var(--bg-input); color: var(--text); }

#send-btn {
  width: 32px; height: 32px; min-width: 32px; border-radius: 8px;
  border: none; background: #fff; color: #000;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.1s; flex-shrink: 0;
}
#send-btn:disabled { opacity: 0.2; background: #676767; color: #b4b4b4; cursor: not-allowed; }

/* === Mobile === */
@media (max-width: 500px) {
  .chat-area { padding: 16px 12px; gap: 16px; }
  .message-bubble { max-width: 95%; font-size: 15px; }
  .input-area { padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
