:root {
  --bg: #fbf6ea;
  --card: #ffffff;
  --ink: #2d2416;
  --muted: #7b6d58;
  --line: #eadfc8;
  --honey: #f2a516;
  --honey-dark: #b8770a;
  --honey-soft: #fff1cf;
  --green: #2f8f5b;
  --red: #c0392b;
  --shadow: 0 1px 2px rgba(70, 50, 10, 0.06), 0 4px 14px rgba(70, 50, 10, 0.06);
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130c;
    --card: #221c12;
    --ink: #f4ead6;
    --muted: #b3a385;
    --line: #3a3020;
    --honey-soft: #3a2c10;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 100% 0, rgba(242, 165, 22, 0.12), transparent 40%),
    var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
body.locked { overflow: hidden; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ----- En-tête ----- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top h1 { grid-column: 2; text-align: center; font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-btn { width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent; display: grid; place-items: center; cursor: pointer; }
.top-btn:active { background: var(--honey-soft); }
#menuBtn { grid-column: 3; }

/* ----- Vue ----- */
.view { max-width: 760px; margin: 0 auto; padding: 14px 14px 90px; }
.view.full { max-width: none; padding: 0; }
.stack { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.card > * { min-width: 0; }

/* ----- Onglets ----- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(70, 50, 10, 0.06);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 700; color: var(--muted); }
.tab .ic { width: 24px; height: 24px; }
.tab.on { color: var(--honey-dark); }
.tab.on .ic { stroke-width: 2.2; }
@media (prefers-color-scheme: dark) { .tab.on { color: var(--honey); } }

/* ----- Cartes ----- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.link { color: var(--honey-dark); font-weight: 700; font-size: 14px; }
.group { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); display: flex; gap: 8px; align-items: center; margin: 6px 4px -4px; }
.group small { background: var(--honey-soft); color: var(--honey-dark); border-radius: 999px; padding: 0 8px; font-size: 12px; }
.warn { color: var(--red); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); display: grid; }
.stat b { font-size: 22px; font-weight: 800; color: var(--honey-dark); }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat.big b { font-size: 28px; }
@media (prefers-color-scheme: dark) { .stat b { color: var(--honey); } }

/* ----- Ruches ----- */
.cards { display: grid; gap: 10px; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.hive-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow);
}
.hive-card:active { transform: scale(0.99); }
.hive-ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--honey-soft); color: var(--honey-dark); }
.hive-ic .ic { width: 28px; height: 28px; }
.hive-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.hive-name { font-weight: 800; display: flex; align-items: center; gap: 8px; }
.hive-sub { font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.go { color: var(--muted); width: 18px; height: 18px; }
.queen { display: inline-flex; align-items: center; gap: 5px; }
.queen i { width: 12px; height: 12px; border-radius: 50%; background: var(--q); box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.25); }
.force { display: flex; gap: 3px; margin-top: 3px; }
.force i { width: 16px; height: 5px; border-radius: 3px; background: var(--line); }
.force i.on { background: var(--honey); }
.force.small i { width: 10px; height: 4px; }

.chip { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.dot.journal { background: var(--muted); opacity: 0.6; }

.hive-head h2 { font-size: 22px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.facts > div { background: var(--bg); border-radius: 12px; padding: 8px 10px; display: grid; gap: 2px; justify-items: start; }
.facts span { font-size: 12px; color: var(--muted); }
.notes { margin: 0; white-space: pre-wrap; background: var(--honey-soft); border-radius: 12px; padding: 10px; font-size: 14px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick .btn { flex-direction: column; gap: 2px; padding: 10px 4px; font-size: 13px; }

.timeline { display: grid; gap: 8px; }
.entry {
  text-align: left; width: 100%; cursor: pointer;
  border: 1px solid var(--line); border-left: 4px solid var(--c);
  background: var(--card); border-radius: 12px; padding: 10px 12px; display: grid; gap: 3px;
}
.entry-top { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.entry-top b { color: var(--c); }
.entry-top span:first-of-type { color: var(--muted); }
.entry-facts { font-size: 13px; color: var(--muted); }
.entry p { margin: 2px 0 0; white-space: pre-wrap; font-size: 14px; }

/* ----- Événements ----- */
.ev { display: flex; align-items: center; gap: 10px; border-radius: 12px; padding: 4px 0; }
.ev-main { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 6px 0; display: grid; gap: 1px; cursor: pointer; border-left: 3px solid var(--c); padding-left: 10px; }
.ev-main b { font-size: 14.5px; }
.ev-main span { font-size: 12.5px; color: var(--muted); }
.ev.done .ev-main b { text-decoration: line-through; color: var(--muted); }
.ev.late .ev-main span { color: var(--red); }
.ev-check { position: relative; width: 28px; height: 28px; flex: none; cursor: pointer; }
.ev-check input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.ev-check span { width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--line); display: grid; place-items: center; color: transparent; transition: 0.15s; }
.ev-check input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.ev-check .ic { width: 18px; height: 18px; stroke-width: 3; }
.journal-link { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); padding: 4px 0; flex-wrap: wrap; }
.journal-link .ic { width: 18px; height: 18px; color: var(--c); }
.journal-link span { flex-basis: 100%; padding-left: 26px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ----- Calendrier ----- */
.cal-head { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 6px; }
.cal-head h2 { text-align: center; text-transform: capitalize; font-size: 18px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--muted); padding-bottom: 2px; }
.cal-day {
  aspect-ratio: 1 / 1; min-height: 40px;
  border: 0; border-radius: 12px; background: var(--bg); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 0;
}
.cal-day.out { background: transparent; cursor: default; }
.cal-day .n { font-weight: 700; font-size: 14px; }
.cal-day .dots { display: flex; gap: 2px; min-height: 7px; }
.cal-day.span { background: color-mix(in srgb, var(--red) 9%, var(--bg)); }
.cal-day.today .n { color: var(--honey-dark); }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--honey); }
.cal-day.sel { background: var(--honey); }
.cal-day.sel .n { color: #2d2416; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ----- Récoltes ----- */
.years { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.pill { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.pill .ic { width: 15px; height: 15px; }
.pill.on { background: var(--honey); border-color: var(--honey); color: #2d2416; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 13.5px; }
.bar-lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 12px; border-radius: 6px; background: var(--bg); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--honey), var(--honey-dark)); }
.cols { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 18px; }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; font-size: 12px; }
.col i { flex: none; width: 70%; max-width: 46px; border-radius: 8px 8px 3px 3px; background: linear-gradient(180deg, var(--honey), var(--honey-dark)); }
.col span { color: var(--muted); }

.row-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: none; padding: 8px 0; cursor: pointer; border-top: 1px solid var(--line); }
.card > .row-item:first-of-type, .menu-list .row-item:first-child, .choose .row-item:first-child { border-top: 0; }
.row-ic { width: 38px; height: 38px; border-radius: 12px; background: var(--honey-soft); color: var(--honey-dark); display: grid; place-items: center; flex: none; }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-main span { font-size: 12.5px; color: var(--muted); }
.row-val { font-weight: 800; }

/* ----- Achats ----- */
.add-row { display: grid; grid-template-columns: 1fr 70px auto; gap: 8px; }
.add-row .btn { padding: 0 14px; }
.sugg { display: flex; flex-wrap: wrap; gap: 6px; }
.shop-item { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.shop-name { flex: 1; font-weight: 600; }
.shop-qty { font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 2px 8px; }
.shop-item.done .shop-name { text-decoration: line-through; color: var(--muted); }

/* ----- Carte ----- */
.map-wrap { position: relative; height: calc(100vh - 53px - var(--tabs-h) - env(safe-area-inset-bottom) - env(safe-area-inset-top)); height: calc(100dvh - 53px - var(--tabs-h) - env(safe-area-inset-bottom) - env(safe-area-inset-top)); }
.map { position: absolute; inset: 0; background: #e8e2d2; }
.map-banner {
  position: absolute; z-index: 500; top: 10px; left: 10px; right: 10px;
  background: var(--card); border-radius: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  padding: 10px 12px; display: grid; gap: 8px; font-weight: 700; font-size: 14px;
}
.map-banner > span { display: flex; align-items: center; gap: 8px; }
.map-banner .ic { color: var(--honey-dark); }
.map-banner.slim { grid-template-columns: 1fr auto; align-items: center; }
.map-banner-btns { display: flex; gap: 8px; }
.map-tools { position: absolute; z-index: 500; right: 10px; bottom: 100px; display: grid; gap: 8px; }
.map-tool { width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--card); box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2); display: grid; place-items: center; cursor: pointer; }
.map-tool.txt { width: auto; padding: 0 10px; font-size: 12px; font-weight: 800; }
.hive-pin { position: relative; width: 40px; height: 40px; border-radius: 12px 12px 12px 2px; transform: rotate(-45deg); background: var(--c); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35); display: grid; place-items: center; border: 2px solid #fff; }
.hive-pin svg { width: 24px; height: 24px; transform: rotate(45deg); fill: none; stroke: #fff; stroke-width: 1.8; stroke-linejoin: round; }
.hive-pin span { position: absolute; left: 50%; top: 50%; transform: rotate(45deg) translate(-50%, 34px); transform-origin: 0 0; background: rgba(255, 255, 255, 0.95); color: #2d2416; font: 700 11px system-ui, sans-serif; padding: 1px 6px; border-radius: 6px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); }
.hive-pin.placing { animation: bob 0.9s ease-in-out infinite; border-color: var(--honey); }
@keyframes bob { 50% { margin-top: -6px; } }
.pop { display: grid; gap: 2px; font: 14px system-ui, sans-serif; min-width: 180px; }
.pop span { color: #7b6d58; font-size: 12.5px; }
.pop-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.leaflet-popup-content-wrapper { border-radius: 14px; }
.leaflet-container a.btn { color: #2d2416; }
.leaflet-container a.btn.primary { color: #2d2416; }

/* ----- Boutons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 10px 14px; font-weight: 700; cursor: pointer; min-height: 42px;
}
.btn .ic { width: 19px; height: 19px; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--honey); border-color: var(--honey); color: #2d2416; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--red); border-color: var(--line); margin-right: auto; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.icon-btn { width: 38px; height: 38px; border: 1px solid var(--line); background: var(--card); border-radius: 12px; display: grid; place-items: center; cursor: pointer; }
.icon-btn.small { width: 32px; height: 32px; border: 0; color: var(--muted); }
.fab {
  position: fixed; z-index: 25; right: max(16px, calc(50vw - 364px)); bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--honey); color: #2d2416; box-shadow: 0 8px 20px rgba(184, 119, 10, 0.4);
  display: grid; place-items: center;
}
.fab .ic { width: 28px; height: 28px; stroke-width: 2.4; }

/* ----- Fenêtre du bas ----- */
.sheet-bg { position: fixed; inset: 0; z-index: 1000; background: rgba(30, 20, 5, 0.45); display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s; }
.sheet {
  width: min(100%, 560px); max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 12px; animation: up 0.2s ease-out;
}
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 22px; } }
.grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 4px; }
.sheet h2 { font-size: 19px; }
@keyframes up { from { transform: translateY(40px); opacity: 0.6; } }
@keyframes fade { from { opacity: 0; } }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* ----- Formulaires ----- */
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 5px; }
.lbl { font-size: 13px; font-weight: 700; color: var(--muted); }
.field small { font-size: 12px; color: var(--muted); }
.inp { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 16px; min-height: 44px; }
.inp:focus { outline: 2px solid var(--honey); outline-offset: 0; border-color: transparent; }
textarea.inp { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.extra { display: grid; gap: 12px; }
.extra:empty { display: none; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; font-size: 13.5px; }
.seg input:checked + span { background: var(--honey); border-color: var(--honey); color: #2d2416; }
.seg input:focus-visible + span { outline: 2px solid var(--honey-dark); }
.check, .switch { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; min-height: 44px; }
.check input, .switch input { width: 20px; height: 20px; accent-color: var(--honey-dark); }
.picker { display: flex; flex-wrap: wrap; gap: 6px; }
.pick input { position: absolute; opacity: 0; }
.pick span { display: inline-block; padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; font-size: 13.5px; cursor: pointer; }
.pick input:checked + span { background: var(--honey-soft); border-color: var(--honey); color: var(--honey-dark); }

/* ----- Divers ----- */
.empty { text-align: center; padding: 40px 20px; display: grid; justify-items: center; gap: 8px; }
.empty-ic { width: 84px; height: 84px; border-radius: 26px; background: var(--honey-soft); color: var(--honey-dark); display: grid; place-items: center; margin-bottom: 6px; }
.empty-ic .ic { width: 46px; height: 46px; stroke-width: 1.5; }
.empty p { color: var(--muted); max-width: 340px; margin: 0 0 8px; }
.toast {
  position: fixed; z-index: 2000; left: 50%; bottom: calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #2d2416; color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); max-width: calc(100vw - 32px); text-align: center; animation: up 0.2s;
}
.about { display: flex; align-items: center; gap: 12px; }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--honey); color: #2d2416; display: grid; place-items: center; }
.logo .ic { width: 34px; height: 34px; }
.menu-list { display: grid; }
.todo { border-color: color-mix(in srgb, var(--honey) 50%, var(--line)); }

/* ----- Compte et synchronisation ----- */
.top-btn.cloud { position: relative; color: var(--muted); }
.sync-dot { position: absolute; right: 7px; bottom: 9px; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--bg); background: var(--muted); }
.sync-dot[data-state="off"] { background: #d68910; }
.sync-dot[data-state="ok"] { background: var(--green); }
.sync-dot[data-state="syncing"] { background: #1f6fb2; animation: blink 0.8s infinite alternate; }
.sync-dot[data-state="error"] { background: var(--red); }
.sync-dot[data-state="offline"] { background: var(--muted); }
@keyframes blink { to { opacity: 0.3; } }
.account { display: flex; align-items: center; gap: 12px; }
.account > div { display: grid; min-width: 0; }
.account b { overflow: hidden; text-overflow: ellipsis; }
.row-item.danger { color: var(--red); }
.row-item.danger .row-ic { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.form-error { margin: 0; color: var(--red); font-weight: 600; font-size: 14px; }
.link-btn { border: 0; background: none; color: var(--honey-dark); font-weight: 700; cursor: pointer; padding: 6px; }
.nudge { border-color: color-mix(in srgb, var(--honey) 50%, var(--line)); background: linear-gradient(135deg, var(--honey-soft), var(--card)); }
.nudge-row { display: flex; gap: 12px; align-items: flex-start; }
.nudge p { margin: 2px 0 0; }
.nudge .actions { margin-top: 0; }

/* ----- Écran d'accès (compte obligatoire) ----- */
body.gated { padding-bottom: 0; }
body.gated .top, body.gated .tabs, body.gated .view { display: none; }
.gate {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.gate-card {
  width: 100%; max-width: 400px;
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow); padding: 24px 20px;
}
.gate-card h2 { font-size: 22px; }
.gate-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-size: 18px; }
.gate-brand .logo { width: 42px; height: 42px; border-radius: 12px; background: var(--honey); color: #2d2416; display: grid; place-items: center; }
.gate-foot { text-align: center; margin: 16px 0 0; }
