:root {
  --bg-sidebar: #161614;
  --bg-main: #1f1f1c;
  --bg-elevated: #262623;
  --bg-hover: #2d2d29;
  --bg-user-msg: #2b2b27;
  --border: #2f2f2a;
  --border-strong: #3d3d37;
  --text-primary: #eceae4;
  --text-secondary: #a8a69e;
  --text-muted: #76746d;
  --accent-warm: #d97757;
  --accent-warm-hover: #e48667;
  --accent-teal: #2dd4bf;
  --accent-teal-soft: rgba(45, 212, 191, 0.12);
  --danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease, min-width 0.2s ease;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-icon {
  font-size: 18px;
}

.sidebar-header-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

.sidebar-search {
  position: relative;
  padding: 10px 12px 6px;
}

.search-icon {
  position: absolute;
  left: 22px;
  top: 20px;
  color: var(--text-muted);
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 7px 10px 7px 30px;
  font-size: 13px;
  outline: none;
}

.sidebar-search input:focus {
  border-color: var(--accent-teal);
}

.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 6px 12px 10px;
}

.cat-pill {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}

.cat-pill:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.cat-pill.active {
  background: var(--accent-teal-soft);
  border-color: var(--accent-teal);
  color: var(--accent-teal);
  font-weight: 500;
}

.sidebar-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 14px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.count-badge {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
}

.recipe-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 12px;
}

.recipe-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 2px;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.15s, border-color 0.15s;
}

.recipe-item:hover {
  background: var(--bg-hover);
}

.recipe-item.active {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.recipe-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recipe-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-muted);
}

.recipe-empty {
  padding: 18px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.role-card-btn {
  width: 100%;
  text-align: left;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  cursor: pointer;
  color: var(--text-primary);
  transition: border-color 0.15s, background 0.15s;
}

.role-card-btn:hover {
  border-color: var(--accent-warm);
  background: var(--bg-hover);
}

.role-card-top {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 12.5px;
}

.role-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-warm);
}

.role-card-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer-row {
  display: flex;
  gap: 6px;
}

.footer-action-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.footer-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ---------------- Main Area & Topbar ---------------- */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-main);
}

.topbar {
  height: 48px;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.view-tabs {
  display: flex;
  gap: 4px;
}

.view-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.view-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.view-tab.active {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

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

.role-badges {
  display: flex;
  gap: 6px;
}

.role-pill {
  font-size: 11.5px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 999px;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--accent-teal);
  background: var(--accent-teal-soft);
  border: 1px solid rgba(45, 212, 191, 0.3);
  padding: 3px 9px;
  border-radius: 999px;
}

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

/* ---------------- Chat View ---------------- */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
}

.chat-container {
  max-width: 760px;
  margin: 0 auto;
}

.welcome-state {
  text-align: center;
  padding: 36px 12px 20px;
}

.welcome-avatar {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(217, 119, 87, 0.2), rgba(45, 212, 191, 0.2));
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}

.welcome-state h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.welcome-state p {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 520px;
  margin: 0 auto 24px;
}

.starter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  text-align: left;
}

.starter-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.starter-card:hover {
  border-color: var(--accent-teal);
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.starter-icon {
  font-size: 18px;
  margin-bottom: 2px;
}

.starter-title {
  font-weight: 600;
  font-size: 13.5px;
}

.starter-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

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

.msg-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 8px;
  background: rgba(217, 119, 87, 0.16);
  border: 1px solid rgba(217, 119, 87, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  margin-top: 2px;
}

.msg-bubble-user {
  background: var(--bg-user-msg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  max-width: 82%;
  white-space: pre-wrap;
}

.msg-assistant-body {
  flex: 1;
  min-width: 0;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  margin: 14px 0 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.markdown-body h1 { font-size: 20px; }
.markdown-body h2 { font-size: 16px; color: var(--accent-warm); }
.markdown-body h3 { font-size: 14.5px; }

.markdown-body p {
  margin-bottom: 10px;
}

.markdown-body ul, .markdown-body ol {
  margin: 6px 0 12px 20px;
}

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

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent-teal);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 8px 0;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg-elevated);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Interactive Option Cards in Chat */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.option-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  text-align: left;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s;
}

.option-card:hover {
  border-color: var(--accent-teal);
  background: var(--bg-hover);
}

.option-card-title {
  font-weight: 600;
  font-size: 13.5px;
}

.option-card-meta {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.option-card-cta {
  margin-top: auto;
  font-size: 12px;
  color: var(--accent-teal);
  font-weight: 500;
}

.action-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.action-chip-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.action-chip-btn:hover {
  border-color: var(--accent-teal);
  background: var(--accent-teal-soft);
  color: var(--accent-teal);
}

.action-chip-btn.primary {
  background: var(--accent-warm);
  border-color: var(--accent-warm);
  color: #fff;
}

.action-chip-btn.primary:hover {
  background: var(--accent-warm-hover);
}

/* ---------------- Composer ---------------- */
.composer-wrapper {
  padding: 8px 20px 14px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.composer-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 10px 12px 8px;
  transition: border-color 0.15s;
}

.composer-box:focus-within {
  border-color: var(--accent-teal);
}

.composer-context-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent-teal-soft);
  border: 1px solid rgba(45, 212, 191, 0.25);
  color: var(--accent-teal);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-bottom: 8px;
}

.clear-ctx-btn {
  background: transparent;
  border: none;
  color: var(--accent-teal);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

#chat-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 180px;
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.composer-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toggle-chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.toggle-chip.active {
  background: var(--accent-teal-soft);
  border-color: var(--accent-teal);
  color: var(--accent-teal);
}

.send-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: none;
  background: var(--accent-warm);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.send-btn:hover {
  background: var(--accent-warm-hover);
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---------------- Recipe View ---------------- */
.recipe-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.recipe-view-inner {
  max-width: 780px;
  margin: 0 auto;
}

.recipe-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.recipe-toolbar-left, .recipe-toolbar-right {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.recipe-read-pane {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
}

.cook-check-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
}

.cook-check-item input[type="checkbox"] {
  margin-top: 4px;
  accent-color: var(--accent-teal);
}

.cook-check-item.done {
  opacity: 0.5;
  text-decoration: line-through;
}

.recipe-edit-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.edit-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------------- Buttons & Forms ---------------- */
.btn-primary, .btn-secondary, .btn-accent-soft, .btn-danger-soft {
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent-warm);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-warm-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-accent-soft {
  background: var(--accent-teal-soft);
  border-color: rgba(45, 212, 191, 0.35);
  color: var(--accent-teal);
}

.btn-danger-soft {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 500;
}

input[type="text"], input[type="number"], input[type="password"], select, textarea {
  background: var(--bg-main);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-teal);
}

/* ---------------- Modals & Toast ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 660px;
  max-height: 90vh;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-card.modal-sm {
  max-width: 480px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-subtitle {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-teal);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  z-index: 200;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    z-index: 50;
    height: 100vh;
  }
  .starter-grid, .form-grid, .edit-row {
    grid-template-columns: 1fr;
  }
  .role-badges {
    display: none;
  }
}
