/* ---- Colors: one place to change the look ---- */
:root {
  --bg: #f4f1ec;
  --card: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665e;
  --border: #e2ddd4;

  /* One color per stage, so you can tell stages apart at a glance */
  --fermenting: #d97706;
  --dry-hopping: #4d7c0f;
  --conditioning: #0369a1;
  --carbonating: #7c3aed;
  --ready: #15803d;
  --packaged: #57534e;
  --empty: #9ca3af;

  /* Tank statuses (for tanks with no beer in them) */
  --cleaning: #0891b2;
  --maintenance: #b91c1c;

  /* A tank that needs an acid cycle before it's filled again */
  --acid-due: #a16207;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --card: #23211e;
    --text: #f2efe9;
    --muted: #a39d93;
    --border: #36332e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* "hidden" always wins over our styles */
body.busy, body.busy * { cursor: progress !important; } /* while saving to the database */

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

/* ---- Sign-in and setup screens ---- */
.screen {
  max-width: 420px;
  margin: 48px auto;
  padding: 0 16px;
}
.screen form { display: grid; gap: 12px; margin-top: 16px; }
.screen label { display: grid; gap: 4px; color: var(--muted); font-size: 0.9rem; }
.screen input {
  font: inherit;
  font-size: 16px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}
.form-message {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--maintenance);
  color: var(--text);
}
.screen-message { text-align: center; color: var(--muted); margin-top: 48px; }
.actions.wrap { flex-wrap: wrap; }

/* ---- Header ---- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}
.top h1 { margin: 0; font-size: 1.6rem; }
.top p { margin: 2px 0 0; }

/* No signal: a band under the header saying how old the data is */
.offline-banner {
  max-width: 1100px;
  margin: 0 auto 12px;
  padding: 10px 16px;
  background: var(--acid-due);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
}

/* Offline changes the database refused: stays until you tap OK */
.sync-problems {
  max-width: 1100px;
  margin: 0 auto 12px;
  padding: 12px 16px;
  border: 2px solid var(--maintenance);
  border-radius: 10px;
  background: var(--card);
}
.sync-problems ul { margin: 6px 0 10px; padding-left: 20px; }

/* ---- Tank area, grouped by location ---- */
#tanks {
  padding: 0 16px 32px;
  max-width: 1100px;
  margin: 0 auto;
}
.location + .location { margin-top: 24px; }
.location h2 { font-size: 1.1rem; margin: 0 0 8px; color: var(--muted); }

/* Card grid: 1 column on phones, more on wider screens */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.card {
  /* It's a <button> so it's tappable, but we want it to look like a card */
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 8px solid var(--stage-color, var(--empty));
  border-radius: 12px;
  padding: 14px 16px;
  display: grid;
  gap: 6px;
}
.card:focus-visible { outline: 3px solid var(--conditioning); }

.card .tank-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.card .tank { font-weight: 700; font-size: 1.15rem; }
.card .type { color: var(--muted); font-size: 0.85rem; }
.card .beer { font-size: 1.3rem; font-weight: 600; }
.card .beer .style { font-size: 0.9rem; font-weight: 400; color: var(--muted); }
.card .beer.none { color: var(--muted); font-weight: 400; }
.card .meta, .muted { color: var(--muted); font-size: 0.9rem; }

.card .stage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}
.badge {
  background: var(--stage-color, var(--empty));
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
}
.days { font-size: 1.6rem; font-weight: 700; }

/* "Acid due · after Sour": on tank cards and in the tank form */
.acid-due {
  justify-self: start;
  margin: 0;
  background: var(--acid-due);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
}
dialog .acid-due { display: inline-block; margin-bottom: 8px; }
.days small { font-size: 0.85rem; font-weight: 400; color: var(--muted); }

/* ---- Lists below the tanks (packaged batches, beers) ---- */
.list-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 32px;
}
.list-section h2 { font-size: 1.1rem; margin: 0 0 8px; }
.list-section ul { list-style: none; margin: 0; padding: 0; }
.list-section .row {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  width: 100%;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

/* Beer rows: name on one line, targets on the next, so every row lines up */
.list-section .row.stacked { flex-direction: column; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.section-head h2 { margin: 0; }

/* ---- Buttons ---- */
.btn {
  font: inherit;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.danger { color: #b91c1c; }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }

/* Simple lists with a button on the right (acid styles, acid log) */
ul.plain { list-style: none; margin: 8px 0 0; padding: 0; }
ul.plain .item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

/* A text box with its Add button beside it */
.inline-add { display: flex; gap: 8px; margin-top: 12px; }
.inline-add input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}

.inline-add select, .inline-label select, ul.plain .item select {
  font: inherit;
  font-size: 16px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}
.inline-label { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; color: var(--muted); }
ul.plain .item .who { min-width: 0; overflow-wrap: anywhere; }
ul.plain .item .controls { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* ---- Edit pop-up ---- */
dialog {
  border: none;
  border-radius: 14px;
  padding: 20px;
  width: min(420px, calc(100vw - 32px));
  background: var(--card);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog h2 { margin-top: 0; }

dialog label {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}
dialog input, dialog select {
  font: inherit;
  font-size: 16px; /* 16px stops iPhones from zooming in when you tap a field */
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
dialog fieldset.acid {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 12px;
  margin: 0 0 12px;
}
dialog fieldset.acid legend { font-weight: 600; padding: 0 4px; }
dialog fieldset.acid p { margin: 0 0 8px; }

.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions .spacer { flex: 1; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two-col input, .two-col select { min-width: 0; width: 100%; }
.link {
  all: unset;
  cursor: pointer;
  display: block;
  margin-top: 14px;
  color: var(--muted);
  text-decoration: underline;
  font-size: 0.9rem;
}
