/* ================================================================
   Jaaba OnField — Style Mobile-First
   Design : vert agricole + interface app native
   ================================================================ */

/* ── Variables ──────────────────────────────────────────────────── */
:root {
  --g1: #1a4a1c; --g2: #2d6a2f; --g3: #4a8c3f; --g4: #6aaa2a; --g5: #8cc858;
  --gold: #f0a500; --earth: #7a5230; --red: #e74c3c; --blue: #2980b9;
  --bg: #f4f7f1; --white: #fff; --card: #fff;
  --shadow: 0 2px 14px rgba(0,0,0,.09);
  --radius: 14px; --radius-sm: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: #1a2e1a;
  min-height: 100vh;
  overflow-x: hidden;
  /* Simule un écran de téléphone en desktop */
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ── Layout des écrans ─────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  background: var(--g1);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 56px;
}
.topbar-back {
  background: rgba(255,255,255,.15);
  border: none; border-radius: 50%;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #fff; font-size: 1.1rem; flex-shrink: 0;
}
.topbar-title { color: #fff; font-weight: 700; font-size: 1rem; flex: 1; }
.topbar-logo { font-size: 1.2rem; }
.topbar-action {
  background: rgba(255,255,255,.15);
  border: none; border-radius: 8px;
  padding: 6px 12px; color: #fff;
  font-size: .8rem; font-weight: 600; cursor: pointer;
}

/* ── Bottom Navigation ───────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: var(--white);
  border-top: 1px solid #e5ede2;
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 200;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
.nav-tab {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; gap: 3px;
  padding: 10px 4px 8px;
  cursor: pointer; border: none; background: none;
  color: #888; font-size: .65rem; font-weight: 600;
  transition: color .2s;
}
.nav-tab .tab-icon { font-size: 1.3rem; line-height: 1; }
.nav-tab.active { color: var(--g3); }
.nav-tab.active .tab-icon { filter: drop-shadow(0 0 4px rgba(74,140,63,.5)); }

/* ── Scroll body pour screens avec bottom-nav ──────────────────── */
.has-bottom-nav { padding-bottom: calc(70px + var(--safe-bottom)); }

/* ── Écran WELCOME ──────────────────────────────────────────────── */
.welcome-bg {
  background: linear-gradient(160deg, var(--g1) 0%, var(--g2) 50%, #1a4a1c 100%);
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 28px; gap: 0;
  min-height: 100vh;
}
.welcome-logo { font-size: 5rem; margin-bottom: 4px; }
.welcome-app-name {
  color: #fff; font-size: 2rem; font-weight: 900;
  letter-spacing: .02em; margin-bottom: 4px;
}
.welcome-subtitle { color: rgba(255,255,255,.75); font-size: .88rem; margin-bottom: 12px; }
.welcome-tagline {
  color: var(--g5); font-size: .78rem; letter-spacing: .08em;
  text-transform: uppercase; margin-bottom: 48px;
}
.welcome-features {
  display: flex; gap: 16px; margin-bottom: 48px; flex-wrap: wrap; justify-content: center;
}
.wf-chip {
  background: rgba(255,255,255,.12); color: rgba(255,255,255,.9);
  border-radius: 20px; padding: 6px 14px; font-size: .75rem; font-weight: 600;
}
.welcome-actions { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.btn-welcome-primary {
  background: var(--g4); color: #fff;
  border: none; border-radius: var(--radius);
  padding: 16px; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: background .2s; text-align: center;
}
.btn-welcome-primary:hover { background: var(--g3); }
.btn-welcome-outline {
  background: transparent; color: #fff;
  border: 2px solid rgba(255,255,255,.5);
  border-radius: var(--radius); padding: 15px;
  font-size: 1rem; font-weight: 700; cursor: pointer; text-align: center;
  transition: all .2s;
}
.btn-welcome-outline:hover { background: rgba(255,255,255,.1); border-color: #fff; }
.welcome-footer { color: rgba(255,255,255,.45); font-size: .72rem; margin-top: 24px; text-align: center; }

/* ── Formulaires Auth ─────────────────────────────────────────── */
.auth-screen {
  background: var(--bg);
  flex: 1; display: flex; flex-direction: column; min-height: 100vh;
}
.auth-header {
  background: linear-gradient(135deg, var(--g1), var(--g2));
  padding: 28px 24px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.auth-logo { font-size: 2.5rem; }
.auth-title { color: #fff; font-size: 1.2rem; font-weight: 800; }
.auth-subtitle { color: rgba(255,255,255,.7); font-size: .8rem; }
.auth-form-wrap { flex: 1; padding: 24px 20px; overflow-y: auto; }
.form-section { margin-bottom: 20px; }
.form-section-title {
  font-size: .7rem; font-weight: 700; color: var(--g3);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 10px; padding-bottom: 6px;
  border-bottom: 1.5px solid #e5ede2;
}
.form-group { margin-bottom: 14px; }
.form-label {
  display: block; font-size: .8rem; font-weight: 600;
  color: #444; margin-bottom: 5px;
}
.inp {
  width: 100%; border: 1.5px solid #d0dbc8;
  border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: .9rem;
  background: #fff; outline: none;
  transition: border-color .2s, box-shadow .2s;
  -webkit-appearance: none;
}
.inp:focus { border-color: var(--g4); box-shadow: 0 0 0 3px rgba(106,170,42,.15); }
.inp-icon-wrap { position: relative; }
.inp-icon-wrap .inp { padding-left: 42px; }
.inp-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 1rem; }
.password-toggle {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1rem; color: #888;
}
select.inp { cursor: pointer; }
.hint { font-size: .72rem; color: #999; margin-top: 4px; }

/* ── Boutons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 12px 20px; border-radius: var(--radius-sm);
  border: none; cursor: pointer; font-weight: 700;
  font-size: .88rem; transition: all .2s; text-decoration: none;
}
.btn-primary { background: var(--g3); color: #fff; }
.btn-primary:hover { background: var(--g2); }
.btn-full { width: 100%; }
.btn-lg { padding: 16px; font-size: .95rem; border-radius: var(--radius); }
.btn-outline { background: transparent; border: 2px solid var(--g4); color: var(--g2); }
.btn-outline:hover { background: var(--g4); color: #fff; }
.btn-ghost { background: transparent; color: var(--g3); padding: 8px; }
.btn-red { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: .78rem; border-radius: 6px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-link { background: none; border: none; color: var(--g3); cursor: pointer; font-size: .82rem; text-decoration: underline; }

/* ── Alertes ─────────────────────────────────────────────────────── */
.alert {
  padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: .82rem; display: none; margin-bottom: 14px; line-height: 1.5;
}
.alert-error { background: #fde8e8; color: #c0392b; border: 1px solid #f5b7b1; }
.alert-success { background: #e8f5e2; color: var(--g2); border: 1px solid #a9dfbf; }
.alert-info { background: #eaf4fb; color: #1a5276; border: 1px solid #85c1e9; }

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner-dark {
  border-color: rgba(0,0,0,.1);
  border-top-color: var(--g3);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Dashboard ───────────────────────────────────────────────────── */
.dash-header {
  background: linear-gradient(135deg, var(--g1), var(--g2));
  padding: 20px 20px 28px;
}
.dash-welcome { color: rgba(255,255,255,.8); font-size: .8rem; }
.dash-name { color: #fff; font-size: 1.3rem; font-weight: 800; margin: 2px 0; }
.dash-role-badge {
  display: inline-block; background: rgba(106,170,42,.3);
  color: var(--g5); border-radius: 10px; padding: 2px 10px;
  font-size: .7rem; font-weight: 700;
}
.dash-stats {
  display: grid; grid-template-columns: repeat(3,1fr);
  gap: 10px; padding: 0 16px;
  margin-top: -16px; margin-bottom: 16px;
}
.stat-card {
  background: #fff; border-radius: var(--radius);
  padding: 14px 12px; text-align: center;
  box-shadow: var(--shadow); border-top: 3px solid var(--g4);
}
.stat-val { font-size: 1.6rem; font-weight: 900; color: var(--g2); }
.stat-lbl { font-size: .65rem; color: #888; margin-top: 2px; font-weight: 600; }
.dash-section { padding: 0 16px 16px; }
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.section-title { font-size: .88rem; font-weight: 700; color: var(--g1); }

/* ── Cartes Parcelles ─────────────────────────────────────────────── */
.parcelle-mini-card {
  background: #fff; border-radius: var(--radius-sm);
  padding: 12px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow); margin-bottom: 8px; cursor: pointer;
  transition: transform .15s;
}
.parcelle-mini-card:hover { transform: translateX(3px); }
.pmc-icon { font-size: 1.8rem; flex-shrink: 0; }
.pmc-info { flex: 1; min-width: 0; }
.pmc-name { font-weight: 700; font-size: .88rem; color: #1a2e1a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pmc-meta { font-size: .72rem; color: #888; margin-top: 2px; }

.parcelle-card {
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  margin-bottom: 12px; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.parcelle-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.13); }
.pc-map-preview {
  height: 80px; background: linear-gradient(135deg, #1a4a1c, #4a8c3f);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; position: relative;
}
.pc-region {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,.4); color: #fff;
  font-size: .65rem; padding: 2px 7px; border-radius: 8px;
}
.pc-body { padding: 12px 14px; }
.pc-name { font-weight: 700; font-size: .95rem; margin-bottom: 4px; }
.pc-meta { font-size: .75rem; color: #666; margin-bottom: 3px; }
.pc-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.pc-date { font-size: .68rem; color: #aaa; }

/* ── Badges ────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: .68rem; font-weight: 700; }
.badge-green { background: #e8f5e2; color: var(--g2); }
.badge-gold  { background: #fff8e1; color: #b7700a; }
.badge-gray  { background: #f0f0f0; color: #888; }
.badge-ia    { background: linear-gradient(135deg,#8e44ad,#2980b9); color:#fff; font-size:.65rem; padding:2px 7px; border-radius:6px; font-weight:700; }

/* ── Rapport preview ─────────────────────────────────────────────── */
.rapport-preview, .rapport-card {
  background: linear-gradient(135deg, #f8f4ff, #e8f5e2);
  border: 1.5px solid var(--g4); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.rapport-card { cursor: pointer; transition: transform .15s; }
.rapport-card:hover { transform: translateY(-2px); }
.rp-header, .rc-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.rp-icon, .rc-icon { font-size: 1.5rem; flex-shrink: 0; }
.rp-title, .rc-title { font-weight: 700; font-size: .88rem; }
.rp-date, .rc-date { font-size: .72rem; color: #888; }
.rp-excerpt, .rc-excerpt { font-size: .78rem; color: #555; line-height: 1.5; margin-bottom: 10px; }
.rc-footer { display: flex; justify-content: space-between; align-items: center; }
.rc-parcelle { font-size: .72rem; color: #888; }
.rapport-meta { display: flex; gap: 12px; font-size: .75rem; color: #888; margin-bottom: 12px; }
.rapport-content { font-size: .82rem; line-height: 1.7; white-space: pre-wrap; color: #2d3748; }

/* ── Map Container ───────────────────────────────────────────────── */
#map-container {
  height: 280px; width: 100%;
  border-radius: var(--radius); overflow: hidden;
  border: 2px solid var(--g4); margin-bottom: 12px;
  background: #e8f5e2;
}
.map-controls {
  display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap;
}
.map-instruction {
  background: linear-gradient(135deg,var(--g4),var(--g3));
  color: #fff; border-radius: var(--radius-sm);
  padding: 8px 14px; font-size: .78rem; font-weight: 600;
  text-align: center; margin-bottom: 10px;
}
.points-container {
  background: #fff; border-radius: var(--radius-sm);
  padding: 10px; border: 1.5px solid #d0dbc8; min-height: 44px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-bottom: 8px;
}
.point-chip {
  background: #e8f5e2; color: var(--g2); border-radius: 6px;
  padding: 3px 8px; font-size: .72rem; font-weight: 600;
  font-family: monospace;
}
.points-hint { color: #aaa; font-size: .78rem; }
.superficie-display { font-size: .8rem; color: var(--g2); font-weight: 600; text-align: right; margin-bottom: 8px; }

/* ── Analyses de Sol ─────────────────────────────────────────────── */
.sol-section {
  background: #fff; border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
  border-left: 4px solid var(--g4); box-shadow: var(--shadow);
}
.sol-section-title { font-size: .78rem; font-weight: 700; color: var(--g2); margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

/* ── Profil ──────────────────────────────────────────────────────── */
.profil-header {
  background: linear-gradient(135deg, var(--g1), var(--g2));
  padding: 32px 20px 24px; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.profil-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--g4); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 800; border: 3px solid rgba(255,255,255,.3);
}
.profil-name { color: #fff; font-size: 1.2rem; font-weight: 800; }
.profil-role-badge { background: rgba(106,170,42,.3); color: var(--g5); border-radius: 10px; padding: 3px 12px; font-size: .72rem; }
.profil-info-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  margin: 16px; overflow: hidden;
}
.info-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid #f0f5ee;
}
.info-row:last-child { border-bottom: none; }
.info-icon { font-size: 1.1rem; width: 28px; text-align: center; flex-shrink: 0; }
.info-content { flex: 1; }
.info-label { font-size: .7rem; color: #999; font-weight: 600; }
.info-value { font-size: .88rem; color: #1a2e1a; font-weight: 600; }
.logout-section { padding: 8px 16px 20px; }

/* ── Detail grid ─────────────────────────────────────────────────── */
.detail-grid { display: flex; flex-direction: column; gap: 2px; }
.detail-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid #f0f5ee; font-size: .82rem;
}
.dl { color: #888; }
.dv { font-weight: 600; color: #1a2e1a; }
.coords-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.coords-list code { background: #f0f5ee; border-radius: 4px; padding: 3px 8px; font-size: .72rem; }

/* ── Modales ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 500; display: none;
  align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px; max-height: 88vh;
  overflow-y: auto; padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
}
.modal-handle {
  width: 40px; height: 4px; background: #d0dbc8;
  border-radius: 2px; margin: 0 auto 16px;
}
.modal-title {
  font-size: 1rem; font-weight: 700; color: var(--g2);
  display: flex; align-items: center; gap: 8px; margin-bottom: 16px;
}

/* ── IA Loading Overlay ──────────────────────────────────────────── */
#ia-loading-overlay {
  position: fixed; inset: 0; background: rgba(26,74,28,.9);
  z-index: 1000; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 16px;
}
.ia-loading-text { color: #fff; font-weight: 700; font-size: 1rem; text-align: center; }
.ia-loading-sub { color: rgba(255,255,255,.7); font-size: .8rem; text-align: center; }
.ia-spinner {
  width: 50px; height: 50px;
  border: 4px solid rgba(255,255,255,.2);
  border-top-color: var(--g5);
  border-radius: 50%; animation: spin .8s linear infinite;
}

/* ── Sync Banner ─────────────────────────────────────────────────── */
#sync-banner {
  position: fixed; top: 56px; left: 0; right: 0; max-width: 480px; margin: 0 auto;
  background: var(--g3); color: #fff;
  padding: 10px 16px; text-align: center; font-size: .82rem; font-weight: 600;
  z-index: 400; display: none; border-radius: 0 0 8px 8px;
}

/* ── États vides ─────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 28px 20px; color: #888;
  font-size: .85rem; line-height: 1.8;
}
.empty-state.full { padding: 60px 24px; }
.loading-state { text-align: center; padding: 40px; color: #888; display: flex; align-items: center; justify-content: center; gap: 10px; }

/* ── Offline indicator ───────────────────────────────────────────── */
.offline-chip {
  background: var(--gold); color: #7a4a00;
  font-size: .7rem; font-weight: 700; padding: 3px 8px; border-radius: 8px;
  display: none;
}
body.offline .offline-chip { display: inline-block; }

/* ── Scrollable content ──────────────────────────────────────────── */
.scroll-content { overflow-y: auto; flex: 1; }
.pad { padding: 16px; }
.pad-sm { padding: 10px 16px; }

/* ── Desktop frame ───────────────────────────────────────────────── */
@media (min-width: 480px) {
  body { box-shadow: 0 0 60px rgba(0,0,0,.2); min-height: 100vh; }
  .bottom-nav, #sync-banner { left: 50%; transform: translateX(-50%); }
}
