/* ============================================================
   BGF Sentinel — design system ("Sentinel Light")

   Light, professional, presentation-layer foundation for the
   worker app, supervisor console and report portal. Loaded FIRST
   after theme.css / grove.css / buttons.css, so each page's own
   stylesheet can build on these tokens and components.

   Palette: soft field greens on paper. NO dark backgrounds.
   ============================================================ */

:root {
  /* ── Tokens ─────────────────────────────────────────── */
  --sd-bg:       #F6F8F6;   /* page background            */
  --sd-surface:  #FFFFFF;   /* cards                      */
  --sd-ink:      #15211A;   /* primary text               */
  --sd-ink2:     #5B6B60;   /* secondary text             */
  --sd-line:     #E2E8E3;   /* hairlines                  */
  --sd-brand:    #177245;   /* deep green (primary)       */
  --sd-brand-dark:#0F5A33;  /* pressed / hover primary    */
  --sd-brand-soft:#E7F1EA;  /* tinted wash                */
  --sd-warn:     #C77700;
  --sd-warn-soft:#FCF3E3;
  --sd-danger:   #C0392B;
  --sd-danger-soft:#FBECEA;
  --sd-info:     #2563EB;
  --sd-info-soft:#EAF1FE;
  --sd-ok:       #177245;
  --sd-ok-soft:  #E7F1EA;

  --sd-r:        14px;       /* card radius                */
  --sd-r-ctl:    10px;       /* control radius             */
  --sd-shadow:   0 1px 2px rgba(21, 33, 26, 0.05),
                 0 4px 14px rgba(21, 33, 26, 0.06);
  --sd-shadow-lg:0 2px 4px rgba(21, 33, 26, 0.06),
                 0 12px 32px rgba(21, 33, 26, 0.10);

  /* 8px spacing scale */
  --sd-1: 8px;
  --sd-2: 16px;
  --sd-3: 24px;
  --sd-4: 32px;
  --sd-5: 40px;

  --sd-sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI",
             Roboto, "Helvetica Neue", Arial, sans-serif;
  --sd-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo,
             Consolas, "Liberation Mono", monospace;
  --sd-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ── Base ───────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
body.sd {
  margin: 0;
  background: var(--sd-bg);
  color: var(--sd-ink);
  font-family: var(--sd-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.sd h1, .sd h2, .sd h3, .sd h4 { color: var(--sd-ink); letter-spacing: -0.01em; }
.sd a { color: var(--sd-brand-dark); }
.sd ::selection { background: #CFE3D6; color: var(--sd-ink); }

/* Tabular figures for timers, coordinates and counts */
.sd .num, .sd code, .sd kbd, .sd pre, .sd .mono {
  font-family: var(--sd-mono);
  font-variant-numeric: tabular-nums;
}

/* ── Layout shells ──────────────────────────────────────── */
.sd-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.sd-wrap {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: var(--sd-2);
  padding-bottom: calc(64px + var(--sd-3)); /* room for tab bar */
}
@media (min-width: 768px) {
  .sd-wrap { max-width: 720px; padding: var(--sd-3); }
}
@media (min-width: 1100px) {
  .sd-wrap { max-width: 960px; }
}
.sd-wrap--wide { max-width: 1100px; }

/* ── Cards ──────────────────────────────────────────────── */
.sd-card {
  background: var(--sd-surface);
  border: 1px solid var(--sd-line);
  border-radius: var(--sd-r);
  box-shadow: var(--sd-shadow);
  padding: var(--sd-2);
}
@media (min-width: 768px) {
  .sd-card { padding: 20px; }
}
.sd-card + .sd-card { margin-top: var(--sd-2); }

/* ── Section titles ─────────────────────────────────────── */
.sd-sect {
  margin: var(--sd-3) 0 var(--sd-1);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sd-ink2);
}
.sd-sect:first-child { margin-top: 0; }

/* ── Buttons ────────────────────────────────────────────── */
.sd-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: var(--sd-r-ctl);
  font-family: var(--sd-sans);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.15s var(--sd-ease),
              border-color 0.15s var(--sd-ease),
              color 0.15s var(--sd-ease),
              transform 0.1s var(--sd-ease),
              box-shadow 0.15s var(--sd-ease);
}
.sd-btn:active:not(:disabled) { transform: translateY(1px); }
.sd-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.sd-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(23, 114, 69, 0.35);
}

/* Variants */
.sd-primary {
  background: var(--sd-brand);
  border-color: var(--sd-brand);
  color: #fff;
}
.sd-primary:hover:not(:disabled) { background: var(--sd-brand-dark); border-color: var(--sd-brand-dark); }
@media (hover: none) {
  .sd-primary:hover:not(:disabled) { background: var(--sd-brand); border-color: var(--sd-brand); }
}

.sd-secondary {
  background: var(--sd-surface);
  border-color: var(--sd-line);
  color: var(--sd-ink);
}
.sd-secondary:hover:not(:disabled) { border-color: #B9C6BB; background: #FAFBFA; }
.sd-secondary:active:not(:disabled) { background: var(--sd-brand-soft); border-color: var(--sd-brand); }

.sd-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--sd-brand-dark);
}
.sd-ghost:hover:not(:disabled) { background: var(--sd-brand-soft); }

.sd-danger {
  background: var(--sd-danger);
  border-color: var(--sd-danger);
  color: #fff;
}
.sd-danger:hover:not(:disabled) { background: #A93226; border-color: #A93226; }

/* Full-width block button */
.sd-block { display: flex; width: 100%; }

/* Small button (secondary actions in rows) */
.sd-sm { min-height: 40px; padding: 8px 14px; font-size: 13px; }

/* Icon-only square */
.sd-iconbtn {
  display: inline-grid;
  place-items: center;
  width: 48px; height: 48px; flex: none;
  border-radius: var(--sd-r-ctl);
  border: 1px solid var(--sd-line);
  background: var(--sd-surface);
  color: var(--sd-ink2);
  cursor: pointer;
}
.sd-iconbtn:active { background: var(--sd-brand-soft); color: var(--sd-brand-dark); }

/* ── Segmented control (farm picker etc.) ───────────────── */
.sd-seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: #EDF1ED;
  border: 1px solid var(--sd-line);
  border-radius: 12px;
}
.sd-seg button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sd-ink2);
  font: 600 14px/1 var(--sd-sans);
  cursor: pointer;
  transition: background-color 0.15s var(--sd-ease), color 0.15s var(--sd-ease);
}
.sd-seg button[aria-pressed="true"],
.sd-seg button.is-on {
  background: var(--sd-surface);
  color: var(--sd-brand-dark);
  box-shadow: var(--sd-shadow);
}

/* ── Forms ──────────────────────────────────────────────── */
.sd-field { margin: 0 0 var(--sd-2); }
.sd-field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--sd-ink2);
}
.sd-input, .sd-select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--sd-line);
  border-radius: var(--sd-r-ctl);
  background: var(--sd-surface);
  color: var(--sd-ink);
  font: 400 16px/1.4 var(--sd-sans); /* 16px stops iOS zoom */
  transition: border-color 0.15s var(--sd-ease), box-shadow 0.15s var(--sd-ease);
}
.sd-input::placeholder { color: #9AA79D; }
.sd-input:focus, .sd-select:focus {
  outline: none;
  border-color: var(--sd-brand);
  box-shadow: 0 0 0 3px rgba(23, 114, 69, 0.22);
}
.sd-hint { margin-top: 6px; font-size: 12px; color: var(--sd-ink2); }

/* ── Chips & badges ─────────────────────────────────────── */
.sd-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--sd-line);
  background: var(--sd-surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--sd-ink2);
  white-space: nowrap;
}
.sd-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.sd-badge.is-ok, .sd-chip.is-ok     { background: var(--sd-ok-soft);   color: var(--sd-brand-dark); border-color: #BFDCC9; }
.sd-badge.is-warn, .sd-chip.is-warn { background: var(--sd-warn-soft); color: #8A5300;               border-color: #F0D9A8; }
.sd-badge.is-danger, .sd-chip.is-danger { background: var(--sd-danger-soft); color: #8E2A20;         border-color: #F0BEB8; }
.sd-badge.is-info, .sd-chip.is-info { background: var(--sd-info-soft); color: #1D4ED8;               border-color: #C3D6F7; }

/* ── Stats grid ─────────────────────────────────────────── */
.sd-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sd-1);
}
@media (max-width: 479px) {
  .sd-stats { grid-template-columns: 1fr; }
}
.sd-stat {
  background: var(--sd-surface);
  border: 1px solid var(--sd-line);
  border-radius: var(--sd-r);
  padding: var(--sd-2);
  box-shadow: var(--sd-shadow);
}
.sd-stat .k {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sd-ink2);
}
.sd-stat .v {
  margin-top: 4px;
  font-family: var(--sd-mono);
  font-size: 24px;
  font-weight: 600;
  color: var(--sd-ink);
  font-variant-numeric: tabular-nums;
}

/* ── Lists ──────────────────────────────────────────────── */
.sd-list { list-style: none; margin: 0; padding: 0; }
.sd-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--sd-line);
  min-height: 56px;
}
.sd-row:last-child { border-bottom: 0; }
.sd-row .grow { flex: 1; min-width: 0; }
.sd-row .t { font-weight: 600; font-size: 15px; color: var(--sd-ink); }
.sd-row .s { font-size: 13px; color: var(--sd-ink2); margin-top: 2px; }

/* ── Bottom tab bar (mobile pattern) ────────────────────── */
.sd-tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  height: 64px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--sd-surface);
  border-top: 1px solid var(--sd-line);
  box-shadow: 0 -4px 16px rgba(21, 33, 26, 0.06);
  padding-bottom: env(safe-area-inset-bottom);
}
.sd-tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--sd-ink2);
  font: 600 11px/1 var(--sd-sans);
  cursor: pointer;
}
.sd-tabbar button .ic { font-size: 20px; line-height: 1; }
.sd-tabbar button[aria-selected="true"] { color: var(--sd-brand-dark); }

/* ── Header ─────────────────────────────────────────────── */
.sd-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--sd-surface);
  border-bottom: 1px solid var(--sd-line);
}
.sd-header-in {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sd-avatar {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  background: var(--sd-brand-soft);
  color: var(--sd-brand-dark);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
}
.sd-header .who { flex: 1; min-width: 0; }
.sd-header .who .n { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sd-header .who .r { font-size: 12px; color: var(--sd-ink2); }

/* ── Tables ─────────────────────────────────────────────── */
.sd-tablewrap {
  overflow-x: auto;
  border: 1px solid var(--sd-line);
  border-radius: var(--sd-r);
  background: var(--sd-surface);
  -webkit-overflow-scrolling: touch;
}
table.sd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.sd-table th, .sd-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--sd-line);
  font-variant-numeric: tabular-nums;
}
.sd-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sd-ink2);
  background: #FAFBFA;
  white-space: nowrap;
}
.sd-table tr:last-child td { border-bottom: 0; }

/* ── Empty states / notices ─────────────────────────────── */
.sd-empty {
  padding: var(--sd-4) var(--sd-2);
  text-align: center;
  color: var(--sd-ink2);
  font-size: 14px;
  line-height: 1.6;
}
.sd-notice {
  border: 1px solid var(--sd-line);
  border-left: 4px solid var(--sd-info);
  border-radius: var(--sd-r-ctl);
  background: var(--sd-surface);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.55;
}
.sd-notice.is-warn { border-left-color: var(--sd-warn); }
.sd-notice.is-danger { border-left-color: var(--sd-danger); }
.sd-notice.is-ok { border-left-color: var(--sd-brand); }

/* ── Responsive utilities ───────────────────────────────── */
.sd-hide-sm { display: none !important; }
@media (min-width: 480px)  { .sd-hide-sm { display: initial !important; } }
@media (max-width: 479px)  { .sd-only-sm-up { display: none !important; } }
@media (min-width: 768px)  { .sd-hide-md { display: none !important; } }
@media (max-width: 767px)  { .sd-only-md-up { display: none !important; } }

/* Two-column → one-column helper */
.sd-cols { display: grid; gap: var(--sd-2); grid-template-columns: 1fr; }
@media (min-width: 768px) { .sd-cols { grid-template-columns: 1fr 1fr; } }

/* ── Motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .sd-btn, .sd-seg button, .sd-iconbtn, .sd-tabbar button {
    transition: none !important;
  }
  .sd-btn:active:not(:disabled) { transform: none; }
}
