:root {
  --fg: #16181d; --muted: #6b7180; --bg: #f6f7f9; --card: #fff; --line: #e6e8ec; --field: #d4d8df;
  --accent: #1f3f94; --accent-soft: #e8edf8; --warn: #9a5b00; --warn-soft: #fff4dc; --ok: #18794e; --ok-soft: #e7f5ee; --no: #b42318; --no-soft: #fdeceb;
  --radius: 12px; --gap: 16px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--fg); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sidhuvud */
header { background: var(--accent); color: #fff; }
.bar { max-width: 760px; margin: 0 auto; padding: 14px var(--gap); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: #fff; letter-spacing: -0.01em; }
.brand img { height: 36px; width: auto; }
.brand:hover { text-decoration: none; }
nav { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; font-size: .95rem; }
nav a, nav button.link { color: rgba(255, 255, 255, .8); font-size: inherit; }
nav a:hover, nav button.link:hover { color: #fff; text-decoration: none; }

main { max-width: 760px; margin: 0 auto; padding: 28px var(--gap) 64px; }
.wide .bar, .wide main { max-width: 1100px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 20px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 14px; }
p { margin: 0 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: var(--gap); }
.card > :last-child { margin-bottom: 0; }

/* Formulär */
label { display: block; margin-bottom: 14px; font-size: .9rem; font-weight: 600; }
input, select, textarea { display: block; width: 100%; min-height: 44px; padding: 10px 12px; margin-top: 6px; font: inherit; font-weight: 400; color: var(--fg); border: 1px solid var(--field); border-radius: 8px; background: #fff; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
small { display: block; margin-top: 4px; color: var(--muted); font-weight: 400; font-size: .85rem; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid > input[type=hidden] { display: none; }
.full { grid-column: 1 / -1; }
.actions { display: flex; gap: 16px; align-items: center; margin-top: 4px; }

button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 18px; font: inherit; font-weight: 600; color: #fff; background: var(--accent); border: 0; border-radius: 8px; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { filter: brightness(1.08); text-decoration: none; }
button:disabled { opacity: .4; cursor: not-allowed; filter: none; }
button.secondary { background: var(--accent-soft); color: var(--accent); }
button.danger { background: var(--no-soft); color: var(--no); }
button.link { min-height: 0; padding: 0; background: none; color: var(--accent); font-weight: 400; }
form.inline { display: inline; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1 1 200px; width: auto; margin: 0; }
.row select { width: auto; margin: 0; }
.row label { margin: 0; display: flex; align-items: center; gap: 8px; font-weight: 400; white-space: nowrap; }
.row label input { margin: 0; width: auto; }
.row label { max-width: 100%; }
.row label select { flex: 1 1 auto; min-width: 0; }
.search { margin-bottom: var(--gap); }
form.row + p, .card form + .muted { margin: 14px 0 0; }

/* Medlemskap */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0 0 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .85rem; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.no { background: var(--no-soft); color: var(--no); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--line); color: var(--muted); }
h3 .badge { margin-left: 6px; vertical-align: 1px; font-size: .75rem; }

/* Statuskort på Mina sidor */
.status-card { border-radius: var(--radius); padding: 22px; margin-bottom: var(--gap); color: #fff; background: var(--accent); }
.status-card.no { background: var(--no); }
.status-card.none { background: var(--card); color: var(--fg); border: 1px solid var(--line); }
.status-card p { margin: 0; }
.status-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; opacity: .85; }
.status-title { font-size: 1.35rem; font-weight: 700; margin: 4px 0 6px !important; }
.status-via { opacity: .85; font-size: .9rem; margin-top: 6px !important; }
.status-action { margin: -6px 0 var(--gap); }

/* Historik i kompakta rader */
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history .when { color: var(--muted); font-size: .9rem; min-width: 8.5em; }
.card h3 + .history .when { min-width: 4em; }
.history .what { flex: 1 1 10em; }
.more { margin: 12px 0 0; }
.card h3:first-of-type { margin-top: 4px; }
.month-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: var(--gap); }
.month-nav strong { font-size: 1.05rem; }
.history .amount { white-space: nowrap; font-weight: 600; }

/* Dörrar */
.doors { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.doors h2 { grid-column: 1 / -1; margin-bottom: 2px; }
.doors form { margin: 0; }
button.door { width: 100%; min-height: 76px; font-size: 1.05rem; border-radius: 10px; }

.door-hint { grid-column: 1 / -1; margin: 0; color: var(--muted); }
.door-result { min-height: calc(100vh - 140px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border-radius: var(--radius); padding: 32px 20px; color: #fff; background: var(--ok); }
.door-result.no { background: var(--no); }
.door-result h1 { font-size: 2.2rem; margin: 0 0 8px; }
.door-result p { font-size: 1.15rem; }
.door-result a { color: #fff; text-decoration: underline; margin-top: 24px; display: inline-block; font-size: 1rem; }
.door-icon { width: 120px; height: 120px; border-radius: 50%; background: rgba(255, 255, 255, .2); display: grid; place-items: center; font-size: 4.5rem; line-height: 1; margin-bottom: 20px; }
.door-body main { padding-top: 16px; }

/* Dörrkoder */
.tag-url { font-family: ui-monospace, monospace; font-size: .8rem; word-break: break-all; }
h3 { font-size: .95rem; margin: 18px 0 8px; }
.qr { text-align: center; }
.qr svg { width: 100%; max-width: 240px; height: auto; }
@media print { header, .muted { display: none; } .card { border: 0; break-inside: avoid; } }

/* Erbjudanden */
.group { padding-bottom: 6px; }
.group h3 { margin: 18px 0 8px; }
.offer { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 12px 14px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 10px; color: var(--fg); }
.offer:hover { border-color: var(--accent); text-decoration: none; background: var(--accent-soft); }
.offer strong { white-space: nowrap; }
.offer-price { text-align: right; }
.offer-price small { margin: 0; }
.price { font-size: 1.6rem; font-weight: 700; margin-bottom: 8px; }

/* Meddelanden */
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: var(--gap); }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--no-soft); color: var(--no); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.muted { color: var(--muted); }

/* Tabeller */
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
.list th, .list td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list .num { text-align: right; white-space: nowrap; }
.list th { color: var(--muted); font-weight: 500; font-size: .85rem; }
.list tr:last-child td { border-bottom: 0; }

/* Admin */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: var(--gap); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; color: var(--muted); font-size: .9rem; }
.stat span { display: block; font-size: clamp(1.4rem, 5vw, 2rem); white-space: nowrap; font-weight: 700; color: var(--fg); line-height: 1.2; }
.status-actions { margin-bottom: 12px; }
form.dates { margin-bottom: 12px; }

.receipt { max-width: 640px; margin-left: auto; margin-right: auto; padding: 28px; }
.receipt-head { display: flex; gap: 14px; align-items: center; padding-bottom: 16px; margin-bottom: 20px; border-bottom: 3px solid var(--accent); }
.receipt-head img { width: 64px; height: 64px; }
.receipt-head > div:nth-child(2) { flex: 1; }
.receipt-head strong { color: var(--accent); font-size: 1.1rem; }
.receipt-no { text-align: right; }
.receipt-no span { display: block; color: var(--accent); font-weight: 700; font-size: 1.4rem; text-transform: uppercase; letter-spacing: .02em; line-height: 1.1; }
.receipt-no strong { color: var(--fg); font-size: .95rem; font-weight: 600; }
.receipt-label { margin: 0 0 2px; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.receipt-lines { width: 100%; border-collapse: collapse; margin: 20px 0 24px; }
.receipt-lines th { background: var(--accent-soft); color: var(--accent); text-align: left; font-size: .85rem; padding: 8px 10px; }
.receipt-lines td { padding: 10px; border-bottom: 1px solid var(--line); }
.receipt-lines .num { text-align: right; white-space: nowrap; }
.receipt-lines tfoot td { border: 0; padding: 4px 10px; color: var(--muted); font-size: .9rem; }
.receipt-lines tfoot tr:first-child td { padding-top: 12px; }
.receipt-lines .total td { color: var(--fg); font-weight: 700; font-size: 1.15rem; border-top: 2px solid var(--accent); padding-top: 10px; }
.receipt-actions { margin-top: 20px; }
@media print { .receipt { border: 0; padding: 0; } .receipt-actions { display: none; } }

/* Mobil */
@media (max-width: 640px) {
  main { padding-top: 20px; }
  h1 { font-size: 1.3rem; }
  .card { padding: 18px 16px; }
  .grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dt { font-size: .85rem; }
  .facts dd { margin-bottom: 8px; }
  .row > button, .row > form, .row > form > button, .actions button { flex: 1 1 auto; }
  .status-actions { flex-direction: column; align-items: stretch; }
  .status-actions form { width: 100%; }
  .status-actions button { width: 100%; }
  button.door { min-height: 88px; }
  .receipt { padding: 20px 16px; }
  .receipt-head { flex-wrap: wrap; }
  .receipt-head img { width: 52px; height: 52px; }
  .receipt-no { flex-basis: 100%; text-align: left; }

  /* Tabeller blir staplade rader */
  .list thead { display: none; }
  .list, .list tbody, .list tr, .list td { display: block; width: 100%; }
  .list tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .list tr:last-child { border-bottom: 0; }
  .list td { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; padding: 3px 0; border: 0; }
  .list td::before { content: attr(data-label); flex: 0 0 38%; color: var(--muted); font-size: .85rem; }
  .list td[data-label=""]::before { display: none; }
  .list .num { text-align: left; }
}

.field-error { color: var(--no); }
.field-error:empty { display: none; }
input[aria-invalid] { border-color: var(--no); }
