/* ======================================================
   DietBot - Teman Diet Sehatmu
   Design System & Styles
   ====================================================== */

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
  /* Primary palette - fresh green tones */
  --primary-50: #edfcf2;
  --primary-100: #d3f9e0;
  --primary-200: #aaf0c6;
  --primary-300: #73e2a5;
  --primary-400: #3acc7f;
  --primary-500: #16b364;
  --primary-600: #0a9150;
  --primary-700: #087342;
  --primary-800: #095c37;
  --primary-900: #084c2f;

  /* Neutral palette */
  --neutral-50: #f8faf9;
  --neutral-100: #f0f4f1;
  --neutral-200: #e2e8e4;
  --neutral-300: #c8d1cb;
  --neutral-400: #9ba8a0;
  --neutral-500: #718078;
  --neutral-600: #576660;
  --neutral-700: #47534d;
  --neutral-800: #3b4541;
  --neutral-900: #1e2522;

  /* Accent */
  --accent-warm: #f59e0b;
  --accent-error: #ef4444;
  --accent-error-bg: #fef2f2;

  /* Surfaces */
  --surface-app: #f0f7f2;
  --surface-chat: #ffffff;
  --surface-header: rgba(255, 255, 255, 0.85);
  --surface-input: #ffffff;
  --surface-bot-bubble: #ffffff;
  --surface-user-bubble: var(--primary-500);

  /* Text */
  --text-primary: var(--neutral-900);
  --text-secondary: var(--neutral-600);
  --text-on-primary: #ffffff;
  --text-bot: var(--neutral-800);
  --text-user: #ffffff;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);
  --shadow-bubble: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-header: 0 1px 12px rgba(0, 0, 0, 0.06);
  --shadow-input: 0 -1px 12px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 20px rgba(22, 179, 100, 0.15);

  /* Borders */
  --border-light: 1px solid rgba(0, 0, 0, 0.06);
  --border-radius-sm: 8px;
  --border-radius-md: 14px;
  --border-radius-lg: 20px;
  --border-radius-xl: 28px;
  --border-radius-full: 999px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Layout */
  --header-height: 70px;
  --input-area-height: auto;
  --max-chat-width: 780px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--surface-app);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle animated gradient background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(22, 179, 100, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(22, 179, 100, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(245, 158, 11, 0.03) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* --- App Container --- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 100%;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* --- Header --- */
.chat-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface-header);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: var(--border-light);
  box-shadow: var(--shadow-header);
  height: var(--header-height);
  flex-shrink: 0;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  max-width: var(--max-chat-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: 100%;
}

.header-avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--border-radius-md);
  background: linear-gradient(135deg, var(--primary-400), var(--primary-600));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  box-shadow: var(--shadow-glow);
  animation: pulse-glow 3s ease-in-out infinite;
}

.header-avatar svg {
  width: 22px;
  height: 22px;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 12px rgba(22, 179, 100, 0.2); }
  50% { box-shadow: 0 0 24px rgba(22, 179, 100, 0.35); }
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-info h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--neutral-900);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.8rem;
  color: var(--primary-600);
  font-weight: 500;
  margin-top: 1px;
}

.header-clear-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--border-radius-sm);
  border: none;
  background: transparent;
  color: var(--neutral-400);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.header-clear-btn svg {
  width: 18px;
  height: 18px;
}

.header-clear-btn:hover {
  background: var(--neutral-100);
  color: var(--accent-error);
}

/* --- Chat Area --- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-lg) var(--space-md);
  scroll-behavior: smooth;
}

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

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

.chat-area::-webkit-scrollbar-thumb {
  background: var(--neutral-300);
  border-radius: var(--border-radius-full);
}

/* --- Welcome Card --- */
.welcome-card {
  max-width: 480px;
  margin: var(--space-2xl) auto;
  text-align: center;
  animation: fade-in-up 0.6s var(--transition-slow);
}

.welcome-icon {
  font-size: 3.5rem;
  margin-bottom: var(--space-md);
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-card h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--neutral-900);
  letter-spacing: -0.03em;
  margin-bottom: var(--space-sm);
}

.welcome-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: var(--space-lg);
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
}

.quick-prompt-btn {
  padding: 10px 18px;
  border-radius: var(--border-radius-full);
  border: 1.5px solid var(--primary-200);
  background: var(--surface-chat);
  color: var(--primary-700);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.quick-prompt-btn:hover {
  background: var(--primary-50);
  border-color: var(--primary-400);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.quick-prompt-btn:active {
  transform: translateY(0);
}

/* --- Messages Container --- */
.messages-container {
  max-width: var(--max-chat-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* --- Chat Bubble Base --- */
.message-row {
  display: flex;
  gap: var(--space-sm);
  animation: fade-in-up 0.35s ease-out both;
}

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

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

/* Bot avatar next to bubble */
.bot-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--border-radius-sm);
  background: linear-gradient(135deg, var(--primary-400), var(--primary-600));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  align-self: flex-end;
  font-size: 0.85rem;
}

.bot-avatar svg {
  width: 16px;
  height: 16px;
}

/* Bubble */
.bubble {
  max-width: 75%;
  padding: 12px 18px;
  border-radius: var(--border-radius-lg);
  font-size: 0.935rem;
  line-height: 1.65;
  word-break: break-word;
  position: relative;
  box-shadow: var(--shadow-bubble);
}

.message-row.user .bubble {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  color: var(--text-user);
  border-bottom-right-radius: var(--space-xs);
}

.message-row.bot .bubble {
  background: var(--surface-bot-bubble);
  color: var(--text-bot);
  border-bottom-left-radius: var(--space-xs);
  border: var(--border-light);
}

/* Timestamp under bubble */
.message-time {
  font-size: 0.7rem;
  color: var(--neutral-400);
  margin-top: var(--space-xs);
  padding: 0 4px;
}

.message-row.user .message-time {
  text-align: right;
}

/* --- Typing Indicator --- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 20px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--primary-400);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

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

/* --- Error Bubble --- */
.bubble.error {
  background: var(--accent-error-bg);
  border: 1.5px solid rgba(239, 68, 68, 0.2);
  color: var(--accent-error);
}

/* --- Input Area --- */
.chat-input-area {
  flex-shrink: 0;
  padding: var(--space-md) var(--space-md) var(--space-sm);
  background: var(--surface-header);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: var(--border-light);
  box-shadow: var(--shadow-input);
}

.input-wrapper {
  max-width: var(--max-chat-width);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  background: var(--surface-input);
  border: 1.5px solid var(--neutral-200);
  border-radius: var(--border-radius-xl);
  padding: 6px 6px 6px 20px;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.input-wrapper:focus-within {
  border-color: var(--primary-400);
  box-shadow: 0 0 0 3px rgba(22, 179, 100, 0.1), var(--shadow-md);
}

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

.input-wrapper textarea::placeholder {
  color: var(--neutral-400);
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-glow);
}

.send-btn svg {
  width: 18px;
  height: 18px;
  transform: translateX(1px);
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
  background: var(--neutral-300);
}

.send-btn:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: 0 0 24px rgba(22, 179, 100, 0.3);
}

.send-btn:not(:disabled):active {
  transform: scale(0.95);
}

.disclaimer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--neutral-400);
  margin-top: var(--space-sm);
  max-width: var(--max-chat-width);
  margin-left: auto;
  margin-right: auto;
}

/* --- Markdown-like formatting inside bot bubbles --- */
.bubble h1, .bubble h2, .bubble h3 {
  font-weight: 700;
  margin: 8px 0 4px;
  line-height: 1.3;
}

.bubble h1 { font-size: 1.1rem; }
.bubble h2 { font-size: 1rem; }
.bubble h3 { font-size: 0.95rem; }

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

.bubble li {
  margin-bottom: 3px;
}

.bubble strong {
  font-weight: 600;
  color: var(--primary-700);
}

.bubble code {
  background: var(--neutral-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'Courier New', monospace;
}

.bubble p {
  margin-bottom: 6px;
}

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

/* --- Animations --- */
@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* --- Hidden utility --- */
.hidden {
  display: none !important;
}

/* ======================================================
   Responsive Design
   ====================================================== */

/* Tablet */
@media (max-width: 768px) {
  :root {
    --header-height: 62px;
    --max-chat-width: 100%;
  }

  .header-inner {
    padding: 0 var(--space-md);
  }

  .header-info h1 {
    font-size: 1.05rem;
  }

  .welcome-card {
    margin: var(--space-lg) auto;
    padding: 0 var(--space-sm);
  }

  .welcome-card h2 {
    font-size: 1.35rem;
  }

  .bubble {
    max-width: 85%;
  }

  .quick-prompt-btn {
    font-size: 0.8rem;
    padding: 8px 14px;
  }
}

/* Mobile */
@media (max-width: 480px) {
  :root {
    --header-height: 58px;
  }

  .chat-area {
    padding: var(--space-md) var(--space-sm);
  }

  .welcome-icon {
    font-size: 2.8rem;
  }

  .welcome-card h2 {
    font-size: 1.2rem;
  }

  .welcome-card p {
    font-size: 0.88rem;
  }

  .bubble {
    max-width: 88%;
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .input-wrapper {
    padding: 4px 4px 4px 16px;
    border-radius: var(--border-radius-lg);
  }

  .input-wrapper textarea {
    font-size: 0.9rem;
  }

  .send-btn {
    width: 38px;
    height: 38px;
  }

  .quick-prompts {
    gap: 6px;
  }

  .quick-prompt-btn {
    font-size: 0.78rem;
    padding: 7px 12px;
  }
}
