/* ==============================================================
   FryingPal - Stylesheet
   ============================================================== */

/* Variablen */
:root {
  --bg: #eef1f7;
  --card: #ffffff;
  --tag: #d9dde4;
  --tag-2: #c8ccd1;
  --ink: #1f2330;
  --ink-soft: #4e5465;
  --muted: #8a90a0;
  --line: #e3e6ec;

  --blue: #4f72f5;
  --blue-deep: #3853c4;
  --red: #e53935;
  --green: #22c55e;

  --radius-card: 14px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
  --shadow-card: 0 1px 3px rgba(17, 24, 39, 0.08), 0 4px 12px rgba(17, 24, 39, 0.04);
  --shadow-lg: 0 10px 40px rgba(17, 24, 39, 0.15);

  --font: 'DM Sans', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont,
          'Segoe UI', 'Helvetica Neue', Arial, sans-serif;

  --side-width: 200px;
}

@font-face {
  font-family: 'DM Sans';
  font-weight: 400 700;
  font-display: swap;
  src: local('DM Sans');
}

/* Reset */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  font-size: 15px;
  touch-action: manipulation;
}
button { font-family: inherit; }
img { user-select: none; -webkit-user-drag: none; }

/* ==============================================================
   Haupt-Layout: 3 Spalten (Leiste | Arbeitsbereich | Leiste)
   ============================================================== */
.app {
  display: grid;
  grid-template-columns: var(--side-width) 1fr var(--side-width);
  gap: 14px;
  padding: 14px;
  height: 100vh;
  height: 100dvh;
}

/* Seitenleisten (Produktkacheln) */
.side-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 4px;
  overflow-y: auto;
  align-content: start;
  scrollbar-width: thin;
}
.side-panel::-webkit-scrollbar { width: 6px; }
.side-panel::-webkit-scrollbar-thumb { background: #c6ccd6; border-radius: 6px; }

/* Arbeitsbereich */
.work-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.baskets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  width: 100%;
  flex: 1;
  min-height: 0;
}
.basket-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.basket-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Slots innerhalb eines Korbs – Grid auf dem SVG */
.basket-slots {
  position: relative;
  z-index: 2;
  width: calc(100% - 60px);
  height: calc(100% - 60px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: min-content;
  align-content: start;
  gap: 10px;
  padding: 6px;
  overflow: hidden;
}
.slot { aspect-ratio: 1; }

/* Action bar unten */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 6px 0 2px;
}
.btn-settings {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 12px;
  background: var(--blue);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(79, 114, 245, 0.35);
  transition: transform .1s ease, background .15s ease;
}
.btn-settings:hover { background: var(--blue-deep); }
.btn-settings:active { transform: scale(.96); }

.btn-clear {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 10px;
  background: #ffffff;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: color .15s ease, background .15s ease;
}
.btn-clear:hover { color: var(--red); background: #fff4f4; }

/* ==============================================================
   Produktkachel (für Seitenleisten UND Bibliothek)
   ============================================================== */
.product-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease;
  user-select: none;
}
.product-card:active { transform: scale(.97); }
.product-card .image {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10%;
}
.product-card .image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.product-card .image.placeholder svg {
  width: 44%;
  height: 44%;
  color: #c2c8d2;
}
.product-card .label {
  background: var(--tag);
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  padding: 7px 6px 8px;
  line-height: 1.1;
  letter-spacing: -0.01em;
  min-height: 30px;
}

/* Kachel "Neues Produkt hinzufügen" */
.product-card.add-card {
  background: #e4e8f0;
  box-shadow: none;
  border: 2px dashed #b9bfcc;
}
.product-card.add-card .image {
  color: #a5abb9;
}

/* Kachel im Bearbeitungs-Modus (Bibliothek) zeigt Edit-Overlay */
.library-panel .product-card {
  cursor: pointer;
}
.library-panel .product-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 0 var(--blue);
  transition: box-shadow .15s;
}
.library-panel .product-card:hover::after {
  box-shadow: inset 0 0 0 2px var(--blue);
}

/* ==============================================================
   Aktive Slots im Korb (Countdown + Fertig-Zustand)
   ============================================================== */
.slot {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: slotPop .22s ease;
}
@keyframes slotPop {
  from { transform: scale(.85); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.slot .image {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8%;
  background: #fff;
  position: relative;
}
.slot .image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.slot .image.placeholder svg {
  width: 40%;
  height: 40%;
  color: #c2c8d2;
}
.slot .label {
  background: var(--tag);
  color: var(--ink);
  font-weight: 600;
  text-align: center;
  padding: 4px 4px 6px;
  line-height: 1.1;
  font-size: 12px;
}
.slot .label .time {
  display: block;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 14px;
  margin-top: 2px;
}

/* Fertig: rotes X + Pulsieren */
.slot.done .image::after {
  content: "";
  position: absolute;
  inset: 6%;
  background: no-repeat center/80% 80% url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><g stroke='%23e53935' stroke-width='14' stroke-linecap='round'><line x1='18' y1='18' x2='82' y2='82'/><line x1='82' y1='18' x2='18' y2='82'/></g></svg>");
  filter: drop-shadow(0 2px 6px rgba(229, 57, 53, 0.35));
}
.slot.done {
  animation: donePulse 1s ease-in-out infinite;
}
.slot.done.ack { animation: none; }
@keyframes donePulse {
  0%, 100% { box-shadow: var(--shadow-card), 0 0 0 0 rgba(229, 57, 53, 0.55); }
  50%      { box-shadow: var(--shadow-card), 0 0 0 8px rgba(229, 57, 53, 0.0); }
}
.slot.done .label {
  background: #ffd7d5;
  color: var(--red);
}
.slot.done .label .time { color: var(--red); }

/* Leerer Slot – wird nicht gerendert (Grid stapelt von oben) */
.slot.empty { display: none; }

/* ==============================================================
   Modals
   ============================================================== */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 100;
}
.modal.is-open { display: block; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 24, 36, 0.45);
  backdrop-filter: blur(2px);
  animation: fadeIn .15s ease;
}
.modal-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: min(92vw, 1200px);
  max-height: 92vh;
  width: 92vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: panelIn .18s ease;
}
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes panelIn { from { opacity: 0; transform: translate(-50%,-46%) scale(.97);}
                     to   { opacity: 1; transform: translate(-50%,-50%) scale(1);} }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--blue-deep);
}
.modal-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--blue);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s;
}
.modal-close:hover { background: var(--blue-deep); }

/* Library Modal */
.library-panel { max-width: 1100px; }
.library-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  overflow-y: auto;
  max-height: calc(92vh - 72px);
}

/* Edit Modal */
.edit-panel { max-width: 820px; }
.edit-form {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 28px;
  padding: 28px;
}
.image-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.image-preview {
  width: 200px;
  height: 200px;
  border: 2px solid var(--blue);
  border-radius: 18px;
  background: #fff;
  color: #b7bfd0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color .15s;
}
.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.image-picker:hover .image-preview { border-color: var(--blue-deep); }
.image-picker-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.form-fields { display: flex; flex-direction: column; gap: 22px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.field input[type="text"],
.field input[type="number"] {
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 8px 2px;
  font-size: 18px;
  color: var(--ink);
  font-weight: 600;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
.field input[type="text"]:focus,
.field input[type="number"]:focus {
  border-bottom-color: var(--blue);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.time-field input { text-align: center; font-size: 22px; }

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  color: var(--ink-soft);
  font-weight: 500;
}
.checkbox-field input { display: none; }
.checkbox-box {
  width: 22px; height: 22px;
  border: 2px solid #bfc6d4;
  border-radius: 6px;
  position: relative;
  transition: all .15s;
}
.checkbox-field input:checked + .checkbox-box {
  background: var(--blue);
  border-color: var(--blue);
}
.checkbox-field input:checked + .checkbox-box::after {
  content: "";
  position: absolute;
  left: 6px; top: 2px;
  width: 6px; height: 12px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 6px;
}
.btn-primary {
  background: var(--blue);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.btn-primary:hover:not(:disabled) { background: var(--blue-deep); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-danger {
  background: #fff4f4;
  color: var(--red);
  border: 1px solid #f6c8c6;
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger:hover { background: #ffe3e1; }

/* ==============================================================
   Auswahl-Modus: Ziel-Korb für neues Produkt wählen
   ============================================================== */
.app.choosing .basket-wrap {
  cursor: pointer;
}
.app.choosing .basket-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-xl);
  border: 3px dashed var(--blue);
  z-index: 3;
  pointer-events: none;
  animation: chooseBlink 1.2s ease-in-out infinite;
}
@keyframes chooseBlink {
  0%, 100% { opacity: .4; }
  50%      { opacity: 1; }
}

/* Ausgewähltes Produkt: in der Leiste markiert */
.product-card.selected {
  outline: 3px solid var(--blue);
  outline-offset: -3px;
}

/* ==============================================================
   Toast
   ============================================================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2330;
  color: white;
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 500;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all .25s ease;
  z-index: 200;
  max-width: 90vw;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.err { background: var(--red); }

/* ==============================================================
   Responsive
   ============================================================== */
@media (max-width: 900px) {
  :root { --side-width: 130px; }
  .app { padding: 8px; gap: 8px; }
  .baskets { gap: 10px; }
  .edit-form { grid-template-columns: 1fr; gap: 18px; padding: 18px; }
  .image-preview { width: 160px; height: 160px; margin: 0 auto; }
  .product-card .label { font-size: 11px; min-height: 26px; padding: 6px 4px; }
  .slot .label { font-size: 10px; }
  .slot .label .time { font-size: 12px; }
}

@media (max-width: 600px) {
  :root { --side-width: 96px; }
  .side-panel { grid-template-columns: 1fr; gap: 6px; }
  .product-card .label { font-size: 10px; }
  .modal-panel { width: 96vw; }
  .library-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); padding: 12px; gap: 10px; }
}
