/* ─── FarmMap NZ — Design System ─────────────────────────────────── */

:root {
  --fm-green-900: #1a3a2a;
  --fm-green-800: #22452f;
  --fm-green-700: #2d5a40;
  --fm-green-500: #4a7c59;
  --fm-green-300: #7fad8e;
  --fm-green-100: #e8f0eb;

  --fm-rust-700:  #8b3a1e;
  --fm-rust-500:  #b84d28;
  --fm-rust-400:  #c4622d;
  --fm-rust-100:  #f5e8e1;

  --fm-amber-700: #92570f;
  --fm-amber-400: #d97706;
  --fm-amber-100: #fef3c7;

  --fm-blue-700:  #1d4ed8;
  --fm-blue-600:  #2563a8;
  --fm-blue-200:  #bcd4f0;
  --fm-blue-100:  #eff6ff;

  --fm-stone-900: #1c1a17;
  --fm-stone-700: #3c3834;
  --fm-stone-600: #5a5550;
  --fm-stone-400: #8c8680;
  --fm-stone-300: #c4bfb8;
  --fm-stone-200: #dedad5;
  --fm-stone-100: #f4f1ec;
  --fm-white:     #fdfcfa;

  --font-body:    'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:  0 10px 15px rgba(0,0,0,.06), 0 4px 6px rgba(0,0,0,.05);

  --nav-h: 56px;
}

/* ─── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  color: var(--fm-stone-900);
  background: var(--fm-stone-100);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
input, button, select, textarea { font: inherit; }
a { color: var(--fm-green-700); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; }
h1,h2,h3,h4 { font-weight: 700; letter-spacing: -0.02em; color: var(--fm-green-900); line-height: 1.2; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }

/* ─── Nav ────────────────────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 0;
  height: var(--nav-h);
  background: var(--fm-green-900);
  border-bottom: 3px solid var(--fm-green-500);
  padding: 0 1.25rem;
}
.nav-logo {
  display: flex; align-items: center; gap: .5rem;
  color: var(--fm-white); font-weight: 700; font-size: 1rem;
  letter-spacing: -0.01em; text-decoration: none; flex-shrink: 0;
}
.nav-logo:hover { text-decoration: none; opacity: .9; }
.nav-logo svg { color: var(--fm-green-300); }
.nav-links {
  display: flex; align-items: center; gap: .125rem;
  margin-left: 1.5rem; flex: 1;
}
.nav-link {
  padding: .375rem .75rem; border-radius: var(--radius-sm);
  color: var(--fm-green-100); font-size: .875rem; font-weight: 500;
  text-decoration: none; transition: background .15s, color .15s;
}
.nav-link:hover, .nav-link.active {
  background: var(--fm-green-800); color: var(--fm-white);
  text-decoration: none;
}
.nav-end {
  display: flex; align-items: center; gap: .75rem; margin-left: auto;
}
.nav-user {
  display: flex; align-items: center; gap: .5rem;
  color: var(--fm-green-100); font-size: .875rem;
}
.nav-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--fm-green-700); color: var(--fm-white);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; flex-shrink: 0;
}
.nav-menu-btn {
  display: none;
  background: none; border: none; color: var(--fm-green-100);
  cursor: pointer; padding: .375rem;
}
@media (max-width: 767px) {
  .nav-links { display: none; }
  .nav-links.open { display: flex; flex-direction: column; align-items: flex-start;
    position: absolute; top: var(--nav-h); left: 0; right: 0;
    background: var(--fm-green-900); padding: .5rem 1rem 1rem; border-bottom: 2px solid var(--fm-green-700); }
  .nav-menu-btn { display: flex; }
}

/* ─── Page shell ─────────────────────────────────────────────────── */
.page { padding: 1.5rem 1.25rem; max-width: 1200px; margin: 0 auto; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-title { font-size: 1.5rem; }
.breadcrumbs {
  font-size: .8125rem; color: var(--fm-stone-600); margin-bottom: .75rem;
}
.breadcrumbs a { color: var(--fm-stone-600); }
.breadcrumbs a:hover { color: var(--fm-green-700); text-decoration: underline; }
.breadcrumbs span::before { content: ' / '; color: var(--fm-stone-300); }

/* ─── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--fm-white); border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm); border: 1px solid var(--fm-stone-200);
  overflow: hidden;
}
.card-header {
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--fm-stone-200);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.card-body { padding: 1.25rem; }
.card-footer {
  padding: .875rem 1.25rem; border-top: 1px solid var(--fm-stone-200);
  background: var(--fm-stone-100); font-size: .875rem;
}

/* ─── Grid ───────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 1023px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 767px)  { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .375rem;
  padding: .5rem 1rem; border-radius: var(--radius-sm); font-size: .875rem;
  font-weight: 600; border: 1.5px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  line-height: 1.4; white-space: nowrap; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: .3125rem .75rem; font-size: .8125rem; }
.btn-lg { padding: .6875rem 1.375rem; font-size: 1rem; }
.btn-full { width: 100%; }
.btn-primary { background: var(--fm-green-900); color: var(--fm-white); border-color: var(--fm-green-900); }
.btn-primary:hover { background: var(--fm-green-700); border-color: var(--fm-green-700); }
.btn-secondary { background: transparent; color: var(--fm-green-900); border-color: var(--fm-green-900); }
.btn-secondary:hover { background: var(--fm-green-100); }
.btn-danger { background: var(--fm-rust-700); color: var(--fm-white); border-color: var(--fm-rust-700); }
.btn-danger:hover { background: var(--fm-rust-500); border-color: var(--fm-rust-500); }
.btn-ghost { background: transparent; color: var(--fm-stone-600); border-color: transparent; }
.btn-ghost:hover { background: var(--fm-stone-100); color: var(--fm-stone-900); }
.btn-icon { padding: .4375rem; aspect-ratio: 1; }

/* ─── Forms ──────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3125rem; }
.field label { font-size: .875rem; font-weight: 600; color: var(--fm-stone-700); }
.field-hint { font-weight: 400; color: var(--fm-stone-400); font-size: .8125rem; margin-left: .25rem; }
.field input, .field select, .field textarea {
  padding: .5rem .75rem; border: 1.5px solid var(--fm-stone-300);
  border-radius: var(--radius-sm); background: var(--fm-white);
  color: var(--fm-stone-900); transition: border-color .15s, box-shadow .15s;
  width: 100%; font-size: .9375rem;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--fm-green-500);
  box-shadow: 0 0 0 3px rgba(74,124,89,.15);
}
.field textarea { resize: vertical; min-height: 80px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.check-label { display: flex; align-items: center; gap: .375rem; font-size: .875rem; cursor: pointer; }
.check-label input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--fm-green-700); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 479px) { .form-grid-2 { grid-template-columns: 1fr; } }

/* ─── Alerts / Flash ─────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .875rem;
  display: flex; gap: .5rem; align-items: flex-start;
}
.alert ul { padding-left: 1.25rem; list-style: disc; }
.alert-error   { background: var(--fm-rust-100); color: var(--fm-rust-700); border: 1px solid #f0c4b4; }
.alert-success { background: var(--fm-green-100); color: var(--fm-green-700); border: 1px solid #b6d4bf; }
.alert-warning { background: var(--fm-amber-100); color: var(--fm-amber-700); border: 1px solid #fcd580; }
.alert-info    { background: var(--fm-blue-100); color: var(--fm-blue-700); border: 1px solid #bcd4f0; }

/* Service alert strip */
.alert-strip {
  background: var(--fm-rust-100); border-bottom: 2px solid var(--fm-rust-400);
  padding: .625rem 1.25rem; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; font-size: .875rem; color: var(--fm-rust-700);
}
.alert-strip a { color: var(--fm-rust-700); font-weight: 600; text-decoration: underline; }

/* ─── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: .1875rem .625rem;
  border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--fm-green-100); color: var(--fm-green-700); }
.badge-rust   { background: var(--fm-rust-100);  color: var(--fm-rust-700); }
.badge-amber  { background: var(--fm-amber-100); color: var(--fm-amber-700); }
.badge-stone  { background: var(--fm-stone-200); color: var(--fm-stone-600); }
.badge-blue   { background: var(--fm-blue-100);  color: var(--fm-blue-700); }

/* ─── Tables ─────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  text-align: left; padding: .625rem 1rem; font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--fm-stone-600);
  background: var(--fm-stone-100); border-bottom: 2px solid var(--fm-stone-200);
}
td { padding: .75rem 1rem; border-bottom: 1px solid var(--fm-stone-200); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--fm-stone-100); }
.td-actions { display: flex; gap: .375rem; align-items: center; }

/* ─── Stat cards (dashboard) ─────────────────────────────────────── */
.stat-card { padding: 1.25rem; }
.stat-label { font-size: .8125rem; font-weight: 600; color: var(--fm-stone-600); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .375rem; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--fm-green-900); line-height: 1; }
.stat-sub   { font-size: .8125rem; color: var(--fm-stone-400); margin-top: .25rem; }

/* ─── Property cards ─────────────────────────────────────────────── */
.property-card { text-decoration: none; display: block; }
.property-card:hover { text-decoration: none; box-shadow: var(--shadow-md); transform: translateY(-1px); transition: box-shadow .15s, transform .15s; }
.property-card .card-body { padding: 1rem; }
.property-name { font-size: 1rem; font-weight: 700; color: var(--fm-green-900); margin-bottom: .25rem; }
.property-meta { font-size: .8125rem; color: var(--fm-stone-600); }
.property-count-link { color: var(--fm-green-700); font-weight: 600; text-decoration: none; }
.property-count-link:hover { text-decoration: underline; }

/* ─── Component type chips ───────────────────────────────────────── */
.type-chip {
  display: inline-flex; align-items: center; gap: .3125rem;
  padding: .1875rem .625rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
}
.type-chip-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ─── Auth layout ────────────────────────────────────────────────── */
.auth-body { background: var(--fm-stone-100); display: flex; min-height: 100dvh; align-items: flex-start; justify-content: center; padding: 2rem 1rem; }
.auth-wrap { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 1rem; }
.auth-logo {
  display: flex; align-items: center; gap: .625rem; justify-content: center;
  color: var(--fm-green-900); font-size: 1.125rem; font-weight: 800; letter-spacing: -0.02em;
  text-decoration: none; padding: .5rem 0;
}
.auth-logo:hover { text-decoration: none; opacity: .85; }
.auth-card { background: var(--fm-white); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); border: 1px solid var(--fm-stone-200); padding: 2rem; }
.auth-card h1 { margin-bottom: .375rem; }
.auth-sub { color: var(--fm-stone-600); font-size: .9375rem; margin-bottom: 1.25rem; }
.auth-footer { font-size: .875rem; color: var(--fm-stone-600); text-align: center; margin-top: .5rem; }
.link-muted { color: var(--fm-stone-600); font-size: .875rem; }
.link-muted:hover { color: var(--fm-green-700); }

/* ─── Mono / detail fields ───────────────────────────────────────── */
.mono { font-family: var(--font-mono); font-size: .875em; }
.detail-grid { display: grid; grid-template-columns: max-content 1fr; gap: .375rem 1rem; font-size: .9375rem; }
.detail-key { font-weight: 600; color: var(--fm-stone-600); font-size: .8125rem; text-transform: uppercase; letter-spacing: .05em; padding-top: .125rem; }
.detail-val { color: var(--fm-stone-900); }

/* ─── Empty state ────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--fm-stone-600); }
.empty-state h3 { color: var(--fm-stone-700); margin-bottom: .5rem; }
.empty-state p { font-size: .9375rem; margin-bottom: 1.25rem; }

/* ─── Toasts ─────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.toast {
  background: var(--fm-stone-900); color: var(--fm-white);
  padding: .75rem 1.125rem; border-radius: var(--radius-md);
  font-size: .875rem; box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease; pointer-events: auto;
  max-width: 320px;
}
.toast.toast-success { background: var(--fm-green-700); }
.toast.toast-error   { background: var(--fm-rust-700); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Misc utils ─────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.text-muted  { color: var(--fm-stone-600); }
.text-sm     { font-size: .875rem; }
.text-xs     { font-size: .75rem; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.hidden { display: none; }
.w-full { width: 100%; }
.divider { border: none; border-top: 1px solid var(--fm-stone-200); margin: 1rem 0; }
