/* MedR — Premium Dark Theme */

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2235;
  --bg-glass: rgba(17, 24, 39, 0.7);
  --surface: #1e293b;
  --surface-hover: #253349;
  --border: rgba(148, 163, 184, 0.1);
  --border-active: rgba(99, 179, 237, 0.4);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.15);
  --accent-gradient: linear-gradient(135deg, #38bdf8, #818cf8);
  --green: #34d399;
  --green-glow: rgba(52, 211, 153, 0.2);
  --orange: #fb923c;
  --red: #f87171;

  --font-sans: 'Noto Sans SC', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── App Layout ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  border-radius: 10px;
  color: white;
  flex-shrink: 0;
}

.header h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--green-glow);
  border: 1px solid rgba(52, 211, 153, 0.3);
  border-radius: 20px;
  font-size: 12px;
  color: var(--green);
  font-weight: 500;
}

.status-badge.thinking {
  background: var(--accent-glow);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--accent);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.status-badge.thinking .status-dot {
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.5;
    transform: scale(1.3);
  }
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 16px;
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border-active);
}

/* ── Language Toggle ── */
.lang-toggle {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.lang-btn {
  padding: 4px 8px;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: var(--transition);
  line-height: 1;
  opacity: 0.5;
}

.lang-btn:hover {
  opacity: 0.8;
  background: var(--surface-hover);
}

.lang-btn.active {
  opacity: 1;
  background: var(--accent-glow);
  box-shadow: 0 0 0 1px var(--border-active);
}

/* ── Model Selector ── */
.model-selector {
  display: flex;
  align-items: center;
  gap: 6px;
}

.model-selector label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.model-selector select {
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  outline: none;
  transition: var(--transition);
  max-width: 220px;
}

.model-selector select:hover {
  border-color: var(--border-active);
}

.model-selector select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
  width: 6px;
}

.chat-area::-webkit-scrollbar-track {
  background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
  background: var(--surface);
  border-radius: 3px;
}

/* ── Welcome Screen ── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  animation: fadeIn 0.5s ease;
}

.welcome.hidden {
  display: none;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

.welcome h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome p {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 400px;
  line-height: 1.6;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
  max-width: 520px;
  justify-content: center;
}

.quick-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
}

.quick-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
  transform: translateY(-1px);
}

.quick-icon {
  font-size: 14px;
}

.model-info {
  margin-top: 24px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

.model-info strong {
  color: var(--accent);
}

/* ── Messages ── */
.messages {
  display: none;
}

.messages.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 8px;
}

.message {
  display: flex;
  gap: 12px;
  animation: messageIn 0.3s ease;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: var(--accent-gradient);
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, #10b981, #34d399);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.message-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  overflow-x: auto;
}

.message.user .message-body {
  background: var(--bg-tertiary);
}

/* Code blocks inside messages */
.message-body pre {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin: 10px 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  position: relative;
}

.message-body code {
  font-family: var(--font-mono);
  font-size: 13px;
}

.message-body p code {
  background: var(--bg-primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.message-body p {
  margin-bottom: 8px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body h2,
.message-body h3 {
  margin: 14px 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
}

.message-body ul,
.message-body ol {
  padding-left: 20px;
  margin: 6px 0;
}

.message-body li {
  margin-bottom: 4px;
}

.message-body strong {
  color: var(--accent);
}

/* Copy button on code blocks */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
  opacity: 0;
}

.message-body pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.copy-btn.copied {
  color: var(--green);
  border-color: rgba(52, 211, 153, 0.3);
}

/* Download .R file button */
.message-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
}

.download-btn:hover {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--border-active);
  transform: translateY(-1px);
}

/* Thinking indicator */
.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.4;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ── Input Area ── */
.input-area {
  padding: 12px 20px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 4px 4px 16px;
  transition: var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  padding: 8px 0;
  resize: none;
  max-height: 120px;
  outline: none;
}

.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.send-btn:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.input-footer {
  text-align: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .app {
    max-width: 100%;
  }

  .header {
    padding: 10px 14px;
  }

  .chat-area {
    padding: 14px;
  }

  .input-area {
    padding: 10px 14px 14px;
  }

  .welcome h2 {
    font-size: 18px;
  }

  .quick-actions {
    gap: 6px;
  }

  .quick-btn {
    font-size: 12px;
    padding: 6px 10px;
  }
}