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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #22222e;
  --border: #2a2a3a;
  --primary: #7c3aed;
  --primary-light: #a78bfa;
  --text: #e8e8f0;
  --text2: #9090a8;
  --text3: #5a5a72;
  --user-bubble: #1e1e3a;
  --assistant-bg: transparent;
  --error: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --sidebar-w: 280px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
}

html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Login ──────────────────────────────────────────────────────────────────── */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 1000;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  width: 100%; max-width: 360px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.login-logo { font-size: 48px; margin-bottom: 16px; }
.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.login-card p { color: var(--text2); margin-bottom: 28px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px;
  padding: 12px 16px; font-size: 15px;
  outline: none; transition: border-color .2s;
}
.login-card input:focus { border-color: var(--primary); }
.login-card button {
  background: var(--primary); color: #fff;
  border: none; border-radius: 10px;
  padding: 12px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .2s;
}
.login-card button:hover { background: #6d28d9; }
.error { color: var(--error); font-size: 13px; }

/* ── App Layout ─────────────────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  transition: transform .25s ease;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 15px; font-weight: 700; letter-spacing: -.3px; }

.search-wrap { padding: 10px 12px; }
.search-wrap input {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-size: 13px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--primary); }

.conversation-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.category-group { margin-bottom: 4px; }
.category-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text3);
  padding: 10px 8px 4px;
}
.conv-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 10px; border-radius: 8px;
  cursor: pointer; transition: background .15s;
  gap: 8px; overflow: hidden;
}
.conv-item:hover { background: var(--surface2); }
.conv-item.active { background: rgba(124,58,237,.18); }
.conv-title-text {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
.conv-date { font-size: 11px; color: var(--text3); flex-shrink: 0; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px;
}
.footer-btn {
  flex: 1; background: var(--surface2);
  border: 1px solid var(--border); color: var(--text2);
  border-radius: 8px; padding: 8px; font-size: 12px;
  cursor: pointer; transition: all .15s;
}
.footer-btn:hover { background: var(--border); color: var(--text); }

/* ── Sidebar overlay (mobile) ───────────────────────────────────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 40;
}

/* ── Main ───────────────────────────────────────────────────────────────────── */
.main {
  flex: 1; display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  min-width: 0;
}
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-height: 52px;
}
.chat-title { font-size: 14px; font-weight: 600; flex: 1; truncate overflow-hidden; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.category-badge {
  font-size: 11px; background: rgba(124,58,237,.2);
  color: var(--primary-light); border-radius: 20px;
  padding: 2px 10px; white-space: nowrap;
}

/* ── Messages ───────────────────────────────────────────────────────────────── */
.messages {
  flex: 1; overflow-y: auto;
  padding: 20px 0; scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.message {
  display: flex; gap: 12px;
  padding: 10px 20px;
  max-width: 860px; margin: 0 auto; width: 100%;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } }

.message.user { flex-direction: row-reverse; }
.message.user .msg-bubble {
  background: var(--user-bubble);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  border: 1px solid var(--border);
  max-width: 80%;
}
.message.assistant .msg-bubble {
  background: var(--assistant-bg);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  flex: 1;
}
.msg-bubble { padding: 12px 16px; font-size: 14.5px; line-height: 1.7; }

/* Markdown inside assistant bubbles */
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { margin: 16px 0 8px; font-weight: 700; }
.msg-bubble h1 { font-size: 20px; } .msg-bubble h2 { font-size: 17px; } .msg-bubble h3 { font-size: 15px; }
.msg-bubble p { margin: 0 0 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul,.msg-bubble ol { padding-left: 20px; margin: 8px 0; }
.msg-bubble li { margin: 4px 0; }
.msg-bubble blockquote { border-left: 3px solid var(--primary); padding-left: 12px; color: var(--text2); margin: 10px 0; }
.msg-bubble code { font-family: var(--font-mono); font-size: 13px; background: rgba(124,58,237,.15); padding: 1px 5px; border-radius: 4px; }
.msg-bubble pre {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; overflow-x: auto;
  margin: 12px 0; position: relative;
}
.msg-bubble pre code { background: none; padding: 0; font-size: 13px; }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
.msg-bubble th,.msg-bubble td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.msg-bubble th { background: var(--surface); font-weight: 600; }
.msg-bubble a { color: var(--primary-light); text-decoration: underline; }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.avatar { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 14px; margin-top: 4px; }
.avatar.user-av { background: var(--primary); }
.avatar.ai-av { background: var(--surface2); border: 1px solid var(--border); }

/* Streaming cursor */
.cursor::after { content: '▋'; animation: blink .7s infinite; color: var(--primary-light); margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }

/* ── Welcome screen ─────────────────────────────────────────────────────────── */
.welcome {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%;
  text-align: center; padding: 40px 20px;
  color: var(--text2);
}
.welcome-icon { font-size: 52px; margin-bottom: 20px; }
.welcome h2 { font-size: 22px; color: var(--text); margin-bottom: 8px; }
.welcome p { color: var(--text2); margin-bottom: 28px; }

.skill-cards { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 500px; }
.skill-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 16px;
  cursor: pointer; transition: all .15s; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.skill-card:hover { border-color: var(--primary); background: rgba(124,58,237,.1); }

/* ── Input area ─────────────────────────────────────────────────────────────── */
.input-area {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 12px 16px 16px;
}
.skill-bar {
  display: flex; gap: 6px; overflow-x: auto;
  padding-bottom: 10px; scrollbar-width: none;
}
.skill-bar::-webkit-scrollbar { display: none; }
.skill-chip {
  flex-shrink: 0; background: var(--surface);
  border: 1px solid var(--border); color: var(--text2);
  border-radius: 20px; padding: 5px 12px; font-size: 12px;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.skill-chip:hover { border-color: var(--primary-light); color: var(--text); }
.skill-chip.active { background: rgba(124,58,237,.2); border-color: var(--primary); color: var(--primary-light); }

/* ── Image upload ───────────────────────────────────────────────────────────── */
.image-preview-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 4px; margin-bottom: 4px;
}
.image-preview-thumb {
  width: 56px; height: 56px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border);
}
.image-clear-btn {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text2); border-radius: 50%;
  width: 22px; height: 22px; font-size: 12px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.image-clear-btn:hover { background: var(--error); color: #fff; border-color: var(--error); }

.img-btn {
  background: none; border: none; color: var(--text3);
  cursor: pointer; padding: 4px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; transition: all .15s;
}
.img-btn:hover { color: var(--primary-light); background: rgba(124,58,237,.1); }

/* Inline images in message bubbles */
.msg-bubble .msg-image {
  max-width: 100%; max-height: 400px;
  border-radius: 10px; margin-bottom: 10px;
  display: block; border: 1px solid var(--border);
}

.input-row {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px 8px 10px;
  transition: border-color .2s;
}
.input-row:focus-within { border-color: var(--primary); }
#msgInput {
  flex: 1; background: none; border: none; color: var(--text);
  font-family: var(--font); font-size: 14.5px; line-height: 1.5;
  resize: none; outline: none; max-height: 200px;
  overflow-y: auto;
}
#msgInput::placeholder { color: var(--text3); }

.send-btn {
  width: 34px; height: 34px; flex-shrink: 0;
  background: var(--primary); color: #fff;
  border: none; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.send-btn:hover { background: #6d28d9; transform: scale(1.05); }
.send-btn:disabled { background: var(--surface2); cursor: not-allowed; transform: none; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.icon-btn {
  background: none; border: none; color: var(--text2);
  cursor: pointer; padding: 6px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.primary-btn {
  background: var(--primary); color: #fff; border: none;
  border-radius: 8px; padding: 9px 16px; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: background .15s;
}
.primary-btn:hover { background: #6d28d9; }

/* ── Memory Modal ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7); z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px;
  width: 100%; max-width: 520px;
  max-height: 80vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-desc { font-size: 13px; color: var(--text2); }

.memory-list { display: flex; flex-direction: column; gap: 8px; }
.memory-item {
  display: flex; align-items: flex-start; justify-content: space-between;
  background: var(--surface2); border-radius: 8px;
  padding: 10px 12px; gap: 10px;
}
.memory-item-info { flex: 1; min-width: 0; }
.memory-key { font-size: 12px; font-weight: 600; color: var(--primary-light); margin-bottom: 2px; }
.memory-val { font-size: 13px; color: var(--text); }
.memory-cat { font-size: 11px; color: var(--text3); margin-top: 2px; }
.del-btn { background: none; border: none; color: var(--text3); cursor: pointer; padding: 2px; font-size: 16px; flex-shrink: 0; }
.del-btn:hover { color: var(--error); }

.memory-form { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 16px; }
.mem-input {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; outline: none;
}
.mem-input:focus { border-color: var(--primary); }

/* ── Model Picker ───────────────────────────────────────────────────────────── */
.model-picker { position: relative; flex-shrink: 0; }
.model-btn {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); border-radius: 20px;
  padding: 4px 10px 4px 12px; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.model-btn:hover { border-color: var(--primary-light); color: var(--text); }

.model-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px;
  min-width: 220px; z-index: 100;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.model-group-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text3);
  padding: 6px 8px 3px;
}
.model-option {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  transition: background .12s; gap: 10px;
}
.model-option:hover { background: var(--surface2); }
.model-option.active { background: rgba(124,58,237,.15); }
.model-option-name { font-size: 13px; font-weight: 500; color: var(--text); }
.model-option-desc { font-size: 11px; color: var(--text3); margin-top: 1px; }
.model-badge {
  font-size: 10px; font-weight: 700; border-radius: 6px;
  padding: 2px 6px; white-space: nowrap; flex-shrink: 0;
}
.badge-claude { background: rgba(124,58,237,.2); color: var(--primary-light); }
.badge-ollama { background: rgba(34,197,94,.15); color: #4ade80; }

/* ── Responsive / Mobile ────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 50; transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .message { padding: 8px 12px; }
  .message.user .msg-bubble { max-width: 92%; }
  .input-area { padding: 10px 12px 20px; }
}

/* ── Recipe Book ────────────────────────────────────────────────────────────── */
:root {
  --recipe: #d97706;
  --recipe-light: #fbbf24;
  --recipe-bg: rgba(217,119,6,.12);
  --recipe-border: rgba(217,119,6,.3);
}

.recipe-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}
.recipe-modal-inner {
  background: var(--surface);
  border: 1px solid var(--recipe-border);
  border-radius: 20px;
  width: 100%; max-width: 860px;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}
.recipe-modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px;
  padding: 24px 28px 20px;
  background: linear-gradient(135deg, rgba(217,119,6,.15), rgba(251,191,36,.05));
  border-bottom: 1px solid var(--recipe-border);
}
.recipe-modal-header h2 { font-size: 22px; font-weight: 700; color: var(--recipe-light); margin-bottom: 4px; }
.recipe-modal-header p { font-size: 13px; color: var(--text2); }
.recipe-header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.recipe-new-btn {
  background: var(--recipe); color: #fff;
  border: none; border-radius: 10px;
  padding: 9px 16px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background .15s; white-space: nowrap;
}
.recipe-new-btn:hover { background: #b45309; }

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 24px 28px;
  min-height: 200px;
}
.recipe-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text3);
  font-size: 14px;
  padding: 40px 0;
}

.recipe-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 16px;
  cursor: pointer;
  transition: all .18s;
  display: flex; flex-direction: column; gap: 8px;
  position: relative; overflow: hidden;
}
.recipe-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--recipe), var(--recipe-light));
  opacity: 0; transition: opacity .18s;
}
.recipe-card:hover {
  border-color: var(--recipe-border);
  background: rgba(217,119,6,.06);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.recipe-card:hover::before { opacity: 1; }

.recipe-card-icon { font-size: 28px; line-height: 1; }
.recipe-card-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.recipe-card-date { font-size: 11px; color: var(--text3); margin-top: auto; }

/* Category badge warm color for Rezepte */
.category-badge.rezepte {
  background: var(--recipe-bg);
  color: var(--recipe-light);
  border: 1px solid var(--recipe-border);
}

@media (max-width: 640px) {
  .recipe-modal { padding: 0; align-items: flex-end; }
  .recipe-modal-inner { border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto; }
  .recipe-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); padding: 16px; gap: 12px; }
  .recipe-modal-header { padding: 20px 16px 16px; }
}

/* ── Scrollbar global ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
