:root {
  --bg: #f7f8f5;
  --surface: #ffffff;
  --border: #e6e9e3;
  --text: #13261c;
  --muted: #62716a;
  --accent: #1f6b47;
  --accent-soft: #e6f3ec;
  --accent-strong: #17583a;
  --cell-empty: #eceeea;
  --cell-empty-border: #dcdfd9;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow: 0 1px 2px rgba(19, 38, 28, 0.04), 0 4px 16px rgba(19, 38, 28, 0.04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

h1, h2, h3, p { margin: 0; }

button { font: inherit; color: inherit; cursor: pointer; }

svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand-icon { width: 24px; height: 24px; fill: var(--accent); stroke: none; }

.link-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  padding: 6px 4px;
  font-weight: 500;
}
.link-button:hover { color: var(--accent); }
.link-button.small { font-size: 13px; color: var(--muted); }
.link-button.small:hover { color: var(--accent); }

.help-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}

/* ── Sida ───────────────────────────────────────────── */
.page { max-width: 1200px; margin: 0 auto; padding: 24px 24px 48px; }

.intro { margin-bottom: 20px; }
.intro h1 { font-size: clamp(26px, 3.4vw, 36px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.intro p { color: var(--muted); margin-top: 4px; font-size: 16px; }

.columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel h2 { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }

/* ── Vänster panel ──────────────────────────────────── */
.goal-panel {
  position: sticky;
  top: 16px;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.goal-panel.drop-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow);
}

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  font-weight: 500;
}

.pill-button {
  border: 1px solid transparent;
  padding: 6px 12px;
  font-size: 14px;
}
.pill-button:hover { border-color: var(--accent); }
.pill-button svg { width: 15px; height: 15px; }

.goal-body {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(0, 1.4fr);
  gap: 16px;
  margin-top: 18px;
}

.stat-percent { font-size: 48px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.stat-grams { font-size: 16px; font-weight: 500; margin-top: 12px; }
.stat-rest { color: var(--muted); font-size: 14px; margin-top: 4px; }

.grid-wrap { display: flex; flex-direction: column; align-items: center; }

.cell-grid { width: 100%; max-width: 320px; }

.cell-block {
  display: grid;
  grid-template-columns: repeat(var(--cols, 10), 1fr);
  gap: 5px;
}

.cell {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--cell-empty);
  border: 1px solid var(--cell-empty-border);
  transition: background-color 0.25s, border-color 0.25s;
}

/* Överskottscirklar visas bara när de är ifyllda. */
.overflow-block .cell:not(.filled) { display: none; }

.cell.filled {
  background: var(--fill);
  border-color: transparent;
}

.cell.pop { animation: pop 0.35s cubic-bezier(0.3, 1.6, 0.5, 1) both; }

@keyframes pop {
  0% { transform: scale(0.4); opacity: 0.3; }
  100% { transform: scale(1); opacity: 1; }
}

.goal-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.goal-line::before,
.goal-line::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--text);
  opacity: 0.55;
  border-radius: 2px;
}

.grid-note { color: var(--muted); font-size: 12.5px; margin-top: 12px; }
.grid-overflow { color: var(--accent); font-size: 13px; font-weight: 600; margin-top: 4px; }

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  padding: 22px 16px;
  border: 1.6px dashed #a9d2bb;
  border-radius: var(--radius-md);
  background: #f5faf7;
  color: var(--accent-strong);
  font-weight: 500;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.dropzone svg { width: 24px; height: 24px; }

.goal-panel.drop-active .dropzone {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: scale(1.02);
}

.added { margin-top: 18px; }
.added-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.added h3 { font-size: 13px; font-weight: 500; color: var(--muted); }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  background: var(--surface);
}
.chip.flash { animation: flash 0.6s ease-out; }

@keyframes flash {
  0% { background: var(--accent-soft); transform: scale(1.06); }
  100% { background: var(--surface); transform: scale(1); }
}

.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }

.chip-remove {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}
.chip-remove:hover { background: #f1f2ef; color: var(--text); }

.empty-hint { color: var(--muted); font-size: 14px; }

/* ── Höger panel ────────────────────────────────────── */
.food-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.food-head .muted { font-size: 14px; margin-top: 2px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 200px;
  max-width: 260px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { border: 0; outline: none; font: inherit; width: 100%; background: none; color: inherit; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }

.filter {
  padding: 7px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #f1f2ef;
  font-size: 14px;
  font-weight: 500;
}
.filter:hover { border-color: var(--border); }
.filter[aria-pressed="true"] { background: var(--accent); color: #fff; }

.food-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.food-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--surface);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: box-shadow 0.15s, transform 0.15s, opacity 0.15s;
}
.food-card:hover { box-shadow: 0 4px 14px rgba(19, 38, 28, 0.08); transform: translateY(-1px); }
.food-card.dragging { opacity: 0.4; }

.food-image {
  display: grid;
  place-items: center;
  height: 84px;
  border-radius: 10px;
  background: #f6f7f4;
  font-size: 46px;
  line-height: 1;
}

.food-info { margin-top: 8px; padding-right: 40px; }
.food-name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.food-portion { color: var(--muted); font-size: 13px; margin-top: 2px; }
.pill-protein { margin-top: 8px; padding: 3px 10px; font-size: 12.5px; }

.add-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
}
.add-btn:hover { background: var(--accent); color: #fff; }
.add-btn:active { transform: scale(0.92); }

.source-note { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ── Dra-spöke ──────────────────────────────────────── */
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(19, 38, 28, 0.18);
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
}
.ghost-emoji { font-size: 26px; line-height: 1; }
.drag-ghost.dropped { animation: ghost-drop 0.25s ease-in forwards; }
.drag-ghost.cancelled { animation: ghost-cancel 0.2s ease-out forwards; }

@keyframes ghost-drop { to { opacity: 0; scale: 0.5; } }
@keyframes ghost-cancel { to { opacity: 0; } }

/* ── Dialoger ───────────────────────────────────────── */
.dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: var(--radius-lg);
  padding: 24px;
  color: var(--text);
  box-shadow: 0 20px 60px rgba(19, 38, 28, 0.25);
}
.dialog::backdrop { background: rgba(19, 38, 28, 0.35); }
.dialog h2 { font-size: 20px; margin-bottom: 8px; }
.dialog .muted { font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 18px; font-weight: 500; font-size: 14px; }
.input-unit { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.input-unit input {
  width: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 17px;
}
.input-unit input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.goal-preview { margin-top: 14px; }

.help-list { padding-left: 20px; margin: 12px 0 16px; display: grid; gap: 8px; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.btn-primary, .btn-secondary {
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: none; border-color: var(--border); }
.btn-secondary:hover { border-color: var(--muted); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Mobil / smal skärm ─────────────────────────────── */
@media (max-width: 900px) {
  .columns { grid-template-columns: 1fr; }
  .goal-panel { position: static; }
}

@media (max-width: 520px) {
  .topbar { padding: 12px 16px; }
  .page { padding: 16px 16px 40px; }
  .panel { padding: 16px; }
  .goal-body { grid-template-columns: 1fr; }
  .stats { display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: end; }
  .stat-percent { grid-row: span 2; font-size: 42px; }
  .stat-grams { margin-top: 0; }
  .search { max-width: none; }
  .food-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .food-image { height: 70px; font-size: 38px; }
  .dropzone span::after { content: " eller tryck på +"; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
