/* ===== Grundlagen ===== */
:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --accent: #e0662f;
  --accent-ink: #fff;
  --live: #2f9e5b;
  --danger: #c23b30;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* Küchen-Display: dunkel, hoher Kontrast, große Schrift */
body.kitchen {
  --bg: #151311;
  --surface: #221f1c;
  --surface-2: #2c2824;
  --ink: #f4efe8;
  --muted: #a89f94;
  --line: #3a352f;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

/* Verwaltung: hell, funktioniert auf Laptop und Handy */
body.admin {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efeae3;
  --ink: #22201d;
  --muted: #6f685f;
  --line: #e2dcd3;
}

/* ===== Buttons & Formulare (gemeinsam) ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.danger { color: var(--danger); }

label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
label small { font-weight: 400; color: var(--muted); }
input:not([type=checkbox]), textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px; font-weight: 400;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.error { color: var(--danger); font-weight: 600; font-size: 14px; }
.muted { color: var(--muted); }

/* ===== Login ===== */
.login-wrap { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); z-index: 10; }
.login-card {
  width: min(400px, 100%); display: grid; gap: 16px; padding: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.login-card h1 { font-size: 24px; }

/* ===== Platzhalter ohne Foto ===== */
.ph, div.ph {
  display: grid; place-items: center;
  background: linear-gradient(135deg, hsl(var(--h) 45% 32%), hsl(calc(var(--h) + 40) 50% 22%));
  color: hsl(var(--h) 60% 88%); font-weight: 800; letter-spacing: .04em;
}
.admin .ph { background: linear-gradient(135deg, hsl(var(--h) 55% 82%), hsl(calc(var(--h) + 40) 50% 72%)); color: hsl(var(--h) 45% 28%); }

/* ===== Küchen-Display ===== */
.k-header {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 20px;
  padding: 18px max(24px, env(safe-area-inset-left)); background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.k-brand { font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
.k-clock { margin-left: auto; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }

.k-grid {
  display: grid; gap: 20px; padding: 24px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.k-card {
  display: flex; flex-direction: column; overflow: hidden; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: transform .12s ease;
}
.k-card:active { transform: scale(.97); }
.k-card-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.k-card-photo.ph span { font-size: 56px; }
.k-card-body { padding: 16px 18px 20px; display: grid; gap: 4px; }
.k-card-body h2 { font-size: 24px; line-height: 1.2; }
.k-empty { grid-column: 1 / -1; padding: 80px 0; text-align: center; font-size: 22px; color: var(--muted); }

.in-detail .k-header { display: none; }
.in-detail { overflow: hidden; }
/* Detailansicht füllt genau den Bildschirm; Zutaten und Zubereitung scrollen jeweils für sich */
.k-detail { height: 100dvh; display: flex; flex-direction: column; padding: 0 24px; }
.d-head {
  flex: none; display: flex; align-items: center; gap: 24px; padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.d-back {
  flex: none; display: inline-flex; align-items: center; min-height: 60px; padding: 0 24px;
  border-radius: 12px; background: var(--surface-2); font-size: 20px; font-weight: 700; text-decoration: none;
}
.d-head h1 { min-width: 0; font-size: 34px; line-height: 1.15; overflow-wrap: anywhere; }

.d-body {
  flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(300px, 2fr) 3fr;
  grid-template-rows: minmax(0, 1fr); gap: 32px; padding-top: 24px;
}
.d-side { min-height: 0; display: flex; flex-direction: column; gap: 20px; }
.d-photo { flex: none; width: 100%; aspect-ratio: 16 / 9; max-height: 32vh; object-fit: cover; border-radius: var(--radius); display: block; }
.d-ingredients, .d-steps { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 32px; }
.d-ingredients { flex: 1; }
.d-ingredients h2, .d-steps h2 { position: sticky; top: 0; z-index: 1; padding-bottom: 10px; margin-bottom: 0 !important; background: var(--bg); }
.d-photo.ph span { font-size: 80px; }
.k-detail h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 10px; }

.tick { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tick button {
  width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; cursor: pointer; transition: opacity .15s;
}
.tick .done button { opacity: .38; }
.tick .done button span, .d-ingredients .done button { text-decoration: line-through; }
.d-ingredients button { padding: 14px 16px; font-size: 20px; line-height: 1.3; }
.d-steps button { display: flex; gap: 16px; padding: 18px; font-size: 22px; line-height: 1.45; }
.d-steps b {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 20px;
}
.d-notes { margin-top: 20px; padding: 16px 18px; border-radius: 12px; background: #3b2a12; color: #f6d9a4; font-size: 19px; }

@media (max-width: 860px) {
  .in-detail { overflow: visible; }
  .k-detail { height: auto; display: block; padding-bottom: 40px; }
  .d-head { position: sticky; top: 0; z-index: 2; background: var(--bg); }
  .d-body { display: grid; grid-template-columns: 1fr; }
  .d-ingredients, .d-steps { overflow: visible; padding-bottom: 0; }
  .d-ingredients h2, .d-steps h2 { position: static; }
  .d-photo { max-height: 320px; }
}
@media (max-width: 520px) {
  .k-detail { padding: 0 16px 32px; }
  .d-head { gap: 14px; }
  .d-back { min-height: 48px; padding: 0 16px; font-size: 17px; }
  .d-head h1 { font-size: 24px; }
}

/* ===== Verwaltung ===== */
.a-header {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.a-brand { font-size: 18px; font-weight: 800; text-decoration: none; }
.a-header-actions { margin-left: auto; display: flex; gap: 6px; }
.demo-banner { max-width: 1100px; margin: 16px auto 0; padding: 10px 14px; border-radius: 10px; background: #fff3d6; color: #6b4b00; font-size: 14px; width: calc(100% - 32px); }
.a-main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

.a-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.a-toolbar input[type=search] { flex: 1 1 220px; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.a-count { margin: 18px 0 10px; font-size: 14px; color: var(--muted); }

.a-list { display: grid; gap: 10px; }
.a-row {
  display: grid; grid-template-columns: 64px 1fr auto auto; align-items: center; gap: 16px;
  padding: 10px 14px 10px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.a-row.is-live { border-left: 4px solid var(--live); }
.a-thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; display: block; }
.a-thumb.ph span { font-size: 20px; }
.a-row-main { min-width: 0; }
.a-row-main h3 { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.a-row-main p { font-size: 14px; color: var(--muted); margin-top: 2px; }
.a-row-actions { display: flex; gap: 4px; }
.a-empty { padding: 48px 0; text-align: center; color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { position: relative; width: 48px; height: 28px; border-radius: 999px; background: #cfc8be; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .15s; }
.switch input:checked + .track { background: var(--live); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-label { width: 52px; color: var(--muted); }
.is-live .switch-label { color: var(--live); }

@media (max-width: 640px) {
  .a-row { grid-template-columns: 56px 1fr auto; gap: 12px; }
  .a-thumb { width: 56px; height: 56px; }
  .a-row-actions { grid-column: 1 / -1; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 8px; }
  .switch-label { display: none; }
  .a-toolbar .btn.primary { flex: 1 1 100%; }
  .a-header .btn.ghost.small:first-child { display: none; }
}

/* Editor */
.a-form { display: grid; gap: 20px; }
.a-form-head { display: flex; align-items: center; gap: 12px; }
.a-form-head h1 { font-size: 24px; }
.a-form-grid { display: grid; grid-template-columns: 320px 1fr; gap: 28px; align-items: start; }
.a-photo-col { display: grid; gap: 10px; position: sticky; top: 76px; }
.a-photo { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); }
.a-photo-img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.a-photo-img.ph span { font-size: 56px; }
.a-photo-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.a-photo-btns .btn { font-size: 14px; padding: 0 10px; }
.a-fields { display: grid; gap: 16px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--live); }
.a-form-foot {
  position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line);
}

@media (max-width: 760px) {
  .a-form-grid { grid-template-columns: 1fr; }
  .a-photo-col { position: static; }
  .a-form-foot .btn { flex: 1; }
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 10px;
  background: #22201d; color: #fff; font-weight: 600; font-size: 15px; transition: .2s; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind=error] { background: var(--danger); }
