:root {
  --bg: #f7f8f7;
  --surface: #ffffff;
  --subtle: #f1f4f3;
  --border: #e5e9e7;
  --text: #111827;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-hover: #0d635c;
  --accent-soft: #e6f4f1;
  --danger: #dc2626;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding: 1.25rem 1rem 4rem;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Sammanfattning */
.summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.summary-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.kcal-big {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.kcal-goal {
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.kcal-goal:hover {
  color: var(--text);
  text-decoration: underline;
}

.kcal-remaining {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.progress-track {
  height: 8px;
  background: var(--subtle);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
}
.progress-bar.over {
  background: var(--danger);
}

/* Tidsberoende snabbknapp (gårdagens frukost/lunch/middag) */
.yesterday-btn {
  width: 100%;
  margin-top: 0.85rem;
  padding: 0.6rem 0.85rem;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.yesterday-btn:hover {
  background: var(--accent);
  color: #fff;
}
.yesterday-btn-meta {
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0.85;
}

/* Snabbval (1-klick) */
.quick-bar {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  scrollbar-width: none;
}
.quick-bar::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--subtle);
  border: 1px solid transparent;
  border-radius: 99px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s;
}
.chip:hover, .chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.chip-sub {
  color: var(--muted);
  font-size: 0.75rem;
}

/* Flikar */
.tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--subtle);
  padding: 0.25rem;
  border-radius: var(--radius);
  gap: 0.2rem;
}

.tab {
  border: none;
  background: transparent;
  padding: 0.55rem 0.25rem;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.tab-panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.tab-panel.active {
  display: block;
}

/* Inmatningsfält & knappar */
.search-wrap {
  position: relative;
  margin-bottom: 0.75rem;
}

.input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
}

.clear-btn {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: var(--subtle);
  color: var(--muted);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.flex-1 {
  flex: 1;
}

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.65rem 0.95rem;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm {
  padding: 0.38rem 0.65rem;
  font-size: 0.8rem;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
}
.btn-ghost {
  background: var(--subtle);
  color: var(--text);
}
.btn-text {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-text:hover {
  color: var(--danger);
}

/* Listor (Sök, Vanliga, Måltider, Dagens logg) */
.list {
  display: flex;
  flex-direction: column;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.item-row:last-child {
  border-bottom: none;
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-title {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
}

.item-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.del-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.15rem;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  line-height: 1;
}
.del-btn:hover {
  color: var(--danger);
}

/* Måltider */
.meals-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.builder {
  background: var(--subtle);
  border-radius: 10px;
  padding: 0.85rem;
  margin-bottom: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.builder-search-wrap {
  position: relative;
}

.dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-top: 0.25rem;
  max-height: 200px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.dropdown-item {
  display: flex;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.dropdown-item:hover {
  background: var(--accent-soft);
}

.builder-items {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.builder-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--surface);
  padding: 0.4rem 0.6rem;
  border-radius: 7px;
  font-size: 0.86rem;
}

.gram-mini {
  width: 64px;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: right;
  font-size: 0.84rem;
}

.builder-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.25rem;
}
.builder-actions {
  display: flex;
  gap: 0.4rem;
}

/* Streckkod & Manuellt */
.barcode-btns {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}
.hidden-file {
  display: none;
}
.scanner-box {
  margin: 0.6rem 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.scanner-top {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--subtle);
  font-size: 0.82rem;
}

.manual-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.quick-kcal {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Dagens logg */
.today-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.today-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}
.today-header h2 {
  font-size: 1rem;
  font-weight: 700;
}
.today-count {
  font-size: 0.8rem;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  font-size: 0.86rem;
  padding: 0.85rem 0.25rem;
  text-align: center;
}

/* Modaler */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
}
.modal-sm {
  max-width: 320px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.modal-head h3 {
  font-size: 1.05rem;
}
.muted {
  font-size: 0.82rem;
  color: var(--muted);
}
.close-btn {
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.presets {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.modal-input-row {
  justify-content: space-between;
  background: var(--subtle);
  padding: 0.6rem 0.8rem;
  border-radius: 9px;
}
.gram-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.gram-field .input {
  width: 95px;
  font-weight: 600;
}
.unit {
  font-size: 0.88rem;
  color: var(--muted);
}
.modal-kcal-preview {
  font-size: 1.25rem;
  color: var(--accent);
}

.modal-foot {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 200;
}
.toast {
  background: #111827;
  color: #fff;
  padding: 0.6rem 0.95rem;
  border-radius: 99px;
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.toast-undo {
  border: none;
  background: none;
  color: #5eead4;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}

.hidden {
  display: none !important;
}
