/* Teitei - mobile first, high contrast for reading a phone in full sun. */
:root {
  /* Genesis Pacific house palette, sampled from the Teitei logo:
     navy #0C2454 frames the product, green #489C30 is growth and crops,
     Pacific blue #0C90E4 is water, geofencing and live data. */
  --navy: #0C2454;
  --navy-2: #163B78;
  --navy-soft: #E7ECF5;

  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --ink: #12203a;
  --ink-2: #47566e;
  --ink-3: #74829a;
  --line: #d6dbe4;
  --green: #35792A;
  --green-dark: #489C30;
  --green-soft: #E6F1E2;
  --ocean: #0C6FA8;
  --ocean-soft: #E2F0FA;
  --sun: #b26a00;
  --sun-soft: #fdf0dc;
  --red: #a52121;
  --red-soft: #fbe6e5;
  --purple: #5b3d86;
  --radius: 14px;
  --topbar-h: 58px;      /* measured, and referenced by the rail and main */
  --nav-w: 200px;
  --shadow: 0 1px 2px rgba(20,40,28,.08), 0 4px 14px rgba(20,40,28,.05);
  --tap: 46px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy: #0A1A38; --navy-2: #1B4A94; --navy-soft: #16233D;
    --bg: #0B1220; --surface: #141D2E; --surface-2: #1D2839;
    --ink: #E7EDF6; --ink-2: #A9B6CA; --ink-3: #7B8AA3; --line: #2A3852;
    --green: #6BC254; --green-dark: #489C30; --green-soft: #172B18;
    --ocean: #3FA9E8; --ocean-soft: #10263A;
    --sun: #e8a33d; --sun-soft: #2e2314;
    --red: #f07b74; --red-soft: #33191a;
    --purple: #a98bd8;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.45; overscroll-behavior-y: contain;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
a { color: var(--green); }

/* ---------- layout ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--navy); color: #fff;
  height: var(--topbar-h); min-height: var(--topbar-h);
  padding: 0 12px; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.14);
}
.topbar .brand {
  display: flex; align-items: center; gap: 9px; min-width: 0; flex: none;
}
.brand-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -.2px; }
.topbar .brand small {
  font-weight: 600; font-size: 9.5px; opacity: .78; letter-spacing: .14em;
  text-transform: uppercase; white-space: nowrap;
}
.topbar .spacer { flex: 1; min-width: 4px; }
.topbar select {
  background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.3);
  border-radius: 9px; padding: 0 8px; height: 36px; font-size: 13.5px;
  /* Shrinkable, so the buttons after it are never pushed off the edge. */
  min-width: 90px; max-width: 34vw; flex: 0 1 auto;
  text-overflow: ellipsis;
}
.topbar select option { color: #000; }
.topbar .farm-label {
  font-size: 13.5px; font-weight: 600; opacity: .92;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 32vw; min-width: 0;
}
.iconbtn {
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28);
  color: #fff; border-radius: 9px; min-width: 36px; width: 36px; height: 36px;
  font-size: 15px; flex: none;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.iconbtn:hover { background: rgba(255,255,255,.26); }
main { flex: 1; padding: 12px 12px 96px; width: 100%; min-width: 0; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; overflow-x: auto; scrollbar-width: none;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-overflow-scrolling: touch;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar button {
  flex: 1 0 auto; min-width: 66px; border: 0; background: none; color: var(--ink-3);
  padding: 7px 4px 8px; font-size: 10.5px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border-top: 3px solid transparent; letter-spacing: .1px;
}
.tabbar button .ico { font-size: 19px; line-height: 1; }
.tabbar button[aria-current="true"] { color: var(--navy-2); border-top-color: var(--navy-2); background: var(--navy-soft); }
.tabbar .badge {
  position: absolute; transform: translate(16px,-4px);
  background: var(--red); color: #fff; border-radius: 9px;
  font-size: 9px; padding: 1px 5px; font-weight: 700;
}

@media (min-width: 900px) {
  :root { --topbar-h: 62px; }
  .app { flex-direction: row; }
  .topbar { position: fixed; top: 0; left: 0; right: 0; }
  /* Sits beside the rail and below the bar, both from the same variables, and
     capped so a very wide screen does not stretch the text lines. */
  main {
    margin-left: var(--nav-w);
    max-width: 1220px;
    padding: calc(var(--topbar-h) + 18px) 26px 40px;
  }
  .tabbar {
    top: var(--topbar-h); bottom: 0; right: auto; width: var(--nav-w);
    flex-direction: column; border-top: 0; border-right: 1px solid var(--line);
    overflow-y: auto; padding-top: 8px;
  }
  .tabbar button {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 10px;
    padding: 11px 16px; font-size: 14px; border-top: 0; border-left: 3px solid transparent;
  }
  .tabbar button[aria-current="true"] { border-left-color: var(--navy-2); }
  .tabbar .badge { position: static; transform: none; margin-left: auto; }
}

/* ---------- primitives ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.card.tight { padding: 11px 12px; }
.card > h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3); margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(255px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
.row { display: flex; align-items: center; gap: 9px; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3); font-weight: 700; }
.stat .value { font-size: 25px; font-weight: 700; margin-top: 3px; letter-spacing: -.5px; }
.stat .value small { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.stat .sub { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.stat.green { border-left: 4px solid var(--green); }
.stat.ocean { border-left: 4px solid var(--ocean); }
.stat.sun { border-left: 4px solid var(--sun); }
.stat.red { border-left: 4px solid var(--red); }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px;
  border-radius: 999px; font-size: 11.5px; font-weight: 700;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.ocean { background: var(--ocean-soft); color: var(--ocean); }
.pill.sun { background: var(--sun-soft); color: var(--sun); }
.pill.red { background: var(--red-soft); color: var(--red); }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 0 14px; min-height: var(--tap); font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

label.field { display: block; margin-bottom: 11px; }
label.field > span { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 0 11px; min-height: var(--tap);
}
textarea { min-height: 78px; padding: 10px 11px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-3); padding: 7px 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.bar { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 99px; }

/* ---------- advice ---------- */
.advice { border-left: 4px solid var(--line); padding: 11px 13px; background: var(--surface); border-radius: 10px; margin-bottom: 9px; border: 1px solid var(--line); }
.advice.critical, .advice.high { border-left-color: var(--red); background: var(--red-soft); }
.advice.medium { border-left-color: var(--sun); background: var(--sun-soft); }
.advice.low { border-left-color: var(--ocean); background: var(--ocean-soft); }
.advice.info { border-left-color: var(--green); background: var(--green-soft); }
.advice h4 { font-size: 15px; margin-bottom: 4px; }
.advice .do { font-size: 14px; margin: 5px 0; }
.advice .why { font-size: 12px; color: var(--ink-2); font-style: italic; }
.advice .acts { display: flex; gap: 7px; margin-top: 9px; flex-wrap: wrap; }

/* ---------- map ---------- */
.map { width: 100%; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--line); display: block; }
.map .blk { fill: var(--green); fill-opacity: .18; stroke: var(--green); stroke-width: 1.5; }
.map .blk.sel { fill-opacity: .42; stroke-width: 2.5; }
.map .fence { fill: none; stroke: var(--ocean); stroke-width: 2.5; stroke-dasharray: 7 4; }
.map text { font-size: 10px; fill: var(--ink-2); font-family: var(--font); font-weight: 600; }
.map .dev { fill: var(--sun); stroke: var(--surface); stroke-width: 1.5; }

/* ---------- misc ---------- */
.banner { padding: 9px 13px; border-radius: 10px; font-size: 13.5px; margin-bottom: 11px; font-weight: 600; }
.banner.warn { background: var(--sun-soft); color: var(--sun); border: 1px solid currentColor; }
.banner.err { background: var(--red-soft); color: var(--red); border: 1px solid currentColor; }
.banner.ok { background: var(--green-soft); color: var(--green); border: 1px solid currentColor; }
.empty { text-align: center; padding: 30px 16px; color: var(--ink-3); }
.empty .ico { font-size: 34px; display: block; margin-bottom: 8px; }

dialog {
  border: 0; border-radius: 16px 16px 0 0; padding: 0; width: 100%; max-width: 560px;
  background: var(--surface); color: var(--ink); box-shadow: 0 -8px 40px rgba(0,0,0,.3);
  margin: auto auto 0; max-height: 92dvh;
}
dialog::backdrop { background: rgba(10,20,14,.55); }
@media (min-width: 700px) { dialog { border-radius: 16px; margin: auto; } }
dialog .head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); border-radius: 16px 16px 0 0; }
dialog .body { padding: 16px; overflow-y: auto; max-height: calc(92dvh - 130px); }
dialog .foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 9px; position: sticky; bottom: 0; background: var(--surface); }
dialog .foot .btn { flex: 1; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; overflow-x: auto; }
.seg button { flex: 1 0 auto; border: 0; background: none; color: var(--ink-2); border-radius: 8px; padding: 8px 11px; font-size: 13px; font-weight: 650; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--green); box-shadow: var(--shadow); }

.spark { display: block; width: 100%; height: 42px; }
.cal { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; }
.cal div { text-align: center; font-size: 9.5px; padding: 6px 1px; border-radius: 5px; font-weight: 700; color: var(--ink-2); }
.loading { text-align: center; padding: 40px; color: var(--ink-3); }
.sp { display: inline-block; width: 17px; height: 17px; border: 2.5px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 17px; border-radius: 11px;
  font-size: 14px; font-weight: 600; z-index: 100; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
}

/* Auth screens have no navigation, so the rail must not reserve space. */
body.no-nav .tabbar { display: none; }
body.no-nav main { padding-left: 12px; padding-bottom: 24px; }
@media (min-width: 900px) {
  body.no-nav main { padding: 74px 22px 30px; }
}


/* ---------- Genesis Pacific branding ---------- */
/* The sprout mark on a white chip: the logo's navy trunk would vanish against
   the navy bar, and inverting the whole lockup to white makes an unreadable
   smudge at this size. */
.topbar .brandmark {
  height: 34px; width: 34px; display: block; flex: none;
  background: #fff; border-radius: 9px; padding: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.topbar .brand { display: flex; align-items: center; gap: 9px; }
.parent-brand {
  font-size: 9.5px; letter-spacing: .22em; text-transform: uppercase;
  opacity: .72; font-weight: 600;
}
.gp-footer {
  margin: 26px 0 8px; padding-top: 14px; border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.gp-footer .gp-name {
  font-weight: 700; font-size: 12px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--navy);
}
:root:not([data-theme="light"]) .gp-footer .gp-name { color: var(--ink); }
@media (prefers-color-scheme: dark) { .gp-footer .gp-name { color: var(--ink); } }
.gp-footer .gp-tag { font-size: 12px; color: var(--ink-3); font-style: italic; }
.auth-logo { display: block; margin: 0 auto 16px; max-height: 118px; width: auto; max-width: 78%; }


/* ---------- phones ---------- */
@media (max-width: 899px) {
  /* Clear the fixed tab bar, plus the home indicator on a notched phone. */
  main { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
  .topbar { padding-left: 10px; padding-right: 10px; gap: 7px; }
  .topbar .brandmark { height: 30px; width: 30px; }
  .brand-name { font-size: 15.5px; }
  .topbar .brand small { font-size: 8.5px; letter-spacing: .1em; }

  h2 { font-size: 20px; }
  .card { padding: 12px; }
  .grid.stats { grid-template-columns: repeat(auto-fit, minmax(146px, 1fr)); }
  .stat .value { font-size: 22px; }
  /* Tables never squash on a phone - they scroll in their own container. */
  table { font-size: 13px; }
  th, td { padding: 7px 6px; }
  .advice { padding: 10px 11px; }
  .advice h4 { font-size: 14.5px; }
  dialog .body { max-height: calc(92dvh - 150px); }
}

/* Very narrow phones: drop the wordmark, keep the mark and the role. */
@media (max-width: 400px) {
  .brand-name { font-size: 14px; }
  .topbar .brand small { display: none; }
  .topbar select { max-width: 40vw; font-size: 12.5px; }
  .grid.stats { grid-template-columns: repeat(2, 1fr); }
  .stat { padding: 10px; }
  .stat .value { font-size: 19px; }
  .tabbar button { min-width: 60px; font-size: 9.5px; }
}

/* Tablet: the rail is still at the bottom, but there is room to breathe. */
@media (min-width: 600px) and (max-width: 899px) {
  main { padding-left: 18px; padding-right: 18px; }
  .grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
}

/* Landscape phone: a short viewport should not lose half its height to chrome. */
@media (max-height: 460px) and (orientation: landscape) {
  :root { --topbar-h: 48px; }
  .tabbar button { padding: 4px 4px 5px; font-size: 9.5px; }
  .tabbar button .ico { font-size: 15px; }
}
