/* Fern Library – Grundlagen: Tokens, Liquid Glass, Knöpfe, Felder, Sheets, Toasts.
   Design-System „Liquid Glass“ (Kalorienbuch) in den Fern-Farben (Navy + Fern-Grün), für Desktop erweitert. */

:root {
  color-scheme: dark;
  --bg: #000312;  --bg-2: #020828;
  --surface: #040A26;  --surface-2: #091233;  --surface-3: #0F1A42;
  --line: rgba(160,175,215,.10);  --line-strong: rgba(160,175,215,.22);
  --fg: #F2F5FF;  --muted: #8D96B5;  --faint: #545E80;
  /* Fern-Grün aus dem Logo (#00FF49), Schrift darauf schwarz wie im Logo */
  --accent: #00FF49;  --accent-2: #5CFF85;  --accent-deep: #00752A;
  --accent-soft: rgba(0,255,73,.12);  --accent-glow: rgba(0,255,73,.45);  --accent-ink: #000000;
  --ok: #34D399;  --warn: #FBBF24;  --over: #FF5C7A;  --hot: #FF7F5C;
  --ok-soft: rgba(52,211,153,.12);  --warn-soft: rgba(251,191,36,.12);  --over-soft: rgba(255,92,122,.12);
  --track: rgba(160,175,215,.12);  --backdrop: rgba(1,3,10,.72);
  --glass: rgba(3,8,30,.62);  --glass-strong: rgba(2,5,22,.80);
  --glass-border: rgba(160,175,215,.13);
  --lg-sheen: radial-gradient(120% 70% at 0% 0%, rgba(255,255,255,.11), rgba(255,255,255,0) 46%),
    linear-gradient(160deg, rgba(255,255,255,.06) 0%, rgba(255,255,255,.015) 40%, rgba(255,255,255,0) 60%, rgba(255,255,255,.035) 100%);
  --lg-border: rgba(255,255,255,.10);
  --lg-shadow: inset 0 1px .5px rgba(255,255,255,.24), inset 0 -1px 1px rgba(0,0,0,.35),
    inset 1px 0 0 rgba(255,255,255,.04), 0 18px 40px -24px rgba(0,0,0,.8);
  --lg-blur: blur(24px) saturate(180%);
  /* Hintergrund wie das Kanal-Banner: Navy-Verlauf, feines Raster, einzelne grüne Lichtpunkte */
  --glow-1: rgba(6,22,82,.85);  --glow-2: rgba(3,13,49,.9);  --glow-3: rgba(0,255,73,.10);
  --grid-line: rgba(160,175,215,.055);
  --glow: 0 8px 24px -8px var(--accent-glow);
  --shadow: 0 30px 80px -30px rgba(0,0,0,.9);
  --r-xl: 26px; --r-lg: 22px; --r-md: 14px; --r-sm: 10px;
  --gutter: 16px;
  --topbar-h: 72px;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;

  /* Basisfarben der Farb-Facette (fest, app-weit) */
  --c-white: #F1F3FA; --c-black: #15171C; --c-gray: #7D8597; --c-silver: #C3CAD6; --c-gold: #D9B24C;
  --c-red: #E5484D; --c-orange: #F08A3C; --c-yellow: #F4D03F; --c-green: #46A758; --c-teal: #2FBFB5;
  --c-blue: #3D7BF0; --c-purple: #8E5BE0; --c-pink: #E862A8; --c-brown: #8A5A35; --c-beige: #D8C3A0;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button, [role="button"], summary, label.btn { cursor: pointer; touch-action: manipulation; }
a { color: var(--accent-2); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); letter-spacing: -0.015em; font-weight: 600; text-wrap: balance; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 20px; line-height: 1.25; }
h3 { font-size: 16px; line-height: 1.3; }
p { margin: 0; }
.ic { flex: none; display: block; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); line-height: 1.3;
}
.ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok-text { color: var(--ok); } .warn-text { color: var(--warn); } .over-text { color: var(--over); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
::selection { background: var(--accent-soft); }

/* Scrollleisten dezent (Desktop) */
* { scrollbar-width: thin; scrollbar-color: rgba(160,175,215,.22) transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Hintergrund-Leuchten ---------- */
.bg-glow {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 100% 168px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 232px 100%,
    radial-gradient(120% 60% at 50% -10%, rgba(3,13,49,.95), rgba(3,13,49,0) 70%), var(--bg);
}
.bg-glow > i { position: absolute; display: block; border-radius: 50%; will-change: transform; }
.bg-glow > i:nth-child(1) {
  width: 110vmax; height: 110vmax; top: -62vmax; left: -48vmax;
  background: radial-gradient(closest-side, var(--glow-1), rgba(6,22,82,.25) 55%, rgba(6,22,82,0) 100%);
  animation: fl-drift-1 46s ease-in-out infinite alternate;
}
.bg-glow > i:nth-child(2) {
  width: 100vmax; height: 100vmax; top: -50vmax; right: -58vmax;
  background: radial-gradient(closest-side, var(--glow-2), rgba(3,13,49,.3) 55%, rgba(3,13,49,0) 100%);
  animation: fl-drift-2 58s ease-in-out infinite alternate;
}
.bg-glow > i:nth-child(3) {
  width: 90vmax; height: 90vmax; top: 30vh; left: -52vmax;
  background: radial-gradient(closest-side, var(--glow-3), rgba(0,255,73,.03) 55%, rgba(0,255,73,0) 100%);
  animation: fl-drift-3 72s ease-in-out infinite alternate;
}
@keyframes fl-drift-1 { from { transform: translate3d(0,0,0) scale(1); } to { transform: translate3d(14vw,8vh,0) scale(1.08); } }
@keyframes fl-drift-2 { from { transform: translate3d(0,0,0) scale(1.05); } to { transform: translate3d(-16vw,12vh,0) scale(.95); } }
@keyframes fl-drift-3 { from { transform: translate3d(0,0,0) scale(.95); } to { transform: translate3d(18vw,-10vh,0) scale(1.1); } }
@media (prefers-reduced-motion: reduce) { .bg-glow > i { animation: none !important; } }

.app { position: relative; z-index: 1; min-height: 100vh; }

/* ---------- Glas ---------- */
.glass, .card {
  background: var(--lg-sheen), var(--glass);
  border: 1px solid var(--lg-border);
  box-shadow: var(--lg-shadow);
  -webkit-backdrop-filter: var(--lg-blur);
  backdrop-filter: var(--lg-blur);
  border-radius: var(--r-lg);
}
/* Ohne Unschärfe (lange Listen, Raster) */
.card.flat { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--lg-sheen), rgba(3,8,30,.82); }
.card { padding: 18px; }

/* ---------- Knöpfe ---------- */
.btn {
  appearance: none; border: 1px solid var(--line-strong); border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; font-weight: 600; font-size: 15px; letter-spacing: .005em;
  background: var(--surface-2); color: var(--fg); white-space: nowrap; text-decoration: none;
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: var(--glow); }
.btn-primary:hover { background: #5CFF85; }
.btn-glass {
  background: var(--lg-sheen), rgba(8,16,48,.55); border-color: rgba(255,255,255,.12);
  box-shadow: inset 0 1px .5px rgba(255,255,255,.28), inset 0 -1px 1px rgba(0,0,0,.3);
}
.btn-glass:hover { background: var(--lg-sheen), rgba(14,26,66,.65); }
.btn-danger { background: transparent; color: var(--over); border-color: rgba(255,92,122,.35); }
.btn-danger:hover { background: var(--over-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent-2); padding: 0 12px; }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-sm { min-height: 34px; padding: 0 14px; font-size: 14px; }
.btn-block { width: 100%; }
.btn .ic { width: 18px; height: 18px; }

.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg);
  width: 40px; height: 40px; border-radius: 999px; padding: 0; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s ease, transform .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.plain { background: none; border-color: transparent; color: var(--muted); }
.icon-btn.plain:hover { color: var(--fg); background: var(--surface-2); }
.icon-btn .ic { width: 20px; height: 20px; }

/* Haupt-Aktion: blaue Glas-Perle */
.pearl {
  appearance: none; border: 0; flex: none;
  width: 44px; height: 44px; border-radius: 50%; padding: 0; color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: radial-gradient(90% 60% at 50% 8%, rgba(255,255,255,.45), rgba(255,255,255,0) 60%),
    linear-gradient(180deg, #5CFF85, #00D93E);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.55), inset 0 -2px 4px rgba(10,20,80,.45), 0 8px 24px -6px var(--accent-glow);
  transition: transform .12s ease, filter .12s ease;
}
.pearl:hover { filter: brightness(1.08); }
.pearl:active { transform: scale(.94); }
.pearl .ic { width: 21px; height: 21px; }
.pearl.wide { width: auto; border-radius: 999px; padding: 0 18px 0 14px; font-weight: 600; font-size: 15px; }

.link-btn {
  appearance: none; border: 0; background: none; padding: 4px 2px; color: var(--accent-2);
  font-size: 14px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Chips & Pillen ---------- */
.chip {
  appearance: none; display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 4px 11px; min-height: 28px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
button.chip { transition: background .12s ease, color .12s ease, border-color .12s ease; }
button.chip:hover { color: var(--fg); border-color: var(--line-strong); background: var(--surface-3); }
.chip.accent { background: var(--accent-soft); color: var(--accent-2); border-color: rgba(0,255,73,.3); }
.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: rgba(52,211,153,.25); }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: rgba(251,191,36,.25); }
.chip.over { color: var(--over); background: var(--over-soft); border-color: rgba(255,92,122,.3); }
.chip .ic { width: 14px; height: 14px; }
.chip-x { appearance: none; border: 0; background: none; color: inherit; padding: 0; margin: 0 -4px 0 0; display: inline-flex; opacity: .7; }
.chip-x:hover { opacity: 1; }

.dot { width: 9px; height: 9px; border-radius: 99px; flex: none; display: inline-block; }

/* Farbpunkte der Basisfarben */
.cdot {
  width: 14px; height: 14px; border-radius: 50%; flex: none; display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 1px 2px rgba(0,0,0,.4);
  background: var(--c, var(--faint));
}
/* englische Basisfarben; deutsche Namen für ältere Assets weiter abgebildet */
[data-color="white"], [data-color="weiß"] { --c: var(--c-white); }
[data-color="black"], [data-color="schwarz"] { --c: var(--c-black); }
[data-color="gray"], [data-color="grey"], [data-color="grau"] { --c: var(--c-gray); }
[data-color="silver"], [data-color="silber"] { --c: linear-gradient(135deg, #E6EAF0, #8E97A6); }
[data-color="gold"] { --c: linear-gradient(135deg, #F2D57A, #A9822A); }
[data-color="red"], [data-color="rot"] { --c: var(--c-red); }
[data-color="orange"] { --c: var(--c-orange); }
[data-color="yellow"], [data-color="gelb"] { --c: var(--c-yellow); }
[data-color="green"], [data-color="grün"] { --c: var(--c-green); }
[data-color="teal"], [data-color="türkis"] { --c: var(--c-teal); }
[data-color="blue"], [data-color="blau"] { --c: var(--c-blue); }
[data-color="purple"], [data-color="lila"] { --c: var(--c-purple); }
[data-color="pink"] { --c: var(--c-pink); }
[data-color="brown"], [data-color="braun"] { --c: var(--c-brown); }
[data-color="beige"] { --c: var(--c-beige); }

/* ---------- Segment-Umschalter ---------- */
.seg {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--lg-sheen), rgba(10,16,34,.5); border: 1px solid rgba(255,255,255,.1);
  box-shadow: inset 0 1px .5px rgba(255,255,255,.2), inset 0 -1px 1px rgba(0,0,0,.3);
  border-radius: 14px; padding: 3px; gap: 2px;
}
.seg button {
  appearance: none; border: 0; background: none; border-radius: 11px;
  min-height: 34px; font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 12px;
  white-space: nowrap; transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 16px -4px var(--accent-glow); }

/* ---------- Felder ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .field-label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; display: flex; align-items: center; gap: 6px; }
.field small, .hint { font-size: 12.5px; color: var(--faint); font-weight: 500; }
.input, .textarea, .select {
  width: 100%; min-width: 0;
  background: var(--surface-2); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; font-size: 16px;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); background: var(--surface-3); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.bad { border-color: rgba(255,92,122,.6); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.45; }
.select { appearance: auto; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent); }

/* Slider */
input[type="range"].range { width: 110px; height: 22px; background: none; }

/* ---------- Sheet (Bottom-Sheet, auf Desktop zentrierter Dialog) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: var(--backdrop);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fl-fade .18s ease; overscroll-behavior: contain;
}
.sheet {
  width: 100%; max-width: 560px; max-height: calc(100% - 24px - env(safe-area-inset-top, 0px));
  background: var(--lg-sheen), rgba(8,13,28,.86);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(255,255,255,.12); border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: inset 0 1px .5px rgba(255,255,255,.25), 0 -18px 50px -20px rgba(0,0,0,.85);
  display: flex; flex-direction: column; overflow: hidden;
  animation: fl-up .26s cubic-bezier(.2,.9,.25,1);
  touch-action: pan-y;
}
.sheet:focus { outline: none; }
.sheet::before { content: ""; flex: none; display: block; width: 38px; height: 5px; border-radius: 3px; margin: 8px auto 0; background: var(--line-strong); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px var(--gutter) 6px 20px; }
.sheet-head h2 { font-size: 20px; min-width: 0; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 14px 20px 20px; display: flex; flex-direction: column; gap: 16px; flex: 1; }
.sheet-body > *, .detail-body > * { flex-shrink: 0; } /* sonst quetscht der Scroll-Bereich Listen zusammen */
.sheet-foot { display: flex; gap: 8px; padding: 12px 20px calc(16px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: rgba(2,5,22,.6); }
.sheet-foot > .btn { flex: 1; }
.sheet-foot > .btn.flex0 { flex: none; }
@media (min-width: 720px) and (min-height: 560px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet { border-radius: var(--r-xl); border-bottom: 1px solid rgba(255,255,255,.12); max-height: min(88vh, 900px); box-shadow: inset 0 1px .5px rgba(255,255,255,.25), var(--shadow); }
  .sheet::before { display: none; }
  .sheet-head { padding-top: 16px; }
  .sheet-foot { padding-bottom: 14px; }
  .sheet.wide { max-width: 760px; }
  .sheet.small { max-width: 460px; }
}
@keyframes fl-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fl-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Toasts ---------- */
.toast-wrap {
  position: fixed; left: 0; right: 0; z-index: 80; pointer-events: none;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px) + var(--upbar-h, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 var(--gutter);
  transition: bottom .2s ease;
}
.toast {
  pointer-events: auto; max-width: 560px; min-width: 0;
  background: rgba(20,29,54,.86); color: var(--fg);
  -webkit-backdrop-filter: var(--lg-blur); backdrop-filter: var(--lg-blur);
  border: 1px solid var(--line-strong); border-radius: 16px; padding: 12px 16px;
  font-weight: 600; font-size: 15px;
  box-shadow: inset 0 1px .5px rgba(255,255,255,.2), 0 16px 40px -12px rgba(0,0,0,.8);
  display: flex; align-items: center; gap: 10px;
  animation: fl-up .2s ease;
}
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
.toast .ic { width: 20px; height: 20px; }
.toast.ok .ic { color: var(--ok); }
.toast.error { border-color: rgba(255,92,122,.5); }
.toast.error .ic { color: var(--over); }
.toast-msg { min-width: 0; overflow-wrap: anywhere; }
.toast-action {
  appearance: none; flex: none; background: var(--accent-soft); color: var(--accent-2);
  border: 1px solid rgba(0,255,73,.4); border-radius: 999px;
  min-height: 36px; margin: -6px -6px -6px 4px; padding: 0 14px; font-weight: 700; font-size: 14px;
}
.toast-action:hover { background: var(--accent); color: var(--accent-ink); }

/* ---------- Kleinteile ---------- */
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--track); border-top-color: var(--accent-2);
  animation: fl-spin .8s linear infinite;
}
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes fl-spin { to { transform: rotate(360deg); } }
.boot { min-height: 100vh; display: grid; place-items: center; }

.bar { height: 6px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); box-shadow: 0 0 10px var(--accent-glow); transition: width .3s ease; }
.bar.ok > i { background: var(--ok); box-shadow: none; }
.bar.over > i { background: var(--over); box-shadow: none; }
.bar.indet > i { width: 35%; animation: fl-indet 1.3s ease-in-out infinite; }
@keyframes fl-indet { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.note {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line); font-size: 14px;
}
.note .ic { width: 18px; height: 18px; margin-top: 1px; color: var(--muted); }
.note.warn { background: var(--warn-soft); border-color: rgba(251,191,36,.3); }
.note.warn .ic { color: var(--warn); }
.note.ok { background: var(--ok-soft); border-color: rgba(52,211,153,.3); }
.note.ok .ic { color: var(--ok); }
.note.over { background: var(--over-soft); border-color: rgba(255,92,122,.35); }
.note.over .ic { color: var(--over); }
.note.accent { background: var(--accent-soft); border-color: rgba(0,255,73,.3); }
.note.accent .ic { color: var(--accent-2); }
.note-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.note-title { font-weight: 700; }

.empty { padding: 60px 20px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .ic { width: 40px; height: 40px; color: var(--faint); }
.empty h3 { color: var(--fg); }

.kbd { font-size: 11px; font-weight: 700; color: var(--faint); border: 1px solid var(--line-strong); border-radius: 6px; padding: 1px 6px; }
