:root {
  --bg:          #f5ede0;
  --surface:     #fefaf4;
  --surface-2:   #ede0cf;
  --ink:         #38302a;
  --ink-soft:    #7d7065;
  --accent:      #b06050;
  --accent-ink:  #fff8f5;
  --accent-soft: #e8d2c6;
  --line:        #dfd0bc;
  --danger:      #a83828;

  --r-card:     18px 22px 20px 16px / 16px 20px 22px 18px;
  --r-bubble-a: 18px 18px 18px 6px;
  --r-bubble-u: 18px 18px 6px 18px;
  --r-input:    12px 14px 12px 14px;
  --r-btn:      14px 16px 14px 16px;
  --r-conv:     12px 14px 12px 10px;

  --shadow:      0 2px 8px rgba(80,55,40,.10), 0 6px 24px rgba(80,55,40,.07);
  --shadow-card: 0 4px 16px rgba(80,55,40,.12), 0 1px 4px rgba(80,55,40,.08);

  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

h1, h2, h3 { font-style: italic; letter-spacing: -0.01em; }

#app { height: 100%; display: flex; flex-direction: column; }

.loading { margin: auto; color: var(--ink-soft); font-style: italic; }

/* ---------- Auth screens ---------- */
.auth {
  margin: auto;
  width: min(92vw, 380px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: 0 1.6rem 2rem;
  overflow: hidden;
}

/* Terrakotta-Streifen oben */
.auth::before {
  content: '';
  display: block;
  height: 5px;
  background: linear-gradient(90deg, var(--accent-soft), var(--accent), var(--accent-soft));
  margin: 0 -1.6rem 2rem;
}

.brand { text-align: center; margin-bottom: 1.4rem; }
.brand h1 {
  font-size: 2rem;
  margin: 0;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.brand p { margin: 0.3rem 0 0; color: var(--ink-soft); font-size: 0.93rem; font-style: italic; }

/* Ornament-Linie zwischen Titel und Untertitel */
.brand::after {
  content: '— ◆ —';
  display: block;
  text-align: center;
  color: var(--accent-soft);
  font-size: 0.68rem;
  letter-spacing: 0.5em;
  margin: 0.5rem 0 0.3rem;
  font-style: normal;
}

label {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0.9rem 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
input, select, textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1.5px solid var(--line);
  border-radius: var(--r-input);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(176,96,80,0.15);
}
textarea { resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  width: 100%; margin-top: 1.2rem; padding: 0.75rem 1rem;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: var(--r-btn); font: inherit; font-size: 1rem;
  font-style: italic; letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(176,96,80,.20);
  transition: filter 0.15s, box-shadow 0.15s;
}
.btn:hover { filter: brightness(1.06); box-shadow: 0 3px 12px rgba(176,96,80,.28); }
.btn:disabled { opacity: 0.55; cursor: default; box-shadow: none; }
.btn.secondary {
  background: var(--surface-2); color: var(--ink);
  font-style: normal; letter-spacing: 0;
  box-shadow: none;
}
.btn.ghost { background: transparent; color: var(--accent); width: auto; margin: 0; padding: 0.4rem 0.6rem; box-shadow: none; font-style: italic; }
.btn.danger { background: transparent; color: var(--danger); box-shadow: none; font-style: normal; }
.btn.danger-solid { background: var(--danger); color: #fff; box-shadow: none; }

.consent { display: flex; gap: 0.5rem; align-items: flex-start; margin-top: 1rem; font-size: 0.85rem; color: var(--ink-soft); }
.consent input { width: auto; margin-top: 0.2rem; }

.switch { text-align: center; margin-top: 1.1rem; font-size: 0.9rem; color: var(--ink-soft); }
.switch a { color: var(--accent); cursor: pointer; }

.msg-error { color: var(--danger); font-size: 0.88rem; margin-top: 0.9rem; min-height: 1.1em; }
.msg-ok { color: #4a7a4a; font-size: 0.88rem; margin-top: 0.9rem; }

/* ---------- App shell ---------- */
.topbar {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 1rem; padding-top: max(0.7rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(80,55,40,.06);
}
.topbar h1 {
  font-size: 1.2rem; margin: 0; margin-right: auto;
  font-style: italic; color: var(--accent);
  cursor: pointer; user-select: none;
  border-radius: 8px; transition: opacity 0.12s;
}
.topbar h1:hover { opacity: 0.7; }
.topbar .iconbtn {
  background: none; border: none; cursor: pointer; color: var(--ink-soft);
  font-size: 1.3rem; border-radius: 10px;
  width: 2.2rem; height: 2.2rem; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s;
}
.topbar .iconbtn:hover { background: var(--surface-2); }
.topbar #profile { font-size: 1.6rem; }

.shell { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 260px; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar .convs { overflow-y: auto; flex: 1; padding: 0.5rem; }
.conv {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.6rem 0.7rem; border-radius: var(--r-conv); cursor: pointer; color: var(--ink);
  font-size: 0.92rem; line-height: 1.3;
  transition: background 0.12s;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--accent-soft); font-weight: 600; }
.conv .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .del { opacity: 0; border: none; background: none; color: var(--ink-soft); cursor: pointer; font-size: 1rem; }
.conv:hover .del { opacity: 1; }
.sidebar .newbtn { margin: 0.6rem; width: calc(100% - 1.2rem); border-radius: var(--r-btn); }
.empty { color: var(--ink-soft); font-size: 0.88rem; padding: 1rem; text-align: center; font-style: italic; }

/* ---------- Chat ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1.2rem; display: flex; flex-direction: column; gap: 1rem; }
.bubble { max-width: 680px; padding: 0.9rem 1.1rem; border-radius: var(--r-bubble-a); line-height: 1.6; }
.bubble.user {
  align-self: flex-end;
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--r-bubble-u);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12);
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-bubble-a);
  box-shadow: 0 1px 6px rgba(80,55,40,.07);
}
.bubble.assistant p { margin: 0 0 0.6rem; }
.bubble.assistant p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 700; }
.welcome { margin: auto; text-align: center; color: var(--ink-soft); max-width: 420px; padding: 2.5rem 2rem; }
.welcome h2 { color: var(--ink); font-weight: 500; font-size: 1.5rem; margin-bottom: 0.6rem; }
.typing { color: var(--ink-soft); font-style: italic; opacity: 0.8; }

.composer {
  display: flex; gap: 0.6rem; padding: 0.8rem;
  padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: linear-gradient(0deg, var(--bg), var(--surface));
}
.composer textarea { flex: 1; max-height: 140px; min-height: 46px; border-radius: var(--r-input); }
.composer .send {
  width: auto; margin: 0; padding: 0.5rem 1.1rem; align-self: flex-end;
  border-radius: 20px 16px 16px 20px;
}

.banner {
  background: linear-gradient(90deg, var(--accent-soft), #f5e6da, var(--accent-soft));
  color: var(--ink); padding: 0.6rem 1rem; font-size: 0.85rem; text-align: center;
  font-style: italic; border-bottom: 1px solid var(--line);
}

/* ---------- Profile / modal ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(45,38,32,.45);
  backdrop-filter: blur(2px);
  display: flex; z-index: 10;
}
.modal {
  margin: auto; width: min(92vw, 440px); background: var(--surface);
  border-radius: var(--r-card); box-shadow: var(--shadow-card);
  border: 1px solid var(--line);
  padding: 1.6rem; max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 0.3rem; font-weight: 600; font-size: 1.25rem; }
.modal .hint { color: var(--ink-soft); font-size: 0.85rem; margin: 0 0 0.5rem; font-style: italic; }
.modal-actions { display: flex; gap: 0.6rem; margin-top: 1.3rem; }
.modal-actions .btn { margin-top: 0; }
.modal-divider { border: none; height: 1px; background: linear-gradient(90deg, transparent, var(--line), transparent); margin: 1.2rem 0 0.8rem; }
.privacy-actions { display: flex; gap: 0.6rem; }
.privacy-actions .btn { flex: 1; margin-top: 0; }

.medical-note { font-size: 0.76rem; color: var(--ink-soft); text-align: center; padding: 0.5rem 1rem; font-style: italic; opacity: 0.75; }

.toast {
  position: fixed; left: 50%; bottom: 5rem; transform: translateX(-50%);
  z-index: 20; max-width: 90vw;
  background: var(--accent-soft); color: var(--ink);
  padding: 0.7rem 1.1rem; border-radius: var(--r-btn); box-shadow: var(--shadow);
  font-size: 0.9rem;
}

/* Versionsanzeige */
.version-tag {
  position: fixed; bottom: 0.4rem; left: 0.6rem;
  font-size: 0.65rem; color: #b0a098;
  pointer-events: none; font-family: monospace; z-index: 999;
}

/* Backdrop */
.backdrop { display: none; position: fixed; inset: 0; background: rgba(45,38,32,.35); z-index: 7; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 8; transform: translateX(-100%); transition: transform 0.2s; box-shadow: 4px 0 32px rgba(80,55,40,.15); width: 80vw; }
  .sidebar.open { transform: translateX(0); }
  .backdrop.show { display: block; }
  .bubble { max-width: 100%; }
}
@media (min-width: 721px) {
  .topbar .menu { display: none; }
}

/* ---------- Schnellfragen ---------- */
.chips-row {
  display: flex; gap: 0.5rem; overflow-x: auto; flex-shrink: 0;
  padding: 0.5rem 0.8rem 0.4rem;
  border-top: 1px solid var(--line);
  scrollbar-width: none;
}
.chips-row:empty { display: none; }
.chips-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  height: 44px; padding: 0 1rem;
  background: var(--surface); border: 1.5px solid var(--accent-soft);
  border-radius: 22px; color: var(--ink); font: inherit; font-size: 0.85rem;
  cursor: pointer; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.chip:hover { background: var(--accent-soft); border-color: var(--accent); }
.chip:active { background: var(--accent); color: var(--accent-ink); }

/* ---------- Wochen-Update Card ---------- */
.weekly-card {
  background: linear-gradient(135deg, var(--surface) 0%, #fdf0e8 100%);
  border: 1.5px solid var(--accent-soft);
  border-radius: 18px 22px 18px 20px / 16px 18px 20px 16px;
  box-shadow: var(--shadow-card);
  padding: 1.1rem 1.3rem;
  max-width: 520px;
  width: 100%;
  align-self: stretch;
}
.weekly-loading {
  display: flex; align-items: center;
  min-height: 60px;
}
.weekly-hint {
  color: var(--ink-soft); font-style: italic; font-size: 0.92rem;
  display: flex; align-items: center; min-height: 54px;
}
.weekly-header { display: flex; flex-direction: column; gap: 0.3rem; }
.weekly-ssw {
  font-size: 1.6rem; font-style: italic; font-weight: 700;
  color: var(--accent); letter-spacing: -0.02em; line-height: 1.1;
}
.weekly-size { font-size: 0.9rem; color: var(--ink); line-height: 1.4; }
.weekly-size-meta { color: var(--ink-soft); font-size: 0.82rem; margin-left: 0.25rem; }
.weekly-toggle-btn {
  margin-top: 0.8rem;
  display: inline-block;
  color: var(--accent); font-size: 0.85rem; font-style: italic;
  cursor: pointer; user-select: none;
  padding: 0.15rem 0;
}
.weekly-toggle-btn:hover { text-decoration: underline; }
.weekly-body { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.85rem; }
.weekly-section h4 {
  margin: 0 0 0.25rem; font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-soft); font-style: normal; font-weight: 600;
}
.weekly-section p { margin: 0; font-size: 0.9rem; line-height: 1.55; color: var(--ink); }
