/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --c-bg:       #fafaf9;
  --c-surface:  #ffffff;
  --c-border:   #e5e7eb;
  --c-text:     #1f2937;
  --c-muted:    #6b7280;
  --c-primary:  #16a34a;
  --c-primary-h:#15803d;
  --c-danger:   #dc2626;
  --c-admin:    #7c3aed;
  --radius:     8px;
  --nav-h:      52px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  color: var(--c-text);
  background: var(--c-bg);
}
body { display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Nav ──────────────────────────────────────────────────────── */
#nav { position: sticky; top: 0; z-index: 100; }
.nav {
  display: flex; align-items: center; gap: 4px;
  height: var(--nav-h); padding: 0 20px;
  background: var(--c-surface); border-bottom: 1px solid var(--c-border);
}
.nav__brand { font-weight: 700; font-size: 18px; margin-right: 12px; color: var(--c-primary); }
.nav__link  { padding: 6px 10px; border-radius: var(--radius); color: var(--c-text); font-size: 14px; }
.nav__link:hover { background: var(--c-bg); text-decoration: none; }
.nav__link--admin { color: var(--c-admin); }
.nav__user  { margin-left: auto; color: var(--c-muted); font-size: 13px; }
.nav__logout {
  background: none; border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 4px 10px; font-size: 13px; cursor: pointer; color: var(--c-muted);
}
.nav__logout:hover { background: var(--c-bg); }

/* ── Main outlet ──────────────────────────────────────────────── */
#outlet { flex: 1; overflow-y: auto; }

/* ── Shared screen layout ─────────────────────────────────────── */
.screen { max-width: 960px; margin: 0 auto; padding: 24px 20px; }
.screen__header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.screen__header h2 { font-size: 20px; font-weight: 600; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 16px; border-radius: var(--radius); font-size: 14px;
  border: 1px solid var(--c-border); background: var(--c-surface);
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover  { background: var(--c-bg); }
.btn:disabled { opacity: .5; cursor: default; }
.btn--primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn--primary:hover { background: var(--c-primary-h); border-color: var(--c-primary-h); }
.btn--danger  { background: none; color: var(--c-danger); border-color: #fca5a5; }
.btn--danger:hover { background: #fef2f2; }
.btn--sm { padding: 4px 10px; font-size: 13px; }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: #e5e7eb; color: #374151;
}
.badge--active       { background: #dcfce7; color: #166534; }
.badge--out_of_stock { background: #fee2e2; color: #991b1b; }
.badge--archived     { background: #f3f4f6; color: #9ca3af; }
.badge--admin        { background: #ede9fe; color: #5b21b6; }
.badge--user         { background: #dbeafe; color: #1e40af; }
.badge--breakfast    { background: #fef9c3; color: #854d0e; }
.badge--lunch        { background: #dcfce7; color: #166534; }
.badge--dinner       { background: #e0f2fe; color: #075985; }
.badge--snack        { background: #fce7f3; color: #831843; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-page {
  max-width: 380px; margin: 60px auto; padding: 32px;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius);
}
.form-page h2 { margin-bottom: 24px; font-size: 20px; }
.form-page__alt { margin-top: 20px; font-size: 13px; color: var(--c-muted); text-align: center; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form__field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--c-muted); }
.form__field input { padding: 8px 12px; border: 1px solid var(--c-border); border-radius: var(--radius); font-size: 15px; }
.form__field input:focus { outline: 2px solid var(--c-primary); border-color: transparent; }
.form .btn--primary { margin-top: 4px; padding: 10px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input { padding: 6px 10px; border: 1px solid var(--c-border); border-radius: var(--radius); font-size: 14px; flex: 1 1 120px; min-width: 80px; }
.form-section { margin-bottom: 24px; }
.form-section h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }

/* ── Cards & lists ────────────────────────────────────────────── */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px;
}
.card-list { display: flex; flex-direction: column; }
.card__main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card__name { font-weight: 500; flex: 1 1 120px; }
.card__qty  { color: var(--c-muted); font-size: 14px; }
.card__expiry { font-size: 12px; color: var(--c-danger); }
.card__cat  { color: var(--c-muted); font-size: 13px; }
.empty { color: var(--c-muted); padding: 16px 0; text-align: center; }
.error { color: var(--c-danger); font-size: 13px; }
.hidden { display: none !important; }

/* ── Toggle ───────────────────────────────────────────────────── */
.toggle-label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--c-muted); cursor: pointer; }

/* ── Pantry ───────────────────────────────────────────────────── */
.pantry-card { display: flex; align-items: center; justify-content: space-between; }
.pantry-card .card__main { flex: 1; }

/* ── Meals ────────────────────────────────────────────────────── */
.date-range { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.date-range input { padding: 5px 8px; border: 1px solid var(--c-border); border-radius: var(--radius); font-size: 14px; }
.meal-card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.meal-card > summary::before { content: '▶'; font-size: 10px; color: var(--c-muted); transition: transform .15s; }
.meal-card[open] > summary::before { transform: rotate(90deg); }
.meal-card__body { padding-top: 12px; }
.meal-card__body h4 { font-size: 13px; font-weight: 600; color: var(--c-muted); margin-bottom: 6px; }
.component-list { list-style: disc; padding-left: 20px; font-size: 14px; margin-bottom: 12px; }
.meal-card__nutrients { margin-bottom: 10px; }
.nutrient-table { font-size: 13px; border-collapse: collapse; width: 100%; }
.nutrient-table th, .nutrient-table td { padding: 4px 10px; text-align: left; border-bottom: 1px solid var(--c-border); }
.nutrient-table th { color: var(--c-muted); font-weight: 600; }

/* ── Toolbar (search + filter row) ───────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-input {
  padding: 6px 10px; border: 1px solid var(--c-border); border-radius: var(--radius);
  font-size: 14px; flex: 1 1 200px; min-width: 140px;
}
.search-input--sm { flex: 0 1 140px; }
.search-select {
  padding: 6px 10px; border: 1px solid var(--c-border); border-radius: var(--radius);
  font-size: 14px; background: var(--c-surface); color: var(--c-text); cursor: pointer;
}

/* ── Pager ────────────────────────────────────────────────────── */
.pager {
  display: flex; align-items: center; gap: 12px; justify-content: center;
  margin-top: 12px; padding: 8px 0;
}
.pager__info { font-size: 14px; color: var(--c-muted); }
.pager__total { font-size: 12px; }

/* ── Admin food ───────────────────────────────────────────────── */
.food-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.food-row .card__name { flex: 1 1 150px; }
.nutrient-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--c-border); font-size: 14px; }
.nutrient-row span:first-child { flex: 0 0 120px; font-weight: 500; }
.nutrient-row span:nth-child(2) { flex: 1; color: var(--c-muted); }

/* ── Tabs ─────────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--c-border); margin-bottom: 20px; }
.tab-btn {
  padding: 8px 18px; background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; font-size: 14px; color: var(--c-muted); margin-bottom: -1px;
}
.tab-btn:hover { color: var(--c-text); }
.tab-btn.active { color: var(--c-primary); border-bottom-color: var(--c-primary); font-weight: 500; }

/* ── Data tables ──────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--c-border); }
.data-table th { font-weight: 600; color: var(--c-muted); background: var(--c-bg); }
.data-table tr:hover td { background: #f9fafb; }
.mono { font-family: monospace; font-size: 12px; }

/* ── Chat screen ──────────────────────────────────────────────── */
.chat {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--nav-h));
}
.chat__header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
}
.chat__header h1 { font-size: 18px; font-weight: 700; color: var(--c-primary); }
.chat__state {
  font-size: 12px; font-weight: 600; padding: 3px 10px;
  border-radius: 999px; white-space: nowrap;
}
.chat__state:empty { display: none; }
.chat__state--clarification { background: #fef9c3; color: #854d0e; }
.chat__state--confirmation  { background: #dbeafe; color: #1e40af; }
.chat__header-controls { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.debug-toggle { font-size: 13px; color: var(--c-muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.history-sep {
  align-self: center; font-size: 11px; color: var(--c-muted); letter-spacing: .03em;
  display: flex; align-items: center; gap: 8px; width: 100%; margin: 4px 0 8px;
}
.history-sep::before, .history-sep::after {
  content: ''; flex: 1; height: 1px; background: var(--c-border);
}
.messages { flex: 1; overflow-y: auto; padding: 16px 20px; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.message { max-width: 680px; padding: 10px 14px; border-radius: var(--radius); line-height: 1.5; font-size: 15px; white-space: pre-wrap; }
.message--user      { background: var(--c-primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 2px; }
.message--assistant { background: var(--c-surface); border: 1px solid var(--c-border); align-self: flex-start; border-bottom-left-radius: 2px; }
.status--clarification { border-color: #fcd34d; }
.status--confirmation  { border-color: #60a5fa; }
.status--unsupported   { opacity: .7; }
.status--error         { border-color: var(--c-danger); color: var(--c-danger); }
.actions { display: flex; gap: 8px; align-self: flex-start; }
.actions button { padding: 6px 14px; border: 1px solid var(--c-primary); border-radius: var(--radius); color: var(--c-primary); background: none; cursor: pointer; font-size: 14px; }
.actions button:hover { background: var(--c-primary); color: #fff; }
.composer { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--c-border); background: var(--c-surface); }
.composer input { flex: 1; padding: 9px 14px; border: 1px solid var(--c-border); border-radius: var(--radius); font-size: 15px; }
.composer input:focus { outline: 2px solid var(--c-primary); border-color: transparent; }
.composer button { padding: 9px 20px; background: var(--c-primary); color: #fff; border: none; border-radius: var(--radius); font-size: 15px; cursor: pointer; font-weight: 500; }
.composer button:hover { background: var(--c-primary-h); }

/* ── Conversation cards (previous conversations) ─────────── */
.conv-card {
  border: 1px solid var(--c-border); border-radius: var(--radius);
  background: var(--c-bg); opacity: .75; margin-bottom: 4px; overflow: hidden;
}
.conv-card__header {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: none; border: none; cursor: pointer;
  text-align: left; font-size: 13px; color: var(--c-muted);
}
.conv-card__header:hover { background: var(--c-border); }
.conv-card__time   { flex: 0 0 auto; font-size: 11px; white-space: nowrap; }
.conv-card__preview { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--c-text); }
.conv-card__meta   { flex: 0 0 auto; font-size: 11px; white-space: nowrap; }
.conv-card__toggle { flex: 0 0 auto; font-size: 10px; }
.conv-card__body   { padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.conv-card__body .message { font-size: 13px; opacity: .8; }

/* ── Typing indicator ─────────────────────────────────────────── */
.typing-indicator {
  align-self: flex-start;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); border-bottom-left-radius: 2px;
  padding: 12px 16px; display: flex; align-items: center; gap: 5px;
}
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--c-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: .4; }
  30%           { transform: translateY(-5px); opacity: 1;  }
}

/* ── Debug panel ──────────────────────────────────────────────── */
.debug-row { align-self: stretch; }
.debug { background: #f8f9fa; border: 1px solid var(--c-border); border-radius: var(--radius); padding: 8px 12px; font-size: 12px; }
.debug summary { cursor: pointer; color: var(--c-muted); font-weight: 600; }
.debug h4 { margin: 8px 0 4px; color: var(--c-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.debug pre { white-space: pre-wrap; word-break: break-all; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 4px; padding: 6px 8px; font-size: 11px; }

/* ── Admin conversation detail panel ─────────────────────────── */
.data-table--clickable tbody tr { cursor: pointer; }
.data-table--clickable tbody tr:hover td { background: #eff6ff; }

.conv-detail { margin-top: 24px; border: 1px solid var(--c-border); border-radius: var(--radius); overflow: hidden; }
.conv-detail.hidden { display: none; }
.conv-detail__header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: #f1f5f9; border-bottom: 1px solid var(--c-border); }
.conv-detail__header h3 { margin: 0; font-size: 14px; }
.conv-detail__turns { display: flex; flex-direction: column; gap: 0; }

.turn { padding: 12px 16px; border-bottom: 1px solid var(--c-border); }
.turn:last-child { border-bottom: none; }
.turn__meta { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.turn__intents { font-size: 11px; color: var(--c-muted); font-family: monospace; }
.turn__time { font-size: 11px; color: var(--c-muted); margin-left: auto; }
.turn__user { margin-bottom: 4px; font-size: 14px; }
.turn__assistant { font-size: 14px; color: #374151; }

.turn__debug { margin-top: 8px; }
.turn__debug summary { font-size: 12px; color: var(--c-muted); cursor: pointer; display: flex; align-items: center; gap: 6px; }
.turn__debug[open] summary { margin-bottom: 8px; }
.debug-row { margin-top: 6px; font-size: 12px; }
.debug-row strong { color: var(--c-muted); display: block; margin-bottom: 2px; }
.debug-pre { white-space: pre-wrap; word-break: break-all; background: #f8f9fa; border: 1px solid var(--c-border); border-radius: 4px; padding: 6px 8px; font-size: 11px; font-family: monospace; margin: 0; }
.debug-pre--long { max-height: 200px; overflow-y: auto; }

.badge--scripted { background: #fef3c7; color: #92400e; }
.badge--model    { background: #ede9fe; color: #5b21b6; font-family: monospace; font-size: 11px; }
