:root {
  --ink: #13201d;
  --muted: #66736f;
  --line: #e3e8e3;
  --canvas: #f5f7f2;
  --surface: #fff;
  --green: #196849;
  --green-soft: #e5f1e8;
  --red: #c83d36;
  --red-soft: #feece8;
  --yellow: #cf9214;
  --yellow-soft: #fff4d7;
  --shadow: 0 12px 34px rgba(25, 42, 34, .06);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.topbar {
  height: 72px;
  padding: 0 max(calc((100vw - 1200px) / 2), 24px);
  display: flex;
  align-items: center;
  gap: 42px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(245, 247, 242, .88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(227, 232, 227, .8);
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; white-space: nowrap; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px;
  color: #fff; background: var(--green); font-weight: 800; font-size: 20px;
}
.brand strong { display: block; font-size: 19px; letter-spacing: 0; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.nav {
  display: flex; gap: 5px; padding: 5px; border-radius: 14px; background: #eaeee8;
}
.nav button {
  height: 40px; padding: 0 21px; border: 0; border-radius: 10px;
  color: var(--muted); background: transparent; font-weight: 650;
}
.nav-icon { display: none; }
.nav button.active { color: var(--green); background: var(--surface); box-shadow: 0 1px 5px rgba(0,0,0,.06); }
.session { display: flex; margin-left: auto; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }
.quiet, .link {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  height: 42px; border-radius: 11px; padding: 0 16px; font-weight: 650;
}
.link { border: 0; height: auto; padding: 5px; color: var(--green); background: transparent; font-size: 14px; }
.shell { max-width: 1200px; margin: 0 auto; padding: 30px 24px 52px; }
.eyebrow {
  color: var(--green); text-transform: uppercase; letter-spacing: 0; font-size: 12px;
  font-weight: 750; margin: 0 0 10px;
}
h1 { margin: 0; font-size: 43px; letter-spacing: 0; line-height: 1.1; }
h2 { margin: 0; font-size: 20px; letter-spacing: 0; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.55; }
.panel, .tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  padding: 22px; box-shadow: var(--shadow);
}
.login-layout { min-height: calc(100vh - 135px); display: grid; grid-template-columns: 1.1fr 430px; gap: 68px; align-items: center; }
.login-intro h1 { font-size: 68px; }
.login-intro p:not(.eyebrow) { color: var(--muted); max-width: 470px; font-size: 18px; line-height: 1.65; }
.login-card { padding: 34px; }
.login-card .muted { margin: 10px 0 27px; }
.auth-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 5px; margin-bottom: 22px;
  border-radius: 14px; background: #eaeee8;
}
.auth-switch button {
  height: 38px; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font-weight: 720;
}
.auth-switch button.active { color: var(--green); background: var(--surface); box-shadow: 0 1px 5px rgba(0,0,0,.06); }
.form { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 650; }
input, select {
  height: 48px; padding: 0 14px; border-radius: 13px; border: 1px solid var(--line);
  color: var(--ink); background: #fbfcfa;
}
input:focus, select:focus { outline: 2px solid #a6ceb9; border-color: var(--green); }
.primary {
  height: 49px; padding: 0 20px; border: 0; border-radius: 13px;
  color: white; background: var(--green); font-weight: 720;
}
.primary.compact { margin-top: 28px; height: 44px; }
.login-form .primary { margin-top: 8px; }
.view { display: none; }
.view.active { display: block; }
.bento { display: grid; gap: 14px; }
.overview-grid { grid-template-columns: 1.45fr repeat(3, .62fr); }
.welcome { grid-row: span 2; min-height: 190px; background: linear-gradient(142deg, #e5f1e8, #fff 72%); }
.welcome h1 { font-size: 34px; margin: 3px 0 10px; }
.stat { min-height: 94px; display: flex; flex-direction: column; justify-content: center; padding: 15px 18px; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 650; }
.stat strong { font-size: 38px; line-height: 1.08; letter-spacing: 0; margin-top: 6px; }
.stat small { color: var(--muted); font-size: 12px; }
.stat.danger { background: var(--red-soft); }
.stat.danger strong { color: var(--red); }
.stat.warning { background: var(--yellow-soft); }
.stat.warning strong { color: var(--yellow); }
.urgent { grid-column: 2 / 5; min-height: 230px; }
.screen-summary {
  grid-column: 1 / 5;
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) minmax(240px, 270px);
  gap: 22px;
  align-items: center;
  padding: 20px 24px;
}
.screen-summary .tile-head { display: grid; gap: 8px; justify-content: start; margin: 0; }
.screen-summary .tile-head .link { justify-self: start; padding: 0; }
.tile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 19px; }
.tile-head .eyebrow { margin-bottom: 6px; }
.priority-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.priority-food {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 3px 12px;
  background: #f8faf7; border-radius: 13px; padding: 11px 12px;
}
.priority-food strong { font-size: 16px; }
.priority-food small { color: var(--muted); font-size: 12px; }
.priority-food .tag { grid-row: 1 / 3; grid-column: 2; }
.screen-copy { color: var(--muted); margin: 0; line-height: 1.6; }
.sync-state {
  display: flex; flex-direction: column; gap: 4px; padding: 13px 15px;
  border-radius: 13px; background: #f8faf7; font-size: 13px;
}
.sync-state strong { font-size: 15px; }
.page-title {
  display: flex; align-items: end; justify-content: space-between; gap: 24px; margin: 8px 0 24px;
}
.page-title h1 { font-size: 37px; }
.pill { padding: 9px 15px; border-radius: 100px; background: var(--green-soft); color: var(--green); font-size: 14px; font-weight: 700; }
.page-title-actions { display: flex; align-items: center; gap: 10px; }
.add-food-action { height: 44px; padding: 0 18px; }
.food-layout { display: grid; grid-template-columns: minmax(340px, 390px) minmax(0, 1fr); gap: 18px; align-items: start; }
.food-list-layout { grid-template-columns: minmax(0, 1fr); }
.entry { position: sticky; top: 96px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 15px; margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 15px; padding: 14px; margin: 2px 0 0; display: flex; flex-direction: column; gap: 11px; }
legend { color: var(--muted); font-size: 13px; font-weight: 700; padding: 0 5px; }
.or { text-align: center; color: #99a49f; font-size: 12px; }
.collection { min-width: 0; padding: 22px 20px; }
.table-frame { border: 1px solid var(--line); border-radius: 17px; overflow: hidden; }
.food-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.food-table th {
  color: var(--muted); background: #f7f9f6; text-align: left; font-size: 12px;
  font-weight: 680; letter-spacing: 0; padding: 12px 13px;
}
.food-table th:nth-child(1) { width: 27%; }
.food-table th:nth-child(2) { width: 16%; }
.food-table th:nth-child(3) { width: 20%; }
.food-table th:nth-child(4) { width: 19%; }
.food-table th:nth-child(5) { width: 18%; text-align: right; }
.food-row { border-top: 1px solid var(--line); transition: background-color .18s; }
.food-row:hover { background: #fafbf9; }
.food-row td { padding: 13px; vertical-align: middle; font-size: 14px; }
.food-name { display: block; font-size: 15px; font-weight: 720; }
.food-row td:first-child small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.food-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.category-pill {
  display: inline-flex; padding: 5px 9px; border-radius: 8px;
  color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 680;
}
.tag {
  display: inline-flex; border-radius: 100px; padding: 5px 10px; font-weight: 720;
  font-size: 12px; border: 1px solid var(--line); white-space: nowrap;
}
.tag.expired { color: #fff; background: var(--red); border-color: var(--red); }
.tag.expiring { color: #8a5a00; background: var(--yellow-soft); border-color: #efd182; }
.actions { display: flex; justify-content: flex-end; gap: 6px; }
.actions button {
  border: 0; background: var(--green-soft); color: var(--green);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; font-weight: 680;
}
.actions button.delete { background: var(--red-soft); color: var(--red); }
.table-empty { text-align: center; padding: 40px 18px !important; color: var(--muted); }
.food-editor-overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  padding: 24px; background: rgba(19, 32, 29, .56);
}
.food-editor {
  width: min(660px, 100%); max-height: calc(100dvh - 48px); overflow: hidden;
  display: flex; flex-direction: column; border: 1px solid rgba(227, 232, 227, .94);
  border-radius: 24px; background: var(--surface); box-shadow: 0 28px 86px rgba(19, 32, 29, .28);
}
.food-editor-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 18px;
  padding: 22px 24px 18px; border-bottom: 1px solid var(--line); background: #fbfcfa;
}
.food-editor-header .eyebrow { margin-bottom: 6px; }
.food-editor-header h2 { font-size: 24px; }
.food-editor-header p:last-child { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.icon-button {
  flex: 0 0 auto; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 13px;
  color: var(--muted); background: var(--surface); font-size: 26px; line-height: 1;
}
.food-editor-form { min-height: 0; display: flex; flex: 1; flex-direction: column; }
.food-editor-body { min-height: 0; overflow-y: auto; padding: 20px 24px 24px; }
.required-hint { margin: 0 0 16px; color: var(--muted); font-size: 12px; }
.required-hint span, .required-mark { color: var(--red); font-weight: 800; }
.optional-mark {
  margin-left: 5px; padding: 2px 6px; border-radius: 6px;
  color: var(--muted); background: #eef1ed; font-size: 10px; font-weight: 700;
}
.food-basic-grid, .calculated-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-group { min-width: 0; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.field-error { min-height: 0; color: var(--red); font-size: 12px; line-height: 1.4; }
.field-error:empty { display: none; }
.field-group.invalid input, .field-group.invalid .select-control, .expiry-panel.invalid .date-control {
  border-color: var(--red); box-shadow: 0 0 0 2px rgba(200, 61, 54, .1);
}
.select-control, .date-control {
  width: 100%; min-height: 50px; display: grid; align-items: center;
  border: 1px solid var(--line); border-radius: 13px; color: var(--ink); background: #fbfcfa;
  text-align: left; font-weight: 650;
}
.select-control { grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; padding: 0 14px; }
.select-control-icon {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px;
  color: var(--green); background: var(--green-soft); font-size: 17px;
}
.select-chevron { color: var(--muted); font-size: 18px; }
.category-picker {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px;
  padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: #f8faf7;
}
.category-option {
  min-width: 0; min-height: 54px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; padding: 6px 3px; border: 1px solid transparent;
  border-radius: 11px; color: var(--muted); background: var(--surface); font-size: 11px; font-weight: 700;
}
.category-option span:first-child { font-size: 18px; }
.category-option.selected { color: var(--green); border-color: #9bcbb2; background: var(--green-soft); }
.expiry-fieldset {
  margin: 2px 0 0; padding: 16px; display: flex; flex-direction: column; gap: 14px;
  border: 1px solid var(--line); border-radius: 17px;
}
.expiry-fieldset legend { color: var(--ink); font-size: 14px; }
.expiry-mode-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 5px;
  border-radius: 13px; background: #eaeee8;
}
.expiry-mode-switch button {
  min-height: 42px; padding: 0 8px; border: 0; border-radius: 9px;
  color: var(--muted); background: transparent; font-size: 13px; font-weight: 720;
}
.expiry-mode-switch button.active { color: var(--green); background: var(--surface); box-shadow: 0 1px 5px rgba(0,0,0,.06); }
.expiry-panel { display: flex; flex-direction: column; gap: 10px; }
.date-presets, .shelf-life-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.date-presets button, .shelf-life-presets button {
  min-height: 42px; padding: 0 6px; border: 1px solid var(--line); border-radius: 10px;
  color: var(--green); background: var(--surface); font-size: 12px; font-weight: 700;
}
.date-presets button.selected, .shelf-life-presets button.selected { color: #fff; border-color: var(--green); background: var(--green); }
.date-control { grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; padding: 0 14px; }
.date-control span:first-child { color: var(--green); }
.date-control span:last-child { color: var(--muted); font-size: 20px; }
.calculated-grid .field-group { margin-bottom: 0; }
.calculated-expiry {
  margin: 0; padding: 12px 13px; border-radius: 11px;
  color: var(--muted); background: #f8faf7; font-size: 13px; line-height: 1.5;
}
.calculated-expiry.ready { color: var(--green); background: var(--green-soft); font-weight: 700; }
.calendar-panel { padding: 13px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.calendar-head { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 8px; margin-bottom: 9px; }
.calendar-head strong { text-align: center; font-size: 15px; }
.calendar-head button {
  width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink); background: #f8faf7; font-size: 24px;
}
.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendar-weekdays span { padding: 5px 0; color: var(--muted); text-align: center; font-size: 11px; font-weight: 700; }
.calendar-day {
  aspect-ratio: 1; min-height: 36px; border: 0; border-radius: 10px;
  color: var(--ink); background: transparent; font-size: 12px;
}
.calendar-day:hover { background: #f0f4ef; }
.calendar-day.today { color: var(--green); box-shadow: inset 0 0 0 1px #9bcbb2; font-weight: 800; }
.calendar-day.selected { color: #fff; background: var(--green); box-shadow: none; font-weight: 800; }
.calendar-spacer { aspect-ratio: 1; }
.food-editor-actions {
  display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px;
  padding: 14px 24px 18px; border-top: 1px solid var(--line); background: var(--surface);
}
.food-editor-actions button { height: 48px; border-radius: 13px; font-weight: 720; }
body.modal-open { overflow: hidden; }
.preview-tools { display: flex; align-items: end; gap: 10px; }
.inline-select { flex-direction: row; align-items: center; gap: 8px; }
.inline-select select { height: 42px; }
#refreshPreview { min-width: 96px; white-space: nowrap; }
.display-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; gap: 18px; }
.display-layout > * { min-width: 0; }
.display-card { padding: 18px; }
.screen {
  --screen-native-width: 480px;
  --screen-native-height: 800px;
  --screen-scaled-width: 480px;
  --screen-scaled-height: 800px;
  --screen-scale: 1;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  background: #eceeea;
  padding: 18px;
  border-radius: 17px;
  overflow: hidden;
}
.screen-scale-frame {
  position: relative;
  width: var(--screen-scaled-width);
  height: var(--screen-scaled-height);
  margin: 0 auto;
}
.screen iframe {
  position: absolute;
  inset: 0 auto auto 0;
  display: block;
  width: var(--screen-native-width);
  height: var(--screen-native-height);
  border: 1px solid #d4dbd2;
  background: white;
  transform: scale(var(--screen-scale));
  transform-origin: top left;
}
.display-notes h2 { margin-bottom: 19px; }
.note { display: flex; flex-direction: column; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 0 16px; margin-bottom: 16px; }
.note strong { font-size: 28px; letter-spacing: 0; color: var(--green); }
.note span { font-size: 13px; color: var(--muted); }
.device-layout { display: grid; grid-template-columns: 400px 1fr; gap: 18px; align-items: start; }
.device-preview-section { margin-top: 34px; scroll-margin-top: 96px; }
.device-section-title { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.device-section-title .eyebrow { margin-bottom: 6px; }
.pairing-action { margin-top: 23px; }
.pairing-code {
  display: grid; gap: 6px; margin-top: 16px; padding: 15px;
  background: #f8faf7; border: 1px solid var(--line); border-radius: 13px;
}
.pairing-code span { color: var(--muted); font-size: 12px; font-weight: 720; }
.pairing-code strong { font-size: 30px; letter-spacing: 0; color: var(--green); }
.pairing-code small { color: var(--muted); font-size: 12px; }
.devices { color: var(--muted); font-size: 14px; }
.device {
  display: flex; flex-direction: column; gap: 6px; padding: 15px; margin-bottom: 10px;
  background: #f8faf7; border-radius: 15px;
}
.device strong { color: var(--ink); }
.status-dot { color: var(--green); font-size: 13px; }
.status-dot::before { content: ""; display: inline-block; width: 8px; height: 8px; background: #45b676; border-radius: 50%; margin-right: 7px; }
.user-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; align-items: start; }
.account-summary { display: grid; gap: 12px; }
.account-line {
  display: grid; gap: 4px; padding: 13px 14px; border-radius: 13px; background: #f8faf7;
}
.account-line span { color: var(--muted); font-size: 12px; font-weight: 680; }
.account-line strong { font-size: 15px; overflow-wrap: anywhere; }
.role-pill {
  display: inline-flex; align-items: center; border-radius: 100px; padding: 5px 10px;
  color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 720;
}
.role-pill.member { color: var(--muted); background: #f8faf7; border: 1px solid var(--line); }
.user-list { display: grid; gap: 10px; }
.user-card {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px;
  padding: 14px; border-radius: 14px; background: #f8faf7;
}
.user-card strong { font-size: 15px; overflow-wrap: anywhere; }
.user-card small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.user-card .role-pill { grid-column: 2; grid-row: 1 / 3; align-self: center; }
.user-meta {
  grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 5px;
}
.user-meta span {
  padding: 4px 8px; border-radius: 8px; color: var(--muted); background: var(--surface);
  font-size: 12px; font-weight: 650;
}
.message {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  margin: 0; background: var(--ink); color: white; border-radius: 12px; padding: 12px 18px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20;
}
.message.show { opacity: 1; }
.dialog-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  padding: 24px; background: rgba(19, 32, 29, .54); backdrop-filter: blur(5px);
}
.dialog-card {
  width: min(460px, 100%); padding: 25px; border: 1px solid rgba(227, 232, 227, .92);
  border-radius: 22px; background: var(--surface); box-shadow: 0 24px 72px rgba(19, 32, 29, .24);
}
.dialog-card h2 { font-size: 22px; line-height: 1.25; }
.dialog-eyebrow {
  margin: 0 0 8px; color: var(--green); font-size: 12px; font-weight: 750;
}
.dialog-body {
  margin: 12px 0 0; color: var(--muted); font-size: 14px; line-height: 1.65;
}
.dialog-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 26px;
}
.dialog-actions button {
  height: 44px; min-width: 92px; padding: 0 18px; border-radius: 12px; font-weight: 720;
}
.dialog-cancel {
  border: 1px solid var(--line); background: #f8faf7; color: var(--ink);
}
.dialog-confirm {
  border: 0; background: var(--green); color: #fff;
}
.dialog-confirm.danger { background: var(--red); }
.dialog-actions button:focus-visible {
  outline: 3px solid #a6ceb9; outline-offset: 2px;
}
@media (max-width: 960px) {
  .topbar { height: auto; min-height: 68px; padding: 12px 16px; flex-wrap: wrap; gap: 12px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .nav button { flex: 1; padding: 0 13px; }
  .shell { padding: 20px 16px 40px; }
  h1 { font-size: 38px; }
  .login-intro h1 { font-size: 48px; }
  .login-layout, .food-layout, .display-layout, .device-layout, .user-layout { grid-template-columns: 1fr; gap: 16px; }
  .page-title { align-items: flex-start; }
  .device-section-title { flex-direction: column; align-items: flex-start; gap: 14px; }
  .device-section-title .preview-tools { width: 100%; justify-content: flex-start; }
  .overview-grid { grid-template-columns: repeat(3, 1fr); }
  .welcome { grid-column: 1 / -1; grid-row: auto; }
  .urgent, .screen-summary { grid-column: 1 / -1; }
  .screen-summary { grid-template-columns: 1fr; gap: 14px; }
  .screen-summary .tile-head { display: flex; align-items: center; justify-content: space-between; }
  .entry { position: static; }
  .collection { order: -1; }
}
@media (max-width: 640px) {
  .topbar {
    min-height: 60px;
    padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
    flex-wrap: nowrap;
    gap: 8px;
    backdrop-filter: none;
  }
  .brand { gap: 9px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 13px; font-size: 19px; }
  .brand strong { font-size: 18px; }
  .brand small { display: none; }
  .session { gap: 8px; font-size: 13px; }
  .session .quiet { height: 44px; padding: 0 13px; border-radius: 11px; }
  .nav {
    position: fixed;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 15;
    width: auto;
    height: 64px;
    gap: 2px;
    padding: 6px;
    overflow: visible;
    border: 1px solid rgba(227, 232, 227, .92);
    border-radius: 18px;
    background: rgba(245, 247, 242, .98);
    box-shadow: 0 14px 34px rgba(19, 32, 29, .16);
  }
  .nav button {
    flex: 1 1 0;
    min-width: 0;
    height: 52px;
    padding: 4px 2px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    line-height: 1;
  }
  .nav-icon { display: block; width: 21px; height: 21px; fill: currentColor; }
  .shell { padding: 14px 16px 32px; }
  #workspace { padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
  .panel, .tile { border-radius: 18px; padding: 18px; }
  h1, .page-title h1 { font-size: 34px; line-height: 1.1; }
  .welcome {
    grid-column: 1 / -1;
    min-height: auto;
    padding: 16px;
  }
  .welcome h1 { margin: 2px 0 0; font-size: 29px; overflow-wrap: anywhere; }
  .welcome .muted { margin: 8px 0 0; line-height: 1.45; }
  .primary.compact { height: 44px; margin-top: 14px; }
  .page-title { flex-direction: column; align-items: flex-start; gap: 14px; margin: 18px 0 18px; }
  .page-title-actions { width: 100%; justify-content: space-between; }
  .add-food-action { min-width: 112px; }
  .pill { padding: 8px 13px; }
  .overview-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .stat {
    grid-column: auto;
    min-width: 0;
    min-height: 96px;
    padding: 12px 10px;
    border-radius: 16px;
  }
  .stat span { min-height: 27px; font-size: 11px; line-height: 1.25; }
  .stat strong { margin-top: 3px; font-size: 30px; }
  .stat small { font-size: 11px; white-space: nowrap; }
  .urgent, .screen-summary { grid-column: 1 / -1; padding: 16px; }
  .tile-head { margin-bottom: 14px; }
  .tile-head .link, .section-head .link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
  }
  .priority-list { grid-template-columns: 1fr; gap: 8px; }
  .priority-food { min-height: 62px; padding: 10px 11px; }
  .screen-summary { gap: 10px; }
  .screen-summary .tile-head { min-height: 44px; margin-bottom: 0; }
  .message {
    bottom: calc(88px + env(safe-area-inset-bottom));
    width: max-content;
    max-width: calc(100vw - 32px);
    text-align: center;
  }
  .form-grid { grid-template-columns: 1fr; }
  .collection { padding: 17px 14px; }
  .table-frame { border: 0; overflow: visible; }
  .food-table, .food-table tbody, .food-row { display: block; }
  .food-table thead { display: none; }
  .food-row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px 12px;
    margin-bottom: 9px; padding: 12px; background: #f8faf7;
    border: 0; border-radius: 14px;
  }
  .food-row td { padding: 0; font-size: 13px; }
  .food-row td::before { display: none; }
  .food-row td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .food-row td:nth-child(4) { grid-column: 2; grid-row: 1; }
  .food-row td:nth-child(2) { grid-column: 1; grid-row: 2; }
  .food-row td:nth-child(3) { grid-column: 2; grid-row: 2; align-self: center; justify-self: end; font-size: 12px; }
  .food-row td:nth-child(3)::before { content: "到期 "; display: inline; }
  .food-row td:nth-child(5) { grid-column: 1 / -1; grid-row: 3; }
  .food-name { font-size: 15px; }
  .food-row td:first-child small { display: inline; margin: 0 0 0 6px; }
  .category-pill { padding: 4px 8px; border-radius: 7px; }
  .tag { padding: 5px 9px; }
  .actions { justify-content: flex-start; margin-top: 1px; }
  .actions button { padding: 5px 8px; }
  .table-empty { display: block; }
  .food-editor-overlay { place-items: end center; padding: 0; }
  .food-editor {
    width: 100%; max-height: calc(100dvh - max(12px, env(safe-area-inset-top)));
    border-width: 1px 0 0; border-radius: 24px 24px 0 0;
  }
  .food-editor-header { padding: 18px 16px 14px; }
  .food-editor-header h2 { font-size: 22px; }
  .food-editor-body { padding: 16px; }
  .food-basic-grid, .calculated-grid { grid-template-columns: 1fr; gap: 0; }
  .category-picker { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .expiry-fieldset { padding: 14px; }
  .date-presets, .shelf-life-presets { gap: 6px; }
  .date-presets button, .shelf-life-presets button { min-height: 44px; padding-inline: 3px; }
  .food-editor-actions {
    grid-template-columns: 1fr 1.5fr; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  }
  .user-card { grid-template-columns: 1fr; }
  .user-card .role-pill { grid-column: auto; grid-row: auto; justify-self: start; }
  .preview-tools {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 8px;
  }
  .inline-select {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    width: 100%;
  }
  .inline-select select { min-width: 0; width: 100%; }
  #refreshPreview { grid-column: 1 / -1; width: 100%; min-width: 92px; padding: 0 12px; }
  .display-layout .panel { padding: 12px; }
  .display-notes { padding: 20px !important; }
  .device-preview-section { margin-top: 28px; scroll-margin-top: 80px; }
  .note { margin-bottom: 13px; padding-bottom: 13px; }
  .dialog-overlay { align-items: end; padding: 16px; }
  .dialog-card { padding: 21px; border-radius: 20px; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dialog-actions button { min-width: 0; }
}
@media (max-width: 380px) {
  .session { gap: 6px; }
  .session .quiet { padding: 0 11px; }
  .stat { padding-inline: 8px; }
  .stat span, .stat small { font-size: 10px; }
  .preview-tools { grid-template-columns: 1fr; }
  #refreshPreview { grid-column: auto; width: 100%; }
}

.token-card { grid-column: 1 / -1; }
.token-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.token-form .primary { height: 48px; }
.new-token { display: grid; gap: 10px; margin: 16px 0; padding: 14px; border-radius: 14px; background: var(--yellow-soft); }
.new-token code { padding: 10px; overflow-wrap: anywhere; border-radius: 9px; background: #fff; user-select: all; }
.new-token .quiet { justify-self: start; }
.token-list { display: grid; gap: 9px; margin-top: 16px; }
.token-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 12px; align-items: center; padding: 12px; border-radius: 13px; background: #f8faf7; }
.token-row div { display: flex; align-items: center; gap: 10px; min-width: 0; }
.token-row code, .token-row small { color: var(--muted); font-size: 12px; }
.token-row small { grid-column: 1; }
.token-row button { grid-column: 2; grid-row: 1 / 3; border: 0; color: var(--red); background: transparent; font-weight: 700; }
.mcp-config { margin-top: 18px; color: var(--muted); font-size: 13px; }
.mcp-config summary { cursor: pointer; font-weight: 700; }
.mcp-config pre { overflow-x: auto; padding: 13px; border-radius: 12px; color: var(--ink); background: #f3f5f1; line-height: 1.55; }
.agent-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; min-height: 640px; }
.conversation-panel, .chat-panel { min-height: 0; }
.conversation-toggle { display: none; }
.conversation-list { display: grid; gap: 7px; }
.conversation-row { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 5px; align-items: stretch; }
.conversation-item { display: grid; gap: 4px; width: 100%; padding: 11px; text-align: left; border: 0; border-radius: 12px; color: var(--ink); background: #f8faf7; }
.conversation-item.active { color: var(--green); background: var(--green-soft); }
.conversation-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item small { color: var(--muted); font-size: 11px; }
.conversation-delete {
  display: grid; place-items: center; width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 10px;
  color: var(--muted); background: transparent; opacity: 0; transition: opacity .15s, color .15s, background-color .15s;
}
.conversation-row:hover .conversation-delete, .conversation-delete:focus-visible { opacity: 1; }
.conversation-delete:hover, .conversation-delete:focus-visible { color: var(--red); background: var(--red-soft); }
.conversation-delete svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-panel { display: grid; grid-template-rows: minmax(0, 1fr) auto; padding: 0; overflow: hidden; }
.agent-messages { display: flex; flex-direction: column; gap: 12px; min-height: 480px; max-height: 620px; padding: 22px; overflow-y: auto; }
.agent-empty { display: grid; place-items: center; align-content: center; gap: 8px; flex: 1; min-height: 360px; color: var(--muted); text-align: center; }
.agent-empty strong { color: var(--ink); font-size: 18px; }
.agent-message { max-width: 82%; }
.agent-message > div:first-child { padding: 12px 14px; border-radius: 15px; line-height: 1.6; background: #f1f4ef; }
.agent-message.user { align-self: flex-end; }
.agent-message.user > div:first-child { color: #fff; background: var(--green); border-bottom-right-radius: 4px; }
.agent-message.assistant { align-self: flex-start; }
.agent-message.assistant > div:first-child { border-bottom-left-radius: 4px; }
.agent-message.thinking { color: var(--muted); }
.agent-markdown { overflow-wrap: anywhere; }
.agent-markdown > :first-child { margin-top: 0; }
.agent-markdown > :last-child { margin-bottom: 0; }
.agent-markdown p { margin: 0 0 10px; }
.agent-markdown h1, .agent-markdown h2, .agent-markdown h3, .agent-markdown h4 { margin: 14px 0 8px; line-height: 1.3; }
.agent-markdown h1 { font-size: 21px; }
.agent-markdown h2 { font-size: 19px; }
.agent-markdown h3, .agent-markdown h4 { font-size: 16px; }
.agent-markdown ul, .agent-markdown ol { margin: 8px 0 10px; padding-left: 24px; }
.agent-markdown li + li { margin-top: 4px; }
.agent-markdown blockquote { margin: 10px 0; padding: 8px 12px; border-left: 3px solid var(--green); color: var(--muted); background: rgba(255,255,255,.55); }
.agent-markdown code { padding: 1px 5px; border-radius: 5px; background: #e4e9e2; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.agent-markdown pre { overflow-x: auto; margin: 10px 0; padding: 11px; border-radius: 9px; background: #e4e9e2; }
.agent-markdown pre code { padding: 0; background: transparent; }
.agent-markdown a { color: var(--green); text-decoration: underline; }
.markdown-table-wrap { max-width: 100%; margin: 10px 0; overflow-x: auto; }
.agent-markdown table { width: 100%; border-collapse: collapse; font-size: 13px; }
.agent-markdown th, .agent-markdown td { padding: 7px 9px; border: 1px solid var(--line); text-align: left; white-space: nowrap; }
.agent-markdown th { background: #e7ece5; }
.agent-compose {
  display: flex; align-items: flex-end; gap: 8px; margin: 14px 16px 16px; padding: 7px 8px 7px 16px;
  border: 1px solid var(--line); border-radius: 27px; background: #fbfcfa; box-shadow: 0 5px 18px rgba(19, 32, 29, .07);
}
.agent-compose:focus-within { border-color: #7aae94; box-shadow: 0 0 0 3px rgba(34, 120, 79, .12); }
.agent-compose textarea {
  flex: 1; width: 100%; height: 40px; min-height: 40px; max-height: 128px; padding: 9px 0;
  resize: none; overflow-y: auto; border: 0; outline: 0; color: var(--ink); background: transparent;
  font: inherit; line-height: 22px;
}
.agent-compose textarea::placeholder { color: #8b938e; }
.agent-send {
  display: grid; place-items: center; flex: 0 0 40px; width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 50%; color: #fff; background: var(--green); box-shadow: 0 4px 10px rgba(27, 111, 75, .2);
}
.agent-send:hover:not(:disabled) { background: #145f42; transform: translateY(-1px); }
.agent-send:disabled { color: #8b938e; background: #d8ddd9; box-shadow: none; }
.agent-send svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.agent-compose.agent-disabled { opacity: .6; }
.pending-action { display: grid; gap: 7px; margin-top: 8px; padding: 13px; border: 1px solid #efd182; border-radius: 13px; background: var(--yellow-soft); }
.pending-action[aria-busy="true"] { opacity: .78; }
.pending-action[aria-busy="true"] button { cursor: wait; }
.pending-action small { color: var(--muted); }
.pending-action > div { display: flex; gap: 8px; }
.pending-action button { height: 38px; }
.pending-details { display: grid; gap: 7px; margin: 3px 0; padding: 0; list-style: none; }
.pending-details li { display: grid; gap: 2px; padding: 9px 10px; border: 1px solid rgba(194, 151, 45, .34); border-radius: 9px; background: rgba(255,255,255,.5); }
.pending-details span { color: var(--muted); font-size: 12px; }
.agent-result { margin-top: 7px; color: var(--green); font-size: 13px; font-weight: 700; }
.agent-result.cancelled { color: var(--muted); }
.user-layout {
  grid-template-columns: minmax(320px, .8fr) minmax(460px, 1.2fr);
  grid-template-areas:
    "account users"
    "ai ai"
    "token token";
}
.user-layout > .account-card { grid-area: account; }
.user-layout > .collection { grid-area: users; }
.user-layout > .ai-settings-card { grid-area: ai; }
.user-layout > .token-card { grid-area: token; }
.ai-settings-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ai-settings-form .ai-base-url { grid-column: 1 / -1; }
.ai-settings-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; }
.ai-settings-actions button { min-width: 130px; }
.welcome-agent { display: grid; gap: 9px; margin-top: 24px; }
.welcome-agent > strong { font-size: 14px; }
.welcome-agent-form { display: grid; gap: 9px; }
.welcome-agent-form textarea {
  min-height: 66px; padding: 12px 14px; resize: vertical; border: 1px solid var(--line);
  border-radius: 13px; color: var(--ink); background: rgba(255,255,255,.9); font: inherit;
}
.welcome-agent-form .primary { width: 100%; height: 46px; }
.welcome-agent-form.agent-disabled { opacity: .58; }
.overview-agent-result .agent-message { max-width: 100%; }
.overview-agent-status:empty { display: none; }
.welcome-manual-add { justify-self: start; margin-top: 9px; padding: 0; }
.agent-quick-error { color: var(--red); font-size: 13px; }

@media (max-width: 960px) {
  .user-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "account" "users" "ai" "token";
  }
  .agent-layout { grid-template-columns: 1fr; min-height: 0; }
  .conversation-panel { max-height: 230px; overflow-y: auto; }
}

@media (max-width: 640px) {
  .token-form { grid-template-columns: 1fr; }
  .ai-settings-form { grid-template-columns: 1fr; }
  .ai-settings-form .ai-base-url, .ai-settings-actions { grid-column: 1; }
  .ai-settings-actions { display: grid; grid-template-columns: 1fr 1.4fr; }
  .ai-settings-actions button { min-width: 0; }
  body.agent-view-active {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    overflow: hidden;
  }
  .agent-view-active .shell {
    height: auto;
    min-height: 0;
    padding: 8px 12px calc(84px + env(safe-area-inset-bottom));
  }
  .agent-view-active #workspace { height: 100%; padding-bottom: 0; }
  [data-view-panel="agent"].active {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100%;
    min-height: 0;
  }
  [data-view-panel="agent"] .page-title {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin: 0 2px 8px;
  }
  [data-view-panel="agent"] .page-title .eyebrow { display: none; }
  [data-view-panel="agent"] .page-title h1 { font-size: 26px; }
  [data-view-panel="agent"] #newConversation { height: 42px; padding: 0 15px; }
  .agent-layout {
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    min-height: 0;
    height: 100%;
  }
  .conversation-panel {
    position: relative;
    z-index: 4;
    max-height: none;
    padding: 0;
    overflow: visible;
    border-radius: 16px;
  }
  .conversation-head { align-items: center; min-height: 54px; margin: 0; padding: 6px 12px; }
  .conversation-head h2 { display: none; }
  .conversation-head > .muted { flex: 0 0 auto; font-size: 12px; white-space: nowrap; }
  .conversation-toggle {
    display: flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0;
    border: 0;
    color: var(--ink);
    background: transparent;
    text-align: left;
  }
  .conversation-toggle span { display: grid; min-width: 0; gap: 1px; }
  .conversation-toggle small { color: var(--muted); font-size: 10px; font-weight: 650; }
  .conversation-toggle strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
  .conversation-toggle svg {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .18s ease;
  }
  .conversation-panel.mobile-open .conversation-toggle svg { transform: rotate(180deg); }
  .conversation-list {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: min(46dvh, 340px);
    padding: 10px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: 0 18px 42px rgba(19, 32, 29, .18);
  }
  .conversation-panel.mobile-open .conversation-list { display: grid; }
  .conversation-delete { opacity: 1; }
  .chat-panel { height: 100%; border-radius: 18px; }
  .agent-compose { margin: 8px 10px 10px; }
  .welcome-agent { margin-top: 18px; }
  .agent-messages { min-height: 0; max-height: none; padding: 14px; }
  .agent-empty { min-height: 0; }
  .agent-message { max-width: 92%; }
  .token-row { grid-template-columns: 1fr auto; }
}
