/* Wein-App — mobile-first, dunkel, große Trefferflächen.
   Aufbau wie beim Fitness Tracker, Farbwelt ins Weinrote gedreht. */

:root {
  --bg: #17141A;
  --bg-raised: #211C24;
  --bg-sunken: #110F13;
  --line: #342D38;
  --line-soft: #29232C;
  --steel: #A39BA8;
  /* Für Text: mindestens 4:1 auf den Kartenflächen. */
  --steel-dim: #8E8593;
  --signal: #C8455E;
  --signal-soft: rgba(200, 69, 94, 0.15);
  --signal-dim: #6E2333;
  --paper: #EEE8E2;
  --good: #6FAE76;
  --good-soft: rgba(111, 174, 118, 0.15);
  --warn: #D9A441;
  --warn-soft: rgba(217, 164, 65, 0.15);

  /* Weinfarben für die Punkte. Rot ist bewusst heller als echter Rotwein,
     sonst verschwindet der Punkt auf dem dunklen Grund. */
  --f-rot: #A3263E;
  --f-weiss: #E6D68A;
  --f-rose: #EC9EAB;
  --f-schaum: #F3EBC6;
  --f-suess: #D0973A;

  --mono: 'SF Mono', ui-monospace, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --r: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --nav-h: 58px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Das Browser-Stylesheet blendet [hidden] über display:none aus — jede eigene
   display-Regel schlägt das aber. Beim Fitness Tracker hing genau daran das
   Overlay: als flex deklariert und damit trotz hidden sichtbar. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
a { color: var(--signal); }

/* Etwas höher als der Bildschirm, damit jede Seite scrollbar bleibt. Sonst
   bleiben auf dem iPhone die Werkzeugleisten ausgefahren und die untere
   Navigation rutscht auf kurzen Seiten nach oben. */
.app {
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  min-height: calc(100vh + 1px);
}
.boot { padding: 40px; text-align: center; color: var(--steel-dim); font-family: var(--mono); }

/* --- Kopfbereich --- */
.topbar {
  padding: calc(var(--safe-t) + 18px) 16px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-row { display: flex; align-items: center; gap: 12px; }
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
}
/* Weinnamen sind lang. Lieber zwei Zeilen als abgeschnitten. */
.topbar h1.lang { font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
.topbar .eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.6px;
  color: var(--steel-dim);
  text-transform: uppercase;
  margin-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-zahl { font-family: var(--mono); font-size: 13px; color: var(--steel); flex: none; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--steel);
  border: 1px solid var(--line);
  flex: none;
  font-size: 20px;
}
.icon-btn:active { background: var(--bg-raised); }

main { padding: 16px; }
.stack > * + * { margin-top: 12px; }

/* --- Karten --- */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
}
.card-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--steel-dim);
  margin-bottom: 10px;
}
.hinweis-scan { border-style: dashed; }
.hinweis-scan p { margin: 0; color: var(--steel); line-height: 1.5; }

/* --- Buttons --- */
.btn {
  display: block;
  width: 100%;
  padding: 15px 16px;
  border-radius: 8px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--paper);
  font-weight: 600;
  font-size: 15px;
  text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--signal);
  border-color: var(--signal);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.2px;
}
.btn-ghost { background: none; color: var(--steel); }
.btn-danger { background: none; border-color: var(--signal-dim); color: var(--signal); }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }
.btn-sm { padding: 9px 12px; font-size: 13px; width: auto; display: inline-block; }

/* --- Untere Navigation --- */
.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: var(--bg-sunken);
  border-top: 1px solid var(--line);
  z-index: 30;
}
.nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--steel-dim);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.nav a .ico { font-size: 18px; line-height: 1; }
.nav a.active { color: var(--signal); }

/* --- Lagerorte --- */
.ort-row {
  display: block; width: 100%; text-align: left;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}
.ort-row:last-of-type { border-bottom: none; }
.ort-kopf { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.ort-zahl { font-family: var(--mono); font-size: 13px; color: var(--steel); flex: none; }
.ort-row.on .ort-name { color: var(--signal); font-weight: 700; }
.ort-row.on .ort-name::after { content: '  ✕'; font-size: 12px; }
.balken { height: 5px; border-radius: 3px; background: var(--bg-sunken); margin-top: 7px; overflow: hidden; }
.balken > div { height: 100%; background: var(--steel-dim); border-radius: 3px; }
.balken > div.voll { background: var(--warn); }

/* --- Suche und Filter --- */
.suche {
  width: 100%;
  padding: 13px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  -webkit-appearance: none;
  appearance: none;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--steel);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
}
.chip.on { border-color: var(--signal); color: var(--paper); background: var(--signal-soft); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--steel); }
.check input { width: 18px; height: 18px; accent-color: var(--signal); }

/* --- Weinliste --- */
.farbpunkt {
  width: 12px; height: 12px; border-radius: 50%;
  flex: none; display: inline-block;
  background: var(--steel-faint, #5B5560);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.farbpunkt.klein { width: 9px; height: 9px; }
.farbpunkt.gross { width: 22px; height: 22px; }
.f-rot { background: var(--f-rot); }
.f-weiss { background: var(--f-weiss); }
.f-rose { background: var(--f-rose); }
.f-schaum { background: var(--f-schaum); }
.f-suess { background: var(--f-suess); }

.wein-liste { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.wein-liste:has(.empty) { background: none; border: none; }
.wein-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft);
  color: inherit; text-decoration: none;
}
.wein-row:last-child { border-bottom: none; }
.wein-row:active { background: var(--bg-sunken); }
.wein-row.leer { opacity: 0.55; }
.wein-txt { flex: 1; min-width: 0; }
.wein-txt .t { font-size: 15px; font-weight: 650; line-height: 1.3; }
.wein-txt .s {
  font-size: 12.5px; color: var(--steel-dim); margin-top: 2px; line-height: 1.4;
  display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center;
}
.wein-zahl { font-family: var(--mono); font-size: 20px; font-weight: 700; flex: none; min-width: 2ch; text-align: right; }

/* Trinkreife-Ampel */
.reife {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.3px;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--line); color: var(--steel);
}
.reife.gross { font-size: 12px; padding: 4px 10px; margin-left: auto; align-self: flex-start; }
.r-jetzt { color: var(--good); border-color: var(--good); background: var(--good-soft); }
.r-bald { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.r-drueber { color: var(--signal); border-color: var(--signal); background: var(--signal-soft); }

/* --- Weinseite --- */
.bestand-kopf { display: flex; align-items: center; gap: 14px; }
.bestand-zahl { font-family: var(--mono); font-size: 24px; font-weight: 700; }
.ort-verteilung { margin-top: 12px; border-top: 1px solid var(--line-soft); padding-top: 4px; }
.kv {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px;
}
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--steel-dim); flex: none; }
.kv .v { text-align: right; overflow-wrap: anywhere; }
.notiz { margin: 10px 0 0; font-size: 14px; line-height: 1.5; color: var(--steel); white-space: pre-wrap; }

.buchung-row {
  display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left;
  padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 13.5px;
}
.buchung-row:last-child { border-bottom: none; }
.buchung-datum { font-family: var(--mono); font-size: 12px; color: var(--steel-dim); flex: none; }
.buchung-text { flex: 1; min-width: 0; color: var(--steel); }
.buchung-zahl { font-family: var(--mono); font-weight: 700; flex: none; }
.a-zugang { color: var(--good); }
.a-abgang { color: var(--signal); }
.a-umlagerung { color: var(--steel); }

/* --- Formulare --- */
.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: block;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.4px;
  text-transform: uppercase; color: var(--steel-dim);
  margin-bottom: 6px;
}
.field-hint { display: block; font-size: 12px; color: var(--steel-dim); margin-top: 5px; line-height: 1.4; }
.field input[type="text"], .field input[type="date"], .field select, .field textarea {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  -webkit-appearance: none;
  appearance: none;
  min-height: 46px;
}
/* iOS zeigt leere Datumsfelder sonst schmaler als die übrigen. */
.field input[type="date"] { display: block; }
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--steel) 50%), linear-gradient(135deg, var(--steel) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
.field textarea { resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus, .suche:focus {
  outline: none; border-color: var(--signal);
}
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; min-width: 0; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; padding: 11px 4px;
  font-family: var(--mono); font-size: 12px; color: var(--steel); background: var(--bg-sunken);
  border-left: 1px solid var(--line);
}
.seg button:first-child { border-left: none; }
.seg button.on { background: var(--signal); color: #fff; font-weight: 700; }

.stepper { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-height: 46px; }
.stepper button { width: 46px; font-size: 20px; color: var(--steel); background: var(--bg-sunken); }
.stepper button:active { background: var(--line-soft); }
.stepper-v { flex: 1; display: grid; place-items: center; font-family: var(--mono); font-size: 17px; font-weight: 700; }

.field input[type="password"] {
  width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-sunken); min-height: 46px; -webkit-appearance: none; appearance: none;
}

/* Vom Scan geschätzte oder schlecht lesbare Felder: prüfen, bevor gespeichert wird. */
.field .unsicher, .seg.unsicher { border-color: var(--warn) !important; background-color: var(--warn-soft) !important; }

/* --- Etikett-Scan --- */
.scan-status:not(:empty) { margin-top: 12px; }
.scan-status .sheet-error { margin: 0; }
.laedt { display: flex; align-items: center; gap: 10px; color: var(--steel); font-size: 14px; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); border-top-color: var(--signal);
  animation: drehen 0.8s linear infinite;
}
@keyframes drehen { to { transform: rotate(360deg); } }
.scan-ergebnis { display: flex; gap: 12px; align-items: flex-start; }
.scan-vorschau { width: 64px; height: 86px; object-fit: cover; border-radius: 6px; flex: none; border: 1px solid var(--line); }
.scan-titel { font-weight: 700; font-size: 15px; margin-bottom: 4px; line-height: 1.3; }
.scan-ergebnis p.small + p.small { margin-top: 4px; }
.scan-doppelt { margin-top: 10px !important; color: var(--warn); }
.scan-rueckseite { margin-top: 12px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.scan-rueckseite p.small { margin-bottom: 10px; color: var(--steel); }
.btn:disabled { opacity: 0.5; }
.recherche { margin-top: 12px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.recherche p.small + p.small { margin-top: 4px; }

.etikett-foto { display: block; width: 100%; max-height: 220px; object-fit: contain; border-radius: 8px; background: var(--bg-sunken); margin-bottom: 8px; }

.sheet-error {
  color: var(--signal); background: var(--signal-soft);
  border-radius: 8px; padding: 10px 12px; font-size: 13.5px; line-height: 1.45;
}

/* --- Sheets --- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: flex-end;
}
.sheet {
  width: 100%;
  background: var(--bg-raised);
  border-top: 2px solid var(--signal);
  border-radius: 14px 14px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b));
  max-height: 88vh;
  overflow-y: auto;
}
.sheet h2 { margin: 0 0 4px; font-size: 17px; font-weight: 800; }
.sheet > p { color: var(--steel); font-size: 13.5px; line-height: 1.5; margin: 0 0 14px; }
.sheet .sheet-error { margin: 0 0 12px; }
.sheet h2 + .field, .sheet h2 + .field-row { margin-top: 14px; }
.sheet p.small { margin: 0 0 12px; }
.sheet-list button {
  display: block; width: 100%; text-align: left;
  padding: 14px 12px; border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: 8px; font-size: 14.5px; background: var(--bg-sunken);
}
.sheet-list button.danger { color: var(--signal); border-color: var(--signal-dim); }
.sheet-list button .sub { display: block; font-family: var(--mono); font-size: 11px; color: var(--steel-dim); margin-top: 3px; }

.toast {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  background: var(--paper);
  color: var(--bg);
  padding: 13px 15px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--steel-dim);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}

/* --- Mehr --- */
.changelog + .changelog { margin-top: 12px; }
.changelog-kopf { display: flex; justify-content: space-between; font-weight: 700; font-size: 14px; }
.changelog ul { margin: 6px 0 0; padding-left: 18px; color: var(--steel); font-size: 13.5px; line-height: 1.55; }
.fuss { text-align: center; font-family: var(--mono); font-size: 11px; color: var(--steel-dim); }

.muted { color: var(--steel-dim); }
.small { font-size: 12.5px; }
p.small { margin: 0; line-height: 1.5; }

@media (min-width: 620px) {
  .app { max-width: 620px; margin: 0 auto; }
  .nav { max-width: 620px; left: 50%; transform: translateX(-50%); }
  .sheet { max-width: 620px; margin: 0 auto; }
  .toast { max-width: 588px; margin: 0 auto; }
}
