:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f1ebe0;
  --line: #e2d9c9;
  --text: #2a2320;
  --muted: #7a6f66;
  --accent: #7a1f2b;
  --accent-ink: #fff8ec;
  --accent-soft: #f4e3e3;
  --gold: #b48a3c;

  --ok: #2f7a4a;     --ok-bg: #e2f1e6;
  --warn: #9a6400;   --warn-bg: #fbedcf;
  --bad: #b3261e;    --bad-bg: #f9dedb;
  --none-bg: #ece6dc;

  --radius: 10px;
  --shadow: 0 1px 2px rgb(40 25 10 / .06), 0 4px 14px rgb(40 25 10 / .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1716; --surface: #241f1d; --surface-2: #2d2725; --line: #3b3431;
    --text: #efe7de; --muted: #a59a90; --accent: #d8737f; --accent-ink: #1b1716; --accent-soft: #3a2427;
    --gold: #d6b06a;
    --ok: #7fcf98; --ok-bg: #213628; --warn: #f0c26b; --warn-bg: #3a2f17; --bad: #f09088; --bad-bg: #3d2220;
    --none-bg: #332d2a;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.45rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 650; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Pasek górny ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 16px;
}
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tabs a {
  padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 500;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.top-actions { display: flex; gap: 4px; white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Logowanie ---------- */
body.locked .tabs, body.locked .top-actions { visibility: hidden; }
.login { max-width: 360px; margin: 8vh auto 0; padding: 28px; display: grid; gap: 14px; text-align: center; }
.login .field { text-align: left; }
.brand-mark.big { width: 52px; height: 52px; font-size: 26px; border-radius: 14px; margin: 0 auto; }
input[type=password] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

main { max-width: 1280px; margin: 0 auto; padding: 24px; outline: none; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }
.sub { color: var(--muted); font-size: .9rem; }

/* ---------- Przyciski i pola ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 8px;
  cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 1.3rem; line-height: 1; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; }
.btn-group .btn + .btn { margin-left: -1px; }

input[type=text], input[type=tel], input[type=search], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .tabs a:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { resize: vertical; min-height: 64px; }
label.field { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
label.field > span { font-weight: 500; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 12px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.credentials { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.credentials > div { padding: 16px; display: grid; gap: 6px; background: var(--surface-2); }
.credentials > div + div { border-left: 1px solid var(--line); }
.credentials strong { font-size: 28px; letter-spacing: .1em; font-variant-numeric: tabular-nums; }
.access-url { overflow-wrap: anywhere; font-size: .9rem; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---------- Karty ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 1.05rem; }

/* ---------- Tydzień ---------- */
.week-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: .85rem; background: var(--surface-2); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }

.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.day { padding: 0; overflow: hidden; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.day-head .date { color: var(--muted); font-size: .88rem; }
.day.today { border-color: var(--accent); }
.day.today .day-head { background: var(--accent-soft); }
.day.today .day-head h3 { color: var(--accent); }
.day.past { opacity: .85; }
.mass { padding: 10px 14px; border-top: 1px solid var(--line); }
.mass:first-of-type { border-top: 0; }
.mass-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.mass-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.mass-desc { color: var(--muted); font-size: .88rem; flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; cursor: pointer;
  padding: 3px 10px 3px 8px; border-radius: 99px; font-size: .88rem; background: var(--none-bg);
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .45; }
.chip:hover { border-color: var(--line); filter: brightness(.97); }
.chip.obecny { background: var(--ok-bg); color: var(--ok); }
.chip.obecny::before { background: var(--ok); opacity: 1; }
.chip.usprawiedliwiony { background: var(--warn-bg); color: var(--warn); }
.chip.usprawiedliwiony::before { background: var(--warn); opacity: 1; }
.chip.nieobecny { background: var(--bad-bg); color: var(--bad); }
.chip.nieobecny::before { background: var(--bad); opacity: 1; }
.chip.usprawiedliwiony .name, .chip.nieobecny .name { text-decoration: line-through; text-decoration-thickness: 1px; }
.chip .sub-for { color: var(--text); font-weight: 500; }
.chip-note { display: block; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.no-mass { padding: 14px; color: var(--muted); font-size: .9rem; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .84rem; color: var(--muted); margin-top: 18px; }
.legend .chip { cursor: default; pointer-events: none; }

/* ---------- Tabele ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { color: var(--muted); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .78rem; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.badge.lektor { background: #e7ecf7; color: #2c4a8a; }
.badge.ceremoniarz { background: #f3ead5; color: #7a5a14; }
.badge.animator { background: #ece3f4; color: #5b2f86; }
.badge.kandydat { background: var(--none-bg); }
@media (prefers-color-scheme: dark) {
  .badge.lektor { background: #23304a; color: #a9c0f0; }
  .badge.ceremoniarz { background: #3a3120; color: #e3c27f; }
  .badge.animator { background: #33263f; color: #cfaef0; }
}
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--ok); }

/* ---------- Grafik ---------- */
.schedule { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.schedule .mass { display: grid; gap: 6px; }
.schedule .names { font-size: .9rem; }
.schedule .names.none { color: var(--bad); }

/* ---------- Wizyty ---------- */
.visits { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.visit { padding: 14px; display: grid; gap: 10px; align-content: start; }
.visit.full { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.visit.past { opacity: .7; }
.visit-top { display: flex; gap: 10px; align-items: flex-start; }
.visit-date { text-align: center; min-width: 54px; padding: 4px 6px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); line-height: 1.1; }
.visit-date b { display: block; font-size: 1.4rem; }
.visit-date small { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.visit-info { flex: 1; min-width: 0; }
.visit-info h3 { font-size: 1rem; }
.visit-meta { font-size: .86rem; color: var(--muted); }
.slots { display: flex; align-items: center; gap: 8px; font-size: .86rem; color: var(--muted); }
.slot-dots { display: flex; gap: 4px; }
.slot-dots i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--muted); }
.slot-dots i.on { background: var(--ok); border-color: var(--ok); }
.signed { display: flex; flex-wrap: wrap; gap: 6px; }
.signed .chip { cursor: default; background: var(--ok-bg); color: var(--ok); padding-right: 4px; }
.signed .chip::before { background: var(--ok); opacity: 1; }
.signed .chip button { border: 0; background: transparent; cursor: pointer; color: inherit; font-size: 1rem; line-height: 1; padding: 0 4px; border-radius: 50%; }
.signed .chip button:hover { background: rgb(0 0 0 / .08); }
.signup { display: flex; gap: 8px; }
.signup select { flex: 1; }
.month-label { grid-column: 1 / -1; margin-top: 8px; color: var(--muted); font-weight: 600; text-transform: capitalize; }
.month-label:first-child { margin-top: 0; }

/* ---------- Modal ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(540px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(30 20 15 / .45); }
.modal-form header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; display: grid; gap: 14px; max-height: 70vh; overflow-y: auto; }
.modal-form footer { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.modal-form footer .spacer { flex: 1; }
.status-choice { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.status-choice label { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.status-choice input { accent-color: var(--accent); }
.status-choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.picker { border: 1px solid var(--line); border-radius: 8px; max-height: 260px; overflow-y: auto; }
.picker label { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.picker label:last-child { border-bottom: 0; }
.picker label:hover { background: var(--surface-2); }
.picker input { accent-color: var(--accent); }
.picker .badge { margin-left: auto; }
.hint { font-size: .84rem; color: var(--muted); margin: 0; }

/* ---------- Powiadomienia ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: .92rem; animation: in .2s ease-out; }
.toast.error { background: var(--bad); color: #fff; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Telefon ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .top-actions { margin-left: auto; }
  main { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
@media print {
  .topbar, .page-head .btn, .legend, .toolbar { display: none; }
  body { background: #fff; }
}
