:root {
  --bg-page: #f4f4f5; /* Zinc-100 */
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #18181b; /* Zinc-900 */
  --text-secondary: #71717a; /* Zinc-500 */
  --border-subtle: #e4e4e7; /* Zinc-200 */
  --accent: #27272a; /* Zinc-800 */

  --user-msg-bg: #18181b;
  --user-msg-text: #ffffff;
  --bot-msg-bg: #ffffff;
  --input-bg: #ffffff;
}

.dark {
  --bg-page: #09090b; /* Zinc-955 */
  --bg-sidebar: #18181b; /* Zinc-900 */
  --bg-card: #18181b;
  --text-primary: #f4f4f5; /* Zinc-100 */
  --text-secondary: #a1a1aa; /* Zinc-400 */
  --border-subtle: #27272a; /* Zinc-800 */
  --accent: #fafafa;

  --user-msg-bg: #fafafa;
  --user-msg-text: #09090b;
  --bot-msg-bg: #18181b;
  --input-bg: #18181b;
}

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* Sidebar Styling - Clean Card Look */
#sidebar {
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-item {
  font-size: 0.85rem;
  padding: 0.7rem 1rem;
  margin: 0.2rem 0.75rem;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-title-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-actions {
  display: flex;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chat-item:hover .chat-item-actions {
  opacity: 1;
}

.chat-action-btn {
  padding: 0.2rem;
  border-radius: 4px;
}

.chat-action-btn:hover {
  background-color: var(--border-subtle);
}

.delete-chat:hover {
  color: #ef4444;
}

.rename-chat:hover {
  color: var(--text-primary);
}

.chat-item:hover {
  background-color: var(--bg-page);
  color: var(--text-primary);
}

.chat-item.active {
  background-color: var(--bg-page);
  border-color: var(--border-subtle);
  color: var(--text-primary);
  font-weight: 600;
}

/* Header & Navigation */
header {
  background-color: rgba(244, 244, 245, 0.7); /* Matching bg-page */
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
}

.dark header {
  background-color: rgba(9, 9, 11, 0.7);
}

#model-select {
  appearance: none;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 0.5rem 2.2rem 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='grey' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
}

/* Chat Area - Layered backgrounds */
#chat-area {
  background-color: var(--bg-page);
}

/* Message Bubbles - Sophisticated Grey Accents */
.message-bubble {
    margin-bottom: 2.5rem;
    animation: slideInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideInUp {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Thinking Indicator (Waiting for first byte) */
.thinking-container {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    opacity: 0.4;
}

.dot-1 { animation: pulse 1.4s infinite 0s; }
.dot-2 { animation: pulse 1.4s infinite 0.2s; }
.dot-3 { animation: pulse 1.4s infinite 0.4s; }

/* Thought Block (Streaming or Completed Thinking) */
.thought-block {
    margin: 1.5rem 0;
    padding: 1.25rem;
    background-color: rgba(0, 0, 0, 0.03);
    border-left: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px 16px 16px 4px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.dark .thought-block {
    background-color: rgba(255, 255, 255, 0.03);
    border-left-color: rgba(255, 255, 255, 0.1);
}

.thought-header {
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.65rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0.6;
}

.thought-content {
    line-height: 1.6;
    font-style: italic;
}

.thought-content p {
    margin-bottom: 0.75rem;
}

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

.thinking-dot-mini {
    width: 6px;
    height: 6px;
    background-color: currentColor;
    border-radius: 50%;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.4; }
    50% { transform: scale(1.3); opacity: 1; }
}

.content-box {
  max-width: 80%;
  line-height: 1.7;
  position: relative;
}

/* User Message: Dark Grey/Charcoal */
.user-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.user-msg .content-box {
  background-color: var(--user-msg-bg);
  color: var(--user-msg-text);
  padding: 1rem 1.4rem;
  border-radius: 20px 20px 4px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* AI Message: Subtle depth with border or slight tint */
.bot-msg .content-box {
  padding: 1.2rem 1.6rem;
  font-size: 1rem;
  color: var(--text-primary);
  background-color: var(--bot-msg-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 20px 20px 20px 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

/* Interaction Bar - Clean Float */
#user-input {
  background-color: transparent;
  border: none;
  box-shadow: none;
  max-height: 200px;
  min-height: 44px;
  line-height: 1.5;
  padding-top: 12px;
  padding-bottom: 12px;
}

#user-input:focus {
  border: none;
  box-shadow: none;
  outline: none;
}

/* Markdown prose */
.prose-custom {
  font-size: 0.95rem;
  line-height: 1.8;
  letter-spacing: -0.011em;
}

.prose-custom p {
  margin-bottom: 1.25rem;
}

.prose-custom p:last-child {
  margin-bottom: 0;
}

.prose-custom ul, .prose-custom ol {
  margin: 1.25rem 0;
  padding-left: 1.5rem;
}

.prose-custom li {
  margin-bottom: 0.5rem;
}

.prose-custom blockquote {
  border-left: 4px solid var(--border-subtle);
  padding-left: 1rem;
  color: var(--text-secondary);
  font-style: italic;
  margin: 1.5rem 0;
}

.prose-custom h1, .prose-custom h2, .prose-custom h3, .prose-custom h4 {
  font-weight: 700;
  margin-top: 2rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
  line-height: 1.3;
}

.prose-custom pre {
  background-color: #0d1117; /* GitHub Darkish bg */
  padding: 1rem;
  border-radius: 12px;
  margin: 1.5rem 0;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  position: relative; /* For copy button */
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.4rem 0.6rem;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #8b949e;
  font-size: 0.65rem;
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
  z-index: 10;
}

.prose-custom pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: #f0f6fc;
}

.copy-btn.copied {
  background-color: #238636;
  color: white;
  border-color: #2ea043;
}

.prose-custom code.hljs {
  background: transparent;
  padding: 0;
  font-family: "JetBrains Mono", "Fira Code", "Courier New", monospace;
  font-size: 0.85em;
  line-height: 1.6;
}

.prose-custom code:not(pre code) {
  background-color: rgba(0, 0, 0, 0.06);
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 0.85em;
  color: #c2410c; /* Warm orange accent */
}

.dark .prose-custom code:not(pre code) {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fdba74;
}

/* Scrollbar within PRE */
.prose-custom pre::-webkit-scrollbar {
  height: 4px;
}
.prose-custom pre::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 10px;
}

/* Scrollbar */
#chat-area {
  scroll-behavior: smooth;
}

::-webkit-scrollbar {
  width: 6px;
}

.bot-msg .prose-custom {
    transition: opacity 0.3s ease;
}

.bot-msg .content-box {
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}


/* Welcome UI */
#welcome-screen h1 {
  font-weight: 900;
  letter-spacing: -0.06em;
  font-size: 4rem;
  background: linear-gradient(
    to bottom,
    var(--text-primary),
    var(--text-secondary)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Code Generating Loader */
.code-generating-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 1.25rem 1.5rem;
    background: #0d1117;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin: 1.25rem 0;
    color: #8b949e;
    font-size: 0.8rem;
    font-family: "JetBrains Mono", monospace;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.code-generating-indicator .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: #58a6ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.code-generating-indicator .cursor {
    width: 6px;
    height: 14px;
    background-color: #58a6ff;
    animation: blink 1s step-end infinite;
    margin-left: auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner-mini {
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-subtle);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes blink {
    from, to { opacity: 1; }
    50% { opacity: 0; }
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 6rem;
    right: 1.5rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    max-width: 320px;
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    font-size: 0.7rem;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(24px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Message Action Buttons (Edit / Delete) */
.msg-actions {
    display: flex;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message-bubble:hover .msg-actions {
    opacity: 1 !important;
}

.msg-actions button {
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.15s ease;
    background: transparent;
    border: none;
}

.msg-actions button:hover {
    background-color: var(--border-subtle);
}

.delete-msg:hover {
    color: #ef4444 !important;
}

.edit-msg:hover {
    color: var(--text-primary) !important;
}
