/* Oil Palm Estate — Mobile-first styles */

:root {
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-50: #f0fdf4;
  --brown-600: #92400e;
  --brown-50: #fefce8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f3f4f6;
  color: #1f2937;
  min-height: 100dvh;
  padding-bottom: 72px; /* space for bottom tab bar */
}

/* ── Tab bar ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  font-size: 11px;
  color: #9ca3af;
  background: none;
  border: none;
  cursor: pointer;
  min-height: 56px;
  transition: color 0.15s;
}

.tab-btn .tab-icon { font-size: 22px; margin-bottom: 2px; }
.tab-btn.tab-active { color: var(--green-700); font-weight: 600; }

/* ── Form styles ── */
.app-header {
  background: linear-gradient(135deg, var(--green-700), #166534);
  color: #fff;
  padding: 16px;
  text-align: center;
}

.app-header h1 { margin: 0; font-size: 18px; font-weight: 700; }
.app-header p { margin: 4px 0 0; font-size: 12px; opacity: 0.85; }

.form-section {
  padding: 12px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--green-700);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--green-700);
}

.section-title-brown {
  color: var(--brown-600);
  border-bottom-color: var(--brown-600);
}

.field-input {
  width: 100%;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 15px;
  background: #fff;
  color: #1f2937;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}

.field-input:focus {
  outline: none;
  border-color: var(--green-600);
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.15);
}

select.field-input { background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%239ca3af'/%3E%3C/svg%3E") no-repeat right 12px center; padding-right: 32px; }

.btn-add {
  width: 100%;
  padding: 10px;
  border: 2px dashed #d1d5db;
  border-radius: 8px;
  background: none;
  color: #6b7280;
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
  transition: border-color 0.15s, color 0.15s;
}

.btn-add:active { border-color: var(--green-600); color: var(--green-600); }

.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--green-600);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  transition: background 0.15s;
}

.btn-primary:active { background: var(--green-700); }

.btn-primary-brown { background: var(--brown-600); }
.btn-primary-brown:active { background: #78350f; }

/* ── Preview modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-content {
  background: #fff;
  min-height: 100dvh;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.btn-action {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-whatsapp { background: #25D366; color: #fff; }
.btn-whatsapp:active { background: #1da851; }
.btn-image { background: #3b82f6; color: #fff; }
.btn-image:active { background: #2563eb; }
.btn-cloud { background: #8b5cf6; color: #fff; }
.btn-cloud:active { background: #7c3aed; }
.btn-close-modal { background: #e5e7eb; color: #374151; }
.btn-close-modal:active { background: #d1d5db; }

/* ── Report card (visual output) ── */
.report-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #1f2937;
  line-height: 1.5;
}

.rc-header {
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  color: var(--green-700);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--green-700);
}

.rc-header-fert { color: var(--brown-600); border-bottom-color: var(--brown-600); }

.rc-meta { margin-bottom: 12px; font-size: 13px; }
.rc-meta div { margin-bottom: 2px; }
.rc-meta b { display: inline-block; min-width: 80px; }

.rc-table-header {
  display: grid;
  grid-template-columns: 60px 50px 1fr 40px;
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  padding: 4px 0;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 4px;
}

.rc-row {
  display: grid;
  grid-template-columns: 60px 50px 1fr 40px;
  padding: 3px 0;
  font-size: 13px;
  align-items: center;
}

.rc-pump-id { font-weight: 700; font-size: 12px; }
.rc-field { font-size: 13px; }
.rc-icons { font-size: 14px; letter-spacing: 1px; }
.rc-wl { font-weight: 700; text-align: right; }

.rc-divider {
  border-top: 2px dashed #d1d5db;
  margin: 8px 0;
}

.rc-summary {
  background: var(--green-50);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 10px 0;
  font-size: 13px;
}

.rc-legend {
  font-size: 11px;
  color: #6b7280;
  margin: 8px 0;
  padding: 6px 0;
  border-top: 1px solid #f3f4f6;
}

.rc-remarks {
  background: #fef2f2;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 13px;
  color: #991b1b;
}

/* ── Fertilizer table (matches paper form) ── */
.fert-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 8px -4px;
}

.rc-fert-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 12px;
  margin: 0;
}

.rc-fert-table th {
  background: var(--brown-50);
  padding: 6px 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--brown-600);
  border: 1px solid #d4a574;
  white-space: nowrap;
}

.rc-fert-table td {
  padding: 5px 4px;
  text-align: center;
  border: 1px solid #e5e0d5;
  font-size: 12px;
}

.rc-fert-table .fert-total-row {
  background: var(--brown-50);
  border-top: 2px solid var(--brown-600);
}

.rc-fert-table .fert-total-row td {
  border-color: #d4a574;
  font-weight: 700;
  color: var(--brown-600);
}

/* ── Toast ── */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  transition: transform 0.3s ease;
  white-space: nowrap;
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast-success { background: #dcfce7; color: #166534; }
.toast-error { background: #fee2e2; color: #991b1b; }

/* ── Analytics tab ── */
.section-title-blue {
  color: #1e40af;
  border-bottom-color: #1e40af;
}

.analytics-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 0;
}

.stat-card-green { border-color: #bbf7d0; background: #f0fdf4; }
.stat-card-red { border-color: #fecaca; background: #fef2f2; }

.stat-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.stat-label {
  font-size: 11px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  color: #1f2937;
}

.stat-green { color: #16a34a; }
.stat-yellow { color: #ca8a04; }
.stat-red { color: #dc2626; }

.analytics-group-title {
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  text-align: center;
  margin: 14px 0 8px;
  letter-spacing: 0.5px;
}

.analytics-pump-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
}

.apc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.apc-title {
  font-weight: 700;
  font-size: 14px;
  color: #1f2937;
}

.apc-reports {
  font-size: 11px;
  color: #9ca3af;
}

.apc-metric {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.apc-label {
  font-size: 12px;
  color: #6b7280;
  width: 52px;
  flex-shrink: 0;
}

.apc-bar-wrap {
  flex: 1;
  height: 12px;
  background: #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}

.apc-bar {
  height: 100%;
  border-radius: 6px;
  transition: width 0.4s ease;
}

.bar-green { background: #16a34a; }
.bar-yellow { background: #ca8a04; }
.bar-red { background: #dc2626; }

.apc-pct {
  font-size: 13px;
  font-weight: 700;
  width: 40px;
  text-align: right;
  flex-shrink: 0;
}

.apc-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid #f3f4f6;
}

.apc-conditions {
  letter-spacing: 1px;
}

.apc-detail {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 4px;
  text-align: center;
}

.apc-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-ok { background: #dcfce7; color: #166534; }
.badge-off { background: #e5e7eb; color: #374151; }
.badge-problem { background: #fef9c3; color: #854d0e; }
.badge-breakdown { background: #fee2e2; color: #991b1b; }

.apc-alert {
  border-color: #fca5a5;
  background: #fff5f5;
}

.apc-streak {
  font-size: 12px;
  color: #dc2626;
  background: #fef2f2;
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 8px;
}

/* ── Fleet overview table ── */
.fleet-table-wrap {
  margin: 12px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.fleet-table-title {
  font-size: 12px;
  font-weight: 700;
  color: #1e40af;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.fleet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.fleet-table th {
  background: #eff6ff;
  padding: 6px 6px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  white-space: nowrap;
}

.fleet-table td {
  padding: 6px 6px;
  border: 1px solid #e5e7eb;
  font-size: 12px;
}

.fleet-table .ft-pump {
  font-weight: 700;
  white-space: nowrap;
}

.fleet-table .ft-center {
  text-align: center;
}

.fleet-table .streak-warn {
  color: #ca8a04;
  font-weight: 700;
}

.fleet-table .streak-danger {
  color: #dc2626;
  font-weight: 700;
  background: #fef2f2;
}

/* ── Water level cards ── */
.wl-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
}

.wl-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 13px;
}

.wl-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.wl-card-body {
  font-size: 12px;
  color: #4b5563;
}

.wl-advice {
  font-size: 11px;
  font-style: italic;
  margin-top: 2px;
  color: #6b7280;
}

/* ── Utility ── */
.hidden { display: none !important; }
