/* Webbappens stilar – mobil-först. Efterliknar iOS-appens utseende (system-
   färger, grupperade listor, blurrade nav/flik-fält, systemgrönt #34C759). */
:root {
  --green: #34c759;        /* iOS systemGreen (appens .tint(.green)) */
  --green-dark: #248a3d;   /* mörkare grön för läsbar text/badge på vitt */
  --green-light: #30d158;
  --ink: #1c1c1e;          /* iOS label */
  --muted: #8e8e93;        /* iOS secondaryLabel */
  --bg: #f2f2f7;           /* iOS systemGroupedBackground */
  --card: #ffffff;         /* iOS secondarySystemGroupedBackground */
  --line: #c6c6c8;         /* iOS separator */
  --line-soft: #d8d8dc;    /* radavdelare i kort */
  --fill: rgba(120,120,128,0.14); /* iOS tertiary fill (chips/segment/ghost) */
  --red: #ff3b30;          /* iOS systemRed */
  --orange: #ff9500;       /* iOS systemOrange */
  --bar: rgba(249,249,249,0.82); /* translucent nav/flik-bakgrund */
  --header-h: 52px;
  --tabbar-h: 58px;
  --maxw: 720px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
.app-body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }
.dim { opacity: 0.6; }
.grow { flex: 1; min-width: 0; }
.ok { color: var(--green); }
.bad { color: var(--red); }
.pad { padding: 0 16px; }

/* ---- Skal ---- */
.app-shell { min-height: 100%; display: flex; flex-direction: column; }
.app-header {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; gap: 8px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
  padding-left: 6px; padding-right: 6px;
}
/* Toppnivå-flik (ingen tillbaka-knapp): stor titel i innehållet. Behåll blur så
   innehåll som skrollar förbi mattas av – ta bara bort kantlinjen i viloläge. */
.app-header.large { border-bottom-color: transparent; }
.app-title {
  flex: 1; text-align: center; font-size: 17px; font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.large-title {
  font-size: 34px; font-weight: 700; letter-spacing: 0.012em;
  color: var(--ink); padding: 4px 16px 6px;
}
.hbtn {
  border: none; background: none; color: var(--green);
  font-size: 17px; font-weight: 400; padding: 8px 10px; border-radius: 8px;
  min-width: 44px;
}
.hbtn.right { font-size: 20px; }
.hbtn-spacer { min-width: 44px; }
.app-content {
  flex: 1;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  width: 100%; max-width: var(--maxw); margin: 0 auto;
}
.view { padding: 6px 0 4px; }
.info-note { background: rgba(22,163,74,0.08); border: 1px solid var(--line); color: var(--muted); font-size: 13px; padding: 11px 13px; border-radius: 12px; line-height: 1.4; }

/* ---- Tabbar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
}
.tab {
  flex: 1; border: none; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10px; font-weight: 500; padding-top: 7px;
}
.tab .tab-icon { line-height: 0; }
.tab .tab-icon svg { width: 26px; height: 26px; display: block; }
.tab.active { color: var(--green); }

/* ---- Kort & sektioner ---- */
.list { display: flex; flex-direction: column; gap: 22px; padding: 8px 16px 16px; }
.card-section {
  background: var(--card); border: none; border-radius: 10px;
  padding: 0 16px;
}
.section-h {
  font-size: 13px; font-weight: 400; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--muted); padding: 12px 0 7px;
}
.card-section > *:not(.section-h) { border-top: 0.5px solid var(--line-soft); }
.card-section > .section-h + * { border-top: none; }
.card-section > *:first-child { border-top: none; }

/* ---- Matchrader ---- */
.match-row { padding: 12px 0; display: flex; flex-direction: column; gap: 7px; }
.match-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.match-teams { display: flex; align-items: center; gap: 8px; }
.match-teams .team { flex: 1; font-size: 15px; }
.match-teams .team.right { text-align: right; }
.team.win { color: var(--green-dark); font-weight: 700; }
.score { font-weight: 800; font-variant-numeric: tabular-nums; }
.score-mid { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 84px; }
.tag-stage { color: var(--green-dark); font-weight: 700; font-size: 12px; }
.match-meta .meta-left { display: inline-flex; align-items: center; gap: 8px; }
.live-badge { display: inline-flex; align-items: center; gap: 5px; color: var(--red); font-weight: 700; font-size: 12px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); display: inline-block; animation: livepulse 1.4s ease-in-out infinite; }
@keyframes livepulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.score.live { color: var(--red); }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: rgba(22,163,74,0.14); color: var(--green-dark); }
.badge.bad { background: rgba(220,38,38,0.12); color: var(--red); }

/* Klickbar matchrad i Hem → matchdetalj med allas tippningar. */
.match-link { display: flex; align-items: center; gap: 4px; width: 100%; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.match-link > .match-row { flex: 1; min-width: 0; }
.match-link:active,
.group-row.btn-row:active,
.lb-row:active,
.group-row:active { background: rgba(120,120,128,0.12); }
.match-chevron { color: var(--muted); font-size: 22px; line-height: 1; flex: none; padding-left: 2px; }

/* Tippningsrader i matchdetaljvyn. */
.pred-row { padding: 11px 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pred-name { font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pred-right { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.pred-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.pred-locked { padding: 11px 0; }

/* ---- Tabell ---- */
.standings { padding: 8px 0 12px; display: flex; flex-direction: column; gap: 5px; }
.st-head, .st-row { display: flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.st-head { font-size: 11px; font-weight: 700; color: var(--muted); }
.st-row { font-size: 13px; }
.st-rank { width: 22px; text-align: left; font-weight: 700; }
.st-rank.go { color: var(--green-dark); }
.st-rank.maybe { color: var(--orange); }
.st-team { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-num { width: 26px; text-align: center; }
.st-num.wide { width: 38px; }
.st-num.strong { font-weight: 800; }
.st-legend { padding-top: 2px; }

/* ---- Segment & chips ---- */
/* iOS UISegmentedControl-stil. */
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; margin: 4px 16px 10px; }
.seg-center { max-width: 320px; margin-left: auto; margin-right: auto; }
.seg-btn {
  flex: 1; border: none; background: none; padding: 7px 10px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.seg-btn.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,0.12), 0 0 1px rgba(0,0,0,0.04); }
.chipbar {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chipbar::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap; border: 1.5px solid transparent; background: var(--fill);
  color: var(--ink); padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip.active { background: rgba(52,199,89,0.18); border-color: var(--green); color: var(--green-dark); font-weight: 700; }
.chip-check { color: var(--green); }

/* ---- Steppers / tippning ---- */
.lock-banner {
  margin: 0 12px 8px; background: rgba(234,88,12,0.12); color: var(--orange);
  padding: 9px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; text-align: center;
}
.score-edit { display: flex; align-items: center; justify-content: center; gap: 8px; }
.score-edit .team-name { flex: 1; text-align: center; font-size: 16px; font-weight: 600; }
.score-edit .vs { width: 34px; text-align: center; color: var(--muted); font-size: 13px; }
.stepper { flex: 1; display: flex; align-items: center; justify-content: center; gap: 14px; }
.step-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: rgba(22,163,74,0.14); color: var(--green-dark); font-size: 22px; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
}
.step-btn:disabled { opacity: 0.4; }
.stepper-num { font-size: 22px; font-weight: 800; min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; }
.linklike { border: none; background: none; color: var(--green-dark); font-weight: 600; font-size: 13px; padding: 4px; align-self: center; }
.linklike.danger { color: var(--red); }

/* ---- Bracket (dubbelsidigt träd, speglar iOS) ---- */
.bracket-scroll { overflow: auto; padding: 8px 4px 18px; -webkit-overflow-scrolling: touch; }
.bracket-tree { display: flex; align-items: flex-start; gap: 18px; width: max-content; padding: 0 6px; }
.bk-col { display: flex; flex-direction: column; align-items: center; }
.bk-col-inner { display: flex; flex-direction: column; }
.bk-center-inner { align-items: center; }
.bk-stage {
  font-size: 9px; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px; white-space: nowrap;
}
.bk-stage-final { color: var(--green-dark); }
.bk-bronze-label {
  font-size: 9px; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase;
  color: #b45309; margin: 28px 0 6px; text-align: center;
}
.bk-card {
  position: relative; width: 144px; height: 52px; flex: 0 0 52px;
}
.bk-final { box-shadow: 0 0 0 1.5px rgba(22,163,74,0.45); }
/* Anslutningslinjer: horisontell stump in mot mitten kopplar samman ronderna. */
.bk-left::after, .bk-right::after {
  content: ""; position: absolute; top: 50%; width: 18px; height: 1.5px; background: var(--line);
}
.bk-left::after { right: -18px; }
.bk-right::after { left: -18px; }
.bk-center::after { content: none; }

.ko-card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.ko-card.locked { opacity: 0.75; }
.ko-div { height: 1px; background: var(--line); }
.ko-team {
  width: 100%; flex: 1; min-height: 0; border: none; background: none; text-align: left;
  display: flex; align-items: center; gap: 6px; padding: 0 9px; font-size: 12px; color: var(--ink);
}
.ko-team:disabled { cursor: default; }
.ko-team.dim .ko-name { color: var(--muted); }
.ko-team .ko-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ko-team .ko-mark { font-weight: 800; }
.ko-team.picked { background: rgba(22,163,74,0.16); font-weight: 700; }
.ko-team.picked .ko-mark { color: var(--green-dark); }
.ko-team.correct { background: rgba(22,163,74,0.18); font-weight: 700; color: var(--green-dark); }
.ko-team.wrong { background: rgba(220,38,38,0.12); font-weight: 700; color: var(--red); }

/* Verkligt slutspel ("Slutspel"-fliken): hint + gissningslista */
.ko-hint { margin: 0 16px 8px; }
.ko-member { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; }
.ko-member-name { font-weight: 700; color: var(--ink); }
.ko-guess-list { display: flex; flex-direction: column; gap: 4px; }
.ko-guess-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.ko-guess-pick { font-weight: 600; color: var(--green-dark); white-space: nowrap; }

/* ---- Grupper ---- */
.toolbar { display: flex; gap: 8px; justify-content: flex-end; padding: 2px 14px 8px; flex-wrap: wrap; }
.group-row { display: flex; align-items: center; gap: 10px; padding: 14px 0; width: 100%; background: none; border: none; text-align: left; }
.group-row.btn-row { cursor: pointer; }
.group-name { font-size: 16px; font-weight: 700; }
.chev { color: var(--muted); font-size: 22px; }
.row-actions { display: flex; gap: 2px; }
.iconlink { border: none; background: none; font-size: 16px; padding: 8px; border-radius: 8px; color: var(--muted); }
.iconlink.danger { color: var(--red); }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 13px 0; width: 100%; background: none; border: none; text-align: left; font-size: 15px; }
.lb-rank { width: 26px; font-weight: 700; }
.pills { display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 8px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pill {
  white-space: nowrap; border: 1.5px solid transparent; background: var(--fill);
  padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--ink);
}
.pill.active { background: rgba(52,199,89,0.18); border-color: var(--green); color: var(--green-dark); font-weight: 700; }
.pill.lock { background: var(--fill); color: var(--muted); }
.pill.lock.on { background: rgba(255,149,0,0.18); color: var(--orange); }
.invite { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0 4px; }
.invite-code { font-size: 22px; font-weight: 800; letter-spacing: 2px; font-family: ui-monospace, Menlo, monospace; flex: 1; }

/* ---- Dashboard dag-header ---- */
.day-header { display: flex; align-items: center; gap: 8px; padding: 8px 16px 14px; }
.day-center { flex: 1; text-align: center; }
.day-title { font-size: 17px; font-weight: 800; }
.icon-btn { border: none; background: none; color: var(--green-dark); font-size: 28px; font-weight: 700; padding: 4px 12px; line-height: 1; }

/* ---- Regler ---- */
.rule { display: flex; gap: 10px; padding: 9px 0; font-size: 14px; }
.rule-n { font-weight: 800; color: var(--green-dark); }
.points-row { display: flex; justify-content: space-between; padding: 9px 0; font-size: 14px; }

/* ---- Auth ---- */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-inner { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 26px; }
.auth-hero { text-align: center; }
.auth-ball { font-size: 60px; }
.auth-hero h1 { font-size: 26px; font-weight: 900; margin-top: 4px; }
.auth-card { display: flex; flex-direction: column; gap: 12px; }
.field {
  width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 11px;
  font-size: 16px; background: var(--card); color: var(--ink);
}
.field:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,0.15); }
.form-error { color: var(--red); font-size: 14px; margin: 4px 12px; }

/* ---- Knappar ---- */
.btn { border: none; border-radius: 11px; padding: 11px 16px; font-size: 15px; font-weight: 700; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:disabled { opacity: 0.5; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: var(--fill); color: var(--green); }
.btn-block { width: 100%; padding: 14px; }

/* ---- Tomt/laddning ---- */
.loading { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty { text-align: center; color: var(--muted); padding: 44px 24px; }
.empty-icon { font-size: 44px; margin-bottom: 8px; }
.empty h3 { font-size: 18px; color: var(--ink); margin-bottom: 6px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(15,23,42,0.45);
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal-card {
  background: var(--card); width: 100%; max-width: 480px;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 85vh; overflow-y: auto;
}
.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 12px; }
.modal-body { display: flex; flex-direction: column; gap: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
/* ---- Installations-modal (PWA) ---- */
.install-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.install-icon { width: 56px; height: 56px; border-radius: 13px; flex: none; box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.install-body { display: flex; flex-direction: column; gap: 12px; }
.install-store { display: block; width: 100%; text-decoration: none; text-align: center; }
.install-or {
  display: flex; align-items: center; gap: 10px; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
}
.install-or::before, .install-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.install-steps { list-style: none; display: flex; flex-direction: column; gap: 12px; padding: 2px 0; }
.install-step { display: flex; align-items: flex-start; gap: 12px; font-size: 15px; line-height: 1.45; }
.install-step-num {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--green); color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; margin-top: 1px;
}
.install-inline-icon { display: inline-flex; vertical-align: -4px; color: var(--green); }
.install-inline-icon svg { width: 18px; height: 18px; }

.changes .change-actor { font-weight: 700; padding: 10px 0 4px; }
.changes .change-item { display: flex; gap: 8px; padding: 4px 0; }
.changes .change-dot { color: var(--orange); }

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal-card { border-radius: 18px; }
}

/* ---- Spinner & toast ---- */
.spinner-overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; background: rgba(241,245,249,0.4); }
.spinner { width: 38px; height: 38px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + 16px); z-index: 300; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  max-width: 480px; width: fit-content; padding: 11px 16px; border-radius: 12px; color: #fff;
  font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  opacity: 0; transform: translateY(10px); transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--red); }
.toast-ok { background: var(--green-dark); }
