:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --color-bg: #f8faf9;
  --color-card: #ffffff;
  --color-text: #1e293b;
  --color-muted: #64748b;
  --color-border: #e2e8f0;

  --color-primary: #15803d;
  --color-primary-hover: #166534;
  --color-danger: #dc2626;
  --color-danger-bg: #fef2f2;
  --color-warning: #d97706;
  --color-warning-bg: #fffbeb;
  --color-info: #0284c7;
  --color-success: #16a34a;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
}

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

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  font-size: 15px;
  min-width: 320px;
}

.container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 14px 60px;
}

.container-admin {
  max-width: 1320px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0 14px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #14532d;
  text-decoration: none;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-badge {
  font-size: 0.82rem;
  color: var(--color-muted);
}
.nav-link {
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

/* Offline & Sync Banner */
.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 14px;
  font-weight: 500;
}
.banner-offline {
  background: #ffedd5;
  color: #9a3412;
  border: 1px solid #fed7aa;
}
.banner-syncing {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}
.banner-outbox {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fef08a;
}

/* Sections */
.section {
  margin-bottom: 22px;
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  cursor: pointer;
  user-select: none;
}
.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.badge-count {
  background: var(--color-border);
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 600;
}
.badge-count-overdue {
  background: #fee2e2;
  color: #991b1b;
}

/* Task Cards */
.task-card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  border-left: 6px solid var(--area-colour, #9FD8A3);
  overflow: hidden;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.task-card.is-overdue {
  background: #fffafa;
  border-top-color: #fecaca;
  border-right-color: #fecaca;
  border-bottom-color: #fecaca;
}
.task-card.is-pending {
  border-left-style: dashed;
  opacity: 0.9;
}
.task-main {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.task-info {
  flex: 1;
  min-width: 0;
}
/* Inline-editable table cells (admin) */
.cell-input {
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--color-text);
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
}
.cell-input:hover {
  border-color: var(--color-border);
  background: #fff;
}
.cell-input:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(21, 128, 61, 0.12);
}
.cell-input-name {
  font-weight: 600;
}
select.cell-input {
  cursor: pointer;
}
.cell-status {
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 2px;
  padding-left: 7px;
}
.cell-status-saving {
  color: var(--color-muted);
}
.cell-status-saved {
  color: var(--color-success);
}
.cell-status-error {
  color: var(--color-danger);
}
tr.row-error td {
  background: var(--color-danger-bg);
}

/* Notes cell button (icon only) */
.cell-notes-btn {
  width: 36px;
  padding: 4px 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

/* Active toggle switch */
.switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 40px;
  height: 22px;
  margin: 0;
  cursor: pointer;
}
.switch-track {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.15s ease;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}
.switch input:checked + .switch-track {
  background: var(--color-primary);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(18px);
}
.switch input:focus-visible + .switch-track {
  box-shadow: 0 0 0 2px rgba(21, 128, 61, 0.35);
}

/* Area group headers (To Do list) */
.area-group {
  margin-bottom: 18px;
}
.area-group + .area-group {
  margin-top: 20px;
}
.area-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  margin-bottom: 9px;
  border-radius: var(--radius-sm);
  border-left: 6px solid var(--area-colour, #9FD8A3);
  background: #eef2f1; /* fallback for no color-mix support */
  background: color-mix(in srgb, var(--area-colour, #9FD8A3) 32%, #ffffff);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
}
.area-group-emoji {
  font-size: 1.1rem;
  line-height: 1;
}
.area-group-name {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}
.area-group-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.65);
  padding: 1px 8px;
  border-radius: 999px;
}

.task-area-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}
.task-name {
  font-size: 0.98rem;
  font-weight: 600;
  word-break: break-word;
  line-height: 1.35;
}
.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--color-muted);
  margin-top: 4px;
  align-items: center;
}
.meta-chip {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
}
.meta-chip-overdue {
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 600;
}

/* Action Button */
.btn-done {
  min-width: 64px;
  height: 48px;
  padding: 0 16px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
}
.btn-done:active {
  background: var(--color-primary-hover);
  transform: scale(0.96);
}
.btn-done:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}
.btn-undo {
  height: 36px;
  padding: 0 12px;
  background: #f1f5f9;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-undo:hover {
  background: #e2e8f0;
}
.btn-undo:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Note Field */
.note-toggle {
  display: inline-block;
  font-size: 0.78rem;
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 0;
  text-decoration: underline;
}
.note-box {
  padding: 0 14px 12px;
  animation: fadeIn 0.15s ease;
}
.note-input {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.88rem;
  resize: vertical;
  background: #fcfdfd;
}
.note-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Recently Done List */
.history-item {
  background: var(--color-card);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.history-text {
  font-size: 0.88rem;
  min-width: 0;
  flex: 1;
}
.history-title {
  font-weight: 600;
  word-break: break-word;
}
.history-sub {
  font-size: 0.75rem;
  color: var(--color-muted);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 24px 16px;
  background: var(--color-card);
  border-radius: var(--radius-md);
  border: 1px dashed var(--color-border);
  color: var(--color-muted);
  font-size: 0.9rem;
}

/* Forms & Auth */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-card);
  padding: 28px 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
}
.login-header {
  text-align: center;
  margin-bottom: 22px;
}
.farm-logo {
  font-size: 1.6rem;
  font-weight: 800;
  color: #14532d;
}
.login-subtitle {
  font-size: 0.88rem;
  color: var(--color-muted);
  margin-top: 4px;
}
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.form-input, .form-select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: #ffffff;
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(21, 128, 61, 0.15);
}
.form-group-checkbox {
  margin-bottom: 18px;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn {
  height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}
.btn-secondary {
  background: #e2e8f0;
  color: var(--color-text);
}
.btn-secondary:hover {
  background: #cbd5e1;
}
.btn-block {
  width: 100%;
}
.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 0.8rem;
}
.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.alert-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid #fca5a5;
}

/* Admin Tabs & Grid */
.admin-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 20px;
}
.tab-btn {
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--color-card);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  text-align: center;
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.2;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--color-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-overdue .stat-value { color: var(--color-danger); }
.stat-today .stat-value { color: var(--color-primary); }
.stat-soon .stat-value { color: var(--color-warning); }
.stat-paused .stat-value { color: #8b5cf6; }

.card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  padding: 16px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}
.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
}
.data-table th {
  background: #f8fafc;
  color: var(--color-muted);
  font-weight: 600;
}
.data-table tr:hover {
  background: #f8fafc;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-card {
  background: white;
  width: 100%;
  max-width: 520px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}
.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
