:root {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #1c2530;
  background: #f4f6f8;
  font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; cursor: pointer; }

/* WCAG 2.4.7 / 2.4.11 — visible focus for keyboard users. outline keeps layout stable. */
:where(button, input, [tabindex]):focus-visible {
  outline: 3px solid #4267b2;
  outline-offset: 2px;
}

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: 0 0 248px; background: #16232e; color: #cbd7e0;
  padding: 24px 16px; display: flex; flex-direction: column; gap: 4px;
}
.brand { font-size: 19px; font-weight: 700; color: #fff; padding: 4px 12px 20px; }
.nav-group { font-size: 11px; letter-spacing: .09em; color: #8194a4; padding: 18px 12px 6px; }
.nav-item {
  text-align: left; background: transparent; color: #cbd7e0; border: 0;
  border-radius: 6px; padding: 9px 12px;
}
.nav-item:hover { background: #223441; }
.nav-item { min-height: 44px; }
.nav-item.active { background: #2e7d6b; color: white; font-weight: 600; }
.content { flex: 1; padding: 32px 40px; max-width: 920px; }
.heading { font-size: 26px; margin: 0 0 20px; }
.section-title {
  font-size: 17px; font-weight: 600; color: #1c2530; margin: 20px 0 8px;
  position: sticky; top: 0; background: #f4f6f8; z-index: 2; padding: 4px 0;
}
.section-card { background: #fff; border: 1px solid #e2e9ee; border-radius: 8px; padding: 4px 16px 12px; margin: 12px 0; }
.row { display: flex; justify-content: space-between; gap: 24px; padding: 7px 0; border-bottom: 1px solid #e5eaee; }
.row .label { color: #62717e; }
.row .value { font-weight: 600; text-align: right; }
.row.warn .value { color: #b4402f; }
.note { color: #62717e; font-size: 13px; line-height: 1.5; margin: 10px 0; }
.note.warn { color: #9c3a2b; }
.rule { border: 0; border-top: 1px solid #d8e0e6; margin: 20px 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.input { padding: 9px 11px; border: 1px solid #c6d2db; border-radius: 6px; max-width: 320px; }
.button {
  background: #e8edf1; color: #1c2530; border: 1px solid #ccd7df;
  border-radius: 6px; padding: 9px 14px; margin: 6px 8px 6px 0;
}
.button:hover { background: #dbe4ea; }
.button.primary { background: #2e7d6b; color: white; border-color: #2e7d6b; }
.button.primary:hover { background: #27695a; }
.selector { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.selector .button { margin: 0; padding: 6px 12px; min-width: 44px; min-height: 44px; }
.selector-value { font-weight: 600; min-width: 200px; text-align: center; }
.notice { background: #fff6d9; border: 1px solid #e5cd7a; padding: 10px 14px; border-radius: 6px; margin-bottom: 18px; display: flex; justify-content: space-between; }
.loading { color: #62717e; padding: 40px 0; }
.popover { border: 1px solid #c6d2db; background: white; border-radius: 10px; padding: 16px; margin-top: 20px; box-shadow: 0 12px 32px rgba(0,0,0,.12); max-width: 700px; }
.popover-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-cell { padding: 10px 4px; min-height: 44px; border: 1px solid #e0e7ec; background: #fafcfd; border-radius: 5px; }
.calendar-cell.active { background: #2e7d6b; color: white; }

.chart-host { width: 100%; max-width: 860px; min-height: 260px; }
.chart-host .uplot { max-width: 100%; }
@media (max-width: 640px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex-basis: auto; flex-direction: row; flex-wrap: nowrap;
    overflow-x: auto; padding: 8px 12px; gap: 4px;
  }
  .brand { padding: 4px 12px 4px 4px; flex: 0 0 auto; font-size: 15px; }
  .nav-group { display: none; }
  .nav-item { flex: 0 0 auto; padding: 8px 10px; min-height: 44px; }
  .content { padding: 16px 12px; }
  .row { flex-direction: column; gap: 2px; }
  .row .value { text-align: left; }
  .chart-host { min-height: 220px; }
}

.chart-tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  background: rgba(22,35,46,.94); color: #eaf1f5; padding: 8px 10px;
  border-radius: 6px; font-size: 12px; line-height: 1.4;
  max-width: 280px; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
.chart-tooltip .tt-title { font-weight: 700; margin-bottom: 3px; }
.chart-tooltip pre { margin: 5px 0 0; white-space: pre-wrap; font-size: 11px; color: #bcd0dc; }
.chart-host { position: relative; }

.daily-table { display: flex; flex-direction: column; gap: 2px; }
.daily-row {
  display: grid; grid-template-columns: 110px 1fr 80px 1fr;
  align-items: center; gap: 8px; padding: 5px 0;
  border-bottom: 1px solid #e8edf1; font-size: 13px;
}
.daily-row .date { color: #62717e; }
.daily-row .units { color: #62717e; text-align: right; }
.trace-cell { position: relative; }
.trace-trigger {
  background: #eef3f6; border: 1px solid #d3dde4; border-radius: 4px;
  padding: 8px 10px; font-size: 12px; cursor: pointer;
  min-height: 44px; min-width: 44px;
}
.trace-trigger:hover { background: #dfe9ef; }
.trace-detail {
  position: absolute; right: 0; top: 100%; z-index: 6;
  background: #fff; border: 1px solid #c9d5dd; border-radius: 6px;
  padding: 8px 10px; box-shadow: 0 8px 22px rgba(0,0,0,.14); min-width: 260px;
}
.trace-detail.hidden { display: none; }
.trace-line { display: grid; grid-template-columns: 1fr 90px 90px 70px; gap: 6px; font-size: 11px; padding: 2px 0; }
.trace-line .ing { font-weight: 600; }
.trace-line .lot, .trace-line .cost, .trace-line .qty { color: #5c6c79; }
@media (max-width: 640px) {
  .daily-row { grid-template-columns: 88px 1fr 58px 1fr; font-size: 11px; gap: 4px; }
  /* Mobile: render inline under the row instead of an absolute popup that clips */
  .trace-cell { position: static; }
  .trace-detail {
    position: static; display: block; width: auto; min-width: 0;
    grid-column: 1 / -1; margin: 6px 0 10px;
    box-shadow: none; border-color: #d8e0e6; background: #f8fafb;
  }
  .daily-row { flex-wrap: wrap; grid-template-columns: 88px 1fr 58px 1fr; }
  .trace-detail.hidden { display: none; }
  .trace-line { grid-template-columns: 1fr 78px 78px; }
  .trace-line .qty { display: none; }
}

.data-table { width: 100%; border-collapse: collapse; margin: 8px 0 4px; font-size: 14px; }
.data-table th {
  text-align: left; font-weight: 600; color: #62717e; font-size: 12px;
  letter-spacing: .03em; text-transform: uppercase;
  padding: 8px 10px; border-bottom: 2px solid #d8e0e6;
}
.data-table td { padding: 8px 10px; border-bottom: 1px solid #e8edf1; }
.data-table th.num, .data-table td.num { text-align: right; white-space: nowrap; }
.data-table td.name { font-weight: 600; }
.data-table tr.row-warn td { color: #b4402f; }
@media (max-width: 640px) {
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 6px 5px; }
}

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

.selector-side { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.selector-side.right { align-items: flex-end; }
.selector-hint { font-size: 11px; color: #62717e; max-width: 110px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ingredient-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.ingredient-chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 8px 12px; min-height: 44px; border: 1px solid #d3dde4;
  border-radius: 6px; background: #f8fafb; cursor: pointer;
}
.ingredient-chip:hover { background: #eef3f6; }
.ingredient-chip.active { border-color: #2e7d6b; background: #e6f2ef; }
.chip-name { font-weight: 600; font-size: 13px; }
.chip-usage { font-size: 11px; color: #62717e; }

/* Elm additions */
.login-card { max-width: 360px; margin: 40px auto; padding: 24px; background: #fff; border: 1px solid #e2e9ee; border-radius: 8px; }
.logout-button { margin-top: 18px; background: #fbeaea; border: 1px solid #e0b7b7; color: #9c3a2b; border-radius: 6px; padding: 8px 14px; min-height: 44px; cursor: pointer; }
.line-chart { width: 100%; max-width: 860px; height: auto; }

.today-footer {
  margin-top: 24px; padding-top: 10px; border-top: 1px solid #d8e0e6;
  text-align: right; font-size: 12px; color: #62717e; letter-spacing: .04em;
}

.top-bar { display: flex; gap: 12px; justify-content: flex-end; margin-bottom: 12px; }
.top-link { background: transparent; border: 0; color: #2e7d6b; font-size: 13px; cursor: pointer; padding: 6px; }
.top-link:hover { text-decoration: underline; }
.menu-list, .ingredient-list { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.menu-card, .ingredient-row { border: 1px solid #dce4e9; border-radius: 6px; background: #fff; }
.menu-card-head { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border: 0; background: transparent; cursor: pointer; min-height: 44px; font-size: 15px; }
.menu-card.expanded .menu-card-head { background: #eef3f6; }
.menu-card-body { padding: 8px 14px 14px; border-top: 1px solid #e8edf1; }
.menu-name { font-weight: 600; }
.menu-price { color: #62717e; }
.ingredient-row { display: grid; grid-template-columns: 1fr 120px 140px; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; text-align: left; min-height: 44px; }
.ingredient-row:hover { background: #f4f8fa; }
.ingredient-row.active { border-color: #2e7d6b; background: #e6f2ef; }
.ingredient-row .stock, .ingredient-row .cost { color: #62717e; font-size: 13px; text-align: right; }
.ingredient-actions { margin-top: 16px; padding: 12px 16px; border: 1px solid #cdd9e1; border-radius: 8px; background: #fbfcfd; }
