/* =========================================================
   AgriSmart — Dashboard authentifié (overlay plein écran)
   N'altère PAS la landing page publique.
   ========================================================= */

#dashboardOverlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #f6fbf7 0%, #eef4fb 100%);
  z-index: 9000;
  overflow-y: auto;
  display: none;
  opacity: 0;
  transition: opacity .25s ease;
}
#dashboardOverlay.active { display: block; opacity: 1; animation: dashFadeIn .35s ease; }
@keyframes dashFadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.dash-shell { max-width: 1280px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 40px) 60px; }

/* ---------- Topbar ---------- */
.dash-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 28px;
  padding: 14px 20px;
  background: white; border-radius: 18px;
  box-shadow: 0 4px 24px rgba(45,122,79,.08);
  position: sticky; top: 12px; z-index: 5;
  backdrop-filter: blur(10px);
}
.dash-brand { display: flex; align-items: center; gap: 12px; font-family: 'Playfair Display', serif; font-weight: 700; font-size: 1.25rem; color: #1a2332; }
.dash-brand .dash-logo { width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(135deg,#2d7a4f,#4caf78); display:flex; align-items:center; justify-content:center; font-size: 20px; }
.dash-brand span { color: #2d7a4f; }
.dash-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.dash-tab {
  border: none; background: transparent; cursor: pointer;
  padding: 9px 16px; border-radius: 10px;
  font-family: 'DM Sans', sans-serif; font-size: .9rem; font-weight: 500;
  color: #4a5568; transition: all .2s;
}
.dash-tab:hover { background: #e8f5ee; color: #2d7a4f; }
.dash-tab.active { background: linear-gradient(135deg,#2d7a4f,#4caf78); color: white; box-shadow: 0 4px 12px rgba(45,122,79,.25); }
.dash-actions { display: flex; gap: 8px; align-items: center; }
.dash-btn {
  border: none; cursor: pointer; padding: 9px 14px; border-radius: 10px;
  font-family: 'DM Sans', sans-serif; font-size: .85rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; transition: all .2s;
}
.dash-btn.ghost { background: #f1f5f9; color: #4a5568; }
.dash-btn.ghost:hover { background: #e2e8f0; }
.dash-btn.primary { background: linear-gradient(135deg,#2d7a4f,#4caf78); color: white; }
.dash-btn.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(45,122,79,.3); }
.dash-btn.danger { background: #fee2e2; color: #b91c1c; }
.dash-btn.danger:hover { background: #fecaca; }

/* ---------- Greeting ---------- */
.dash-hero {
  display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center;
  padding: 28px 32px;
  background: linear-gradient(120deg,#2d7a4f 0%, #4caf78 100%);
  color: white; border-radius: 22px;
  margin-bottom: 24px;
  box-shadow: 0 12px 40px rgba(45,122,79,.25);
  position: relative; overflow: hidden;
}
.dash-hero::before { content:''; position:absolute; right:-60px; top:-60px; width:220px; height:220px; border-radius:50%; background:rgba(255,255,255,.08); }
.dash-hero::after { content:''; position:absolute; right:60px; bottom:-40px; width:140px; height:140px; border-radius:50%; background:rgba(255,255,255,.06); }
.dash-hero h2 { font-family:'Playfair Display',serif; font-size: clamp(1.4rem, 2.6vw, 2rem); font-weight: 700; margin-bottom: 6px; position:relative; }
.dash-hero p { opacity: .92; font-size: .95rem; position:relative; }
.dash-hero .dash-hero-cta { display: flex; gap: 10px; position: relative; }
.dash-hero .dash-hero-cta button {
  border: none; cursor: pointer; padding: 11px 18px; border-radius: 12px;
  font-family:'DM Sans',sans-serif; font-weight: 600; font-size: .9rem;
  background: white; color: #2d7a4f; transition: all .2s;
}
.dash-hero .dash-hero-cta button.outline { background: rgba(255,255,255,.15); color: white; backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.3); }
.dash-hero .dash-hero-cta button:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.18); }

/* ---------- KPI grid ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-card {
  background: white; padding: 20px; border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,.04);
  transition: all .25s; border: 1px solid #f1f5f9;
  animation: kpiPop .4s ease both;
}
@keyframes kpiPop { from { opacity: 0; transform: translateY(10px); } to { opacity:1; transform:translateY(0); } }
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(45,122,79,.10); }
.kpi-card .kpi-icon { width: 42px; height: 42px; border-radius: 12px; display:flex; align-items:center; justify-content:center; font-size:20px; margin-bottom: 12px; }
.kpi-card.k-green .kpi-icon { background:#e8f5ee; color:#2d7a4f; }
.kpi-card.k-blue  .kpi-icon { background:#e8f0fb; color:#2563a8; }
.kpi-card.k-pink  .kpi-icon { background:#fdf0f4; color:#e07a9a; }
.kpi-card.k-amber .kpi-icon { background:#fef3c7; color:#b45309; }
.kpi-card.k-red   .kpi-icon { background:#fee2e2; color:#b91c1c; }
.kpi-card .kpi-val { font-family:'Playfair Display',serif; font-size: 1.85rem; font-weight: 700; color: #1a2332; line-height: 1; }
.kpi-card .kpi-label { font-size: .8rem; color: #4a5568; margin-top: 6px; font-weight: 500; }
.kpi-card .kpi-trend { font-size: .72rem; color: #2d7a4f; margin-top: 4px; font-weight: 600; }

/* ---------- 2-col layout ---------- */
.dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 960px) { .dash-grid { grid-template-columns: 1fr; } }

.dash-panel {
  background: white; border-radius: 18px; padding: 22px;
  box-shadow: 0 4px 16px rgba(0,0,0,.04);
  border: 1px solid #f1f5f9;
  animation: kpiPop .4s ease both;
}
.dash-panel-head { display:flex; justify-content:space-between; align-items:center; margin-bottom: 16px; }
.dash-panel-head h3 { font-family:'Playfair Display',serif; font-size: 1.1rem; color:#1a2332; font-weight: 700; }
.dash-panel-head .panel-link { font-size: .8rem; color: #2d7a4f; text-decoration: none; font-weight: 600; cursor: pointer; }
.dash-panel-head .panel-link:hover { text-decoration: underline; }

/* ---------- Recent analyses list ---------- */
.recent-list { display: flex; flex-direction: column; gap: 10px; }
.recent-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px; border-radius: 12px;
  background: #fafbfc; border: 1px solid #f1f5f9;
  cursor: pointer; transition: all .2s;
}
.recent-item:hover { background: white; border-color: #e8f5ee; transform: translateX(2px); box-shadow: 0 4px 12px rgba(45,122,79,.06); }
.recent-thumb {
  width: 52px; height: 52px; border-radius: 12px;
  background: linear-gradient(135deg,#e8f5ee,#fafbfc);
  display:flex; align-items:center; justify-content:center; font-size: 24px; flex-shrink:0;
  background-size: cover; background-position: center;
}
.recent-body { flex: 1; min-width: 0; }
.recent-title { font-weight: 600; color:#1a2332; font-size: .9rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.recent-meta { font-size: .75rem; color: #8a9ab0; margin-top: 2px; }
.sev-pill { padding: 4px 10px; border-radius: 20px; font-size: .7rem; font-weight: 700; flex-shrink:0; }
.sev-pill.ok { background:#dcfce7; color:#166534; }
.sev-pill.low { background:#fef3c7; color:#92400e; }
.sev-pill.mid { background:#ffedd5; color:#9a3412; }
.sev-pill.high{ background:#fee2e2; color:#991b1b; animation: pulseRed 1.8s infinite; }
@keyframes pulseRed { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.35); } 50% { box-shadow: 0 0 0 6px rgba(220,38,38,0); } }

/* ---------- Alerts panel ---------- */
.alert-list { display:flex; flex-direction:column; gap: 10px; }
.alert-item {
  padding: 12px 14px; border-radius: 12px; border-left: 4px solid #2d7a4f;
  background: #fafbfc; display:flex; gap:10px; align-items:flex-start;
  animation: alertSlide .35s ease both;
}
@keyframes alertSlide { from { opacity:0; transform: translateX(-8px); } to { opacity:1; transform:translateX(0); } }
.alert-item.urgent { border-left-color:#dc2626; background:#fef2f2; }
.alert-item.warn { border-left-color:#f59e0b; background:#fffbeb; }
.alert-item.info { border-left-color:#2563a8; background:#eff6ff; }
.alert-icon { font-size: 18px; }
.alert-body { flex:1; }
.alert-title { font-weight: 700; font-size: .85rem; color:#1a2332; }
.alert-desc { font-size: .78rem; color:#4a5568; margin-top: 3px; line-height: 1.45; }
.alert-time { font-size: .68rem; color:#8a9ab0; margin-top: 6px; font-weight: 500; }

/* ---------- Zones grid ---------- */
.zone-mini-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 12px; }
.zone-mini {
  padding: 14px; border-radius: 14px; border: 1px solid #f1f5f9;
  background: linear-gradient(180deg,white,#fafbfc); cursor: pointer; transition: all .2s;
}
.zone-mini:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(45,122,79,.08); border-color: #e8f5ee; }
.zone-mini-head { display:flex; align-items:center; justify-content:space-between; margin-bottom: 10px; }
.zone-mini-name { font-weight: 700; color:#1a2332; font-size: .9rem; }
.zone-dot { width:10px; height: 10px; border-radius: 50%; }
.zone-dot.ok { background:#22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.zone-dot.warn { background:#f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,.2); }
.zone-dot.alert { background:#dc2626; box-shadow: 0 0 0 3px rgba(220,38,38,.2); animation: pulseRed 1.6s infinite; }
.zone-mini-meta { font-size: .72rem; color:#8a9ab0; }
.zone-mini-stats { display:flex; gap: 10px; margin-top: 10px; font-size: .72rem; color:#4a5568; }

/* ---------- Recommendations ---------- */
.reco-list { display:flex; flex-direction:column; gap: 10px; }
.reco-item {
  padding: 12px; border-radius: 12px; background: #f8faf8;
  border: 1px solid #e8f5ee; display:flex; gap:10px; align-items:flex-start;
}
.reco-item .reco-ico { font-size: 18px; }
.reco-item .reco-text { font-size: .82rem; color:#1a2332; line-height: 1.5; }
.reco-item strong { color: #2d7a4f; }

/* ---------- Empty / loading ---------- */
.dash-empty { text-align:center; padding: 30px 20px; color:#8a9ab0; font-size: .9rem; }
.dash-empty .empty-ico { font-size: 36px; margin-bottom: 10px; opacity: .5; }
.dash-skel { height: 14px; border-radius: 6px; background: linear-gradient(90deg,#f1f5f9,#fafbfc,#f1f5f9); background-size: 200% 100%; animation: skel 1.4s infinite; }
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Profile button in topbar ---------- */
.dash-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg,#2d7a4f,#4caf78); color: white;
  display:flex; align-items:center; justify-content:center; font-weight: 700; font-size: .85rem; cursor: pointer;
  transition: transform .2s; flex-shrink: 0;
}
.dash-avatar:hover { transform: scale(1.08); }

/* Dashboard nav button (visible only when logged in) */
#dashboardNavBtn { display: none; }
body.is-auth #dashboardNavBtn { display: inline-flex; align-items: center; gap: 6px; }

/* Hide guest buttons / show user badge handled by api.js, kept here for safety */
body.is-auth #guestButtons { display: none !important; }
body.is-auth #userBadge { display: flex !important; }
body:not(.is-auth) #userBadge { display: none !important; }

@media (max-width: 700px) {
  .dash-hero { grid-template-columns: 1fr; text-align: center; }
  .dash-hero .dash-hero-cta { justify-content: center; flex-wrap: wrap; }
  .dash-tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .dash-topbar { flex-direction: column; align-items: stretch; }
}
