/* ============ Ma Cave — thème sombre "cave à vin" ============ */
:root {
  --bg: #14090d;
  --panel: #1f1218;
  --panel2: #281720;
  --border: #3a2430;
  --text: #f3e9ec;
  --muted: #b394a0;
  --accent: #c22f4a;
  --accent-dark: #7b1e3b;
  --gold: #d9a441;
  --ok: #3d9a63;
  --soon: #c98a2d;
  --keep: #4a7fb5;
  --late: #b04040;
  --radius: 14px;
  --nav-h: 62px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}
a { color: var(--gold); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0 0 .6rem; }
h2 { font-size: 1.05rem; margin: 1.2rem 0 .5rem; color: var(--gold); }
h3 { font-size: 1rem; margin: 0 0 .6rem; }

/* ---------- Top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .9rem;
  background: linear-gradient(180deg, var(--accent-dark), #5c1630);
  border-bottom: 1px solid var(--border);
  padding-top: calc(.55rem + env(safe-area-inset-top, 0px));
}
.brand { display: flex; align-items: center; gap: .45rem; color: #fff; font-weight: 700; font-size: 1.05rem; }
.brand svg { color: var(--gold); }
.topbar-user { font-size: .8rem; color: #e8c9d4; }

/* ---------- Layout ---------- */
#app { max-width: 860px; margin: 0 auto; padding: .9rem .9rem 1.5rem; }
.loading { text-align: center; color: var(--muted); padding: 3rem 0; }

/* ---------- Bottom nav ---------- */
#navbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; background: #1a0d13; border-top: 1px solid var(--border);
}
#navbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: .68rem;
}
#navbar a.active { color: var(--gold); }
#navbar a.nav-add {
  flex: 0 0 64px; margin-top: -22px; height: calc(var(--nav-h) + 22px);
  background: var(--accent); border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  color: #fff; box-shadow: 0 -2px 14px rgba(194, 47, 74, .45);
}
#navbar a.nav-add svg { margin-top: 14px; }

/* ---------- Cards & stats ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; margin-bottom: .4rem; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .7rem .8rem;
}
.card .big { font-size: 1.5rem; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: .78rem; }
.card.warn .big { color: var(--late); }
.card.ok .big { color: var(--ok); }
.card.gold .big { color: var(--gold); }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem .9rem; margin-bottom: .8rem;
}
.panel > h2:first-child { margin-top: 0; }

/* ---------- Alertes ---------- */
details.alert-group { margin-bottom: .6rem; }
details.alert-group summary {
  cursor: pointer; list-style: none; font-weight: 600; padding: .45rem .2rem;
  display: flex; align-items: center; gap: .5rem;
}
details.alert-group summary::-webkit-details-marker { display: none; }
details.alert-group summary::before { content: "▸"; color: var(--muted); }
details.alert-group[open] summary::before { content: "▾"; }
.count-pill {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 999px;
  font-size: .75rem; padding: .05rem .5rem; color: var(--muted);
}

/* ---------- Liste bouteilles ---------- */
.bottle {
  display: flex; align-items: center; gap: .6rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem .7rem; margin-bottom: .5rem; cursor: pointer;
}
.bottle:hover { border-color: var(--accent-dark); }
.bottle .dot { flex: 0 0 12px; width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255,255,255,.08); }
.bottle .b-main { flex: 1; min-width: 0; }
.bottle .b-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bottle .b-name .vintage { color: var(--gold); font-weight: 500; margin-left: .3rem; }
.bottle .b-sub { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bottle .b-side { text-align: right; font-size: .78rem; color: var(--muted); flex: 0 0 auto; }
.bottle .b-actions { display: flex; gap: .25rem; flex: 0 0 auto; }

.badge {
  display: inline-block; border-radius: 999px; padding: .1rem .55rem; font-size: .72rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--panel2); color: var(--muted);
}
.badge.ok   { color: #7fd6a4; border-color: #2c5c40; background: #1c3527; }
.badge.soon { color: #ecc27f; border-color: #6e5225; background: #3a2d15; }
.badge.keep { color: #9cc3e8; border-color: #2c4a6e; background: #1a2c42; }
.badge.late { color: #f0a1a1; border-color: #6e2c2c; background: #421a1a; }
.badge.none { color: var(--muted); }
.badge.drunk { color: #d8b36a; border-color: #6e5225; background: #3a2d15; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: .55rem 1rem; font-size: .92rem; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #d43a57; }
.btn.secondary { background: var(--panel2); border: 1px solid var(--border); color: var(--text); }
.btn.secondary:hover { border-color: var(--accent); }
.btn.danger { background: #5c1f26; border: 1px solid #8a3038; color: #f0b8bc; }
.btn.small { padding: .3rem .6rem; font-size: .8rem; border-radius: 8px; }
.btn-icon {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .3rem .5rem; cursor: pointer; font-size: .9rem; line-height: 1;
}
.btn-icon:hover { border-color: var(--accent); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Formulaires ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem .7rem; }
.form-grid .full { grid-column: 1 / -1; }
label.fld { display: flex; flex-direction: column; gap: .25rem; font-size: .78rem; color: var(--muted); }
input, select, textarea {
  background: #160b10; color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: .5rem .6rem; font-size: .95rem; width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.hint { font-size: .76rem; color: var(--muted); margin-top: .2rem; }
.form-actions { display: flex; gap: .5rem; margin-top: .9rem; flex-wrap: wrap; }
details.fold { margin: .6rem 0; }
details.fold summary { cursor: pointer; color: var(--gold); font-size: .85rem; font-weight: 600; }

/* ---------- Étoiles ---------- */
.stars { display: inline-flex; gap: 2px; }
.stars .star {
  background: none; border: none; color: #4a3038; font-size: 1.6rem; cursor: pointer; padding: 0 .1rem; line-height: 1;
}
.stars .star.on { color: var(--gold); }
.stars-view { color: var(--gold); letter-spacing: 1px; font-size: .9rem; }
.stars-view .off { color: #4a3038; }

/* ---------- Modale ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.65);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 560px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px 16px 0 0;
  width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; padding: 1rem;
}
@media (min-width: 560px) { .modal { border-radius: 16px; } }
.modal h3 { margin-bottom: .4rem; }
.modal video { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 4/3; object-fit: cover; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: calc(var(--nav-h) + 12px); left: 0; right: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; gap: .4rem; pointer-events: none; }
.toast {
  background: #2c1a22; border: 1px solid var(--accent-dark); color: var(--text);
  padding: .5rem .9rem; border-radius: 999px; font-size: .85rem; box-shadow: 0 4px 16px rgba(0,0,0,.5);
  animation: pop .18s ease-out;
}
.toast.error { border-color: var(--late); color: #f0b8bc; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Divers ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .7rem; align-items: center; }
.toolbar input[type="search"] { flex: 1 1 160px; }
.toolbar select { width: auto; flex: 0 0 auto; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .7rem; }
.chip {
  background: var(--panel2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: .25rem .7rem; font-size: .78rem; cursor: pointer;
}
.chip.active { background: var(--accent-dark); color: #fff; border-color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .2rem .8rem; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 1.6rem .5rem; }
.muted { color: var(--muted); }
.row { display: flex; gap: .5rem; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.mt { margin-top: .8rem; }
.lookup-result {
  display: block; width: 100%; text-align: left; background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem; margin-bottom: .4rem; cursor: pointer;
}
.lookup-result:hover { border-color: var(--accent); }
.lookup-result .sub { color: var(--muted); font-size: .78rem; }
.tasting {
  border-left: 3px solid var(--accent-dark); background: var(--panel2);
  border-radius: 0 10px 10px 0; padding: .45rem .7rem; margin-bottom: .45rem; font-size: .88rem;
}
.tasting .t-head { display: flex; justify-content: space-between; color: var(--muted); font-size: .78rem; margin-bottom: .15rem; }
.install-banner {
  background: linear-gradient(90deg, var(--accent-dark), #8a2547); border-radius: var(--radius);
  padding: .6rem .8rem; margin-bottom: .8rem; display: flex; align-items: center; gap: .6rem;
}
.install-banner p { margin: 0; font-size: .85rem; flex: 1; }
