:root {
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-2: #eef1e8;
  --text: #1f2a1c;
  --muted: #687263;
  --border: #dde2d5;
  --accent: #3d7a3a;
  --accent-strong: #2c5e2a;
  --accent-soft: #e2efdc;
  --on-accent: #ffffff;
  --danger: #b3412f;
  --danger-soft: #f8e3df;
  --warn-soft: #fbf0d4;
  --warn: #8a6510;
  --info-soft: #e1ecf7;
  --info: #2f5e8c;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141912;
    --surface: #1c2219;
    --surface-2: #242c20;
    --text: #e4eadf;
    --muted: #97a291;
    --border: #333d2e;
    --accent: #7bbf6f;
    --accent-strong: #9bd68f;
    --accent-soft: #263a22;
    --on-accent: #10200d;
    --danger: #e98a78;
    --danger-soft: #3d2420;
    --warn-soft: #3a3118;
    --warn: #e2c06a;
    --info-soft: #1d2c3b;
    --info: #8fb9e2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }

.muted { color: var(--muted); }
small { font-size: .85em; }

/* Layout */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
  padding: .75rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand small { font-weight: 400; color: var(--muted); margin-left: .25rem; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; }
.topbar nav a, .topbar nav .link-button {
  padding: .3rem .65rem; border-radius: 6px; color: var(--muted);
}
.topbar nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.topbar nav form { display: inline; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 4rem; }

.page-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .75rem; margin-bottom: 1rem;
}
.page-header .subtitle { color: var(--muted); font-style: italic; margin-top: .15rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { display: inline; }

/* Buttons */
.button, button, input[type=submit] {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .9rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; text-decoration: none;
}
.button:hover, button:hover { text-decoration: none; border-color: var(--accent); }
.button-primary, input[type=submit] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.button-primary:hover, input[type=submit]:hover { background: var(--accent-strong); }
.button-danger { color: var(--danger); }
.button-danger:hover { border-color: var(--danger); }
.button-small { padding: .2rem .55rem; font-size: .85rem; }
.link-button { background: none; border: none; padding: 0; color: var(--accent-strong); cursor: pointer; font: inherit; }

/* Flash & errors */
.flash { padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash-notice { background: var(--accent-soft); color: var(--accent-strong); }
.flash-alert { background: var(--danger-soft); color: var(--danger); }
.errors { background: var(--danger-soft); color: var(--danger); padding: .5rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.errors ul { margin: 0; padding-left: 1.1rem; }

/* Cards & tables */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.card + .card { margin-top: 1rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
td.num { white-space: nowrap; }
td .sci { display: block; color: var(--muted); font-style: italic; font-size: .85rem; }

.group-heading { font-size: 1.35rem; margin: 2rem 0 .25rem; padding-bottom: .35rem; border-bottom: 2px solid var(--accent); }
.tabs-purpose a { font-weight: 600; }
.category-heading { display: flex; align-items: baseline; gap: .5rem; }
.category-heading .count { color: var(--muted); font-weight: 400; font-size: .9rem; }

/* Badges & tabs */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-active { background: var(--accent-soft); color: var(--accent-strong); }
.badge-wished { background: var(--info-soft); color: var(--info); }
.badge-unwanted { background: var(--warn-soft); color: var(--warn); }
.badge-dead { background: var(--surface-2); color: var(--muted); }
.kind-fertilizer { background: var(--accent-soft); color: var(--accent-strong); }
.kind-fungicide { background: var(--info-soft); color: var(--info); }
.kind-insecticide { background: var(--warn-soft); color: var(--warn); }
.kind-other { background: var(--surface-2); color: var(--muted); }

.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: .75rem; }
.tabs a { padding: .35rem .8rem; border-radius: 999px; color: var(--muted); border: 1px solid var(--border); background: var(--surface); }
.tabs a.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tabs a:hover { text-decoration: none; }

/* Forms */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.filters input, .filters select { min-width: 0; }

form .field { margin-bottom: .9rem; }
form label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
form .hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: .45rem .6rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.filters input, .filters select { width: auto; }
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.checkbox-inline { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.checkbox-inline input { width: auto; margin: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.form-narrow { max-width: 640px; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.inline-form .field { margin: 0; flex: 1 1 140px; }

/* Plant picker for bulk applications */
.plant-picker fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 .75rem; padding: .5rem .75rem .75rem; background: var(--surface); }
.plant-picker legend { font-weight: 700; padding: 0 .35rem; }
.plant-picker .options { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .15rem 1rem; }
.plant-picker label { font-weight: 400; display: flex; gap: .4rem; align-items: baseline; margin: 0; }
.plant-picker label input { width: auto; }

/* Definition list for plant details */
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem 1.25rem; margin: 0; }
.details dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.details dd { margin: .1rem 0 0; }
.notes { white-space: pre-line; }

.species-layout { display: grid; grid-template-columns: minmax(0, 280px) 1fr; gap: 1rem; align-items: start; }
.species-photo { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); }
@media (max-width: 640px) { .species-layout { grid-template-columns: 1fr; } }
code { background: var(--surface-2); padding: .1rem .35rem; border-radius: 4px; }

/* Photos */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.photo-upload { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.photo-upload label.button { margin: 0; font-size: 1rem; }
.photo-upload .caption { flex: 1 1 220px; width: auto; }
.photo-upload.uploading label.button { opacity: .5; pointer-events: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.photo-grid figure { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.photo-grid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--surface-2); }
.photo-grid figcaption { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .5rem; font-size: .8rem; color: var(--muted); }
.photo-grid figcaption form { display: inline; }
.plant-cell { display: flex; gap: .6rem; align-items: flex-start; }
.plant-cell .thumb { flex: none; }
.plant-cell .thumb img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; display: block; }

/* Calendar */
.task { display: flex; gap: .6rem; align-items: flex-start; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: none; }
.task form { display: inline; }
.task .check { width: 1.6rem; height: 1.6rem; padding: 0; justify-content: center; border-radius: 6px; flex: none; }
.task.done .check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.task.done .description { color: var(--muted); text-decoration: line-through; }
.task .body { flex: 1; }
.task .meta { font-size: .8rem; color: var(--muted); }

.empty { color: var(--muted); padding: 1rem 0; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  td.num small { display: block; }
  th, td { padding: .45rem .5rem; }
}
