/* ============================================================================
   FamFeed — NOVA Design System
   Tokens, layout (Topbar / Sidebar / Feed / Right-Rail), components, responsive.
   Styling only — the markup contract (data-testid / ids) is unchanged.
   ========================================================================== */

/* ----------------------------- DESIGN TOKENS ----------------------------- */
:root {
  --grad: linear-gradient(135deg, #7C5CFF 0%, #5B8DEF 50%, #22D3EE 100%);
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-pill: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
  --font: 'Inter', -apple-system, 'Segoe UI', Roboto, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --t: 160ms cubic-bezier(.4, 0, .2, 1);
}

[data-theme="light"] {
  --bg: #F4F6FB; --bg-glow: rgba(124, 92, 255, 0.07);
  --surface: #FFFFFF; --surface-2: #EEF1F8; --surface-glass: rgba(255, 255, 255, 0.72);
  --border: #E3E8F2; --border-strong: #D2D9E8;
  --text: #0D1220; --text-muted: #5A647B; --text-faint: #97A0B5;
  --accent: #6A4DFF; --accent-soft: rgba(106, 77, 255, 0.10); --accent-line: rgba(106, 77, 255, 0.30);
  --like: #F0457A;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.05), 0 8px 24px rgba(20, 30, 60, 0.06);
  --glow: 0 0 0 transparent;
}

[data-theme="dark"] {
  --bg: #080A12; --bg-glow: rgba(124, 92, 255, 0.16);
  --surface: #11141F; --surface-2: #181C2A; --surface-glass: rgba(15, 18, 28, 0.66);
  --border: #222738; --border-strong: #2E3447;
  --text: #EAEEF8; --text-muted: #9099AE; --text-faint: #5B6478;
  --accent: #8A7BFF; --accent-soft: rgba(138, 123, 255, 0.14); --accent-line: rgba(138, 123, 255, 0.35);
  --like: #FF5C8A;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.45);
  --glow: 0 0 28px rgba(138, 123, 255, 0.28);
}

/* Default to dark before the inline theme script runs. */
:root { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  position: relative;
}
/* Subtle ambient glow behind everything. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(900px 500px at 12% -8%, var(--bg-glow), transparent 60%),
    radial-gradient(700px 480px at 100% 0%, var(--bg-glow), transparent 55%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* View switching: only one top-level view visible at a time. */
.view { display: none; position: relative; z-index: 1; }
.view.active { display: block; }

/* ------------------------------- TOPBAR ---------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--text);
}
/* Gradient logo mark. */
.logo {
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  background: var(--grad);
  box-shadow: var(--glow);
  display: inline-grid;
  place-items: center;
  flex: none;
}
.logo svg { width: 18px; height: 18px; display: block; }
.topbar .spacer { flex: 1; }
.topbar .user {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: .95rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Round icon button (theme toggle etc.). */
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: border-color var(--t), background var(--t), transform var(--t);
}
.icon-btn:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.icon-btn:active { transform: scale(.94); }

/* Topbar search: a pill input that collapses to an icon on mobile. */
.search {
  flex: 1;
  max-width: 440px;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  padding: 9px 14px;
  color: var(--text-muted);
  transition: border-color var(--t), background var(--t), box-shadow var(--t);
}
.search:focus-within {
  border-color: var(--accent-line);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search svg { width: 18px; height: 18px; flex: none; display: block; }
.search input {
  flex: 1;
  width: auto;
  background: none;
  border: 0;
  outline: none;
  padding: 0;
  border-radius: 0;
  color: var(--text);
  font: inherit;
  font-size: .95rem;
}
.search input:focus { box-shadow: none; }
.search input::placeholder { color: var(--text-faint); }
/* The icon-only search fallback is hidden until the mobile breakpoint. */
.search-ic { display: none; }
.search-ic svg { width: 18px; height: 18px; }

/* ------------------------------- LAYOUT ---------------------------------- */
/* The app shell is the container-query context: the responsive layout below
   reacts to the shell's own inline width via @container (not the viewport).
   Bottom-tabs / FAB live OUTSIDE the shell so they stay viewport-fixed. */
.app-shell { container-type: inline-size; }

.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 320px;
  gap: var(--sp-5);
  max-width: 1200px;
  margin: var(--sp-5) auto;
  padding: 0 var(--sp-5);
  align-items: start;
}

/* ------------------------------- SIDEBAR --------------------------------- */
.side {
  position: sticky;
  top: 78px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.nav-item .nav-ico { font-size: 1.15rem; width: 1.4em; text-align: center; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--accent-line);
}

/* ------------------------------- MAIN ------------------------------------ */
main { min-width: 0; }

.section { display: none; }
.section.active { display: block; }

.feed { display: block; }

/* ------------------------------- STORIES --------------------------------- */
/* Horizontal, scrollable strip of ring avatars — only shown on mobile. */
.stories {
  display: none;
  gap: var(--sp-3);
  overflow-x: auto;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.stories::-webkit-scrollbar { display: none; }
.story {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: none;
  cursor: pointer;
}
.story .ring {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 2.5px;
  background: var(--grad);
}
.story .ring .pic {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--surface-2);
}
.story span {
  font-size: .7rem;
  color: var(--text-muted);
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------- CARDS ----------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
  box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; font-size: 1.15rem; letter-spacing: -0.01em; }
.card h3 { margin-top: 0; font-size: 1.02rem; }

/* Compose box. */
.compose { }
.compose textarea { min-height: 84px; }

/* ------------------------------- BUTTONS --------------------------------- */
button.primary,
.authbox button[type='submit'] {
  background: var(--grad);
  color: #fff;
  border: 0;
  border-radius: var(--r-pill);
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--glow);
  transition: transform var(--t), filter var(--t);
}
button.primary:hover,
.authbox button[type='submit']:hover { filter: brightness(1.08); }
button.primary:active,
.authbox button[type='submit']:active { transform: translateY(1px); }

button.ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  font-family: inherit;
  transition: background var(--t), color var(--t), border-color var(--t);
}
button.ghost:hover { border-color: var(--accent-line); color: var(--text); }
button[aria-pressed='true'] {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--accent-line);
}

/* --------------------------- INPUTS / LABELS ----------------------------- */
input, textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color var(--t), box-shadow var(--t);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type='file'] { padding: 8px; background: transparent; border-style: dashed; cursor: pointer; }
textarea { resize: vertical; min-height: 64px; }
label { display: block; font-size: .82rem; color: var(--text-muted); margin: 10px 0 4px; font-weight: 600; }
/* „Angemeldet bleiben"-Zeile: Checkbox + Text nebeneinander statt blockig. */
label.remember { display: flex; align-items: center; gap: 8px; cursor: pointer; }
label.remember input { width: auto; margin: 0; }

/* --------------------------------- POSTS --------------------------------- */
.post {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
  box-shadow: var(--shadow);
  transition: border-color var(--t), transform var(--t);
}
.post:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.post .author {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
}
.post .meta { color: var(--text-faint); font-size: .8rem; margin-top: 2px; }
.post .text { white-space: pre-wrap; margin-top: var(--sp-3); }
.post img.photo {
  max-width: 100%;
  border-radius: var(--r-md);
  margin-top: var(--sp-3);
  display: block;
  border: 1px solid var(--border);
}
.post .actions, .actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); flex-wrap: wrap; }

/* Like heart uses the dedicated --like token when active. */
[data-testid="like-button"][aria-pressed='true'] {
  color: var(--like);
  background: color-mix(in srgb, var(--like) 14%, transparent);
  border-color: color-mix(in srgb, var(--like) 40%, transparent);
}

.comments { margin-top: var(--sp-3); }
.comment {
  margin-top: var(--sp-2);
  padding-left: var(--sp-3);
  border-left: 2px solid var(--accent-line);
}
.comment .author { font-weight: 600; }

/* ------------------------------- AVATARS --------------------------------- */
.avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  background: var(--grad);
  display: block;
}
.avatar-sm {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  flex: none;
}
/* Gradient fallback avatar (rendered when no avatar image is set). */
.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .8rem;
  letter-spacing: .02em;
  text-transform: uppercase;
  background: var(--grad);
}

/* ----------------------------- GALLERY ----------------------------------- */
.thumbs { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }
.thumbs img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: var(--r-md);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform var(--t), border-color var(--t);
}
.thumbs img:hover { transform: scale(1.04); border-color: var(--accent-line); }
.album-cover {
  width: 100%;
  max-height: 170px;
  object-fit: cover;
  border-radius: var(--r-md);
  margin-bottom: var(--sp-2);
}

/* ------------------------------ LIGHTBOX --------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--sp-4);
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: var(--r-md); }
.lightbox .close {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
  font-size: 1.5rem;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 0;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

/* ------------------------------ RIGHT RAIL ------------------------------- */
.rail {
  position: sticky;
  top: 78px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow);
}
.panel h3 {
  margin: 0 0 var(--sp-3);
  font-size: .92rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.birthday-item,
.rail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-top: 1px solid var(--border);
}
.birthday-item:first-child,
.rail-item:first-child { border-top: 0; }
.rail-item { flex-direction: column; align-items: flex-start; gap: 2px; }
.rail-item-title { font-weight: 600; }

.rail-member,
.participant-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  font-weight: 600;
}

.participant { font-size: .9rem; padding: 2px 0; }

/* ------------------------- WUNSCH / FEEDBACK ----------------------------- */
.feedback-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.feedback-item:last-child { border-bottom: 0; }
.feedback-item .meta { margin-top: 6px; }
.feedback-item .badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .78rem;
  font-weight: 600;
}
.feedback-item[data-status="done"] .badge { background: rgba(52,211,153,.16); color: #34d399; }
.feedback-item[data-status="rejected"] .badge { background: rgba(255,107,107,.16); color: #ff6b6b; }

/* ------------------------------ UTILITIES -------------------------------- */
.muted { color: var(--text-muted); font-size: .9rem; }
.error { color: #ff6b6b; }
[data-theme="light"] .error { color: #b91c1c; }
.ok { color: #34d399; }
[data-theme="light"] .ok { color: #047857; }

/* -------------------------------- AUTH ----------------------------------- */
.authbox {
  max-width: 400px;
  margin: 8vh auto;
  padding: 0 var(--sp-4);
}
.authbox .card {
  padding: var(--sp-8);
  text-align: center;
}
.authbox .card form { text-align: left; }
.authbox .card h1 {
  margin-top: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}
.authbox .card h1 .logo { vertical-align: middle; margin-right: var(--sp-2); }
.authbox input { margin-bottom: var(--sp-3); }
.authbox button[type='submit'] { width: 100%; margin-top: var(--sp-2); }
.authbox .demo { margin-top: var(--sp-4); font-size: .85rem; color: var(--text-faint); }

/* DSGVO-Hinweis (Login/Startseite) — dezent, vertrauensbildend, Light + Dark.
   Inline-SVG EU-Flagge + Herz; verdeckt das Formular nicht und bricht auf
   Mobile sauber um. */
.gdpr-badge {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
  padding: var(--sp-3);
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-muted);
}
.gdpr-badge .gdpr-emblem { flex-shrink: 0; line-height: 0; }
.gdpr-badge .gdpr-emblem svg {
  display: block;
  border-radius: var(--r-sm);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.gdpr-badge .gdpr-text { font-size: .8rem; line-height: 1.45; }
.gdpr-badge .gdpr-text strong { color: var(--text); font-weight: 600; }
@media (max-width: 420px) {
  .gdpr-badge { flex-direction: column; text-align: center; }
}

/* ----------------------- ADMIN: EINLADUNGEN ------------------------------ */
.invite-result { border-top: 1px solid var(--border); padding-top: var(--sp-4); }
.invite-link-row { display: flex; gap: var(--sp-2); align-items: stretch; margin-top: var(--sp-1); }
.invite-link-row input { flex: 1; margin: 0; }
.invite-link-row button { white-space: nowrap; }
.invite-qr svg { border-radius: var(--r-sm, 10px); display: block; }
.invite-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.invite-item:last-child { border-bottom: 0; }
.invite-item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.invite-item-label { font-weight: 600; }
.invite-item-actions { display: flex; gap: var(--sp-2); }
@media (max-width: 520px) {
  .invite-link-row { flex-direction: column; }
}

/* --------------------- MOBILE OVERLAYS (tabs + FAB) ---------------------- */
/* Viewport-fixed overlays. They live outside .app-shell so the container's
   layout containment does not capture their fixed positioning. Hidden by
   default; revealed at the phone breakpoint (see RESPONSIVE below). */
.tabs {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: 64px;
  background: var(--surface-glass);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); /* iPhone-Notch / Home-Indicator */
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 44px; /* komfortable Touch-Fläche */
  border: 0;
  background: none;
  color: var(--text-faint);
  font-family: inherit;
  font-size: .62rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}
.tab .tab-ico { font-size: 1.25rem; line-height: 1; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  width: 26px;
  height: 3px;
  border-radius: 3px;
  background: var(--grad);
}

.fab {
  display: none;
  position: fixed;
  right: 18px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  z-index: 35;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  background: var(--grad);
  color: #fff;
  box-shadow: var(--glow), 0 8px 20px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: transform var(--t);
}
.fab:active { transform: scale(.94); }
.fab svg { width: 26px; height: 26px; display: block; }

/* ----------------------------- RESPONSIVE -------------------------------- */
/* Container-query driven: the app shell reacts to its OWN inline width.
   Three breakpoints — Desktop ≥1080px (3-col), Tablet 700–1080px (2-col,
   no rail), Phone <700px (1-col, bottom-tabs + FAB + stories). */

/* Tablet (≤1080px): drop the right rail → two columns (sidebar + feed). */
@container (max-width: 1080px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr); }
  .rail { display: none; }
}

/* Phone (<700px): single column, hidden sidebar, edge-to-edge feed. */
@container (max-width: 700px) {
  .topbar { padding: var(--sp-3) var(--sp-4); gap: var(--sp-2); }
  .topbar .user { display: none; }
  .search { display: none; }
  .search-ic { display: inline-grid; }

  .layout {
    grid-template-columns: 1fr;
    gap: 0;
    margin: 0 auto;
    padding: 0 0 96px; /* Platz für die Bottom-Tabs */
  }
  .side { display: none; }
  .stories { display: flex; }

  /* Inline-Compose-Box auf Mobile ausblenden: der FAB (+) übernimmt das
     Erstellen, damit die Box nicht den knappen Platz wegnimmt (WI-0035). */
  .compose { display: none; }
  /* Der FAB blendet die Box bei Bedarf ein und springt hinein. */
  .compose.compose--open {
    display: block;
    margin: var(--sp-4) var(--sp-4) 0;
  }

  /* Borderless, edge-to-edge cards: border-bottom statt Rahmen/Shadow. */
  .post {
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    margin-bottom: 0;
  }
  .post:hover { transform: none; }
  .post .actions .ghost { min-height: 44px; } /* größere Touch-Fläche */
}

/* The fixed overlays sit outside the container, so they track the viewport. */
@media (max-width: 700px) {
  .tabs { display: flex; }
  .fab { display: flex; }
}
