:root {
  --bg: #f4f6f1;
  --surface: #ffffff;
  --surface-2: #edf1e8;
  --line: #d6dccc;
  --ink: #1f241f;
  --muted: #62695f;
  --green: #2c6f5c;
  --green-2: #d9eadf;
  --amber: #b8702d;
  --amber-2: #f1dfc8;
  --red: #9d3d3d;
  --red-2: #f0d8d6;
  --blue: #316987;
  --shadow: 0 18px 44px rgba(31, 36, 31, 0.08);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 36px);
  background: rgba(244, 246, 241, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.1;
}

.brand small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.date-control,
.select-control,
.pin-input,
.goal-input,
.text-input {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  min-width: 0;
}

.date-control {
  width: 152px;
}

.pin-input {
  width: 132px;
}

.icon-button,
.action-button,
.secondary-button,
.danger-button,
.ghost-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface);
  white-space: nowrap;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.action-button {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

.secondary-button {
  background: var(--surface);
  border-color: var(--line);
}

.danger-button {
  background: var(--red-2);
  border-color: #e5bcb8;
  color: #6f2424;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  color: currentColor;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.86fr) minmax(460px, 1.35fr);
  grid-template-areas:
    "entry overview"
    "entry ledger";
  gap: 18px;
  padding: 18px clamp(16px, 4vw, 36px) 36px;
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.entry-panel {
  grid-area: entry;
  align-self: start;
  position: sticky;
  top: 86px;
}

.overview-panel {
  grid-area: overview;
}

.ledger-panel {
  grid-area: ledger;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 1rem;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.panel-body {
  padding: 18px;
}

.entry-grid {
  display: grid;
  gap: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field label,
.goals-grid label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.field select,
.field input,
.field textarea {
  width: 100%;
}

textarea {
  min-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  padding: 12px;
  line-height: 1.45;
}

.voice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.status-line {
  min-height: 22px;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-line[data-tone="error"] {
  color: var(--red);
}

.status-line[data-tone="good"] {
  color: var(--green);
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 118px;
  display: grid;
  align-content: space-between;
  background: #fbfcfa;
}

.metric strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1.1;
  margin-top: 8px;
}

.metric span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 10px;
}

.progress-fill {
  height: 100%;
  width: var(--pct, 0%);
  max-width: 100%;
  border-radius: inherit;
  background: var(--green);
}

.progress-fill.over {
  background: var(--amber);
}

.meals-section {
  border-top: 1px solid var(--line);
  padding: 14px 18px 18px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title-row h3 {
  margin: 0;
  font-size: 0.95rem;
}

.meal-list {
  display: grid;
  gap: 10px;
}

.meal-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.meal-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.meal-card h4 {
  margin: 0;
  font-size: 0.98rem;
}

.meal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.pill.green {
  background: var(--green-2);
  color: #1d5948;
}

.pill.amber {
  background: var(--amber-2);
  color: #744616;
}

.meal-text {
  color: var(--muted);
  margin: 10px 0 0;
  line-height: 1.4;
}

.source-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
}

.ledger-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segmented button {
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.segmented button[aria-pressed="true"] {
  background: var(--green-2);
  border-color: #afcfbd;
  color: #1d5948;
}

.nutrient-table {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.nutrient-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) minmax(90px, 0.7fr) minmax(110px, 0.7fr) minmax(130px, 1fr) minmax(76px, 0.5fr);
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 8px 12px;
  background: #fbfcfa;
}

.nutrient-row.header {
  min-height: 38px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.nutrient-name strong {
  display: block;
}

.nutrient-name span,
.confidence,
.empty-state {
  color: var(--muted);
}

.confidence {
  font-size: 0.85rem;
}

.goal-cell {
  display: grid;
  gap: 6px;
}

.goal-text {
  color: var(--muted);
  font-size: 0.82rem;
}

details.goals {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

details.goals summary {
  cursor: pointer;
  font-weight: 800;
}

.goals-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.goal-input {
  width: 100%;
}

.file-input {
  display: none;
}

.hidden {
  display: none !important;
}

@media (max-width: 1060px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "entry"
      "overview"
      "ledger";
  }

  .entry-panel {
    position: static;
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar > * {
    flex: 1 1 auto;
  }

  .date-control,
  .pin-input {
    width: 100%;
  }

  .layout {
    padding: 12px 12px 24px;
  }

  .panel-header {
    flex-direction: column;
  }

  .field-row,
  .voice-row,
  .goals-grid {
    grid-template-columns: 1fr;
  }

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

  .nutrient-row {
    grid-template-columns: 1fr;
    gap: 6px;
    align-items: start;
  }

  .nutrient-row.header {
    display: none;
  }
}

