:root {
  --bg: #f6f7f5;
  --panel: #ffffff;
  --text: #1d2420;
  --muted: #5f6b64;
  --line: #dde2de;
  --accent: #2f6b45;
  --accent-text: #ffffff;
  --accent-soft: #e5f0e8;
  --error: #b42318;
  --error-soft: #fdecea;
  --ok: #1f7a3d;
  --warn-soft: #fff6dc;
  --row-alt: #fafbfa;
  --focus: #2f6b45;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --panel: #1c211e;
    --text: #e6ebe7;
    --muted: #9aa69f;
    --line: #2e3631;
    --accent: #5fae7b;
    --accent-text: #0e1410;
    --accent-soft: #1f3327;
    --error: #ff8a80;
    --error-soft: #3a1f1d;
    --ok: #7bd197;
    --warn-soft: #3a3320;
    --row-alt: #191d1b;
    --focus: #7bd197;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar .title { font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--muted); font-size: 13px; }
.topbar .btn { min-height: 40px; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }

.btn {
  border: 1px solid var(--line); background: var(--panel);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 4px 10px; font-size: 13px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .toolbar input {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 1px;
}

.msg { padding: 10px 12px; border-radius: 8px; margin: 10px 0; }
.msg.error { background: var(--error-soft); color: var(--error); }
.msg.ok { background: var(--accent-soft); color: var(--ok); }
.msg.info { background: var(--warn-soft); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* sign in */
.login { max-width: 360px; margin: 10vh auto 0; }
.login h1 { font-size: 20px; margin: 0 0 4px; }

/* page list */
.pages { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.pages a.card { text-decoration: none; color: var(--text); display: block; }
.pages a.card:hover { border-color: var(--accent); }
.pages h2 { font-size: 17px; margin: 0 0 6px; }

/* toolbar + grid */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 12px; }
.toolbar .field { margin: 0; }
.grid-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: auto; max-height: calc(100vh - 230px);
}
table.grid { border-collapse: collapse; width: 100%; font-size: 14px; }
.grid th, .grid td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.grid th { position: sticky; top: 0; background: var(--panel); z-index: 2; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.grid tbody tr:nth-child(even) { background: var(--row-alt); }
.grid td.num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.desc { white-space: normal; min-width: 180px; }
.grid td.count { width: 110px; }
.grid td.count input {
  width: 96px; padding: 8px; text-align: right; font-size: 16px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
  font-variant-numeric: tabular-nums;
}
.grid tr.counted td.count input { border-color: var(--accent); background: var(--accent-soft); }
.grid tr.bad td.count input { border-color: var(--error); background: var(--error-soft); }
.grid td.text input {
  width: 100%; min-width: 120px; padding: 8px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
}
.grid tr.saved td.text input { color: var(--muted); }
.grid td.status { font-size: 13px; white-space: normal; min-width: 140px; }
.grid td.status .err { color: var(--error); }
.grid td.status .ok { color: var(--ok); }
.grid tr.saved td { color: var(--muted); }

.footer {
  position: sticky; bottom: 0; margin-top: 12px;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
}
.footer .spacer { flex: 1; }

@media (max-width: 700px) {
  main { padding: 10px; }
  .grid .hide-sm { display: none; }
  .grid-wrap { max-height: calc(100vh - 260px); }
}

/* plant tiles (Inventory Counts) */
.tiles {
  display: grid; gap: 8px; margin-bottom: 12px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  max-height: 196px; overflow-y: auto; padding: 2px;
}
.tile {
  text-align: left; border: 1px solid var(--line); background: var(--panel);
  border-radius: 10px; padding: 8px 10px; cursor: pointer; min-height: 58px;
  display: flex; flex-direction: column; gap: 2px;
}
.tile:hover { border-color: var(--muted); }
.tile .name { font-weight: 600; font-size: 13px; line-height: 1.25;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.tile.done { border-color: var(--accent); background: var(--accent-soft); }
.tile.done .meta .tally { color: var(--ok); font-weight: 600; }
.tile.issue .meta .tally { color: var(--error); font-weight: 600; }
.tile[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
@media (max-width: 700px) {
  .tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); max-height: 150px; }
}

/* add-line dialog */
.dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 20px;
  background: var(--panel); color: var(--text); width: min(420px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgb(0 0 0 / .35); }
.dialog h2 { margin: 0 0 4px; font-size: 18px; }
.dialog select, .dialog input {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.dialog .row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.grid tr.newline td:first-child, .grid tr.newline td:nth-child(2) { box-shadow: inset 3px 0 0 var(--accent); }
.grid .remove { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px; font-size: 15px; }
.grid .remove:hover { color: var(--error); }
.tag { font-size: 11px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 4px; margin-right: 4px; }

/* sign-in location picker */
.profile-row { display: flex; gap: 6px; }
.profile-row select { flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.small { font-size: 12px; }
.login { max-width: 440px; }

/* Entry pages: the page is exactly one screen tall, the grid takes whatever height is
   left and scrolls inside, and the footer sits under it instead of covering rows. */
body.entry { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
body.entry main { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; }
body.entry .grid-wrap { flex: 1; min-height: 0; max-height: none; }
body.entry .footer { position: static; flex: none; }
body.entry main > p.muted { flex: none; margin: 8px 0 0; }

.grid .row-status { display: none; font-size: 13px; margin-top: 2px; }
.grid .row-status:empty { display: none !important; }
.grid .row-status .err { color: var(--error); }
.grid .row-status .ok { color: var(--ok); }
.grid.one-section .col-section { display: none; }
.grid .short { display: none; }

/* Tablet landscape and smaller desktops: fit every column, no sideways scrolling. */
@media (max-width: 1099px) {
  .grid .col-status { display: none; }
  .grid .row-status { display: block; }
  .grid th, .grid td { padding: 6px 7px; }
  .grid td.desc { min-width: 150px; }
  .grid td.text input { min-width: 0; }
  .grid td.text:has(input[data-f="vendor"]) { width: 110px; }
  .grid td.text:has(input[data-f="notes"]) { width: 150px; }
  .grid td.count { width: 92px; }
  .grid td.count input { width: 80px; }
  .grid .long { display: none; }
  .grid .short { display: inline; }
}
@media (max-width: 999px) {
  .grid .col-sell { display: none; }
}

/* Short screens (a tablet held landscape): tighter chrome, plant tiles in one sideways row. */
@media (max-height: 640px) {
  .topbar { padding: 4px 12px; }
  body.entry main { padding: 8px 12px; }
  .toolbar { margin-bottom: 8px; gap: 8px; }
  .toolbar { align-items: center; }
  .toolbar .field { flex-direction: row; align-items: center; gap: 8px; }
  .toolbar .field label { font-size: 12px; max-width: 90px; line-height: 1.2; }
  .toolbar input { padding: 7px 10px; }
  .toolbar .btn { padding: 7px 16px; }
  .tiles {
    grid-auto-flow: column; grid-auto-columns: 200px; grid-template-columns: none;
    max-height: none; overflow-x: auto; overflow-y: hidden; margin-bottom: 8px;
  }
  .tile { min-height: 0; padding: 5px 10px; gap: 0; }
  .tile .name { -webkit-line-clamp: 1; }
  .grid td.count input, .grid td.text input { padding: 6px 8px; }
  .msg { margin: 6px 0; padding: 7px 10px; }
  .footer { margin-top: 8px; padding: 6px 12px; }
  body.entry main > p.muted { display: none; }
}
