:root {
  --brand:      #1f6b43;
  --brand-dk:   #164f30;
  --brand-lt:   #eaf3ed;
  --good:       #27ae60;
  --warn:       #f39c12;
  --danger:     #c0392b;
  --muted:      #607060;
  --bg:         #f2f5f3;
  --card:       #ffffff;
  --border:     #d4e0d7;
  --topbar-h:   52px;
  --bottom-h:   62px;
  --radius:     10px;
  --shadow:     0 2px 10px rgba(0,0,0,.10);
  --shadow-lg:  0 6px 24px rgba(0,0,0,.15);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 14px;
  color: #1a2b1e;
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── TOPBAR ── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 200;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}
.topbar-left  { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.brand { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  background: none; border: none; color: #fff;
  font-size: 20px; cursor: pointer;
  padding: 6px 8px; border-radius: 6px; line-height: 1;
  touch-action: manipulation;
}
.icon-btn:active { background: rgba(255,255,255,.2); }

.net-pill {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: rgba(0,0,0,.3); white-space: nowrap;
}
.net-pill.online  { background: rgba(39,174,96,.7); }
.net-pill.offline { background: rgba(192,57,43,.6); }

/* ── MAIN CONTENT ── */
.main-content {
  position: fixed;
  top: var(--topbar-h);
  bottom: var(--bottom-h);
  left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}

/* ── BOTTOM NAV ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 200;
  box-shadow: 0 -2px 10px rgba(0,0,0,.08);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none; border: none; cursor: pointer;
  color: var(--muted);
  touch-action: manipulation;
  transition: color .2s;
  padding: 8px 0;
}
.nav-btn:active { background: var(--brand-lt); }
.nav-btn.active { color: var(--brand); }
.nav-btn.active .nav-icon { transform: scale(1.1); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 600; }

/* ── CARDS ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── DASHBOARD GRID ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card.warn  { border-left: 4px solid var(--warn);   }
.stat-card.danger{ border-left: 4px solid var(--danger);  }
.stat-card.good  { border-left: 4px solid var(--good);    }
.stat-card.brand { border-left: 4px solid var(--brand);   }
.stat-val  { font-size: 28px; font-weight: 700; color: #1a2b1e; line-height: 1; }
.stat-lbl  { font-size: 12px; color: var(--muted); }

/* ── LIST ITEMS ── */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: box-shadow .15s;
}
.list-item:active { box-shadow: var(--shadow-lg); }
.list-item-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--brand-lt);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub   { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-right { flex-shrink: 0; text-align: right; }
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}
.badge-good   { background: #d4edda; color: #1a6e32; }
.badge-warn   { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #842029; }
.badge-muted  { background: #e9ecef; color: #6c757d; }

/* ── SECTION TITLE ── */
.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 16px 0 8px;
  padding: 0 2px;
}
.section-title:first-child { margin-top: 0; }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: calc(var(--bottom-h) + 14px);
  right: 14px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  touch-action: manipulation;
  transition: transform .15s;
}
.fab:active { transform: scale(.93); }

/* ── SLIDE PANEL ── */
.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.panel-overlay.open { opacity: 1; pointer-events: all; }

.slide-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  z-index: 310;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.slide-panel.open { transform: translateY(0); }

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-close {
  background: #f0f0f0; border: none; border-radius: 50%;
  width: 30px; height: 30px; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.panel-title { font-size: 17px; font-weight: 700; }
.panel-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 24px;
  flex: 1;
}

/* ── FORM ELEMENTS ── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 5px;
}
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: #fafcfb;
  color: #1a2b1e;
  appearance: none;
  -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31,107,67,.15);
}
textarea.form-control { min-height: 80px; resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 8px; font-size: 15px; font-weight: 600;
  border: none; cursor: pointer; touch-action: manipulation;
  transition: opacity .15s;
  width: 100%; margin-top: 4px;
}
.btn:active { opacity: .8; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); }
.btn + .btn  { margin-top: 8px; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-h) + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a2b1e;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  z-index: 500;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── LOGIN ── */
.login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, var(--brand-dk) 0%, var(--brand) 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.login-overlay.hidden { display: none; }

.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-logo { font-size: 56px; text-align: center; line-height: 1; }
.login-card h1 { font-size: 24px; font-weight: 700; color: var(--brand); text-align: center; }
.login-card input {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 16px; background: #fafcfb;
}
.login-card input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31,107,67,.15);
}
.login-card button {
  width: 100%; padding: 13px;
  background: var(--brand); color: #fff;
  border: none; border-radius: 10px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  margin-top: 4px;
}
.login-card button:active { background: var(--brand-dk); }
.login-err {
  color: var(--danger); font-size: 13px;
  text-align: center; min-height: 18px;
}

/* ── RECORD ROW ── */
.record-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.record-row:last-child { border-bottom: none; }
.record-date {
  font-size: 12px; color: var(--muted); min-width: 80px; padding-top: 2px;
}
.record-body { flex: 1; }
.record-type { font-weight: 600; font-size: 14px; }
.record-detail { font-size: 12px; color: var(--muted); margin-top: 2px; }
.record-cost { font-size: 13px; font-weight: 600; color: var(--brand); }

/* ── DUE ROW ── */
.due-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.due-row.overdue  { border-left: 4px solid var(--danger); }
.due-row.upcoming { border-left: 4px solid var(--warn);   }
.due-row.ok       { border-left: 4px solid var(--good);   }
.due-info { flex: 1; }
.due-machine { font-weight: 600; font-size: 14px; }
.due-when    { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── LEAFLET OVERRIDES ── */
/* Replace external layers.png with inline icon to avoid 404 */
.leaflet-control-layers-toggle {
  background-image: none !important;
  font-size: 20px;
  line-height: 36px;
  text-align: center;
  width: 36px !important;
  height: 36px !important;
}
.leaflet-control-layers-toggle::after {
  content: '⊞';
  color: #333;
}

/* ── LOADER ── */
.spinner {
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  color: var(--muted);
  font-size: 15px;
}

/* ── DASHBOARD HERO CARD ── */
.dash-hero {
  background: linear-gradient(135deg, var(--brand-dk) 0%, var(--brand) 60%, #2d8a55 100%);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  margin-bottom: 12px;
  color: #fff;
  box-shadow: 0 4px 16px rgba(31,107,67,.35);
}
.dash-hero-greeting { font-size: 13px; opacity: .85; margin-bottom: 2px; }
.dash-hero-date { font-size: 20px; font-weight: 700; letter-spacing: -.3px; margin-bottom: 10px; }
.dash-hero-stats { display: flex; gap: 16px; }
.dash-hero-stat { display: flex; flex-direction: column; gap: 1px; }
.dash-hero-stat-val { font-size: 22px; font-weight: 700; line-height: 1; }
.dash-hero-stat-lbl { font-size: 11px; opacity: .8; }
.dash-hero-divider { width: 1px; background: rgba(255,255,255,.3); align-self: stretch; }

/* ── IMPROVED STAT CARDS ── */
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  overflow: hidden;
  border-left: none;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.stat-card.warn::before   { background: var(--warn); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.good::before   { background: var(--good); }
.stat-card.brand::before  { background: var(--brand); }
.stat-card .stat-icon { font-size: 22px; line-height: 1; margin-bottom: 4px; }
.stat-val { font-size: 30px; font-weight: 800; color: #1a2b1e; line-height: 1; }
.stat-lbl { font-size: 11px; color: var(--muted); font-weight: 600; }

/* ── CROP CHIPS ── */
.crop-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.crop-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: 20px;
  padding: 4px 10px 4px 7px; font-size: 12px; font-weight: 600; color: #1a2b1e;
  box-shadow: var(--shadow);
}
.crop-chip-ha { color: var(--muted); font-weight: 400; font-size: 11px; }

/* ── INSPECTION CARDS ── */
.insp-card {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
  border-left: 4px solid var(--brand);
  touch-action: manipulation; transition: box-shadow .15s;
}
.insp-card:active { box-shadow: var(--shadow-lg); }
.insp-card-left { flex: 1; min-width: 0; }
.insp-card-right { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.insp-field { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insp-sub   { font-size: 12px; color: var(--muted); margin-top: 2px; }
.insp-notes { font-size: 12px; color: #444; margin-top: 4px; line-height: 1.4; }
.insp-photo-badge {
  font-size: 12px; font-weight: 700; background: var(--brand-lt);
  color: var(--brand); border-radius: 12px; padding: 2px 8px;
}
.insp-photo-badge.muted { background: #f0f0f0; color: var(--muted); }

/* ── INSPECTION DETAIL ── */
.insp-detail-header {
  background: linear-gradient(135deg, var(--brand-dk), var(--brand));
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px; color: #fff;
}
.insp-detail-field   { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.insp-detail-date    { font-size: 13px; opacity: .85; }
.insp-detail-weather { font-size: 13px; margin-top: 4px; }

/* ── PHOTO GRID ── */
.photo-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px;
}
.photo-thumb {
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  background: #f0f0f0; position: relative;
  aspect-ratio: 4/3;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-note {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.6); color: #fff;
  font-size: 11px; padding: 3px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── WEATHER CHIPS ── */
.weather-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0; }
.weather-chip {
  background: #f0f4f2; border: 1.5px solid var(--border); border-radius: 20px;
  padding: 6px 12px; font-size: 13px; cursor: pointer;
  touch-action: manipulation; transition: all .15s;
}
.weather-chip.selected {
  background: var(--brand-lt); border-color: var(--brand); color: var(--brand); font-weight: 700;
}

/* ── PHOTO PREVIEW ROWS ── */
.photo-preview-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.photo-preview-thumb {
  width: 52px; height: 52px; object-fit: cover; border-radius: 8px; flex-shrink: 0;
}
.photo-preview-del {
  background: var(--danger); color: #fff; border: none; border-radius: 6px;
  width: 30px; height: 30px; font-size: 14px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
