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

:root {
  --warm: #E8D5B7;
  --cream: #FFF8F0;
  --spice: #C4652A;
  --spice-dark: #9E4F1E;
  --spice-light: rgba(196, 101, 42, 0.1);
  --herb: #4A6741;
  --herb-light: #6B8F60;
  --charcoal: #2A2420;
  --charcoal-light: #3A342E;
  --stone: #8C7E72;
  --stone-light: #A89B8F;
  --linen: #F5EDE3;
  --danger: #C44A2A;
  --sidebar-w: 280px;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--charcoal);
  overflow: hidden;
  height: 100vh;
  line-height: 1.6;
}

h1, h2, h3, h4 { font-family: 'Outfit', sans-serif; }

/* ---- Auth Screen ---- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(165deg, var(--cream) 0%, var(--linen) 40%, var(--warm) 100%);
  padding: 20px;
}

.auth-card {
  background: white;
  border-radius: 20px;
  padding: 48px 40px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(42, 36, 32, 0.08);
}

.auth-card .logo {
  font-family: 'Outfit', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--charcoal);
  margin-bottom: 8px;
}

.auth-card .logo span { color: var(--spice); }

.auth-card .subtitle {
  color: var(--stone);
  font-size: 0.95rem;
  margin-bottom: 32px;
}

.auth-card h2 {
  font-size: 1.5rem;
  margin-bottom: 24px;
  color: var(--charcoal);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--stone);
  margin-bottom: 6px;
  font-family: 'Outfit', sans-serif;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--linen);
  border-radius: 12px;
  font-size: 0.95rem;
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--charcoal);
  transition: border-color 0.2s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--spice);
  background: white;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--spice);
  color: white;
  width: 100%;
}

.btn-primary:hover { background: var(--spice-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--spice);
  padding: 8px 12px;
}

.btn-ghost:hover { background: var(--spice-light); }

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: 0.9rem;
  color: var(--stone);
}

.auth-toggle a {
  color: var(--spice);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}

.auth-toggle a:hover { text-decoration: underline; }

.auth-error {
  background: rgba(196, 74, 42, 0.08);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

/* ---- Main App Layout ---- */
#app {
  display: none;
  height: 100vh;
  flex-direction: column;
}

#app.active { display: flex; }

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 56px;
  background: white;
  border-bottom: 1px solid var(--linen);
  flex-shrink: 0;
  z-index: 10;
}

.topbar .logo {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--charcoal);
  margin-right: 32px;
}

.topbar .logo span { color: var(--spice); }

.topbar nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.topbar nav button {
  padding: 6px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  color: var(--stone);
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.topbar nav button:hover { color: var(--charcoal); background: var(--linen); }
.topbar nav button.active { color: var(--spice); background: var(--spice-light); }

.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--stone);
}

.topbar .user-info .name {
  font-weight: 500;
  color: var(--charcoal);
}

#logout-btn {
  padding: 6px 12px;
  border: 1px solid var(--linen);
  border-radius: 8px;
  background: transparent;
  font-size: 0.8rem;
  color: var(--stone);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
}

#logout-btn:hover { border-color: var(--stone); color: var(--charcoal); }

/* Main Content */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- Views ---- */
.view { display: none; flex: 1; overflow: hidden; }
.view.active { display: flex; }

/* ---- Chat View ---- */
#chat-view {
  display: none;
  flex: 1;
}

#chat-view.active { display: flex; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: white;
  border-right: 1px solid var(--linen);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--linen);
}

#new-chat-btn {
  width: 100%;
  padding: 10px;
  border: 1.5px dashed var(--warm);
  border-radius: 10px;
  background: transparent;
  font-size: 0.85rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--spice);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

#new-chat-btn:hover {
  background: var(--spice-light);
  border-color: var(--spice);
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-item {
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: all 0.15s;
}

.conv-item:hover { background: var(--linen); }
.conv-item.active { background: var(--spice-light); }

.conv-item .conv-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--charcoal);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item .conv-preview {
  font-size: 0.75rem;
  color: var(--stone);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item .conv-delete {
  display: none;
  background: none;
  border: none;
  color: var(--stone);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  float: right;
}

.conv-item:hover .conv-delete { display: inline-block; }
.conv-item .conv-delete:hover { background: rgba(196, 74, 42, 0.1); color: var(--danger); }

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  min-width: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--warm); border-radius: 3px; }

/* Welcome state */
.welcome-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.welcome-state h2 {
  font-size: 1.6rem;
  color: var(--charcoal);
  margin-bottom: 12px;
}

.welcome-state p {
  color: var(--stone);
  font-size: 1rem;
  max-width: 400px;
  margin-bottom: 32px;
}

.welcome-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 520px;
}

.suggestion-chip {
  padding: 10px 18px;
  background: white;
  border: 1px solid var(--linen);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--charcoal);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.2s;
}

.suggestion-chip:hover {
  border-color: var(--spice);
  background: var(--spice-light);
  color: var(--spice);
}

/* Message bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 680px;
  animation: fadeIn 0.2s ease;
}

.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.message .msg-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--stone);
  margin-bottom: 4px;
  font-family: 'Outfit', sans-serif;
  font-weight: 500;
}

.message .msg-content {
  padding: 14px 20px;
  border-radius: 18px;
  font-size: 0.92rem;
  line-height: 1.6;
  max-width: 100%;
  word-wrap: break-word;
}

.message.user .msg-content {
  background: var(--spice);
  color: white;
  border-bottom-right-radius: 6px;
}

.message.assistant .msg-content {
  background: white;
  color: var(--charcoal);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--linen);
}

.message.assistant .msg-content strong { color: var(--spice-dark); }

/* Typing indicator */
.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 14px 20px;
  background: white;
  border: 1px solid var(--linen);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}

.typing-indicator.visible { display: flex; }

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--stone-light);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

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

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

/* Chat Input */
.chat-input-area {
  padding: 16px 24px 20px;
  background: var(--cream);
  border-top: 1px solid var(--linen);
}

.chat-input-wrap {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 720px;
  margin: 0 auto;
}

#chat-input {
  flex: 1;
  padding: 14px 18px;
  border: 1.5px solid var(--linen);
  border-radius: 16px;
  font-size: 0.92rem;
  font-family: 'DM Sans', sans-serif;
  background: white;
  color: var(--charcoal);
  resize: none;
  outline: none;
  min-height: 48px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.2s;
}

#chat-input:focus { border-color: var(--spice); }

#chat-input::placeholder { color: var(--stone-light); }

#send-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: var(--spice);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

#send-btn:hover { background: var(--spice-dark); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#send-btn svg {
  width: 20px;
  height: 20px;
}

/* ---- Recipes View ---- */
#recipes-view {
  flex-direction: column;
  padding: 32px;
  overflow-y: auto;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.view-header h2 {
  font-size: 1.5rem;
  color: var(--charcoal);
}

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.recipe-card {
  background: white;
  border-radius: 14px;
  padding: 20px;
  border: 1px solid var(--linen);
  cursor: pointer;
  transition: all 0.2s;
}

.recipe-card:hover {
  border-color: var(--spice);
  box-shadow: 0 4px 16px rgba(42, 36, 32, 0.06);
}

.recipe-card h3 {
  font-size: 1.05rem;
  color: var(--charcoal);
  margin-bottom: 6px;
}

.recipe-card .recipe-meta {
  font-size: 0.8rem;
  color: var(--stone);
  display: flex;
  gap: 12px;
}

.recipe-card .recipe-mod {
  font-size: 0.82rem;
  color: var(--spice);
  margin-top: 8px;
  font-style: italic;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--stone);
}

.empty-state h3 {
  font-size: 1.2rem;
  color: var(--charcoal);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9rem;
  max-width: 360px;
  margin: 0 auto;
}

/* Recipe Detail Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 36, 32, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: white;
  border-radius: 20px;
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 32px;
}

.modal h2 {
  font-size: 1.4rem;
  color: var(--charcoal);
  margin-bottom: 4px;
}

.modal .modal-meta {
  font-size: 0.85rem;
  color: var(--stone);
  margin-bottom: 20px;
}

.modal .close-modal {
  float: right;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--stone);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}

.modal .close-modal:hover { background: var(--linen); }

.version-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  overflow-x: auto;
}

.version-tab {
  padding: 6px 14px;
  border: 1px solid var(--linen);
  border-radius: 8px;
  background: transparent;
  font-size: 0.8rem;
  color: var(--stone);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  white-space: nowrap;
}

.version-tab.active {
  background: var(--spice);
  color: white;
  border-color: var(--spice);
}

.version-tab:hover:not(.active) { border-color: var(--spice); }

.ingredients-list {
  margin-bottom: 20px;
}

.ingredients-list h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--spice);
  margin-bottom: 10px;
}

.ingredients-list li {
  padding: 6px 0;
  font-size: 0.9rem;
  color: var(--charcoal);
  border-bottom: 1px solid var(--linen);
  list-style: none;
}

.instructions-list h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--herb);
  margin-bottom: 10px;
}

.instructions-list li {
  padding: 8px 0;
  font-size: 0.9rem;
  color: var(--charcoal);
  list-style-position: inside;
}

.modification-note {
  background: var(--spice-light);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--spice-dark);
  margin-bottom: 16px;
  font-style: italic;
}

/* ---- Grocery View ---- */
#grocery-view {
  flex-direction: column;
  padding: 32px;
  overflow-y: auto;
}

.grocery-card {
  background: white;
  border-radius: 14px;
  padding: 20px;
  border: 1px solid var(--linen);
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.grocery-card:hover {
  border-color: var(--herb);
  box-shadow: 0 4px 16px rgba(42, 36, 32, 0.06);
}

.grocery-card h3 {
  font-size: 1rem;
  color: var(--charcoal);
  margin-bottom: 4px;
}

.grocery-card .grocery-meta {
  font-size: 0.82rem;
  color: var(--stone);
  display: flex;
  gap: 16px;
}

.grocery-card .progress-bar {
  height: 4px;
  background: var(--linen);
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
}

.grocery-card .progress-fill {
  height: 100%;
  background: var(--herb);
  border-radius: 2px;
  transition: width 0.3s;
}

/* Grocery Detail */
.grocery-detail { padding: 32px; }

.grocery-detail .back-btn {
  background: none;
  border: none;
  color: var(--spice);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: 'DM Sans', sans-serif;
  margin-bottom: 16px;
  padding: 4px 0;
}

.grocery-detail .back-btn:hover { text-decoration: underline; }

.grocery-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--linen);
  cursor: pointer;
  transition: opacity 0.2s;
}

.grocery-item.checked { opacity: 0.4; }

.grocery-item .checkbox {
  width: 22px;
  height: 22px;
  border: 2px solid var(--warm);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.grocery-item.checked .checkbox {
  background: var(--herb);
  border-color: var(--herb);
}

.grocery-item .checkbox svg {
  width: 12px;
  height: 12px;
  color: white;
  display: none;
}

.grocery-item.checked .checkbox svg { display: block; }

.grocery-item .item-name {
  font-size: 0.9rem;
  color: var(--charcoal);
}

.grocery-item.checked .item-name { text-decoration: line-through; }

.grocery-item .item-amount {
  font-size: 0.82rem;
  color: var(--stone);
  margin-left: auto;
}

.grocery-item.skipped {
  opacity: 0.3;
}

.grocery-item.skipped .item-name {
  text-decoration: line-through;
  font-style: italic;
}

.skipped-label {
  font-size: 0.75rem;
  color: var(--herb);
  background: rgba(74, 103, 65, 0.08);
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: auto;
}

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { display: none; }

  .topbar nav button { padding: 6px 10px; font-size: 0.8rem; }

  #recipes-view, #grocery-view { padding: 20px; }

  .recipe-grid { grid-template-columns: 1fr; }

  .messages { padding: 16px; }

  .chat-input-area { padding: 12px 16px 16px; }

  .modal { padding: 24px; margin: 12px; }
}

@media (max-width: 480px) {
  .topbar .user-info .name { display: none; }
  .topbar .logo { margin-right: 16px; }
}
