:root {
  --bg: #f4f5f3; --card: #fff; --ink: #17201c; --muted: #66716b; --line: #e1e5e2;
  --brand: #0f6b4f; --brand-ink: #fff; --soft: #e5f1ec;
  --warn: #a15c00; --warn-bg: #fdf1dc; --bad: #b3261e; --bad-bg: #fbe9e7; --info: #1d4f91; --info-bg: #e6eefb;
  --radius: 14px; --bad-solid: #c0352b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101412; --card: #1a201d; --ink: #e9eeeb; --muted: #98a39d; --line: #2b332f;
    --brand: #3fb489; --brand-ink: #06261b; --soft: #1d3129;
    --warn: #f0b660; --warn-bg: #3a2c12; --bad: #ff8a80; --bad-bg: #3d1a17; --info: #8fb8f5; --info-bg: #17263d;
  }
}
* { box-sizing: border-box; }
/* hidden ska alltid vinna, även över regler som sätter display (menyn syntes annars på inloggningssidan) */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main, header { max-width: 720px; margin: 0 auto; padding: 0 16px; }
header { padding-top: calc(14px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 10px; min-height: 58px; }
header h1 { font-size: 24px; margin: 0; flex: 1; letter-spacing: -.02em; }
header .back { font-size: 17px; color: var(--brand); text-decoration: none; padding: 8px 8px 8px 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
p.lead { color: var(--muted); margin: 4px 0 14px; }
a { color: var(--brand); }

/* nav – mobil: fält i nederkant med +-knappen i mitten */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
#nav .brand, #nav .tip, #add span { display: none; }
#nav a { position: relative; text-align: center; text-decoration: none; color: var(--muted); font-size: 11px; padding: 4px 0; }
#nav .ico { display: block; width: 24px; height: 24px; margin: 0 auto 2px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#nav a.on { color: var(--brand); font-weight: 600; }
#nav a b {
  position: absolute; top: 0; left: 50%; margin-left: 8px; background: var(--bad-solid); color: #fff; font-size: 11px; font-weight: 600;
  border-radius: 9px; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px;
}
#add {
  width: 60px; height: 60px; margin: -22px auto 0; border-radius: 50%; border: 4px solid var(--bg); padding: 0;
  background: var(--brand); color: var(--brand-ink); cursor: pointer;
}
#add i { font-style: normal; font-size: 34px; line-height: 1; font-weight: 300; }

/* listor */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; text-decoration: none; color: inherit; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .kind { width: 38px; height: 38px; border-radius: 10px; background: var(--soft); display: grid; place-items: center; font-size: 19px; flex: none; }
.row .mid { flex: 1; min-width: 0; }
.row .title, .row .sub { display: block; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.row .amt small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 44px 20px; }
.empty .big { font-size: 44px; display: block; margin-bottom: 8px; }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--soft); color: var(--brand); white-space: nowrap; }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.grey { background: var(--line); color: var(--muted); }

/* grupper i Att göra */
.group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.group > .head { padding: 14px; display: flex; gap: 10px; align-items: baseline; }
.group > .head strong { flex: 1; font-size: 17px; }
.group > .head span { color: var(--muted); font-variant-numeric: tabular-nums; }
.group > .actions { display: flex; gap: 8px; padding: 0 14px 14px; flex-wrap: wrap; }
.group > .actions > * { flex: 1; white-space: nowrap; }
.group .list { border: 0; border-top: 1px solid var(--line); border-radius: 0; }

/* knappar och formulär */
button, .btn {
  font: inherit; border-radius: 11px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 10px 14px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center;
}
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.danger { color: var(--bad); }
button.small { padding: 7px 11px; font-size: 14px; }
button:disabled { opacity: .5; }
button.block { display: block; width: 100%; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 11px 12px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); appearance: none; -webkit-appearance: none;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr; gap: 0 12px; }
input[type=date] { min-height: 46px; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 12px; scrollbar-width: none; }
select {
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
.filters select { width: auto; padding: 7px 30px 7px 12px; font-size: 14px; border-radius: 20px; flex: none;
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; }
.total { color: var(--muted); font-size: 14px; margin: 0 2px 8px; }

/* kvittosidan */
.pages { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px 6px; }
.page { flex: none; width: 100%; scroll-snap-align: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.page img { display: block; width: 100%; max-height: 62vh; object-fit: contain; background: #111; }
.page iframe { display: block; width: 100%; height: 62vh; border: 0; background: #fff; }
.page .cap { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; font-size: 13px; color: var(--muted); }
.note { border-radius: 12px; padding: 10px 12px; margin: 12px 0; font-size: 14px; background: var(--info-bg); color: var(--info); }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.bad { background: var(--bad-bg); color: var(--bad); }
.note button { margin-top: 8px; }
.choice { display: grid; gap: 8px; margin-top: 8px; }
.choice button { text-align: left; padding: 12px 14px; }
.choice button strong { display: block; }
.choice button span { font-size: 13px; color: var(--muted); }
.choice button.sel { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--soft); }
.bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.bar > * { flex: 1; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card p { margin: 4px 0; color: var(--muted); font-size: 14px; }

#login { max-width: 340px; margin: 16vh auto 0; text-align: center; }
#login img { width: 84px; height: 84px; border-radius: 20px; }
#login h1 { margin: 14px 0 20px; }
#login button { margin-top: 12px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin-top: 8px; }

#toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 9;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 22px; font-size: 14px; max-width: 90vw; text-align: center;
}

/* dra-och-släpp på datorn */
body.drop::after {
  content: "Släpp för att lägga in"; position: fixed; inset: 12px; z-index: 20; display: grid; place-items: center;
  border: 3px dashed var(--brand); border-radius: 22px; background: color-mix(in srgb, var(--soft) 88%, transparent);
  color: var(--brand); font-size: 22px; font-weight: 600; pointer-events: none;
}

/* ---------- dator: sidomeny, bredare yta, kvittot bredvid formuläret ---------- */
@media (min-width: 900px) {
  body { padding-bottom: 48px; }
  body.in { padding-left: 248px; }
  main, header { max-width: 1080px; padding: 0 40px; }
  header { padding-top: 30px; min-height: 76px; }
  header h1 { font-size: 28px; }
  h2 { margin-top: 28px; }

  #nav {
    top: 0; right: auto; bottom: 0; width: 248px; display: flex; flex-direction: column; gap: 2px;
    border-top: 0; border-right: 1px solid var(--line); padding: 22px 14px;
  }
  #nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; padding: 0 8px 18px; }
  #nav .brand img { width: 32px; height: 32px; border-radius: 8px; }
  #nav a { display: flex; align-items: center; gap: 12px; text-align: left; font-size: 15px; padding: 10px 12px; border-radius: 10px; color: var(--ink); }
  #nav a:hover { background: var(--bg); }
  #nav a.on { background: var(--soft); color: var(--brand); }
  #nav .ico { margin: 0; width: 20px; height: 20px; flex: none; }
  #nav a span { flex: 1; }
  #nav a b { position: static; margin: 0; }
  #add { order: -1; width: auto; height: auto; margin: 0 0 14px; border: 0; border-radius: 11px; padding: 11px 14px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; }
  #nav .brand { order: -2; }
  #add i { font-size: 22px; font-weight: 400; margin-top: -2px; }
  #add span { display: inline; }
  #add:hover, button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
  #nav .tip { display: block; margin: auto 8px 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }

  .group > .actions > * { flex: none; }
  .row { padding: 14px 18px; gap: 16px; }
  .row:hover { background: color-mix(in srgb, var(--soft) 45%, transparent); }
  .row .kind { width: 42px; height: 42px; }
  .row .amt { display: flex; align-items: center; gap: 14px; flex-direction: row-reverse; min-width: 250px; justify-content: flex-start; }
  .row .amt small { display: inline; min-width: 150px; text-align: right; }
  button:not(.primary):not(:disabled):hover, .btn:not(.primary):hover { border-color: var(--muted); }
  .empty { padding: 90px 20px; }

  /* smala formulärsidor ska inte dras ut över hela bredden */
  #view[data-view=more] > *, #view[data-view=all] > #q { max-width: 620px; }
  #view[data-view=more] > .card, #view[data-view=more] > form.card { max-width: 620px; }

  /* kvittosidan: underlaget till vänster (ligger kvar när man rullar), uppgifterna till höger */
  #view[data-view=detail] { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 32px; align-items: start; }
  .doc { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow: auto; border-radius: var(--radius); }
  .pages { display: block; margin: 0; padding: 0; overflow: visible; }
  .page { width: auto; margin-bottom: 12px; }
  .page img { max-height: none; background: var(--card); }
  .page iframe { height: calc(100vh - 100px); }
  .side > #ai > .note:first-child { margin-top: 0; }
  .side > form > label:first-child { margin-top: 0; }

  #toast { bottom: 28px; left: calc(50% + 124px); }
  body:not(.in) #toast { left: 50%; }
  #login { margin-top: 20vh; }
}
