/* FarmMint shared components (plain CSS). Catalogue: docs/DESIGN_SYSTEM.md §5.
   Uses tokens from tokens.css only. Shared by Admin and Website. */

/* Buttons */
.fm-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--fm-space-2);
  min-height: 40px; padding: 0 var(--fm-space-4);
  border: 1px solid transparent; border-radius: var(--fm-radius-md);
  font: 600 14px/20px var(--fm-font); text-decoration: none; cursor: pointer;
}
.fm-btn:focus-visible { outline: 2px solid var(--fm-primary); outline-offset: 2px; box-shadow: var(--fm-focus-ring); }
.fm-btn--primary { background: var(--fm-primary); color: #fff; }
.fm-btn--primary:hover { background: var(--fm-primary-dark); }
/* Brand green fill with dark text (#1F2937 on #4CAF61 ≈ 5.3:1, AA); navy-on-green is only ~4.1:1 and white-on-green ~2.7:1 */
.fm-btn--cta { background: var(--fm-accent); color: var(--fm-text); }
.fm-btn--cta:hover { filter: brightness(0.95); }
.fm-btn--outline { background: transparent; color: var(--fm-primary); border-color: var(--fm-primary); }
.fm-btn--outline:hover { background: var(--fm-background); }
.fm-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Inputs — ONE spacing system for every form: 44 px controls, 6 px label gap, 16 px gap between fields */
.fm-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fm-field > label { font: 600 13px/18px var(--fm-font); color: var(--fm-text); }
.fm-input {
  height: 44px; padding: 0 var(--fm-space-3); background: var(--fm-surface);
  border: 1px solid var(--fm-border); border-radius: 10px;
  font: var(--fm-text-body); color: var(--fm-text); width: 100%;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
.fm-input:hover { border-color: #cfd5de; }
textarea.fm-input { height: auto; padding: 10px var(--fm-space-3); min-height: 104px; resize: vertical; line-height: 22px; }
.fm-input:focus { outline: none; border-color: var(--fm-primary); box-shadow: var(--fm-focus-ring); }
.fm-field--error .fm-input { border-color: var(--fm-error); }
.fm-field__error { margin: 0; color: var(--fm-error); font: var(--fm-text-caption); }
.fm-field__error:empty { display: none; }
.fm-field__hint { margin: 0; color: var(--fm-text-secondary); font: var(--fm-text-caption); }
/* Reusable form layout: .fm-form (1 column) / .fm-form--2 (2 columns, 1 column on narrow screens); .fm-field--wide spans both */
.fm-form { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 640px) { .fm-form--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; } .fm-form--2 > .fm-field--wide { grid-column: 1 / -1; } }
.fm-modal--lg { max-width: 640px; }

/* Cards */
.fm-card {
  background: var(--fm-surface); border: 1px solid var(--fm-border);
  border-radius: var(--fm-radius-md); box-shadow: var(--fm-shadow-1); padding: var(--fm-space-4);
}
.fm-card__title { font: var(--fm-text-h3); color: var(--fm-primary); margin: 0 0 var(--fm-space-2); }
.fm-stat__label { color: var(--fm-text-secondary); font: var(--fm-text-body); margin: 0; }
.fm-stat__value { font: var(--fm-text-h1); color: var(--fm-primary); margin: var(--fm-space-1) 0 0; }

/* Status chips: text + colour, never colour alone */
.fm-chip {
  display: inline-block; padding: 2px var(--fm-space-3); border-radius: var(--fm-radius-full);
  font: 600 12px/16px var(--fm-font); background: #eef0f3; color: var(--fm-text);
}
.fm-chip--success { background: var(--fm-accent-light); color: var(--fm-accent-text); }
.fm-chip--warning { background: #fef3c7; color: #92400e; }
.fm-chip--error { background: #fee2e2; color: #991b1b; }
.fm-chip--info { background: #dbeafe; color: #1e40af; }

/* Tables: scroll horizontally on small screens */
.fm-table-wrap { overflow-x: auto; border: 1px solid var(--fm-border); border-radius: var(--fm-radius-md); background: var(--fm-surface); }
.fm-table { width: 100%; border-collapse: collapse; font: var(--fm-text-body); }
.fm-table th { position: sticky; top: 0; text-align: left; background: var(--fm-background); color: var(--fm-text-secondary); font-weight: 600; }
.fm-table th, .fm-table td { padding: var(--fm-space-3) var(--fm-space-4); border-bottom: 1px solid var(--fm-border); white-space: nowrap; }
.fm-table tbody tr:hover { background: var(--fm-background); }
.fm-table tbody tr:last-child td { border-bottom: 0; }

/* States */
.fm-empty { text-align: center; padding: var(--fm-space-12) var(--fm-space-4); color: var(--fm-text-secondary); }
.fm-empty__icon { font-size: 32px; }
.fm-empty__title { font: var(--fm-text-h3); color: var(--fm-text); margin: var(--fm-space-2) 0 var(--fm-space-1); }

/* OFFICIAL LOGO (assets/brand/farmmint-logo-original.webp, 1261×1108, white background).
   Never stretch: set ONE dimension and let the other follow the aspect ratio.
   On navy/dark areas place it on a white card (.fm-logo-card) — the artwork is never edited. */
.fm-logo { display: block; height: var(--fm-logo-h, 56px); width: auto; aspect-ratio: 1261 / 1108; }
.fm-logo-card { background: #fff; border-radius: var(--fm-radius-md); padding: var(--fm-space-2); display: inline-flex; }
/* Compact emblem = a crop of the original (circle mark only), shown via CSS from the same file. */
.fm-logo-emblem {
  --s: var(--fm-emblem-size, 40px);
  display: block; flex: none; width: var(--s); height: var(--s);
  background: #fff url('../assets/brand/farmmint-logo-original.webp') no-repeat;
  background-size: calc(var(--s) * 1.7274) calc(var(--s) * 1.5178);  /* 1261/730, 1108/730 */
  background-position: calc(var(--s) * -0.3575) calc(var(--s) * -0.026); /* crop origin 261,19 of 730×730 */
  border-radius: var(--fm-radius-md);
}

/* Small / danger button variants */
.fm-btn--sm { min-height: 32px; padding: 0 var(--fm-space-3); font-size: 13px; border-radius: var(--fm-radius-sm); }
.fm-btn--danger { background: var(--fm-error); color: #fff; }
.fm-btn--danger:hover { filter: brightness(0.92); }
.fm-btn--outline-danger { background: transparent; color: var(--fm-error); border-color: var(--fm-error); }
.fm-btn--outline-danger:hover { background: #fee2e2; }
select.fm-input { appearance: auto; }

/* Sortable table headers + row actions + pagination */
.fm-th-btn { all: unset; cursor: pointer; display: inline-flex; gap: var(--fm-space-1); align-items: center; font-weight: 600; color: inherit; }
.fm-th-btn:focus-visible { outline: 2px solid var(--fm-primary); outline-offset: 2px; }
.fm-actions { display: flex; gap: var(--fm-space-2); }
.fm-pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--fm-space-3); flex-wrap: wrap; padding: var(--fm-space-3) var(--fm-space-4); border-top: 1px solid var(--fm-border); font: var(--fm-text-body); color: var(--fm-text-secondary); }
.fm-pagination__btns { display: flex; gap: var(--fm-space-2); }

/* Modal (bottom-aligned sheet on mobile) */
.fm-modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgb(0 0 0 / 50%); display: grid; place-items: center; padding: var(--fm-space-4); }
.fm-modal { background: var(--fm-surface); border-radius: var(--fm-radius-lg); box-shadow: var(--fm-shadow-2); width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; }
.fm-modal__header { padding: var(--fm-space-4) var(--fm-space-6) 0; }
.fm-modal__title { font: var(--fm-text-h2); color: var(--fm-primary); margin: 0; }
.fm-modal__body { padding: var(--fm-space-4) var(--fm-space-6); display: grid; gap: var(--fm-space-4); }
.fm-modal__footer { display: flex; justify-content: flex-end; gap: var(--fm-space-3); padding: 0 var(--fm-space-6) var(--fm-space-6); flex-wrap: wrap; }
@media (max-width: 639px) {
  .fm-modal-backdrop { align-items: end; padding: 0; }
  .fm-modal { max-width: none; border-radius: var(--fm-radius-lg) var(--fm-radius-lg) 0 0; }
}

/* Row action menu (fixed-positioned by JS) */
.fm-menu { position: fixed; z-index: 90; min-width: 180px; background: var(--fm-surface); border: 1px solid var(--fm-border); border-radius: var(--fm-radius-md); box-shadow: var(--fm-shadow-2); padding: var(--fm-space-1); display: flex; flex-direction: column; }
.fm-menu__item { all: unset; box-sizing: border-box; cursor: pointer; padding: var(--fm-space-3); border-radius: var(--fm-radius-sm); font: var(--fm-text-body); color: var(--fm-text); }
.fm-menu__item:hover, .fm-menu__item:focus-visible { background: var(--fm-background); }
.fm-menu__item:focus-visible { outline: 2px solid var(--fm-primary); }
.fm-menu__item--danger { color: var(--fm-error); }
.fm-actions-cell { text-align: right; width: 1%; }

/* Toasts */
.fm-toasts { position: fixed; right: var(--fm-space-4); bottom: var(--fm-space-4); z-index: 120; display: grid; gap: var(--fm-space-2); max-width: min(360px, calc(100vw - 32px)); }
.fm-toasts .fm-alert { box-shadow: var(--fm-shadow-2); }
/* On phones toasts sit at the top so they never cover bottom action bars (drawer footers, bulk bars) */
@media (max-width: 639px) { .fm-toasts { bottom: auto; top: 76px; left: var(--fm-space-3); right: var(--fm-space-3); max-width: none; } }

/* Alerts */
.fm-alert { display: flex; gap: var(--fm-space-3); align-items: flex-start; padding: var(--fm-space-3) var(--fm-space-4); border-radius: var(--fm-radius-md); border: 1px solid transparent; font: var(--fm-text-body); }
.fm-alert--success { background: var(--fm-accent-light); color: var(--fm-accent-text); border-color: #bfe3c6; }
.fm-alert--warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.fm-alert--error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.fm-alert--info { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }

/* Loading skeleton */
.fm-skeleton { display: grid; gap: var(--fm-space-3); }
.fm-skeleton__line { height: 16px; border-radius: var(--fm-radius-sm); background: linear-gradient(90deg, #eceff4 25%, #f7f9fc 50%, #eceff4 75%); background-size: 200% 100%; animation: fm-shimmer 1.4s linear infinite; }
@keyframes fm-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .fm-skeleton__line { animation: none; } }

/* Tabs */
.fm-tabs { display: flex; gap: var(--fm-space-1); border-bottom: 1px solid var(--fm-border); margin-bottom: var(--fm-space-4); overflow-x: auto; }
.fm-tab { all: unset; box-sizing: border-box; cursor: pointer; padding: var(--fm-space-3) var(--fm-space-4); font: 600 14px/20px var(--fm-font); color: var(--fm-text-secondary); border-bottom: 3px solid transparent; white-space: nowrap; }
.fm-tab:hover { color: var(--fm-primary); }
.fm-tab[aria-selected='true'] { color: var(--fm-primary); border-bottom-color: var(--fm-accent); }
.fm-tab:focus-visible { outline: 2px solid var(--fm-primary); outline-offset: -2px; box-shadow: var(--fm-focus-ring); }
.fm-tabpanel:focus-visible { outline: 2px solid var(--fm-primary); outline-offset: 4px; }

/* Checkbox */
.fm-check { display: inline-flex; align-items: center; gap: var(--fm-space-2); cursor: pointer; font: var(--fm-text-body); min-height: 48px; border-radius: var(--fm-radius-md); transition: background-color 0.15s ease-out; }
.fm-check--bare { min-width: 48px; justify-content: center; }
.fm-check:hover { background: var(--fm-background); }
.fm-check input { width: 20px; height: 20px; accent-color: var(--fm-primary); cursor: pointer; margin: 0; }
.fm-check input:focus-visible { outline: 2px solid var(--fm-primary); outline-offset: 2px; }
.fm-check input:disabled { cursor: not-allowed; }

/* Bar chart */
.fm-chart { display: grid; gap: var(--fm-space-2); }
.fm-chart__bars { display: flex; align-items: stretch; gap: var(--fm-space-3); height: 200px; padding-top: var(--fm-space-2); border-bottom: 1px solid var(--fm-border); }
.fm-chart__col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: var(--fm-space-1); }
.fm-chart__val { font: var(--fm-text-caption); color: var(--fm-text-secondary); }
.fm-chart__track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; min-height: 0; }
.fm-chart__bar { width: 100%; max-width: 56px; background: var(--fm-primary); border-radius: var(--fm-radius-sm) var(--fm-radius-sm) 0 0; min-height: 2px; }
.fm-chart__labels { display: flex; gap: var(--fm-space-3); }
.fm-chart__labels span { flex: 1; text-align: center; font: var(--fm-text-caption); color: var(--fm-text-secondary); }

/* Side drawer (right-hand panel; full-width sheet on mobile) */
.fm-drawer-backdrop { position: fixed; inset: 0; z-index: 95; background: rgb(0 0 0 / 45%); display: flex; justify-content: flex-end; animation: fm-drawer-fade 0.2s ease-out; }
.fm-drawer { width: min(520px, 100%); height: 100%; background: var(--fm-surface); box-shadow: var(--fm-shadow-2); display: flex; flex-direction: column; animation: fm-drawer-in 0.28s cubic-bezier(0.22, 0.8, 0.3, 1); }
.fm-drawer__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--fm-space-3); padding: var(--fm-space-4) var(--fm-space-6); border-bottom: 1px solid var(--fm-border); }
.fm-drawer__title { margin: 0; font: var(--fm-text-h2); color: var(--fm-primary); }
.fm-drawer__sub { margin: 2px 0 0; font: var(--fm-text-body); color: var(--fm-text-secondary); }
.fm-drawer__close { all: unset; box-sizing: border-box; flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--fm-radius-md); color: var(--fm-text-secondary); cursor: pointer; }
.fm-drawer__close:hover { background: var(--fm-background); color: var(--fm-primary); }
.fm-drawer__close:focus-visible { outline: 2px solid var(--fm-primary); box-shadow: var(--fm-focus-ring); }
.fm-drawer__body { flex: 1; overflow-y: auto; padding: var(--fm-space-4) var(--fm-space-6) var(--fm-space-6); }
.fm-drawer__footer { display: flex; flex-wrap: wrap; gap: var(--fm-space-2); padding: var(--fm-space-3) var(--fm-space-6); border-top: 1px solid var(--fm-border); background: var(--fm-surface); }
@keyframes fm-drawer-in { from { transform: translateX(32px); opacity: 0; } }
@keyframes fm-drawer-fade { from { opacity: 0; } }
@media (max-width: 639px) { .fm-drawer__header, .fm-drawer__body, .fm-drawer__footer { padding-left: var(--fm-space-4); padding-right: var(--fm-space-4); } }
@media (prefers-reduced-motion: reduce) { .fm-drawer, .fm-drawer-backdrop { animation: none; } }

.fm-muted { color: var(--fm-text-secondary); }
.fm-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
