.farmer-section {
  padding: 25px;
}

.farmer-header-actions { display: flex; gap: 8px; }
.farmer-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.farmer-settings[hidden] { display: none; }
.farmer-settings article { border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: var(--surface); }
.farmer-settings h3 { margin: 0; font-size: 1rem; }
.farmer-settings p { margin: 5px 0 13px; color: var(--muted); font-size: .74rem; }
.settings-form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 9px; }
.settings-form label { display: grid; gap: 5px; color: var(--muted); font-size: .7rem; }
.settings-form input { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--text); padding: 9px 10px; }
.settings-form .primary-button { padding: 9px 11px; }

.farmer-auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.account-card {
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 20px;
  background: rgba(255, 255, 255, .025);
}

.account-card h3,
.plot-form h3,
.farmer-workspace h3 {
  margin: 0 0 8px;
  font-size: 1.08rem;
}

.account-card > p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: .82rem;
}

.account-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.account-form label,
.plot-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .75rem;
}

.account-form input,
.plot-form input,
.plot-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

.account-form input:focus,
.plot-form input:focus,
.plot-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.account-form .primary-button {
  grid-column: 1 / -1;
}

.text-button {
  grid-column: 1 / -1;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  text-align: center;
  font: inherit;
}

.auth-flow-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 15px;
  padding: 15px 17px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.auth-flow-panel[hidden] {
  display: none;
}

.auth-flow-panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: .78rem;
}

.auth-flow-form {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, .7fr) auto;
}

.auth-flow-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
}

.farmer-profile {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 17px;
  background: linear-gradient(110deg, rgba(83, 217, 173, .13), rgba(255, 211, 107, .04));
}

.farm-alerts-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface);
}

.irrigation-plan-panel { margin-top: 14px; border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: var(--surface); }
.plan-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }
.plan-heading small { color: var(--muted); font-size: .7rem; letter-spacing: .08em; }
.plan-heading h3 { margin: 3px 0 0; font-size: 1rem; }
.plan-controls { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.plan-controls select { border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--text); padding: 8px 10px; font-size: .72rem; }
.plan-controls .primary-button { padding: 8px 11px; font-size: .72rem; }
.plan-hint,.plan-note { color: var(--muted); font-size: .75rem; }
.plan-hint { padding: 20px 0 5px; text-align: center; }
.irrigation-plan-days { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); gap: 7px; margin-top: 14px; }
.plan-day { min-width: 0; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: color-mix(in srgb,var(--surface-2) 65%,transparent); }
.plan-day small,.plan-day strong,.plan-day span,.plan-day em { display: block; }
.plan-day small { color: var(--muted); font-size: .65rem; }
.plan-day strong { margin-top: 7px; font-size: 1rem; }
.plan-day span { margin-top: 5px; min-height: 34px; font-size: .68rem; line-height: 1.3; }
.plan-day em { margin-top: 8px; color: var(--muted); font-size: .62rem; font-style: normal; }
.plan-day.urgent { border-color: color-mix(in srgb,#ef4444 55%,var(--line)); }
.plan-day.rain,.plan-day.wet { border-color: color-mix(in srgb,var(--accent) 50%,var(--line)); }
.plan-note { margin: 10px 0 0; }

.alerts-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}

.alerts-heading small { color: var(--muted); font-size: .7rem; letter-spacing: .08em; }
.alerts-heading h3 { margin: 3px 0 0; font-size: 1rem; }
.alert-count { min-width: 29px; height: 29px; display: grid; place-items: center; border-radius: 50%; background: color-mix(in srgb, #f59e0b 18%, transparent); color: #f59e0b; font-weight: 700; }
.farm-alerts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.farm-alert { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.farm-alert:hover { border-color: var(--accent); }
.farm-alert strong, .farm-alert small { display: block; }
.farm-alert strong { font-size: .8rem; }
.farm-alert small { margin-top: 3px; color: var(--muted); font-size: .71rem; line-height: 1.35; }
.alert-icon { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 9px; font-weight: 800; }
.farm-alert.critical .alert-icon { color: #f87171; background: color-mix(in srgb, #ef4444 15%, transparent); }
.farm-alert.warning .alert-icon { color: #f59e0b; background: color-mix(in srgb, #f59e0b 15%, transparent); }
.farm-alert.info .alert-icon { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.all-clear { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 13px; color: var(--accent); }
.all-clear span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: color-mix(in srgb, var(--accent) 14%, transparent); }
.all-clear strong, .all-clear small { display: block; }
.all-clear small { margin-top: 2px; color: var(--muted); }

.profile-avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--accent);
  color: #06241d;
  font-size: 1.4rem;
}

.farmer-profile small,
.farmer-profile p,
.profile-count span {
  color: var(--muted);
  font-size: .75rem;
}

.farmer-profile h3,
.farmer-profile p {
  margin: 2px 0 0;
}

.profile-count {
  text-align: right;
}

.profile-count strong,
.profile-count span {
  display: block;
}

.profile-count strong {
  font-size: 1.8rem;
}

.farmer-workspace {
  display: grid;
  grid-template-columns: .8fr 1.2fr;
  gap: 14px;
  margin-top: 14px;
}

.farmer-workspace > * {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
}

.plot-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.plot-form h3,
.plot-form-actions {
  grid-column: 1 / -1;
}

.plot-form-actions {
  display: flex;
  gap: 9px;
}

.danger-button {
  border: 1px solid color-mix(in srgb, #ef4444 52%, var(--line));
  border-radius: 10px;
  background: color-mix(in srgb, #ef4444 10%, transparent);
  color: #ef7777;
  padding: 7px 10px;
  font: inherit;
  font-size: .7rem;
  cursor: pointer;
}

.owned-plots {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.owned-plot {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px;
  transition: border-color .2s, background .2s;
}

.owned-plot.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

.plot-select {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.plot-select > span,
.plot-select strong,
.plot-select small {
  display: block;
}

.plot-select strong {
  font-size: .88rem;
}

.plot-select small {
  margin-top: 4px;
  color: var(--muted);
  font-size: .74rem;
}

.sensor-summary {
  text-align: right;
}

.sensor-summary b {
  color: var(--accent);
  font-size: 1.1rem;
}

.plot-actions {
  display: flex;
  gap: 7px;
  margin-top: 9px;
}

.plot-actions .secondary-button {
  padding: 7px 10px;
  font-size: .7rem;
}

.plot-map-panel {
  margin-top: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.map-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.map-heading small {
  color: var(--muted);
}

.map-heading h3 {
  margin: 3px 0 0;
  font-size: 1rem;
}

#plotMap {
  display: block;
  width: 100%;
  height: 340px;
  border: 0;
  border-top: 1px solid var(--line);
}

.sensor-history-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface);
}

.sensor-history-panel[hidden],
#sensorHistoryContent[hidden],
.history-empty[hidden] {
  display: none;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-heading small,
.history-empty {
  color: var(--muted);
}

.history-heading h3 {
  margin: 4px 0 0;
}

.history-legend {
  display: flex;
  gap: 14px;
  font-size: .75rem;
}

.history-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.history-tools .secondary-button { padding: 7px 10px; font-size: .7rem; }
.history-tools .secondary-button:disabled { opacity: .45; cursor: not-allowed; }

.history-legend span::before {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
}

.moisture-dot::before { background: var(--accent); }
.temperature-dot::before { background: #f59e0b; }
.history-empty { padding: 28px 0 12px; text-align: center; font-size: .82rem; }
#sensorChart { width: 100%; min-height: 180px; margin-top: 12px; overflow: visible; }
#sensorChart text { fill: var(--muted); font-size: 11px; }
.chart-grid line { stroke: var(--line); stroke-width: 1; }
.moisture-line, .temperature-line { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.moisture-line { stroke: var(--accent); }
.temperature-line { stroke: #f59e0b; }
.history-table-wrap { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: .76rem; }
.history-table th, .history-table td { padding: 9px 8px; border-top: 1px solid var(--line); text-align: left; white-space: nowrap; }
.history-table th { color: var(--muted); font-weight: 500; }

.sensor-key-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  border: 1px solid var(--accent);
  border-radius: 15px;
  padding: 15px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.sensor-key-panel[hidden] {
  display: none;
}

.sensor-key-panel p {
  margin: 5px 0 9px;
  color: var(--muted);
  font-size: .78rem;
}

.sensor-key-panel code {
  display: block;
  max-width: 680px;
  overflow-wrap: anywhere;
  color: var(--accent);
}

.empty-plots {
  border: 1px dashed var(--line);
  border-radius: 13px;
  padding: 22px;
  color: var(--muted);
  text-align: center;
  font-size: .82rem;
}

html[data-theme="light"] .account-card,
html[data-theme="light"] .farmer-workspace > * {
  background: rgba(255, 255, 255, .55);
}

body.view-mobile .farmer-auth-grid,
body.view-mobile .farmer-workspace,
body.view-mobile .account-form,
body.view-mobile .plot-form {
  grid-template-columns: 1fr;
}

body.view-mobile .farmer-settings,
body.view-mobile .settings-form { grid-template-columns: 1fr; }

body.view-mobile .farm-alerts { grid-template-columns: 1fr; }
body.view-mobile .plan-heading { align-items: flex-start; flex-direction: column; }
body.view-mobile .plan-controls { justify-content: flex-start; }
body.view-mobile .irrigation-plan-days { grid-template-columns: repeat(2,minmax(0,1fr)); }

body.view-mobile .auth-flow-panel,
body.view-mobile .auth-flow-form {
  grid-template-columns: 1fr;
}

body.view-mobile #plotMap {
  height: 260px;
}

body.view-mobile .account-form .primary-button,
body.view-mobile .plot-form h3,
body.view-mobile .plot-form-actions {
  grid-column: auto;
}

@media (max-width: 820px) {
  .farmer-auth-grid,
  .farmer-workspace {
    grid-template-columns: 1fr;
  }

  .farmer-settings { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .farmer-section {
    padding: 18px;
  }

  .account-form,
  .plot-form,
  .settings-form {
    grid-template-columns: 1fr;
  }

  .farmer-header-actions { width: 100%; flex-wrap: wrap; }

  .farm-alerts { grid-template-columns: 1fr; }
  .plan-heading { align-items: flex-start; flex-direction: column; }
  .plan-controls { justify-content: flex-start; }
  .irrigation-plan-days { grid-template-columns: repeat(2,minmax(0,1fr)); }

  .account-form .primary-button,
  .plot-form h3,
  .plot-form-actions {
    grid-column: auto;
  }

  .farmer-profile {
    grid-template-columns: auto 1fr;
  }

  .auth-flow-panel,
  .auth-flow-form {
    grid-template-columns: 1fr;
  }

  .profile-count {
    grid-column: 1 / -1;
    display: flex;
    align-items: baseline;
    gap: 6px;
    text-align: left;
  }

  .map-heading,
  .history-heading,
  .sensor-key-panel {
    grid-template-columns: 1fr;
  }

  .history-tools { justify-content: flex-start; }

  .map-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  #plotMap {
    height: 240px;
  }
}
