:root {
  --bg: #f4f6f8; --card: #fff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #0f766e; --accent-2: #ccfbf1; --danger: #dc2626; --ok: #16a34a;
  --radius: 14px; --tabbar: 64px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #131c2e; --text: #e2e8f0; --muted: #94a3b8; --line: #243047; --accent: #2dd4bf; --accent-2: #134e4a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1 { font-size: 1.3rem; margin: 0; }
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 .6rem; }
.view { padding: 0 1rem calc(var(--tabbar) + 1.5rem + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 1rem 0 .75rem;
  position: sticky; top: 0; background: var(--bg); z-index: 5; }
.month-nav h1 { text-transform: capitalize; }
.card { background: var(--card); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: 0 1px 2px rgb(0 0 0 / .05); }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }
input, select { width: 100%; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem .75rem; margin-top: .25rem; min-height: 46px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=color] { padding: 2px; width: 46px; flex: 0 0 46px; }
.check { display: flex; gap: .5rem; align-items: center; }
.check input { width: auto; min-height: 0; margin: 0; }
.amount-input { font-size: 1.4rem; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.stack { display: grid; gap: .5rem; }
.stack input { margin: 0; }

.btn { display: flex; align-items: center; justify-content: center; gap: .5rem; width: 100%; font: inherit; font-weight: 600;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: .8rem 1rem; min-height: 48px; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #042f2e; } }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { width: auto; min-height: 40px; padding: .5rem .9rem; font-size: .9rem; }
.btn.big { min-height: 120px; flex-direction: column; font-size: 1.1rem; }
.btn.big svg { width: 40px; height: 40px; fill: currentColor; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 1.8rem; width: 44px; height: 44px; cursor: pointer; border-radius: 50%; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-size: .85rem; padding: .25rem 0; cursor: pointer; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: .25rem 0; }
.hint { color: var(--muted); font-size: .85rem; margin: -.4rem 0 .75rem; }

.login { display: grid; place-items: center; min-height: 100vh; }
.login form { width: 100%; max-width: 360px; text-align: center; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { margin: .5rem 0 1rem; }
.login label { text-align: left; }

.capture { display: grid; gap: .75rem; padding-top: .5rem; }
.processing { text-align: center; padding: 3rem 0; color: var(--muted); }
.spinner { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  margin: 0 auto 1rem; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.thumb-wrap { display: flex; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
.thumb-wrap img { width: 96px; height: 128px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; }
.ocr-text { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .75rem; font-size: .75rem;
  max-height: 220px; overflow: auto; white-space: pre-wrap; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: .45rem .8rem;
  font: inherit; font-size: .9rem; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; }
.chip .dot, .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 10px; }
.chip.active { border-color: var(--accent); background: var(--accent-2); font-weight: 600; }

.line { display: grid; grid-template-columns: 1fr 110px 36px; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.line select, .line input { margin: 0; }
.line .note { grid-column: 1 / 3; }
.line .rm { background: none; border: 0; color: var(--muted); font-size: 1.3rem; cursor: pointer; height: 46px; }
.line + .line { border-top: 1px dashed var(--line); padding-top: .5rem; }
.split-row { display: flex; justify-content: space-between; align-items: center; margin: .25rem 0 1rem; gap: .5rem; }
.remaining { font-size: .9rem; font-weight: 600; }
.remaining.bad { color: var(--danger); }
.remaining.good { color: var(--ok); }
.actions { display: grid; grid-template-columns: 1fr 2fr; gap: .75rem; }

.total-card .label { color: var(--muted); font-size: .9rem; }
.total-card .total { font-size: 2.2rem; font-weight: 700; }
.total-card .sub { color: var(--muted); font-size: .9rem; }
.cat-sum { padding: .6rem 0; cursor: pointer; }
.cat-sum + .cat-sum { border-top: 1px solid var(--line); }
.cat-sum .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.cat-sum .name { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.cat-sum .amt { font-weight: 600; white-space: nowrap; }
.cat-sum .meta { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: .4rem; }
.bar > span { display: block; height: 100%; border-radius: 99px; }
.over { color: var(--danger); font-weight: 600; }
.up { color: var(--danger); } .down { color: var(--ok); }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .75rem; }
.filters input, .filters select { margin: 0; }
.receipt-item { display: flex; gap: .75rem; align-items: center; background: var(--card); border-radius: 12px; padding: .75rem;
  margin-bottom: .5rem; cursor: pointer; }
.receipt-item .date { width: 42px; text-align: center; font-size: .75rem; color: var(--muted); line-height: 1.1; }
.receipt-item .date b { display: block; font-size: 1.2rem; color: var(--text); }
.receipt-item .info { flex: 1; min-width: 0; }
.receipt-item .store { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.receipt-item .cats { display: flex; flex-wrap: wrap; gap: .3rem .6rem; font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.receipt-item .cats span { display: inline-flex; align-items: center; gap: .3rem; }
.receipt-item .amt { font-weight: 700; white-space: nowrap; }

.user-row { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.whoami { text-align: center; color: var(--muted); font-size: .85rem; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar button { flex: 1; background: none; border: 0; color: var(--muted); font: inherit; font-size: .72rem; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

dialog { border: 0; padding: 0; border-radius: var(--radius); width: min(94vw, 600px); max-height: 92vh; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .55); }
.detail-body { padding: 1rem; position: relative; }
.detail-body .close { position: absolute; top: .4rem; right: .4rem; font-size: 1.2rem; }
.detail-body img { width: 100%; border-radius: 10px; margin: .75rem 0; }
.detail-body h2 { margin: 0 2.5rem .25rem 0; }
.detail-lines { margin: .5rem 0 1rem; }
.detail-lines div { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--line); gap: .5rem; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.zoom img { width: 100%; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + 1rem); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .6rem 1rem; border-radius: 10px; z-index: 50; font-size: .9rem; max-width: 90vw; }

/* ---------- Administration ---------- */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.card-head .section-title { margin: 0; }
.admin-list { display: grid; }
.admin-row { display: flex; align-items: center; gap: .25rem; border-top: 1px solid var(--line); }
.admin-row:first-child { border-top: 0; }
.admin-row.archived { opacity: .55; }
.admin-row .order { display: flex; flex-direction: column; }
.icon-btn.sm { width: 32px; height: 24px; font-size: .7rem; color: var(--muted); border-radius: 6px; }
.icon-btn.sm:disabled { opacity: .25; }
.icon-btn.sm:not(:disabled):hover { background: var(--line); }
.row-main { flex: 1; display: flex; align-items: center; gap: .75rem; min-width: 0; background: none; border: 0; color: var(--text);
  font: inherit; text-align: left; padding: .7rem .25rem; cursor: pointer; border-radius: 8px; }
.row-main:not(:disabled):hover { background: var(--bg); }
.row-main:disabled { cursor: default; color: var(--text); }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-text b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-text small { color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.chev { color: var(--muted); font-size: 1.4rem; }
.dot.lg { width: 16px; height: 16px; flex-basis: 16px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-2); color: var(--accent); display: grid; place-items: center;
  font-weight: 700; flex: 0 0 34px; }
.whoami { text-align: left; margin: 0 0 .75rem; }
#btn-logout { margin-top: .5rem; }
.swatches { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: -.4rem 0 1rem; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--card); box-shadow: 0 0 0 2px var(--text); }
.swatches input[type=color] { width: 44px; height: 38px; min-height: 0; margin: 0; flex: 0 0 44px; }
#editor .detail-body h2 { margin-bottom: 1rem; }
.editor-actions { display: flex; justify-content: space-between; align-items: flex-end; gap: .75rem; flex-wrap: wrap; margin-top: .5rem; }
.editor-actions > .btn { width: auto; min-width: 120px; }
#editor-extra { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.merge { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.merge select { margin: 0; width: auto; min-height: 40px; padding: .4rem .5rem; font-size: .9rem; }
.btn.danger { color: var(--danger); }
.brand { display: none; }
.capture.drag { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 12px; }
.drop-hint { display: none; text-align: center; margin: 0; }
.settings-grid { display: grid; gap: 0; }

/* ---------- PC / bred skærm ---------- */
@media (min-width: 900px) {
  :root { --side: 230px; }
  body { padding-left: var(--side); }
  .tabbar { top: 0; bottom: 0; right: auto; width: var(--side); height: auto; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line); padding: 1rem .75rem; gap: .25rem; }
  .tabbar .brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; padding: .25rem .5rem 1.25rem; }
  .tabbar .brand img { width: 34px; height: 34px; border-radius: 9px; }
  .tabbar button { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: .75rem; font-size: .95rem; padding: .7rem .75rem;
    border-radius: 10px; }
  .tabbar button:hover { background: var(--bg); }
  .tabbar button.active { background: var(--accent-2); }
  .view { padding: 1rem 2rem 2rem; max-width: 760px; }
  .view.wide { max-width: 1150px; }
  .top { padding-top: 1rem; }
  .settings-grid { grid-template-columns: 1.15fr 1fr; gap: 1rem; align-items: start; }
  .toast { bottom: 1.5rem; left: calc(50% + var(--side) / 2); }
  .drop-hint { display: block; }
  .btn.big { min-height: 160px; }
}
