:root {
  color-scheme: light;
  --background: #f5f6fa;
  --ink: #192139;
  --soft: #52607b;
  --line: #dce1ed;
  --accent: #2947da;
  --tint: #edf0ff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, h3, p, ul { margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .75rem;
  padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: white;
}

.home-link { font-weight: 720; text-decoration: none; }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.account p:empty, .feedback p:empty, form p:empty, #search-summary:empty, #comparison-status:empty { display: none; }
.account p { flex-basis: 100%; }

main {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: clamp(24px, 5vw, 58px) clamp(14px, 4vw, 48px) calc(36px + env(safe-area-inset-bottom));
}

h1 { margin-bottom: 22px; font-size: clamp(1.95rem, 5vw, 3rem); line-height: 1.08; letter-spacing: -.045em; overflow-wrap: anywhere; }
h2 { font-size: 1.21rem; letter-spacing: -.02em; }
h3 { font-size: 1rem; overflow-wrap: anywhere; }
p { color: var(--soft); line-height: 1.48; overflow-wrap: anywhere; }
section > p, form > p, .card > fieldset { margin-top: .5rem; }

.card {
  padding: clamp(16px, 3vw, 25px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: white;
  min-width: 0;
}

.login { max-width: 450px; }
.login fieldset { display: grid; gap: .9rem; }
.login button { justify-self: start; }

fieldset { min-inline-size: 0; border: 0; padding: 0; margin: 0; }
label { display: grid; gap: .36rem; font-size: .9rem; font-weight: 650; }
input, select, button { font: inherit; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: white;
  font-size: 1rem;
}

button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .5rem .85rem;
  color: white;
  background: var(--accent);
  font-weight: 680;
  cursor: pointer;
}

button.quiet { color: #233cb4; background: var(--tint); }
button.warning { color: #a51f42; background: #fff0f3; }
button:disabled { opacity: .53; cursor: default; }
button:not(:disabled):hover { filter: brightness(.92); }

.editor-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.feedback { display: flex; align-items: center; flex-wrap: wrap; gap: .65rem; }
.feedback:not(:empty):has(p:not(:empty), button:not([hidden])) { margin-bottom: 14px; }

#catalog, #my-plans, #plan-form, #charts, .comparison-grid { margin-top: 16px; }
#catalog > input { margin-top: 5px; }
#search-summary { margin-top: 6px; font-size: .86rem; }
#my-plans, #product-results, .legend { padding: 0; list-style: none; }
#product-results { display: grid; gap: 5px; margin-top: 8px; }
#product-results button { display: block; width: 100%; text-align: left; overflow-wrap: anywhere; }
#new-product { margin-top: 12px; }
summary { color: #233cb4; cursor: pointer; font-weight: 650; padding: .55rem 0; }
#product-form { padding: .85rem; background: var(--background); border-radius: 11px; }
#plan-form { border-top: 1px solid var(--line); padding-top: 14px; }
.selection { margin: 0 0 12px; color: var(--ink); font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.full { grid-column: 1 / -1; }
.button-row { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: 13px; }
#my-plans { display: grid; gap: 10px; }
#my-plans li { padding: 13px; border: 1px solid var(--line); border-radius: 11px; }
#my-plans li p { margin-top: .3rem; }

.comparison { margin-top: 18px; }
.comparison-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) repeat(2, minmax(0, 1fr)) auto; gap: .7rem; align-items: end; }
#charts { display: grid; gap: 20px; }
#charts:empty, #my-plans:empty { display: none; }
.plot { padding: 14px; border: 1px solid var(--line); border-radius: 13px; }
.plot canvas { display: block; width: 100%; height: 236px; margin-top: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 7px 18px; margin-top: .2rem; }
.legend li { display: flex; align-items: center; gap: .4rem; overflow-wrap: anywhere; }
.swatch { width: .72rem; height: .72rem; border-radius: 50%; flex: none; }
.table-frame { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .42rem .58rem; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: end; }
th:first-child { text-align: start; }

@media (max-width: 700px) {
  .editor-grid { grid-template-columns: minmax(0, 1fr); }
  .comparison-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .comparison-grid > :first-child { grid-column: 1 / -1; }
}

@media (max-width: 370px) {
  .form-grid, .comparison-grid { grid-template-columns: minmax(0, 1fr); }
  .plot { padding: 8px; }
}

.ingredient-editor { display: grid; gap: .6rem; }
.ingredient-editor legend { margin-bottom: .4rem; font-weight: 650; }
#ingredient-inputs { display: grid; gap: .85rem; }
#ingredient-inputs:empty { display: none; }
#add-ingredient { justify-self: start; }

.ingredient-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(4.5rem, .5fr);
  align-items: end;
  gap: .55rem;
  padding: .65rem;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.remove-ingredient { grid-column: 1 / -1; justify-self: end; }
#ingredient-preview { margin-top: .75rem; }
.ingredient-values { font-size: .88rem; }
.ingredient-values th:first-child { white-space: normal; }
.ingredient-values tbody th, .ingredient-values tbody td { vertical-align: top; }
.source { margin-top: .4rem; font-size: .88rem; }
.compare-metric { max-width: 22rem; margin-top: .7rem; }

@media (max-width: 410px) {
  .ingredient-row { grid-template-columns: minmax(0, 1fr) minmax(4.5rem, .55fr); }
  .ingredient-row > :first-child { grid-column: 1 / -1; }
  .ingredient-values th, .ingredient-values td { padding-inline: .35rem; }
}
