:root {
  color-scheme: light;
  --bg: #f7f4ec;
  --text: #20231d;
  --muted: #687064;
  --panel: #fffdf7;
  --line: #ded7c8;
  --accent: #1f7a4d;
  --accent-strong: #145b3a;
  --warning: #b56b17;
  --danger: #b53939;
  --shadow: 0 14px 34px rgba(48, 42, 28, 0.1);
}

:root.dark {
  color-scheme: dark;
  --bg: #171a17;
  --text: #f4f1e8;
  --muted: #a9afa4;
  --panel: #222820;
  --line: #3a4237;
  --accent: #73c98f;
  --accent-strong: #9be0ad;
  --warning: #e0a251;
  --danger: #ff8b8b;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(31, 122, 77, 0.1), transparent 300px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

#app {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 2px 16px;
}

.eyebrow,
.card-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 12vw, 3.6rem);
  line-height: 0.94;
}

h2 {
  margin-bottom: 0;
  font-size: 1.03rem;
  line-height: 1.2;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(14px);
}

.tab,
.icon-button,
.secondary,
.primary,
.action {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.tab {
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab.is-active {
  background: var(--text);
  color: var(--bg);
}

.icon-button {
  width: 44px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--shadow);
}

.add-plant-button {
  flex: 0 0 46px;
  margin-top: 27px;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

[hidden] {
  display: none !important;
}

.panel,
.result-card,
.plant-card,
.history-card,
.empty-state,
.summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.load-form,
.plant-form {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.plant-form {
  margin-bottom: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  position: relative;
  display: grid;
  gap: 7px;
}

label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, var(--bg));
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

textarea {
  min-height: 82px;
  padding-block: 12px;
  resize: vertical;
}

.address-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.address-suggestion {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.address-suggestion:last-child {
  border-bottom: 0;
}

.address-suggestion:hover,
.address-suggestion.is-active {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

.address-suggestion strong,
.address-suggestion span {
  overflow-wrap: anywhere;
}

.address-suggestion span {
  color: var(--muted);
  font-size: 0.86rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.culture-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.culture-picker legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.culture-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--text);
}

.culture-picker input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.primary {
  width: 100%;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.primary:disabled {
  cursor: wait;
  opacity: 0.72;
}

.secondary {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
}

.primary:active,
.secondary:active,
.action:active,
.icon-button:active {
  transform: translateY(1px);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 14px 0;
  padding: 14px;
}

.summary span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.summary strong {
  display: block;
  margin-top: 4px;
  font-size: 1.1rem;
}

.status-line {
  grid-column: 1 / -1;
}

.results,
.plant-list,
.history-list {
  display: grid;
  gap: 12px;
}

.result-card,
.plant-card,
.history-card {
  padding: 14px;
}

.result-card.is-best {
  border-color: color-mix(in srgb, var(--accent) 72%, var(--line));
}

.card-head,
.toolbar,
.history-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.toolbar {
  align-items: flex-end;
  margin-bottom: 12px;
}

.search-field {
  flex: 1;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 13%, var(--panel));
  color: var(--accent-strong);
  padding: 7px 9px;
  font-size: 0.82rem;
  font-weight: 800;
}

.price-editor {
  flex: 0 0 132px;
  display: grid;
  gap: 5px;
}

.price-editor span {
  color: var(--muted);
  font-size: 0.72rem;
}

.price-editor input {
  min-height: 38px;
  padding: 0 9px;
  font-weight: 800;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.metrics div {
  min-width: 0;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 72%, var(--panel));
  padding: 9px;
}

dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

dd {
  margin: 4px 0 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.profit-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
  font-size: 1rem;
}

.profit-line strong {
  font-size: 1.25rem;
}

.positive {
  color: var(--accent-strong);
}

.negative {
  color: var(--danger);
}

.address {
  margin: 10px 0;
  color: var(--muted);
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.action {
  display: inline-grid;
  place-items: center;
  min-width: 0;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 70%, var(--bg));
  color: var(--text);
  padding: 0 8px;
  font-weight: 800;
  text-align: center;
}

.danger-action {
  color: var(--danger);
}

.plant-card .actions {
  grid-template-columns: repeat(4, 1fr);
}

.plant-card p:not(.card-kicker):not(.address) {
  margin-bottom: 0;
  color: var(--muted);
}

.history-result {
  display: grid;
  gap: 4px;
  text-align: right;
}

.history-result span {
  color: var(--muted);
  font-size: 0.82rem;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 18px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
}

@media (max-width: 560px) {
  #app {
    padding-inline: 10px;
  }

  .field-grid,
  .summary,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: end;
  }

  .add-plant-button {
    margin-top: 0;
  }

  .form-actions,
  .plant-card .actions {
    grid-template-columns: 1fr 1fr;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .culture-picker {
    grid-template-columns: 1fr;
  }

  .card-head,
  .history-card {
    align-items: stretch;
    flex-direction: column;
  }

  .history-result {
    text-align: left;
  }
}
