:root {
  --page: #f6f7f9;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #18212f;
  --muted: #64748b;
}

body {
  background: var(--page);
  color: var(--text);
}

.top-tabs {
  gap: 0.35rem;
}

.top-tabs .nav-link {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #334155;
  padding: 0.4rem 0.65rem;
}

.top-tabs .nav-link:hover,
.top-tabs .nav-link:focus {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}

.panel,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.panel {
  padding: 1rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1rem;
}

.goal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

.goal-label {
  color: var(--muted);
  font-weight: 600;
}

.goal-numbers {
  font-size: 1.25rem;
  font-weight: 700;
}

.goal-numbers span {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  margin-left: 0.5rem;
}

.goal-track {
  position: relative;
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.goal-food,
.goal-fill {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  border-radius: inherit;
  transition: width 0.16s ease;
}

.goal-food {
  background: #bfdbfe;
}

.goal-fill {
  background: #16a34a;
}

.goal-panel.over .goal-fill {
  background: #dc2626;
}

.goal-panel.over .goal-numbers span {
  color: #b91c1c;
}

.goal-form {
  display: flex;
  gap: 0.5rem;
}

.goal-form input {
  width: 110px;
}

.goal-breakdown,
.goal-legend {
  color: var(--muted);
  font-size: 0.92rem;
}

.goal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.goal-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.goal-legend i {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 999px;
}

.legend-food {
  background: #bfdbfe;
}

.legend-net {
  background: #16a34a;
}

.goal-panel.over .legend-net {
  background: #dc2626;
}

.metric {
  padding: 1rem;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  font-size: 1.8rem;
  line-height: 1.2;
  margin: 0.35rem 0;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.55rem;
}

.quick-grid.single {
  grid-template-columns: 1fr;
}

.quick-category {
  border-top: 1px solid var(--line);
  padding-top: 0.65rem;
  margin-top: 0.65rem;
}

.quick-category:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.quick-category summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  list-style: none;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  user-select: none;
}

.quick-category summary::-webkit-details-marker {
  display: none;
}

.quick-category summary::before {
  content: ">";
  color: var(--muted);
  font-size: 0.8rem;
  transition: transform 0.12s ease;
}

.quick-category[open] summary::before {
  transform: rotate(90deg);
}

.quick-category summary:hover,
.quick-category summary:focus {
  background: #f8fafc;
}

.smart-suggest-wrap {
  position: relative;
}

.smart-suggest-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  display: none;
  overflow: hidden;
  background: #334155;
  border: 1px solid #475569;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.smart-suggest-menu.show {
  display: block;
}

.smart-suggest-menu button {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid #475569;
  background: #334155;
  color: #f8fafc;
  padding: 0.65rem 0.75rem;
  text-align: left;
}

.smart-suggest-menu button span,
.smart-suggest-menu button small {
  display: block;
}

.smart-suggest-menu button small {
  color: #cbd5e1;
  font-size: 0.78rem;
}

.smart-suggest-menu button:last-child {
  border-bottom: 0;
}

.smart-suggest-menu button:hover,
.smart-suggest-menu button:focus {
  background: #475569;
}

.category-count {
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: auto;
}

.insight-list {
  display: grid;
  gap: 0.45rem;
  list-style: none;
  padding-left: 0;
}

.quick-button {
  width: 100%;
  min-height: 64px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0.65rem 0.75rem;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.quick-food-list {
  display: grid;
  gap: 0.55rem;
}

.category-editor {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.category-title,
.category-color-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.category-title {
  min-width: 0;
  font-weight: 700;
}

.category-swatch {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 999px;
}

.form-control-color-sm {
  width: 2.25rem;
  height: 2rem;
  padding: 0.2rem;
}

.category-order-input {
  width: 5rem;
}

.quick-food-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
}

.quick-food-row small {
  display: block;
  color: var(--muted);
}

.quick-button:hover,
.quick-button:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.quick-button span,
.quick-button small {
  display: block;
}

.quick-button span {
  font-weight: 600;
}

.quick-button small {
  color: var(--muted);
}

.measurement-list {
  margin: 0;
}

.measurement-list div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 0.4rem 0;
}

.measurement-list div:last-child {
  border-bottom: 0;
}

.measurement-list dt {
  color: var(--muted);
  font-weight: 500;
}

.measurement-list dd {
  margin: 0;
  font-weight: 600;
}

.narrow {
  max-width: 780px;
  margin: 0 auto;
}

.chart-wrap {
  height: 360px;
}

.estimate-box {
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  padding: 0.75rem;
  font-size: 0.95rem;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.source-branded {
  border-color: #86efac;
  background: #dcfce7;
  color: #166534;
}

.source-reference {
  border-color: #93c5fd;
  background: #dbeafe;
  color: #1d4ed8;
}

.source-personal {
  border-color: #fcd34d;
  background: #fef3c7;
  color: #92400e;
}

.source-generic {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #475569;
}

.duplicate-group {
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 0.65rem;
}

.mobile-fast-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.action-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.login-wrap {
  min-height: calc(100vh - 140px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(100%, 420px);
}

.undo-toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1080;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: min(92vw, 420px);
  border: 1px solid #0f172a;
  border-radius: 8px;
  background: #18212f;
  color: #fff;
  padding: 0.75rem 0.85rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.24);
}

.portion-tools,
.export-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.estimate-review {
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  padding: 0.85rem;
}

.smart-food-list {
  display: grid;
  gap: 0.65rem;
}

.smart-food-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.65rem;
}

.smart-food-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.smart-food-row small {
  display: block;
  color: var(--muted);
}

@media (max-width: 900px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-tabs {
    gap: 0.45rem;
    padding-top: 0.75rem;
  }
}

@media (max-width: 560px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .container {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .panel {
    padding: 0.85rem;
  }

  .quick-grid {
    grid-template-columns: 1fr;
  }

  .metric strong {
    font-size: 1.5rem;
  }

  .table {
    min-width: 640px;
  }

  .action-row {
    white-space: normal;
  }

  .quick-food-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .category-editor {
    align-items: flex-start;
    flex-direction: column;
  }

  .quick-category summary {
    align-items: flex-start;
  }

  .goal-form {
    width: 100%;
  }

  .goal-form input {
    flex: 1;
    width: auto;
  }

  .top-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-tabs .nav-link,
  .top-tabs form,
  .top-tabs form button {
    width: 100%;
    text-align: center;
  }

  .nav-secondary {
    font-size: 0.92rem;
  }

  .smart-food-row,
  .undo-toast {
    align-items: flex-start;
    flex-direction: column;
  }

  .mobile-fast-actions {
    display: grid;
  }
}
