:root {
  --cream: #fbf6ea;
  --card: #fffdf6;
  --line: #eadfc6;
  --dill: #27442e;
  --dill-2: #3f6b48;
  --green: #a8cf6b;
  --green-soft: #e6f1cf;
  --onion: #8a3d6e;
  --onion-soft: #f1dfe9;
  --salmon: #f4a08b;
  --salmon-soft: #fde3da;
  --over: #d9573f;
  --muted: #62705f;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(39, 68, 46, .06), 0 6px 18px rgba(39, 68, 46, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--dill);
  font-family: "Outfit", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overflow-x: hidden;
}
.app { max-width: 760px; margin: 0 auto; padding: 14px 16px 40px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 800; }
h3 { font-size: 1rem; font-weight: 800; }
p { margin: .4em 0; }
a { color: var(--onion); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--onion); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Topp */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 6px 0 12px; }

.seg { display: inline-flex; background: var(--green-soft); border-radius: 999px; padding: 4px; }
.seg button {
  min-height: 44px; min-width: 76px; padding: 0 18px; border: 0; border-radius: 999px; background: transparent;
  font: inherit; font-weight: 800; color: var(--dill); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--dill); color: #fff; }

.sync-status {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--dill-2); font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer;
}
.sync-status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.sync-status[data-status="syncing"] .dot { background: var(--dill-2); animation: pulse 1s ease-in-out infinite alternate; }
.sync-status[data-status="pending"] .dot, .sync-status[data-status="consent"] .dot { background: var(--salmon); }
.sync-status[data-status="offline"] .dot { background: var(--muted); }
.sync-status[data-status="error"] .dot { background: var(--over); }
@keyframes pulse { to { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .sync-status .dot { animation: none !important; } }
.link-btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; border: 0; background: transparent;
  font: inherit; font-weight: 700; color: var(--onion); text-decoration: underline; cursor: pointer;
}

/* Navigering: flikrad nederst på mobil, överst på bredare skärmar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(39, 68, 46, .08);
  padding: 0 4px env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1 1 0; min-width: 0; min-height: 60px; padding: 6px 2px; border: 0; background: transparent; font: inherit; font-size: .78rem; font-weight: 700;
  color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-top: 3px solid transparent;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs svg circle { fill: currentColor; stroke: none; }
.tabs button[aria-current="page"] { color: var(--onion); border-top-color: var(--onion); }
.app { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

@media (min-width: 560px) {
  .tabs {
    position: static; gap: 6px; padding: 0; margin-bottom: 14px; background: transparent; box-shadow: none;
    border-top: 0; border-bottom: 2px solid var(--line);
  }
  .tabs button {
    flex: 1 1 auto; flex-direction: row; gap: 8px; min-height: 46px; font-size: 1rem;
    border-top: 0; border-bottom: 4px solid transparent; margin-bottom: -2px;
  }
  .tabs svg { width: 20px; height: 20px; }
  .tabs button[aria-current="page"] { border-bottom-color: var(--onion); }
  .app { padding-bottom: 40px; }
}

/* Kort */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }

/* Knappar och fält */
.btn, .icon-btn {
  min-height: 48px; border-radius: 14px; border: 2px solid transparent; font: inherit; font-weight: 800; cursor: pointer; padding: 0 18px;
}
.btn.primary { background: var(--dill-2); color: #fff; }
.btn.primary:hover { background: var(--dill); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--dill); }
.btn.danger { background: var(--salmon-soft); color: #9a2f1b; }
.icon-btn { min-width: 48px; padding: 0; background: var(--green-soft); color: var(--dill); font-size: 1.6rem; line-height: 1; }

input, select {
  width: 100%; min-height: 48px; padding: 0 14px; border: 2px solid var(--line); border-radius: 14px;
  background: #fff; color: var(--dill); font: inherit; font-size: 16px;
}
input:focus, select:focus { border-color: var(--dill-2); outline: none; box-shadow: 0 0 0 3px var(--green-soft); }
input[type="file"] { padding: 10px; height: auto; }
label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 4px; }
.field { margin-bottom: 12px; min-width: 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; }
.check input { width: 24px; height: 24px; min-height: 0; accent-color: var(--dill-2); }

/* Datum */
.datenav { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.datenav input { flex: 1; min-width: 0; font-weight: 700; text-align: center; }

/* Dagtyp: diskret rad som fälls ut */
.daytype { margin: -4px 0 12px; }
.daytype-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--dill); font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer;
}
.daytype-btn .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--onion); }
.daytype-btn .dot.free { background: var(--green); }
.daytype-btn .chev { color: var(--muted); font-size: .8rem; transition: transform .2s; }
.daytype-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.daytype-panel { margin-top: 8px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 2px solid var(--line); background: #fff;
  font: inherit; font-weight: 700; color: var(--dill); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--onion); border-color: var(--onion); color: #fff; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: .9rem; }

/* Veckan i 5:2 */
.week-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-weight: 700; font-size: .9rem; }
.week-head b { font-size: 1.1rem; color: var(--onion); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.wd {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 56px; min-width: 0; padding: 4px 0;
  border: 2px solid var(--line); border-radius: 14px; background: #fff; font: inherit; color: var(--dill); cursor: pointer;
}
.wd span { font-size: .72rem; font-weight: 700; color: var(--muted); }
.wd b { font-size: 1rem; }
.wd[aria-pressed="true"] { background: var(--onion); border-color: var(--onion); color: #fff; }
.wd[aria-pressed="true"] span { color: #fff; }
.wd.cur { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--dill-2); }

/* Mätare */
.gauges { display: grid; grid-template-columns: minmax(0, 220px); justify-content: center; gap: 12px; }
.gauges.two { grid-template-columns: repeat(2, minmax(0, 220px)); }
.gauge { position: relative; text-align: center; }
.gauge svg { display: block; width: 100%; max-width: 170px; margin: 0 auto; transform: rotate(-90deg); }
.gauge circle { fill: none; stroke-width: 11; }
.gauge .track { stroke: var(--green-soft); }
.gauge .fill { stroke: var(--green); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.gauge.prot .track { stroke: var(--onion-soft); }
.gauge.prot .fill { stroke: var(--onion); }
.gauge.warn .fill { stroke: var(--salmon); }
.gauge.over .fill { stroke: var(--over); }
.gauge-mid {
  position: absolute; left: 0; right: 0; top: 0; aspect-ratio: 1; max-width: 170px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gv { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.gu { font-size: .8rem; font-weight: 600; color: var(--muted); }
.gauge-left { margin-top: 6px; font-weight: 800; color: var(--dill-2); }
.gauge.prot .gauge-left { color: var(--onion); }
.gauge.warn .gauge-left { color: #a5502f; }
.gauge.over .gauge-left { color: var(--over); }
.gauge-max { font-size: .8rem; color: var(--muted); }
.kcal-plain { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.kcal-plain .muted { margin-left: auto; }
.big { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.unit { color: var(--muted); font-weight: 600; }

.minis { display: flex; justify-content: space-around; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.mini { display: flex; flex-direction: column; align-items: center; min-width: 0; text-align: center; }
.mini .ml { font-size: .75rem; font-weight: 700; color: var(--muted); }
.mini .mv { font-size: 1rem; font-weight: 800; }
.mini .mg { font-size: .72rem; color: var(--muted); }

.alert { margin-top: 12px; padding: 10px 14px; border-radius: 14px; background: var(--salmon-soft); color: #7d2a18; font-weight: 700; font-size: .9rem; }
.alert.over { background: var(--over); color: #fff; }

/* Måltider: ett kort med en rad per måltid */
.meals { padding: 4px 16px; }
.meal + .meal { border-top: 1px solid var(--line); }
.meal { padding: 8px 0; }
.meal-head { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.meal-head h2 { font-size: 1.05rem; margin-right: auto; }
.meal-head .kc { font-weight: 800; color: var(--dill-2); white-space: nowrap; }
.add-btn {
  min-height: 44px; padding: 0 12px; border: 0; border-radius: 12px; background: transparent;
  font: inherit; font-weight: 700; color: var(--dill-2); cursor: pointer; white-space: nowrap;
}
.add-btn:hover { background: var(--green-soft); }
.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; text-align: left;
  min-height: 52px; padding: 6px 4px; background: transparent; border: 0; border-top: 1px dashed var(--line);
  font: inherit; color: inherit; cursor: pointer;
}
.entry .nm { font-weight: 700; overflow-wrap: anywhere; }
.entry .gr { color: var(--muted); font-size: .85rem; }
.entry .ek { font-weight: 800; white-space: nowrap; color: var(--dill-2); }

/* Historik */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--green-soft); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { font-size: .8rem; font-weight: 700; color: var(--dill-2); }
.hrow {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; width: 100%; text-align: left; min-height: 64px;
  padding: 12px 14px; margin-bottom: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); font: inherit; color: inherit; cursor: pointer; box-shadow: var(--shadow);
}
.hrow .d { font-weight: 800; }
.hrow .t { color: var(--muted); font-size: .85rem; }
.hrow .n { text-align: right; font-weight: 700; font-size: .9rem; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 800; background: var(--green-soft); color: var(--dill); }
.badge.bad { background: var(--salmon-soft); color: #8a2b18; }
.badge.neutral { background: var(--onion-soft); color: var(--onion); }

/* Din data */
.data-card { margin-top: 4px; }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.data-actions .btn { flex: 1 1 200px; }
.data-msg { margin-top: 12px; padding: 10px 14px; border-radius: 14px; background: var(--green-soft); font-weight: 700; }
.data-msg.bad { background: var(--salmon-soft); color: #7d2a18; }

/* Konto och synk */
.check.consent { align-items: flex-start; padding: 6px 0; font-weight: 500; font-size: .92rem; line-height: 1.4; }
.check.consent input { flex: none; margin-top: 1px; }
#deleteAccount:empty { display: none; }

/* Import från kalkylark */
.csv-days { list-style: none; margin: 10px 0; padding: 0; }
.csv-day { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.csv-day span { display: block; }
.csv-day .warn, #csvBody p.warn { color: #a5502f; font-weight: 700; font-size: .85rem; }
.csv-skipped { margin: 8px 0 12px; border: 1px solid var(--line); border-radius: 14px; padding: 4px 12px; }
.csv-skipped summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.csv-skipped ul { margin: 0 0 8px; padding-left: 18px; font-size: .85rem; }
@media (min-width: 560px) { .csv-day { grid-template-columns: 1fr 180px; align-items: center; } }

/* Mina matvaror */
.food-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.food-row .nm { font-weight: 700; overflow-wrap: anywhere; }
.food-row .sub { font-size: .8rem; color: var(--muted); }

/* Dialog */
dialog {
  width: min(600px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); margin: auto; padding: 18px;
  border: 0; border-radius: 22px; background: var(--card); color: var(--dill); box-shadow: 0 20px 60px rgba(39, 68, 46, .35);
}
dialog::backdrop { background: rgba(39, 68, 46, .45); }
dialog h2 { margin-bottom: 4px; }
.results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 240px; overflow-y: auto; border-radius: 14px; }
.results:empty { display: none; }
.results button {
  display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 10px; min-height: 48px; padding: 8px 12px;
  background: var(--cream); border: 0; border-bottom: 1px solid var(--line); text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.results button:hover { background: var(--green-soft); }
.results .src { font-size: .72rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--onion-soft); color: var(--onion); white-space: nowrap; }
fieldset.per100 { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 4px; margin: 0 0 12px; min-width: 0; }
fieldset.per100 legend { font-weight: 800; font-size: .9rem; padding: 0 6px; }
.grid5 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details.photo { margin-bottom: 12px; border: 1px solid var(--line); border-radius: 14px; padding: 4px 12px 12px; }
details.photo summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.preview img { width: 100%; max-height: 50vh; object-fit: contain; border-radius: 12px; margin-top: 10px; background: #fff; }
.live { min-height: 1.4em; margin: 6px 0 12px; font-weight: 700; }
.live .warn { display: block; margin-top: 6px; padding: 8px 12px; border-radius: 12px; background: var(--salmon-soft); color: #7d2a18; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }
.actions .primary { flex: 2 1 140px; }

#modeCard .seg { margin: 8px 0 14px; }
.mode-settings { border-top: 1px solid var(--line); padding-top: 12px; }
.mode-settings .label { font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.inline-field { display: flex; gap: 8px; }
.inline-field input { flex: 1; min-width: 0; }
.cycle { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.cycle li { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; white-space: nowrap; padding: 8px 12px; border-radius: 12px; background: var(--onion-soft); font-weight: 700; font-size: .9rem; }
.cycle li:last-child { background: var(--green-soft); }
.cycle .muted { font-weight: 600; font-size: .8rem; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekdays .chip { padding: 0; min-width: 0; font-size: .85rem; }
@media (min-width: 560px) { .cycle { grid-template-columns: repeat(3, 1fr); } }

@media (min-width: 560px) {
  .grid5 { grid-template-columns: repeat(5, 1fr); }
  .actions .btn { flex: 0 0 auto; }
  .actions .primary { flex: 0 0 auto; }
}
@media (max-width: 380px) {
  .grid2 { grid-template-columns: 1fr; }
  .seg button { min-width: 64px; padding: 0 12px; }
}
@media (prefers-reduced-motion: reduce) { .gauge .fill, .daytype-btn .chev { transition: none; } }
