:root {
  --font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-chat-in: #f1f5f9;
  --bg-chat-out: #0f172a;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-chat-out: #ffffff;
  --text-chat-in: #0f172a;
  --border-color: #e2e8f0;
  --accent-color: #0284c7;
  --danger-color: #e11d48;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
  --bg-primary: #090d16;
  --bg-surface: #131a29;
  --bg-chat-in: #1e293b;
  --bg-chat-out: #38bdf8;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-chat-out: #090d16;
  --text-chat-in: #f8fafc;
  --border-color: #1e293b;
  --accent-color: #38bdf8;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Utilities */
.hidden { display: none !important; }
.btn {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--text-primary); color: var(--bg-surface); }
.btn-secondary { background: var(--bg-chat-in); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-danger { background: var(--danger-color); color: #ffffff; }
.btn-text { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--text-secondary); }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 50%;
  color: var(--text-primary);
}
.icon-btn:hover { background-color: var(--border-color); }

/* AUTH VIEW */
.auth-container {
  display: flex;
  height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-surface);
  padding: 30px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow);
  text-align: center;
}
.brand h1 { font-size: 2rem; letter-spacing: -1px; font-weight: 700; margin-bottom: 4px; }
.brand p { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 24px; }
.input-group { text-align: left; margin-bottom: 16px; }
.input-group label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.input-group input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
}
.input-group input:focus { outline: 2px solid var(--accent-color); border-color: transparent; }
.error-msg { margin-top: 14px; font-size: 0.85rem; color: var(--danger-color); }

/* CHAT VIEW */
#chat-view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
}

.app-header {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
}
.header-left .app-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.5px; }
.header-left .user-greeting { font-size: 0.75rem; color: var(--text-secondary); }
.header-actions { display: flex; gap: 8px; }

/* Typing indicator */
.typing-bar {
  padding: 4px 18px;
  font-size: 0.75rem;
  color: var(--accent-color);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}

/* Message List */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-bubble {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  position: relative;
  word-break: break-word;
}
.msg-in { align-self: flex-start; }
.msg-out { align-self: flex-end; }

.bubble-sender {
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 3px;
  color: var(--text-secondary);
}
.msg-out .bubble-sender { text-align: right; }

.bubble-body {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.45;
}
.msg-in .bubble-body {
  background: var(--bg-chat-in);
  color: var(--text-chat-in);
  border-bottom-left-radius: 4px;
}
.msg-out .bubble-body {
  background: var(--bg-chat-out);
  color: var(--text-chat-out);
  border-bottom-right-radius: 4px;
}

.bubble-body a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.68rem;
  opacity: 0.75;
}
.msg-out .bubble-meta { justify-content: flex-end; }

/* Chat Attachments */
.chat-media {
  max-width: 240px;
  max-height: 280px;
  border-radius: var(--radius-sm);
  display: block;
  margin-top: 6px;
  object-fit: cover;
}

/* Reply Block inside Bubble */
.bubble-reply {
  background: rgba(0, 0, 0, 0.08);
  border-left: 3px solid var(--accent-color);
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}
[data-theme="dark"] .bubble-reply {
  background: rgba(255, 255, 255, 0.08);
}

/* Message Actions Menu */
.bubble-actions {
  display: none;
  position: absolute;
  top: -12px;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 2px 4px;
  gap: 4px;
}
.message-bubble:hover .bubble-actions { display: flex; }

/* Context Banner (Reply/Edit) */
.context-banner {
  padding: 8px 18px;
  background: var(--bg-chat-in);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-color);
}
.context-label { font-size: 0.75rem; font-weight: 600; color: var(--accent-color); }
.context-snippet { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }

/* Footer & Input */
.app-footer {
  padding: 10px 14px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  position: relative;
}
.footer-controls { display: flex; gap: 4px; margin-bottom: 4px; }
.input-wrapper {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
}
.input-wrapper textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  max-height: 100px;
  outline: none;
}
.btn-send {
  background: var(--text-primary);
  color: var(--bg-surface);
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-bottom: 2px;
}

/* Emoji Popover */
.emoji-popover {
  position: absolute;
  bottom: 60px;
  left: 10px;
  z-index: 100;
}
emoji-picker {
  --num-columns: 8;
  --category-emoji-size: 1.1rem;
}

/* Modal Settings */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}
.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.settings-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--border-color);
}
.settings-section h4 { font-size: 0.85rem; font-weight: 700; margin-bottom: 8px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.hint { font-size: 0.75rem; color: var(--text-secondary); }
.input-inline { width: 70px; padding: 6px; border-radius: var(--radius-sm); border: 1px solid var(--border-color); background: var(--bg-primary); color: var(--text-primary); text-align: center; }
.danger-zone { border-bottom: none; }

/* Switch Slider */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background-color: var(--border-color); transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent-color); }
input:checked + .slider:before { transform: translateX(20px); }
