/* ══════════════════════════════════════════════════════════════════════
   AstaBee Terrain — Design System — v88
   Thème sombre · Palette AstaBee · S7.2
   ══════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@600;700&family=Roboto:wght@300;400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Palette AstaBee ─────────────────────────────────────────────── */
  --bg:             #0F172A;   /* Bleu Minuit Profond */
  --card:           #1E293B;   /* Slate Sombre */
  --border:         #334155;   /* Bordures discrètes */
  --border-light:   #263447;   /* Bordures très légères */
  --text:           #F8FAFC;   /* Blanc Pur */
  --text-sec:       #CBD5E1;   /* Gris clair — sous-titres lisibles ↑ */
  --text-ter:       #94A3B8;   /* Gris moyen — labels, méta ↑ */
  --primary:        #FBBF24;   /* Orange Bille — plus vif et chaud ↑ */
  --primary-hover:  #F59E0B;
  --primary-dark:   #0F172A;   /* Texte sur bouton primary */
  --secondary:      #2DD4BF;   /* Sarcelle */
  --secondary-hover:#0D9488;
  --mint:           #5EEAD4;   /* Menthe vive — Génération, badges ↑ */
  --teal:           #2DD4BF;   /* Sarcelle franche — accents forts */
  --green:          #34D399;   /* Vert vif ↑ */
  --green-light:    #064E3B;
  --green-border:   #065F46;
  --red:            #F87171;   /* Rouge plus doux sur sombre ↑ */
  --red-light:      #450A0A;
  --red-border:     #7F1D1D;
  --surface:        #1E293B;
  --touch-target:   52px;      /* UX-B — ergonomie gants */
  --safe-top:       env(safe-area-inset-top, 0px);
  --safe-bottom:    env(safe-area-inset-bottom, 20px);
  --topbar-h:       0px;
  --nav-h:          0px;
  --font-title:     'Poppins', system-ui, sans-serif;
  --font-body:      'Roboto', system-ui, sans-serif;

  /* ── Alias rétro-compatibilité ─── ne pas supprimer, référencés dans app.js */
  --amber:          #FBBF24;
  --amber-dark:     #F59E0B;
  --amber-deeper:   #CBD5E1;   /* → text-sec clair */
  --amber-darkest:  #F8FAFC;   /* → text blanc */
  --amber-light:    #2A2010;   /* → fond icônes tinte orange */
  --amber-lighter:  #253347;   /* → hover / active states */
}

html, body {
  height: 100%;
  background: var(--bg);
}
body {
  font-family: var(--font-body);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ── Coque de l'app ──────────────────────────────────────────────────── */
#app {
  position: fixed;
  top: var(--topbar-h, 0px);
  bottom: var(--nav-h, 0px);
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  height: auto;
  display: flex;
  flex-direction: column;
  z-index: 150;
  background: var(--bg);
}

/* ── Barre de statut safe area ───────────────────────────────────────── */
.status-bar {
  background: var(--bg);
  height: var(--safe-top);
  flex-shrink: 0;
}

/* ── Topbar AstaBee (montée via mountTopbar()) ───────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  z-index: 200;
  height: calc(52px + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding-left: 14px;
  padding-right: 14px;
  gap: 10px;
}
.topbar-logo {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-title {
  font-family: var(--font-title);
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  letter-spacing: -.2px;
}
.topbar-title span { color: var(--primary); }
.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ── UX-D — Pastille réseau "AstaBee Live" ───────────────────────────── */
.network-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  position: relative;
  transition: background .3s;
}
.network-dot::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: var(--green);
  opacity: .25;
  animation: pulse-dot 2s infinite;
}
.network-dot.offline {
  background: var(--text-ter);
}
.network-dot.offline::after { animation: none; opacity: 0; }
@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: .25; }
  50%       { transform: scale(1.6); opacity: 0; }
}

/* ── Header screens (fallback statique) ──────────────────────────────── */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 16px;
  flex-shrink: 0;
}
.header-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-dark);
  background: var(--primary);
  cursor: pointer;
  margin-bottom: 8px;
  border: none;
  border-radius: 8px;
  padding: 6px 12px 6px 8px;
  font-family: inherit;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}
.header-back svg { flex-shrink: 0; stroke: var(--primary-dark) !important; }
.header-title { font-size: 20px; font-weight: 600; color: var(--text); line-height: 1.2; font-family: var(--font-title); }
.header-sub   { font-size: 12px; color: var(--text-sec); margin-top: 2px; }

/* ── Header rucher compact ───────────────────────────────────────────── */
.header-apiary-row  { display: flex; align-items: center; gap: 10px; padding: 6px 0 2px; }
.header-apiary-back {
  flex-shrink: 0;
  border: none;
  background: var(--primary);
  padding: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  line-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-apiary-name {
  flex: 1; font-size: 20px; font-weight: 600; color: var(--text);
  line-height: 1.2; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-title);
}
.header-apiary-meta {
  flex-shrink: 0; font-size: 12px; color: var(--text-sec);
  white-space: nowrap; max-width: 130px; overflow: hidden;
  text-overflow: ellipsis; text-align: right;
}

/* ── Bouton ✕ fermeture modale ───────────────────────────────────────── */
.modal-close-btn {
  position: absolute; top: 10px; right: 14px;
  border: none; background: none;
  font-size: 22px; line-height: 1; color: var(--text-ter);
  cursor: pointer; padding: 4px 6px;
  -webkit-tap-highlight-color: transparent;
}

/* ── Écran scrollable ────────────────────────────────────────────────── */
.screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── Auth ────────────────────────────────────────────────────────────── */
.auth-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px calc(32px + var(--safe-bottom));
  background: var(--bg);
}
.auth-logo {
  font-size: 52px;
  text-align: center;
  margin-bottom: 8px;
}
.auth-title {
  font-family: var(--font-title);
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 6px;
}
.auth-sub {
  font-size: 14px;
  color: var(--text-sec);
  text-align: center;
  margin-bottom: 32px;
}
.auth-baseline {
  font-size: 12px;
  color: var(--text-ter);
  text-align: center;
  margin-top: 4px;
  margin-bottom: 28px;
  font-style: italic;
}
.field { margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sec);
  margin-bottom: 6px;
}
.field-input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  padding: 0 14px;
  font-size: 16px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  -webkit-appearance: none;
}
.field-input::placeholder { color: var(--text-ter); }
.field-input:focus { border-color: var(--primary); }
.error-msg {
  font-size: 13px;
  color: var(--red);
  background: var(--red-light);
  border: 1px solid var(--red-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.btn-primary {
  width: 100%;
  height: var(--touch-target);
  background: var(--primary);
  color: var(--primary-dark);
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-title);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  margin-top: 6px;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { opacity: .85; transform: scale(.98); }
.btn-primary:disabled { opacity: .45; cursor: default; }

/* ── Barre de recherche ──────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.search-input-wrap svg {
  position: absolute;
  left: 10px;
  flex-shrink: 0;
  pointer-events: none;
  color: var(--text-ter);
}
.search-input {
  width: 100%;
  height: 38px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px 0 34px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
}
.search-input::placeholder { color: var(--text-ter); }
.search-input:focus { border-color: var(--primary); }
.qr-btn {
  width: 44px;
  height: 44px;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.qr-btn:active { opacity: .8; }
.qr-btn svg { stroke: var(--primary-dark); }

/* ── En-tête de section ──────────────────────────────────────────────── */
.list-section {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .7px;
  color: var(--mint);
  padding: 10px 16px 4px;
  background: var(--bg);
  text-transform: uppercase;
}

/* ── Item rucher ─────────────────────────────────────────────────────── */
.apiary-item {
  display: flex;
  align-items: center;
  padding: 13px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
  gap: 12px;
}
.apiary-item:active { background: var(--amber-lighter); }
.apiary-icon {
  width: 38px;
  height: 38px;
  background: var(--amber-light);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.apiary-info { flex: 1; min-width: 0; }
.apiary-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.apiary-meta {
  font-size: 12px;
  color: var(--text-ter);
  margin-top: 1px;
}
.fav-btn {
  font-size: 20px;
  color: var(--text-sec);
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.fav-btn.active { color: var(--primary); }
.chevron { flex-shrink: 0; color: var(--text-sec); }

/* ── Bottom navigation ───────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  z-index: 100;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
}
.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  border: none;
  background: none;
  cursor: pointer;
  gap: 3px;
  -webkit-tap-highlight-color: transparent;
  color: var(--text-sec);
  font-size: 10px;
  font-family: inherit;
  transition: color .15s;
  min-height: var(--touch-target);
}
.nav-tab.active { color: var(--primary); }
.nav-tab svg { flex-shrink: 0; }

/* ── FAB ─────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(20px + 56px + env(safe-area-inset-bottom, 0px));
  right: 16px;
  width: 56px;
  height: 56px;
  z-index: 110;
  background: var(--primary);
  border: none;
  border-radius: 28px;
  box-shadow: 0 4px 16px rgba(251, 191, 36, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s, box-shadow .15s;
}
.fab:active { transform: scale(.93); box-shadow: 0 2px 8px rgba(251, 191, 36, .25); }

/* ── Carte activité ──────────────────────────────────────────────────── */
.act-card {
  display: flex;
  align-items: center;
  margin: 5px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 14px;
  cursor: pointer;
  gap: 13px;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.act-card:active { background: var(--amber-lighter); }
.act-icon {
  width: 42px;
  height: 42px;
  background: var(--amber-light);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.act-info { flex: 1; }
.act-label { font-size: 15px; font-weight: 500; color: var(--text); }
.act-desc  { font-size: 12px; color: var(--text-ter); margin-top: 2px; }

/* ── Scanner QR ──────────────────────────────────────────────────────── */
.scanner-wrap {
  height: 100%;
  background: #000;
  display: flex;
  flex-direction: column;
  position: relative;
}
.scanner-close {
  position: absolute;
  top: calc(16px + var(--safe-top));
  left: 16px;
  z-index: 10;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
#qr-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* UX-C — Cadre scanner hexagonal sarcelle */
.scanner-frame {
  width: 240px;
  height: 240px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner-frame::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--secondary);
  clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
  border-radius: 0;
  border: none;
  box-shadow: 0 0 0 2px var(--secondary), inset 0 0 0 2px var(--secondary);
  animation: scanner-pulse 2.5s ease-in-out infinite;
}
.scanner-frame::after {
  content: '';
  position: absolute;
  inset: 8px;
  background: rgba(45, 212, 191, .06);
  clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}
@keyframes scanner-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .55; }
}
.scanner-hint {
  margin-top: 24px;
  color: #fff;
  font-size: 14px;
  text-align: center;
  background: rgba(0,0,0,.55);
  padding: 8px 16px;
  border-radius: 20px;
}

/* ── Modale bottom-sheet ─────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: flex-end;
  z-index: 200;
}
.modal-sheet {
  width: 100%;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}
.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.modal-sub { font-size: 14px; color: var(--text-sec); margin-bottom: 20px; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.btn-secondary {
  height: 48px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:active { background: var(--amber-lighter); }

/* ── UX-A — Skeleton cards ───────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -300px 0; }
  100% { background-position: 300px 0; }
}
.skeleton {
  background: linear-gradient(90deg,
    var(--card) 0%,
    var(--border) 50%,
    var(--card) 100%
  );
  background-size: 600px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 8px;
}
.skeleton-item {
  display: flex;
  align-items: center;
  padding: 13px 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border-light);
}
.skeleton-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  flex-shrink: 0;
}
.skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.skeleton-line-1 { height: 14px; width: 60%; }
.skeleton-line-2 { height: 11px; width: 40%; }

/* ── Loader / état vide ──────────────────────────────────────────────── */
.loading, .empty-state {
  padding: 40px 20px;
  text-align: center;
  font-size: 14px;
  color: var(--text-ter);
}

/* ── Toast ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 20px;
  z-index: 99;
  transition: transform .25s ease, opacity .25s;
  opacity: 0;
  white-space: nowrap;
  max-width: 320px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
#toast.success { background: var(--green); border-color: var(--green); color: #fff; }
#toast.error   { background: var(--red);   border-color: var(--red);   color: #fff; }

/* ── Badges & Pills ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: .2px;
}
.badge-teal    { background: rgba(45,212,191,.18); color: var(--mint);    border: 1px solid rgba(45,212,191,.35); }
.badge-orange  { background: rgba(251,191,36,.18); color: var(--primary); border: 1px solid rgba(251,191,36,.35); }
.badge-green   { background: rgba(52,211,153,.18); color: var(--green);   border: 1px solid rgba(52,211,153,.35); }
.badge-red     { background: rgba(248,113,113,.18); color: var(--red);    border: 1px solid rgba(248,113,113,.35); }
.badge-muted   { background: rgba(148,163,184,.12); color: var(--text-sec); border: 1px solid rgba(148,163,184,.25); }

/* ── Textes colorés utilitaires ─────────────────────────────────────── */
.text-teal    { color: var(--mint); }
.text-orange  { color: var(--primary); }
.text-muted   { color: var(--text-sec); }
.text-dimmed  { color: var(--text-ter); }
