/* ============================================================
   Cohaushalt — Design-System
   Markenkit: Salbeigrün #5C7A52 · Dunkelbraun #2D2A23 · Creme #F5F0E8
   Schrift: Poppins (selbst gehostet)
   ============================================================ */

@font-face {
  font-family: "Poppins";
  src: url("../fonts/poppins-v24-latin_latin-ext-regular.2f07ada47e98.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Poppins";
  src: url("../fonts/poppins-v24-latin_latin-ext-500.dea8e165c40a.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Poppins";
  src: url("../fonts/poppins-v24-latin_latin-ext-600.8b827b197d2a.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Poppins";
  src: url("../fonts/poppins-v24-latin_latin-ext-700.e1a64a8e81a5.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Markenfarben */
  --green: #5c7a52;
  --green-dark: #47603f;
  --green-light: #a9bfa0;
  --green-soft: #eef2ec;
  --brown: #2d2a23;
  --cream: #f5f0e8;
  --beige: #e7dfd2;

  /* Semantik */
  --bg: var(--cream);
  --card: #fcfaf5;
  --border: #e3dccd;
  --fg: var(--brown);
  --muted-fg: #857e6f;
  --primary: var(--green);
  --primary-hover: var(--green-dark);
  --primary-fg: #fdfcf9;
  --destructive: #b3452f;
  --destructive-bg: #f7e8e4;
  --warning: #c9a84c;
  --success: var(--green);

  --input-bg: #ffffff;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(45, 42, 35, 0.06);
  --shadow-md: 0 4px 16px rgba(45, 42, 35, 0.1);
  --font: "Poppins", system-ui, -apple-system, sans-serif;

  --sidebar-w: 264px;
  --bottomnav-h: 64px;
}

/* ---------- Dark Mode ---------- */

.dark {
  --bg: #1d1a15;
  --card: #26221b;
  --border: #3a352b;
  --fg: #f0e9da;
  --muted-fg: #a59c88;
  --green: #7ba06c;
  --green-dark: #8fb37f;
  --green-light: #45543d;
  --green-soft: #2e3627;
  --beige: #363126;
  --destructive: #d9705a;
  --destructive-bg: #45291f;
  --input-bg: #2b271f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.dark .toast { background: #3c372c; color: var(--fg); }
.dark .toast.success { background: var(--green-light); }
.dark .toast.error { background: var(--destructive-bg); color: #f3c2b5; }
.dark .avatar { color: #dfe9d8; }
.dark .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a59c88' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* Logo-Varianten je Theme */
.only-dark { display: none !important; }
.dark .only-dark { display: inline-block !important; }
.dark .only-light { display: none !important; }

/* Switch (Einstellungen) */
.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--beige);
  position: relative;
  cursor: pointer;
  border: 0;
  transition: background 0.2s;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: left 0.2s;
}
.switch:checked { background: var(--green); }
.switch:checked::after { left: 21px; }
.switch:disabled { opacity: 0.4; cursor: default; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 600; margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; }
svg.icon { flex-shrink: 0; }

.page-title {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted-fg);
}

/* ---------- App-Layout ---------- */

.app-shell { min-height: 100dvh; }
.app-main {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px calc(var(--bottomnav-h) + 32px + env(safe-area-inset-bottom));
}
.page-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 10px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.page-header .subtitle { color: var(--muted-fg); font-size: 0.82rem; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.sidebar { display: none; }

@media (min-width: 768px) {
  .app-main {
    max-width: 1040px;
    margin-left: var(--sidebar-w);
    padding: 0 32px 48px;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--card);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    z-index: 40;
  }
  .bottom-nav { display: none !important; }
}

/* Sidebar */
.sidebar-logo { display: flex; align-items: center; padding: 4px 10px 18px; }
.sidebar-logo img { height: 40px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-weight: 500;
  color: var(--fg);
  transition: background 0.15s;
}
.sidebar-link:hover { background: var(--green-soft); }
.sidebar-link.active { background: var(--green); color: var(--primary-fg); }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; font-size: 0.85rem; color: var(--muted-fg); }

.ws-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  text-align: left;
}
.ws-switcher:hover { border-color: var(--green-light); }

/* Bottom-Nav (mobil) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
}
.bottom-nav a, .bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--muted-fg);
  font-size: 0.65rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 0;
}
.bottom-nav a.active { color: var(--green-dark); }
.bottom-nav a.active svg { color: var(--green); }

/* ---------- Karten & Listen ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 12px; }
.card-title { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; font-weight: 600; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
}
.list-row + .list-row { border-top: 1px solid color-mix(in srgb, var(--border) 55%, transparent); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 500; }
.list-row .meta { font-size: 0.78rem; color: var(--muted-fg); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.done .title { text-decoration: line-through; color: var(--muted-fg); font-weight: 400; }

/* Check-Kreis */
.check-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: transparent;
  transition: all 0.15s;
  flex-shrink: 0;
  padding: 0;
}
.check-circle:hover { border-color: var(--green); }
.check-circle.checked { background: var(--green); border-color: var(--green); color: #fff; }

/* Farb-Punkt */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* Avatar */
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--green-light);
  color: var(--green-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--primary);
  color: var(--primary-fg);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: center;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-outline { background: transparent; color: var(--fg); border-color: var(--border); }
.btn-outline:hover { background: var(--green-soft); border-color: var(--green-light); }
.btn-ghost { background: transparent; color: var(--fg); }
.btn-ghost:hover { background: var(--green-soft); }
.btn-danger { background: var(--destructive); }
.btn-danger:hover { background: #9a3a27; }
.btn-danger-outline { background: transparent; border-color: color-mix(in srgb, var(--destructive) 40%, transparent); color: var(--destructive); }
.btn-danger-outline:hover { background: var(--destructive-bg); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; border-radius: 10px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  border: 0;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}
.icon-btn:hover { background: var(--green-soft); }
.icon-btn.danger { color: var(--destructive); }
.icon-btn.danger:hover { background: var(--destructive-bg); }
.icon-btn.subtle { color: var(--muted-fg); }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--bottomnav-h) + 20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-fg);
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 35;
}
.fab:hover { background: var(--primary-hover); }
@media (min-width: 768px) {
  .fab { bottom: 32px; right: 40px; }
}

/* ---------- Formulare ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.82rem; font-weight: 500; }
.hint { font-size: 0.76rem; color: var(--muted-fg); }

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--fg);
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--green) 45%, transparent);
  outline-offset: 0;
  border-color: var(--green);
}
.textarea { resize: vertical; min-height: 72px; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23857e6f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px; }

.form-error { color: var(--destructive); font-size: 0.8rem; }

/* Segmented Control / Tabs */
.segmented {
  display: flex;
  background: var(--beige);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}
.segmented > *,
.segmented form > button {
  flex: 1;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  border-radius: 9px;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--muted-fg);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}
.segmented > form { padding: 0; display: flex; }
.segmented > .active,
.segmented form > button.active { background: var(--card); color: var(--fg); box-shadow: var(--shadow-sm); }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--fg);
}
.chip:hover { border-color: var(--green); background: var(--green-soft); }
.chip.selected { background: var(--green); border-color: var(--green); color: #fff; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--green-light);
  color: var(--green-dark);
}
.badge.warn { background: #f3e8cd; color: #8a6d1f; }
.badge.danger { background: var(--destructive-bg); color: var(--destructive); }
.badge.neutral { background: var(--beige); color: var(--muted-fg); }

/* Farbwähler */
.color-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline-offset: 2px;
}
.color-swatch.selected { outline: 2px solid var(--brown); }

/* Fortschrittsbalken */
.progress { height: 8px; background: var(--beige); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--green); border-radius: 999px; transition: width 0.3s; }

/* ---------- Dialog ---------- */

dialog.modal {
  border: 0;
  border-radius: var(--radius-xl);
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  max-height: min(85dvh, 720px);
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow-md);
  margin: auto;
}
dialog.modal::backdrop { background: rgba(45, 42, 35, 0.45); }
.modal-inner { padding: 20px; overflow-y: auto; max-height: inherit; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { font-size: 1.05rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

@media (max-width: 767px) {
  dialog.modal.sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 92dvh;
  }
  dialog.modal.sheet .modal-inner { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* ---------- Toasts ---------- */

#toast-stack {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--brown);
  color: var(--cream);
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.22s ease;
}
.toast.success { background: var(--green-dark); }
.toast.error { background: var(--destructive); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast.hide { opacity: 0; transform: translateY(-8px); transition: all 0.25s; }

/* ---------- Auth / Setup ---------- */

.auth-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.auth-card { width: min(400px, 100%); }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 26px; text-align: center; }
.auth-logo img { height: 96px; }
.auth-logo .tagline { color: var(--muted-fg); font-size: 0.9rem; letter-spacing: 0.14em; text-transform: uppercase; }

/* ---------- Diverses ---------- */

.empty-state {
  text-align: center;
  color: var(--muted-fg);
  padding: 28px 12px;
  font-size: 0.9rem;
}
.muted { color: var(--muted-fg); }
.small { font-size: 0.8rem; }
.text-danger { color: var(--destructive); }
.text-success { color: var(--green-dark); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.text-center { text-align: center; }

details.collapsible > summary { list-style: none; cursor: pointer; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary .chev { transition: transform 0.2s; }
details.collapsible[open] > summary .chev { transform: rotate(180deg); }

.htmx-request.htmx-indicator-target { opacity: 0.5; pointer-events: none; }

/* Statistik */
.stat-value { font-size: 1.7rem; font-weight: 600; }
.mini-tile { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; text-align: center; }
.mini-tile .label { font-size: 0.68rem; color: var(--muted-fg); font-weight: 500; }
.mini-tile .value { font-size: 0.95rem; font-weight: 600; margin-top: 2px; }

/* Wochentags-Buttons (Aufgaben-Dialog) */
.weekday-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.weekday-picker button {
  width: 40px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--fg);
}
.weekday-picker button.selected { background: var(--green); border-color: var(--green); color: #fff; }

/* Essensplan */
.day-tile {
  width: 46px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
  text-align: center;
  padding: 6px 0;
  flex-shrink: 0;
}
.day-tile.today { background: var(--green); border-color: var(--green); color: #fff; }
.day-tile .dow { font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.day-tile .date { font-size: 1.05rem; font-weight: 600; }
.meal-thumb { width: 52px; height: 52px; border-radius: var(--radius); object-fit: cover; background: var(--beige); }
.meal-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted-fg); }

/* Mehr-Menü Grid */
.section-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.section-grid a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 500;
  text-align: center;
}
.section-grid a:hover { border-color: var(--green-light); background: var(--green-soft); }

/* Onboarding */
.onboarding-progress { display: flex; gap: 6px; margin-bottom: 20px; }
.onboarding-progress span { flex: 1; height: 5px; border-radius: 99px; background: var(--beige); }
.onboarding-progress span.done { background: var(--green); }

/* Balken (Finanzen Kategorien) */
.bar-row { display: flex; flex-direction: column; gap: 4px; }
.bar-track { height: 10px; border-radius: 99px; background: var(--beige); overflow: hidden; }
.bar-track > div { height: 100%; border-radius: 99px; }

/* Drag & Drop (Einstellungen) */
.drag-handle {
  cursor: grab;
  color: var(--muted-fg);
  touch-action: none;
  display: inline-flex;
  align-items: center;
  padding: 4px;
  flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { box-shadow: var(--shadow-md); }

.bar-preview { display: flex; gap: 8px; }
.bar-chip {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 12px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 0.7rem;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  text-align: center;
}
.bar-chip:active { cursor: grabbing; }
.bar-chip.static { cursor: default; opacity: 0.45; border-style: dashed; touch-action: auto; }
