:root {
  --primary: #2d6a4f;
  --primary-hover: #1b4332;
  --primary-light: #e8f5e9;
  --primary-border: #c8e6c9;
  --green: var(--primary);
  --green-light: var(--primary-light);
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --danger-hover: #b91c1c;
  --warning-bg: #fefce8;
  --warning-border: #fef08a;
  --warning-text: #854d0e;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.12), 0 4px 8px -2px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14.5px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1 { font-size: 1.6rem; font-weight: 700; margin: 0 0 1.25rem; color: var(--text); letter-spacing: -0.02em; }
h2 { font-size: 1.2rem; font-weight: 600; margin: 1.75rem 0 .75rem; color: var(--text); letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .35rem; color: var(--text); }
a { color: var(--primary); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

header.top {
  background: linear-gradient(135deg, var(--primary-hover) 0%, var(--primary) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: .65rem 1.5rem;
  flex-wrap: wrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  position: sticky;
  top: 0;
  z-index: 10;
}
header.top .brand {
  font-weight: 700;
  font-size: 1.15rem;
  margin-right: .75rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: .5rem;
}
header.top .brand .logo { height: 34px; width: auto; background: #fff; padding: 2px 6px; border-radius: var(--radius-sm); display: block; }
header.top nav { display: flex; gap: .35rem; flex: 1; flex-wrap: wrap; }
header.top nav a {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  padding: .4rem .85rem;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  font-weight: 500;
  transition: all .15s ease;
}
header.top nav a.active {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-weight: 600;
}
header.top nav a:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  text-decoration: none;
}
header.top .who {
  font-size: .88rem;
  display: flex;
  gap: .75rem;
  align-items: center;
  color: rgba(255, 255, 255, 0.95);
}
header.top .who button {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  font-size: .82rem;
  padding: .25rem .6rem;
  border-radius: var(--radius-sm);
  transition: all .15s ease;
}
header.top .who button:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.6);
}

main { max-width: 1140px; margin: 0 auto; padding: 1.5rem 1.25rem 3.5rem; }
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1.25rem; }
.toolbar .spacer { flex: 1; }

button, .btn {
  font: inherit;
  font-weight: 500;
  font-size: .9rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text-secondary);
  padding: .45rem 1rem;
  border-radius: var(--radius);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  box-shadow: var(--shadow-xs);
  transition: all .15s ease;
}
button:hover, .btn:hover {
  background: #f8fafc;
  border-color: var(--border-hover);
  color: var(--text);
  text-decoration: none;
}
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(45, 106, 79, 0.2);
}
button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #ffffff;
}
button.danger {
  color: var(--danger);
  border-color: var(--border);
  background: #ffffff;
}
button.danger:hover {
  background: var(--danger-light);
  border-color: #fca5a5;
  color: var(--danger-hover);
}
button.small {
  padding: .22rem .55rem;
  font-size: .82rem;
  border-radius: var(--radius-sm);
}
button:disabled {
  opacity: .5;
  cursor: not-allowed;
  box-shadow: none;
}

input, select, textarea {
  font: inherit;
  font-size: .92rem;
  width: 100%;
  padding: .45rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 4.5rem; }
label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: .3rem; color: var(--muted); }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1rem 1.15rem; }
.grid .wide { grid-column: 1 / -1; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
th, td {
  padding: .65rem .85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  background: #f8fafc;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
tr.past { color: var(--muted); }
tr.past td { opacity: .75; }
tr.next td {
  background: var(--warning-bg);
  color: var(--text);
}
tr.next:hover td { background: #fef9c3; }
td.actions { white-space: nowrap; text-align: right; }
.empty {
  padding: 2.5rem;
  text-align: center;
  color: var(--muted);
  background: #ffffff;
  border: 1px dashed var(--border-hover);
  border-radius: var(--radius-lg);
}

.login { max-width: 380px; margin: 10vh auto; }
.login .card { padding: 2rem; box-shadow: var(--shadow-lg); }
.login .card > * + * { margin-top: 1rem; }
.login h1 { text-align: center; margin-bottom: 1.5rem; }
.login-logo { display: block; width: 180px; max-width: 70%; height: auto; margin: 0 auto 1rem; }
.error { color: var(--danger); font-weight: 600; font-size: .88rem; }
.muted { color: var(--muted); font-size: .88rem; }
.badge {
  display: inline-flex;
  align-items: center;
  font-size: .75rem;
  font-weight: 600;
  padding: .12rem .55rem;
  border-radius: 9999px;
  background: var(--primary-light);
  color: var(--primary-hover);
}
.badge.admin { background: #fef3c7; color: #92400e; }

.items { display: flex; flex-direction: column; gap: .75rem; margin-top: .75rem; }
.item {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .85rem 1rem;
  display: grid;
  grid-template-columns: 5.5rem 1fr 12rem 10rem auto;
  gap: .65rem;
  align-items: start;
  box-shadow: var(--shadow-xs);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.item:focus-within {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}
.item .notes { grid-column: 2 / 5; }
.item .resolved {
  padding: .45rem .65rem;
  background: var(--primary-light);
  color: var(--primary-hover);
  font-weight: 500;
  font-size: .88rem;
  border-radius: var(--radius);
  min-height: 2.2rem;
  display: flex;
  align-items: center;
}
.item .ctrl { display: flex; gap: .25rem; grid-row: 1 / 3; grid-column: 5; }
@media (max-width: 800px) {
  .item { grid-template-columns: 1fr 1fr; }
  .item .notes, .item .ctrl { grid-column: 1 / -1; grid-row: auto; }
}

.history li { padding: .65rem 0; border-bottom: 1px solid var(--border); list-style: none; font-size: .9rem; }
.history li:last-child { border-bottom: none; }
.history ul {
  margin: 0;
  padding: 0 1.25rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.history .chg { margin: .25rem 0 0 1rem; font-size: .85rem; color: var(--muted); }
.history .chg del { color: var(--danger); text-decoration: line-through; }
.history .chg ins { color: var(--primary); text-decoration: none; font-weight: 600; }

.stamp { margin-top: 1.25rem; font-size: .82rem; color: var(--muted); }
.dialog-back {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.dialog {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: min(480px, 92vw);
  box-shadow: var(--shadow-lg);
}
.dialog .row { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.25rem; }

#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #ffffff;
  padding: .65rem 1.25rem;
  border-radius: 9999px;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all .2s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

@media print {
  header.top, .toolbar, .ctrl, #toast, button { display: none !important; }
  body { background: #fff; }
}

/* ---- Redigerare: anteckning och avstånd ---- */
.item .ctrl { grid-row: 1; }
.item .ctrl button {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: .85rem;
  border-radius: var(--radius-sm);
}
.item .ctrl button.details { width: auto; padding: 0 .65rem; white-space: nowrap; }
.item textarea.notes { min-height: 2.6rem; font-size: .88rem; }
.item .gap {
  grid-column: 5;
  grid-row: 2;
  display: flex;
  gap: .35rem;
  align-items: center;
  margin: 0;
  font-weight: 500;
  font-size: .8rem;
  color: var(--muted);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
}
.item .gap input { width: auto; cursor: pointer; }
@media (max-width: 800px) { .item .gap { grid-column: 1 / -1; grid-row: auto; } }

/* ---- Visaläge (read-only) för programpunkter ---- */
.item-ro {
  display: flex; align-items: baseline; gap: .7rem;
  padding: .45rem .7rem; border-radius: 6px; background: var(--surface);
  border: 1px solid var(--border);
}
.item-ro-time { font-size: .78rem; color: var(--text-muted); min-width: 3rem; flex-shrink: 0; }
.item-ro-title { font-weight: 600; flex: 1; }
.item-ro-resp { font-size: .82rem; color: var(--text-muted); flex-shrink: 0; }

/* ---- Rollhantering ---- */
.roles-cards { display: flex; flex-direction: column; gap: 1rem; margin-top: .5rem; }
.role-card { padding: 1rem 1.15rem; }
.role-card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .4rem; }
.role-card-perms { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; min-height: 1.4rem; }
.role-perm-tag {
  display: inline-block; padding: .18rem .55rem; border-radius: 12px;
  font-size: .75rem; background: var(--primary-light); color: var(--primary-dark);
  border: 1px solid var(--primary-border);
}
/* Behörighetsdialog */
.role-perm-note {
  font-size: .83rem; color: var(--text-muted); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: .5rem .7rem; margin: .5rem 0;
}
.role-perm-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .5rem 1.2rem;
  margin: .8rem 0;
}
.role-perm-group { display: flex; flex-direction: column; gap: .25rem; }
.role-perm-group-title {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); font-weight: 600; margin-bottom: .1rem;
}
.role-perm-row {
  display: flex; align-items: center; gap: .4rem; font-size: .88rem;
  cursor: pointer; padding: .1rem 0;
}
.role-perm-row input[type=checkbox] { width: auto; cursor: pointer; flex-shrink: 0; }



/* ---- Utskrift av gudstjänstprogram: A4 stående, mått hämtade från GudstjänstProgramExempel.png ---- */
.sheet {
  width: 210mm; min-height: 297mm; margin: 0 auto; background: #fff; color: #231f20; position: relative;
  box-shadow: 0 1px 8px rgba(0, 0, 0, .25); padding: 4mm 13mm 6mm 9.5mm;
  display: grid; grid-template-columns: 1fr auto 1fr; grid-template-rows: auto 1fr auto; column-gap: 4mm;
  font-family: Montserrat, "Segoe UI", system-ui, sans-serif;
  print-color-adjust: exact; -webkit-print-color-adjust: exact;
}
.sheet .p-head { grid-column: 1 / -1; width: 182mm; display: block; }
.sheet .p-prog {
  grid-column: 1 / -1; display: grid; grid-template-columns: 43.5% 1fr; align-content: start; align-self: start;
  position: relative; margin: 2mm -13mm 3mm -9.5mm; padding: 0; width: 210mm;
}
.sheet .p-prog::before { content: ""; position: absolute; left: 43.5%; top: 1mm; bottom: 1mm; width: .45mm; background: #231f20; }
.sheet .p-label {
  text-align: right; text-transform: uppercase; font-weight: 700; font-size: 16pt; letter-spacing: .08em;
  line-height: 8.6mm; padding-right: 4.5mm; align-self: center;
}
.sheet .p-value { font-size: 16pt; font-weight: 500; letter-spacing: .08em; line-height: 8.6mm; padding: 0 9mm 0 4.5mm; }
.sheet .p-value.small { font-size: 12.5pt; line-height: 6.8mm; padding-top: .9mm; padding-bottom: .9mm; }
.sheet .gap { margin-top: 8.6mm; }
.sheet .p-foot-left, .sheet .p-foot-right { font-size: 10pt; text-transform: uppercase; letter-spacing: .1em; line-height: 5.6mm; align-self: end; }
.sheet .p-foot-left b, .sheet .p-foot-right b { font-weight: 700; }
.sheet .p-foot-right { text-align: right; }
.sheet .p-logo { width: 46mm; display: block; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff !important; }
  main { max-width: none; padding: 0; margin: 0; }
  .sheet { box-shadow: none; margin: 0; width: 210mm; height: 297mm; min-height: 0; overflow: hidden; page-break-after: avoid; }
}
/* ---- Information / Sånger: register, väljare, kort ---- */
.ann-list { display: flex; flex-direction: column; gap: .85rem; }
.ann-card {
  display: flex;
  gap: 1.25rem;
  justify-content: space-between;
  align-items: flex-start;
  transition: transform .15s ease, box-shadow .15s ease;
}
.ann-card:hover {
  box-shadow: var(--shadow-md);
}
.ann-card h3 { margin: 0 0 .4rem; font-size: 1.1rem; color: var(--text); }
.ann-text { white-space: pre-wrap; margin-bottom: .6rem; color: var(--text-secondary); line-height: 1.55; }
.ann-text a, .rich-editor a { color: #1d4ed8; text-decoration: underline; word-break: break-word; }
.ann-thumbs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.ann-thumbs img {
  height: 72px;
  max-width: 130px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
  transition: transform .15s ease;
}
.ann-thumbs img:hover { transform: scale(1.03); }
.ann-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.dialog.wide { width: min(680px, 94vw); }
.ann-edit-images { display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; }
.ann-edit-img {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: .75rem;
  align-items: center;
  width: 100%;
  padding: .4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ann-edit-img img { width: 90px; height: 60px; object-fit: cover; border-radius: var(--radius-sm); }
.ann-picker { grid-column: 1 / -1; display: flex; flex-direction: column; gap: .45rem; }
.ann-chosen { display: flex; gap: .45rem; flex-wrap: wrap; }
.ann-tag {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  color: var(--primary-hover);
  font-weight: 500;
  border-radius: var(--radius);
  padding: .25rem .4rem .25rem .6rem;
  font-size: .85rem;
  box-shadow: var(--shadow-xs);
}
.ann-tag img { height: 22px; width: 22px; object-fit: cover; border-radius: 50%; }
.ann-tag button {
  border: none;
  background: transparent;
  padding: 0 .35rem;
  color: var(--muted);
  cursor: pointer;
  font-size: .85rem;
  box-shadow: none;
}
.ann-tag button:hover { color: var(--danger); background: transparent; }
.ann-textimage-opt {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  font-weight: 500;
  color: var(--primary-hover);
  cursor: pointer;
  white-space: nowrap;
  margin: 0;
}
.ann-textimage-opt input[type=checkbox] {
  width: auto;
  padding: 0;
  margin: 0;
  cursor: pointer;
}
.ann-tag select {
  width: auto;
  padding: .1rem .35rem;
  font-size: .8rem;
  border-radius: var(--radius-sm);
  height: auto;
  line-height: 1.4;
  box-shadow: none;
}
.type-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-start; margin-top: .15rem; }
.type-row > select, .type-row > input { width: auto; min-width: 12rem; max-width: 100%; }
.type-row > input { flex: 1 1 16rem; }
.type-row > .ann-picker { flex: 1 1 20rem; grid-column: auto; }
.type-row > .hymn-name {
  flex: 1 1 100%;
  margin: 0;
  font-size: .88rem;
  color: var(--primary);
  font-weight: 500;
  background: var(--primary-light);
  padding: .3rem .6rem;
  border-radius: var(--radius-sm);
}
.type-row > .hymn-name:empty { display: none; }
textarea.lyrics { width: 100%; min-height: 14rem; font-family: inherit; font-size: .92rem; line-height: 1.6; resize: vertical; }
.song-audio-box { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.song-audio-row { display: flex; align-items: center; gap: .75rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .75rem; font-size: .9rem; width: 100%; }
.song-audio-row span { flex: 1; }



.sheet.attach { margin-top: 1rem; padding: 12mm; display: block; page-break-before: always; break-before: page; }
.sheet.attach h2 { margin: 0 0 6mm; font-size: 18pt; }
.sheet.attach h3 { margin: 4mm 0 2mm; font-size: 13pt; }
.attach-text { white-space: pre-wrap; font-size: 12pt; margin-bottom: 3mm; }

.attach-imgs { display: flex; flex-wrap: wrap; gap: 4mm; }
.attach-imgs img { max-width: 100%; max-height: 120mm; object-fit: contain; }
.attach-item { break-inside: avoid; }
@media print {
  .sheet.attach { height: auto; min-height: 0; overflow: visible; margin: 0; }
}
.swatches { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.swatch { aspect-ratio: 1; min-width: 0; padding: 0; border: 2px solid transparent; border-radius: 4px; cursor: pointer; }
.swatch:hover { transform: scale(1.12); }
.swatch.sel { border-color: var(--text); box-shadow: 0 0 0 2px #fff inset; }

/* Formaterad text i informationsredigeraren */
.rich-wrap { border: 1px solid var(--border, #d1d5db); border-radius: 6px; background: #fff; }
.rich-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: .35rem; border-bottom: 1px solid var(--border, #d1d5db); background: #f7f8fa; border-radius: 6px 6px 0 0; }
.rich-btn { min-width: 2rem; padding: .2rem .5rem; line-height: 1.2; }
.rich-sep { width: 1px; align-self: stretch; background: var(--border, #d1d5db); margin: 0 .2rem; }
.rich-swatch { width: 1.4rem; height: 1.4rem; aspect-ratio: auto; }
.rich-color { width: 2rem; height: 1.6rem; padding: 0; border: none; background: none; }
.rich-editor { min-height: 8rem; max-height: 22rem; overflow: auto; padding: .6rem; line-height: 1.5; white-space: pre-wrap; outline: none; }
.rich-editor:focus { box-shadow: 0 0 0 2px var(--accent, #3b82d4) inset; border-radius: 0 0 6px 6px; }

