:root {
  color-scheme: dark;
  --bg: #0e100f;
  --surface: #171a18;
  --surface-2: #202421;
  --surface-3: #292e2a;
  --text: #f2f4f2;
  --muted: #aeb7b0;
  --line: #353b37;
  --accent: #df3f34;
  --accent-strong: #f35247;
  --accent-soft: rgba(223, 63, 52, .15);
  --green: #8cc99b;
  --green-soft: rgba(140, 201, 155, .14);
  --amber: #e8bd68;
  --danger: #ff756b;
  --radius: 18px;
  --radius-small: 12px;
  --shadow: 0 16px 50px rgba(0, 0, 0, .24);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 10% -10%, rgba(223, 63, 52, .15), transparent 34rem),
    linear-gradient(180deg, #121513 0, var(--bg) 30rem);
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
a:focus-visible,
[tabindex="0"]:focus-visible {
  outline: 3px solid rgba(243, 82, 71, .65);
  outline-offset: 3px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .4rem; font-size: clamp(1.75rem, 3vw, 2.6rem); line-height: 1.08; letter-spacing: -.035em; }
h2 { margin-bottom: .35rem; font-size: clamp(1.25rem, 2vw, 1.65rem); line-height: 1.2; letter-spacing: -.02em; }
h3 { margin-bottom: .3rem; font-size: 1.05rem; }
p { line-height: 1.55; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.is-hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
  display: block;
  margin-bottom: .5rem;
  color: var(--green);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.app-shell { min-height: 100dvh; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 74px;
  padding: .85rem max(1rem, env(safe-area-inset-left)) .85rem max(1rem, env(safe-area-inset-right));
  border-bottom: 1px solid rgba(255,255,255,.07);
  background: rgba(14, 16, 15, .88);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-mark { width: 38px; height: 38px; flex: 0 0 auto; color: var(--accent-strong); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: -.01em; }
.brand small { margin-top: .15rem; color: var(--muted); font-size: .72rem; }

.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: .65rem; min-width: 0; }

.compact-select {
  max-width: min(35vw, 230px);
  padding: .6rem 2rem .6rem .75rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.status-banner {
  padding: .65rem 1rem;
  color: #20110e;
  background: var(--amber);
  text-align: center;
  font-size: .88rem;
  font-weight: 700;
}

.app-main {
  width: min(1180px, 100%);
  min-height: calc(100dvh - 150px);
  margin: 0 auto;
  padding: clamp(1.2rem, 3vw, 2.5rem) clamp(1rem, 3vw, 2.25rem) calc(7rem + env(safe-area-inset-bottom));
}

.view { animation: view-in .18s ease-out; }
@keyframes view-in { from { opacity: .3; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }

.button {
  min-height: 44px;
  padding: .68rem 1rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 750;
  line-height: 1;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}

.button:active { transform: translateY(1px); }
.button-primary { color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-strong); }
.button-secondary { color: var(--text); border-color: var(--line); background: var(--surface-2); }
.button-secondary:hover { border-color: #59625c; background: var(--surface-3); }
.button-danger { color: var(--danger); border-color: rgba(255, 117, 107, .38); background: rgba(255, 117, 107, .08); }
.button:disabled { cursor: not-allowed; opacity: .5; }

input, select, textarea {
  width: 100%;
  min-height: 46px;
  padding: .72rem .8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  color: var(--text);
  background: #121513;
}

textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: #747c76; }
input:disabled, select:disabled { color: var(--muted); background: var(--surface); cursor: not-allowed; }

label > span:first-child,
.label-text {
  display: block;
  margin-bottom: .45rem;
  color: #d7dcd8;
  font-size: .84rem;
  font-weight: 700;
}

.input-with-unit { position: relative; display: block; }
.input-with-unit input { padding-right: 2.6rem; }
.input-with-unit > span:last-child {
  position: absolute;
  top: 50%;
  right: .9rem;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.empty-state {
  max-width: 680px;
  margin: clamp(2rem, 8vw, 6rem) auto;
  padding: clamp(1.5rem, 4vw, 3rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(255,255,255,.035), rgba(255,255,255,.012));
  text-align: center;
  box-shadow: var(--shadow);
}
.empty-state p { max-width: 560px; margin: 0 auto 1.4rem; color: var(--muted); }

.today-headline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.4rem;
}

.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  margin-bottom: .75rem;
  padding: .4rem .68rem;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .025em;
}
.stage-badge::before { width: .48rem; height: .48rem; border-radius: 50%; background: currentColor; content: ""; }

.date-chip {
  flex: 0 0 auto;
  min-width: 126px;
  padding: .8rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  text-align: right;
}
.date-chip span, .date-chip strong { display: block; }
.date-chip span { margin-bottom: .2rem; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; }
.date-chip strong { font-size: .95rem; }

.notice {
  margin-bottom: 1rem;
  padding: .85rem 1rem;
  border-left: 4px solid var(--amber);
  border-radius: 0 var(--radius-small) var(--radius-small) 0;
  color: #f1dfbd;
  background: rgba(232, 189, 104, .1);
  line-height: 1.45;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.summary-item {
  min-width: 0;
  padding: .95rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: rgba(23, 26, 24, .75);
}
.summary-item span, .summary-item strong { display: block; }
.summary-item span { margin-bottom: .3rem; color: var(--muted); font-size: .73rem; letter-spacing: .05em; text-transform: uppercase; }
.summary-item strong { font-size: .96rem; line-height: 1.3; overflow-wrap: anywhere; }

.mix-panel {
  padding: clamp(1.1rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(32,36,33,.96), rgba(23,26,24,.96));
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.section-heading > p { max-width: 44ch; margin-bottom: .1rem; text-align: right; }
.page-heading { margin-bottom: clamp(1.4rem, 3vw, 2.2rem); }

.mix-controls {
  display: grid;
  grid-template-columns: minmax(180px, .7fr) minmax(220px, 1fr);
  gap: .9rem;
  margin-bottom: 1.1rem;
}

.recipe-list { display: grid; gap: .55rem; margin: 0; padding: 0; list-style: none; }
.recipe-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .8rem;
  min-height: 62px;
  padding: .65rem .8rem;
  border-bottom: 1px solid var(--line);
}
.recipe-item:last-child { border-bottom: 0; }
.recipe-check { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--accent); }
.recipe-name strong, .recipe-name span { display: block; }
.recipe-name strong { font-size: .98rem; }
.recipe-name span { margin-top: .18rem; color: var(--muted); font-size: .78rem; }
.recipe-amount { padding-left: .7rem; text-align: right; }
.recipe-amount strong, .recipe-amount span { display: block; }
.recipe-amount strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.recipe-amount span { margin-top: .15rem; color: var(--muted); font-size: .72rem; }

.water-only {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-radius: var(--radius-small);
  color: #a9cef2;
  background: rgba(99, 160, 216, .11);
}
.water-only svg { width: 42px; height: 42px; flex: 0 0 auto; }
.water-only strong, .water-only span { display: block; }
.water-only span { margin-top: .2rem; color: #c1d5e8; font-size: .85rem; }

.mix-guidance, .record-panel {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
}
.mix-guidance summary, .record-panel summary {
  padding: 1rem 0 .2rem;
  font-weight: 800;
  cursor: pointer;
}
.mix-guidance ol { margin: .8rem 0 .5rem; padding-left: 1.25rem; color: #d4dad5; }
.mix-guidance li { margin-bottom: .45rem; line-height: 1.5; }
.mix-guidance p { margin: .8rem 0 0; color: var(--muted); font-size: .82rem; }

.record-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .8rem;
  margin: 1rem 0;
}
.wide-field { grid-column: 1 / -1; }

.stage-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1rem; }

.schedule-key {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .75rem;
  color: var(--muted);
  font-size: .8rem;
}
.schedule-key span { display: inline-flex; align-items: center; gap: .4rem; }
.key-current { width: .72rem; height: .72rem; border-radius: 3px; background: var(--accent); }

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overscroll-behavior-inline: contain;
}

.schedule-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .82rem;
}
.schedule-table th, .schedule-table td {
  min-width: 72px;
  padding: .72rem .65rem;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.schedule-table tr:last-child td { border-bottom: 0; }
.schedule-table th:last-child, .schedule-table td:last-child { border-right: 0; }
.schedule-table thead th { position: sticky; top: 0; z-index: 2; color: #d8ded9; background: #222622; }
.schedule-table .product-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 190px;
  max-width: 230px;
  color: var(--text);
  background: var(--surface);
  text-align: left;
  font-weight: 700;
}
.schedule-table thead .product-cell { z-index: 4; background: #222622; }
.schedule-table .active-col { color: #fff; background: var(--accent-soft); box-shadow: inset 0 3px 0 var(--accent); }
.schedule-table tbody .active-col { box-shadow: inset 2px 0 0 rgba(243,82,71,.65), inset -2px 0 0 rgba(243,82,71,.65); }
.schedule-table .dose-none { color: #626a64; }
.schedule-table .unit-note { display: block; margin-top: .15rem; color: var(--muted); font-size: .67rem; font-weight: 500; }

.source-note { margin: .8rem .2rem 0; color: var(--muted); font-size: .78rem; }

.history-list { display: grid; gap: .8rem; }
.history-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
}
.history-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.history-card-head p { margin-bottom: 0; color: var(--muted); font-size: .8rem; }
.history-card-head button { flex: 0 0 auto; }
.history-meta { display: flex; flex-wrap: wrap; gap: .45rem; margin: .75rem 0; }
.history-meta span { padding: .3rem .5rem; border-radius: 999px; color: #c9d0ca; background: var(--surface-3); font-size: .72rem; }
.history-products { display: flex; flex-wrap: wrap; gap: .35rem 1rem; margin: .4rem 0 0; padding: 0; color: #dce1dd; list-style: none; font-size: .82rem; }
.history-notes { margin: .8rem 0 0; padding-top: .75rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; }
.icon-button {
  min-width: 40px;
  min-height: 40px;
  padding: .4rem .65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
}
.icon-button:hover { color: var(--danger); border-color: rgba(255,117,107,.4); }
.history-empty { padding: 3rem 1rem; color: var(--muted); text-align: center; }

.grow-form {
  padding: clamp(1rem, 3vw, 1.7rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.products-fieldset { margin: 1.4rem 0 0; padding: 0; border: 0; }
.products-fieldset legend { padding: 0; font-size: 1.05rem; font-weight: 800; }
.products-fieldset > p { margin: .35rem 0 .9rem; color: var(--muted); font-size: .82rem; }
.product-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.product-option {
  display: flex;
  align-items: center;
  gap: .7rem;
  min-height: 50px;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: #121513;
}
.product-option input { width: 20px; height: 20px; min-height: 0; margin: 0; accent-color: var(--accent); }
.product-option span { margin: 0; font-size: .83rem; }
.product-option em { margin-left: auto; color: var(--green); font-size: .68rem; font-style: normal; text-transform: uppercase; letter-spacing: .08em; }
.form-error { margin-top: 1rem; padding: .75rem .9rem; border-radius: var(--radius-small); color: #ffd0cc; background: rgba(255,117,107,.12); }
.form-actions { display: flex; justify-content: space-between; gap: .75rem; margin-top: 1.25rem; }

.backup-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 1rem;
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(23,26,24,.75);
}
.backup-panel h2 { font-size: 1rem; }
.backup-panel p { max-width: 58ch; margin-bottom: 0; color: var(--muted); font-size: .8rem; }
.backup-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: .4rem max(.6rem, env(safe-area-inset-right)) calc(.4rem + env(safe-area-inset-bottom)) max(.6rem, env(safe-area-inset-left));
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(18, 21, 19, .95);
  backdrop-filter: blur(18px);
}
.nav-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .22rem;
  min-height: 58px;
  border: 0;
  border-radius: var(--radius-small);
  color: var(--muted);
  background: transparent;
  font-size: .72rem;
  font-weight: 700;
}
.nav-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-button.is-active { color: #fff; background: var(--accent-soft); }
.nav-button.is-active svg { color: var(--accent-strong); }

.toast {
  position: fixed;
  z-index: 50;
  right: 1rem;
  bottom: calc(5.4rem + env(safe-area-inset-bottom));
  max-width: min(420px, calc(100vw - 2rem));
  padding: .8rem 1rem;
  border: 1px solid #455048;
  border-radius: var(--radius-small);
  color: var(--text);
  background: #202821;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 760px) {
  .app-header { flex-wrap: wrap; }
  .brand small { display: none; }
  .header-actions { flex: 1 1 auto; }
  .compact-select { max-width: 100%; flex: 1 1 auto; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-heading { align-items: flex-start; }
  .section-heading > p { text-align: left; }
  .mix-controls, .form-grid, .record-fields { grid-template-columns: 1fr; }
  .wide-field { grid-column: auto; }
  .product-options { grid-template-columns: 1fr; }
  .backup-panel { align-items: flex-start; flex-direction: column; }
  .backup-actions { justify-content: flex-start; }
}

@media (max-width: 500px) {
  .app-header { gap: .65rem; }
  .brand { flex: 1 1 auto; }
  .brand-mark { width: 33px; height: 33px; }
  .header-actions { width: 100%; }
  #installButton { padding-inline: .8rem; font-size: .78rem; }
  .app-main { padding-top: 1.2rem; }
  .today-headline { display: block; }
  .date-chip { display: inline-block; margin-top: .7rem; min-width: 0; text-align: left; }
  .date-chip span, .date-chip strong { display: inline; }
  .date-chip span { margin-right: .4rem; }
  .summary-grid { gap: .5rem; }
  .summary-item { padding: .75rem; }
  .mix-panel { padding: 1rem; }
  .section-heading { display: block; }
  .section-heading > p { margin-top: .5rem; }
  .recipe-item { grid-template-columns: auto minmax(0, 1fr); }
  .recipe-amount { grid-column: 2; padding-left: 0; text-align: left; }
  .recipe-amount strong, .recipe-amount span { display: inline; }
  .recipe-amount span { margin-left: .35rem; }
  .form-actions { flex-direction: column; }
  .form-actions .button { width: 100%; }
  .backup-actions { width: 100%; }
  .backup-actions .button { flex: 1 1 100%; }
}

@media print {
  body { color: #111; background: #fff; }
  .app-header, .bottom-nav, .button, .status-banner, .source-note { display: none !important; }
  .app-main { width: 100%; padding: 0; }
  .view { display: none !important; }
  #scheduleView { display: block !important; }
  .table-scroll { overflow: visible; border-color: #bbb; box-shadow: none; }
  .schedule-table { width: 100%; font-size: 7pt; }
  .schedule-table th, .schedule-table td { min-width: 0; padding: 4px; border-color: #ccc; }
  .schedule-table .product-cell, .schedule-table thead th { position: static; color: #111; background: #eee; }
  .schedule-table .active-col { color: #111; background: #ffd9d5; box-shadow: none; }
}
