/*
 * Zapisy na posługi – Parafia Nawiedzenia NMP w Poznaniu
 * Mobile-first: base rules are for phones; wider screens add rules with min-width media queries
 *   640px  – tablet (two-column dialogs); 900px – toolbar in one row
 *   720px  – filters in one row, Masses of one day side by side (2 columns)
 *   1100px – laptop (3 columns)
 * Dark theme is the default. Light theme is used when the device asks for it (prefers-color-scheme: light).
 */

/* ============================================================ tokens */
:root {
  color-scheme: dark light;
  --bg: #0f1419;
  --header-bg: #131b25;
  --surface: #18212c;
  --surface-2: #202b39;
  --border: #2d3b4d;
  --text: #e9eef5;
  --muted: #a8b4c4;
  --accent: #6fa9f4;          /* primary button background */
  --accent-ink: #08213f;      /* text on the primary button */
  --link: #8dbdff;            /* accent used as text */
  --danger: #ff9d95;
  --ok: #86dba1;  --ok-bg: #14301f;
  --warn: #f3cd78; --warn-bg: #33290f;
  --match: #3b3612;
  --ok-line: #3f8f6f; --ok-soft: rgba(134, 219, 161, .09);
  --mine-bg: #1c3556; --mine-line: #6fa9f4;
  --bar-taken: #d9985f; --bar-quiet: #56657a;
  --focus: #a9d0ff;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f4f8;
    --header-bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --border: #ccd5e0;
    --text: #17202b;
    --muted: #4a5767;
    --accent: #1f5fae;
    --accent-ink: #ffffff;
    --link: #1a559f;
    --danger: #b3261e;
    --ok: #1b6e38;  --ok-bg: #e1f3e7;
    --warn: #7a5200; --warn-bg: #fff1cf;
    --match: #fff3b8;
    --ok-line: #5aa57a; --ok-soft: rgba(27, 110, 56, .08);
    --mine-bg: #e3eefb; --mine-line: #1f5fae;
    --bar-taken: #b8691f; --bar-quiet: #8c99ab;
    --focus: #1f5fae;
    --shadow: 0 8px 28px rgba(20, 30, 50, .18);
  }
}

/* Each day of the week has its own hue (--h), so neighbouring days never blend together.
   The weekday name and the date are always written out too, colour is only a helper. */
.day[data-wd="0"] { --h: 44;  }   /* niedziela    – złoty      */
.day[data-wd="1"] { --h: 212; }   /* poniedziałek – niebieski  */
.day[data-wd="2"] { --h: 135; }   /* wtorek       – zielony    */
.day[data-wd="3"] { --h: 335; }   /* środa        – różowy     */
.day[data-wd="4"] { --h: 175; }   /* czwartek     – morski     */
.day[data-wd="5"] { --h: 20;  }   /* piątek       – miedziany  */
.day[data-wd="6"] { --h: 268; }   /* sobota       – fioletowy  */

.day {
  --panel:        hsl(var(--h), 24%, 14%);
  --panel-border: hsl(var(--h), 28%, 26%);
  --bar:          hsl(var(--h), 62%, 60%);
  --ink:          hsl(var(--h), 75%, 84%);
  --sub:          hsl(var(--h), 22%, 74%);
  --badge-bg:     hsl(var(--h), 40%, 24%);
  --badge-ink:    hsl(var(--h), 85%, 90%);
}
@media (prefers-color-scheme: light) {
  .day {
    --panel:        hsl(var(--h), 42%, 93%);
    --panel-border: hsl(var(--h), 32%, 78%);
    --bar:          hsl(var(--h), 55%, 40%);
    --ink:          hsl(var(--h), 65%, 20%);
    --sub:          hsl(var(--h), 30%, 28%);
    --badge-bg:     hsl(var(--h), 50%, 86%);
    --badge-ink:    hsl(var(--h), 70%, 20%);
  }
}

/* ============================================================ base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.modal-open { overflow: hidden; }
h1, h2, h3, p { margin-top: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); font-size: 16px; }

.wrap {
  width: 100%; max-width: 1180px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 50; padding: 10px 14px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 8px; }

/* ============================================================ header */
.site-header { background: var(--header-bg); border-bottom: 1px solid var(--border); }
.header-inner {
  display: flex; align-items: center; gap: 14px;
  padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: 14px;
}
.brand-icon { width: 52px; height: 52px; border-radius: 12px; flex: none; background: #fff; border: 1px solid var(--border); }
.brand-text { min-width: 0; }
.parish { margin: 0; font-size: 16px; font-weight: 700; color: var(--link); line-height: 1.25; }
.site-header h1 { font-size: 24px; line-height: 1.2; margin: 2px 0 0; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 16px; line-height: 1.35; }
.pill-mode {
  display: inline-block; margin-right: 6px; padding: 1px 10px; border-radius: 999px;
  background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); font-weight: 700; font-size: 14px;
}

/* ============================================================ toolbar (sticky) */
.toolbar-wrap { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--border); }
body.sacristy .toolbar-wrap { border-bottom: 3px solid var(--warn); }
.toolbar { position: relative; display: flex; gap: 8px; padding-top: 8px; padding-bottom: 8px; }
.toolbar .btn { flex: 1 1 0; padding: 0 10px; }
.toolbar .more-toggle { flex: 0 0 auto; padding: 0 16px; }
.btn-help { color: var(--link); border-color: var(--link); }

.more-menu {
  display: none; position: absolute; right: max(16px, env(safe-area-inset-right)); top: calc(100% + 4px); z-index: 12;
  flex-direction: column; gap: 6px; width: min(300px, calc(100vw - 32px)); padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.more-menu.open { display: flex; }
.toolbar .more-menu .btn { flex: none; width: 100%; justify-content: flex-start; }

/* ============================================================ buttons */
.btn {
  min-height: 48px; padding: 0 16px; font: inherit; font-size: 17px; line-height: 1.2;
  border-radius: 12px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 16px; }
.linkbtn {
  background: none; border: 0; padding: 10px 0; min-height: 44px; font: inherit; font-size: 16px;
  color: var(--link); text-decoration: underline; cursor: pointer; text-align: left;
}

/* ============================================================ progress, spinner, banner, toast */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 4px; z-index: 60; overflow: hidden; }
.progress-bar { height: 100%; width: 40%; background: var(--accent); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.spinner {
  width: 1em; height: 1em; border-radius: 50%; display: inline-block; flex: none;
  border: .15em solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
.spinner.big { width: 40px; height: 40px; border-width: 4px; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .progress-bar, .spinner { animation-duration: 3s; } .btn:active { transform: none; } }
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 0; color: var(--muted); text-align: center; }

.banner { margin: 12px 0 0; padding: 10px 14px; border-radius: 12px; background: var(--surface-2); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner .btn { margin-top: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: max-content; max-width: min(92vw, 520px); padding: 12px 18px; border-radius: 12px; z-index: 70;
  background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); font-weight: 600; box-shadow: var(--shadow);
}
.toast.error { background: var(--warn-bg); color: var(--danger); border-color: var(--danger); }

/* ============================================================ filters */
.filters { margin: 14px 0 0; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.filters-top { display: flex; gap: 10px; align-items: flex-end; }
.field-person { flex: 1; min-width: 0; }
.field label, .filters .check { font-size: 15px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.filters-toggle { flex: none; position: relative; }
.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 700;
}
.filters-more { display: none; margin-top: 12px; }
.filters.open .filters-more { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.filters-more .check { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 17px; }
.check input { width: 24px; height: 24px; flex: none; }
.filters-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 10px; min-height: 24px; }

select, input[type="search"], .dialog input[type="text"], .dialog input[type="tel"], .dialog input[type="password"], .dialog textarea {
  width: 100%; min-height: 48px; font: inherit; font-size: 17px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.dialog textarea { min-height: 128px; resize: vertical; line-height: 1.4; }
::placeholder { color: var(--muted); opacity: .85; }

/* ============================================================ list: days and Masses */
#list { outline: none; }
.day {
  margin: 18px 0; padding: 12px 12px 12px; background: var(--panel);
  border: 1px solid var(--panel-border); border-left: 6px solid var(--bar); border-radius: var(--radius);
}
.day-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.day-badge {
  flex: none; width: 58px; height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 12px; border: 2px solid var(--bar); background: var(--badge-bg); color: var(--badge-ink); line-height: 1;
}
.day-num { font-size: 26px; font-weight: 800; }
.day-mon { margin-top: 3px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.day-title { min-width: 0; flex: 1; }
.day-title h2 { margin: 0; font-size: 22px; line-height: 1.2; color: var(--ink); }
.day-date { margin-top: 2px; font-size: 16px; color: var(--sub); }
.day-tag {
  flex: none; align-self: flex-start; padding: 2px 12px; border-radius: 999px; font-size: 14px; font-weight: 700;
  background: var(--badge-bg); color: var(--badge-ink); border: 1px solid var(--bar);
}
.day-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px 4px; }
.card-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.mass-time { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 700; font-variant-numeric: tabular-nums; }
.description { color: var(--muted); font-size: 16px; }
.slot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px 12px; flex-wrap: wrap;
  padding: 10px 0; margin-top: 10px; border-top: 1px solid var(--border);
}
.slot.match { background: var(--match); margin-left: -8px; margin-right: -8px; padding-left: 8px; padding-right: 8px; border-radius: 8px; }
.slot-info { flex: 1 1 140px; min-width: 0; }
.role { display: block; font-weight: 700; }
.name { display: block; overflow-wrap: anywhere; }
.free { display: block; color: var(--muted); }
.phone { color: var(--muted); }
.me {
  display: inline-block; margin-left: 8px; padding: 0 8px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); vertical-align: 1px;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { padding: 32px 8px; text-align: center; color: var(--muted); }

/* ============================================================ footer */
.site-footer { margin-top: 28px; padding: 20px 0 calc(28px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); color: var(--muted); font-size: 16px; }
.footer-parish { margin: 0 0 6px; font-weight: 700; color: var(--text); }
.footer-privacy { margin: 0 0 6px; }
.footer-links { margin: 0; display: flex; flex-wrap: wrap; gap: 0 22px; }

/* ============================================================ dialog */
.overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 30; display: none;
  align-items: center; justify-content: center; padding: 12px; background: rgba(4, 8, 14, .72);
}
.overlay.open { display: flex; }
.dialog {
  width: min(520px, 100%); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow: auto;
  padding: 18px; border-radius: 16px; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow); outline: none; overscroll-behavior: contain;
}
.dialog.wide { width: min(680px, 100%); }
.dialog h2 { margin: 0 0 8px; font-size: 22px; line-height: 1.25; }
.dialog h3 { margin: 18px 0 6px; font-size: 18px; color: var(--link); }
.dialog h3:first-child { margin-top: 4px; }
.dialog p { margin: 8px 0; }
.dialog .field { margin: 12px 0; }
.dialog .field label { font-size: 16px; }
.note { color: var(--muted); font-size: 15px; line-height: 1.4; }
.dialog-status { min-height: 1.4em; margin: 8px 0 0; color: var(--muted); }
.dialog-status.error { color: var(--danger); font-weight: 600; }
.buttons { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; }
.buttons .btn { flex: 1 1 auto; }
.steps, .bullets { margin: 6px 0; padding-left: 22px; }
.steps li, .bullets li { margin: 8px 0; padding-left: 2px; }
.facts { margin: 0; }
.facts dt { margin-top: 14px; font-weight: 700; color: var(--link); }
.facts dt:first-child { margin-top: 2px; }
.facts dd { margin: 2px 0 0; }

.kind { margin: 12px 0; padding: 0; border: 0; min-width: 0; }
.kind legend { padding: 0; margin-bottom: 6px; font-weight: 600; font-size: 16px; }
.radios { display: flex; gap: 8px; flex-wrap: wrap; }
.radio {
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 16px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
}
.radio input { width: 22px; height: 22px; margin: 0; }
.radio:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.counter { text-align: right; color: var(--muted); font-size: 14px; margin-top: 2px; }
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* ============================================================ tablet and up */
@media (min-width: 640px) {
  .wrap { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
  .site-header h1 { font-size: 28px; }
  .parish { font-size: 17px; }
  .brand-icon { width: 60px; height: 60px; }

  .more-menu { right: auto; }
  .dialog { padding: 22px 24px; }
  .buttons .btn { flex: 0 0 auto; }
}

@media (min-width: 720px) {
  /* filters in one row */
  .filters { display: grid; grid-template-columns: minmax(220px, 2fr) 1fr 1fr auto; gap: 10px 16px; align-items: end; padding: 14px 16px; }
  .filters-top, .filters-more, .filters.open .filters-more { display: contents; }
  .filters-toggle { display: none; }
  .filters-foot { grid-column: 1 / -1; margin-top: 0; }
  .filters .check { margin-bottom: 2px; }

  .day { padding: 16px 16px 16px; margin: 22px 0; }
  .day-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .day-title h2 { font-size: 24px; }
}

@media (min-width: 900px) {
  /* every action is visible in the toolbar, no "Więcej" menu */
  .toolbar .btn { flex: 0 0 auto; padding: 0 18px; }
  .more-toggle { display: none; }
  .more-menu, .more-menu.open { display: contents; }
  .toolbar .more-menu .btn { width: auto; justify-content: center; }
  .btn-mode { margin-left: auto; }
}

@media (min-width: 1100px) {
  .day-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ============================================================ print */
@media print {
  body { background: #fff; color: #000; font-size: 13px; }
  .progress, .skip-link, .toolbar-wrap, .filters, .banner, .toast, .overlay, .site-footer .footer-links, .btn, .phone, .subtitle, .day-tag, .me { display: none !important; }
  .site-header { background: none; border-bottom: 2px solid #000; }
  .brand-icon { display: none; }
  .parish, .site-header h1 { color: #000; }
  .day { background: none; border: 1px solid #666; border-left: 6px solid #000; padding: 8px; margin: 10px 0; break-inside: avoid; }
  .day-badge { background: none; border-color: #000; color: #000; }
  .day-title h2, .day-date { color: #000; }
  .day-grid { display: block; }
  .card { break-inside: avoid; border-color: #999; background: none; margin-bottom: 8px; }
  .slot.match { background: none; }
  .site-footer { color: #000; border-color: #999; }
}

/* ---- "Moje zapisy" panel ---- */
.mine { margin: 18px 0; padding: 12px; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); }
.mine h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; font-size: 20px; }
.mine-count { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; padding: 0 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 700; }
.mine-list { list-style: none; margin: 0; padding: 0; }
.mine-row { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); }
.mine-row:first-child { border-top: 0; }
.mine-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mine-when { font-weight: 700; }
.mine-what { color: var(--muted); overflow-wrap: anywhere; }
.mine-actions { display: flex; gap: 8px; }
.mine-actions .btn { flex: 1; }
@media (min-width: 640px) {
  .mine-row { flex-direction: row; align-items: center; justify-content: space-between; }
  .mine-actions .btn { flex: none; }
}
.card.flash { animation: flash 1.8s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 3px transparent; } }
@media print { .mine { display: none; } }
.mine-who { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.mine-who .linkbtn { min-height: 40px; }
.who { display: flex; flex-direction: column; gap: 2px; margin: 12px 0; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }
.who-label { color: var(--muted); font-size: 14px; }
.who-name { font-size: 20px; }
.who .linkbtn { align-self: flex-start; min-height: 40px; margin-top: 4px; }

.has-role { margin: 0 0 6px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 15px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.phone-check { margin: -4px 0 8px; font-size: 14px; color: var(--muted); min-height: 20px; }
.phone-check.bad { color: var(--warn); }
.prompt-box { border-style: dashed; }
.prompt-box h2 { margin: 0 0 6px; font-size: 20px; }
.prompt-text { margin: 0 0 12px; color: var(--muted); }
.notice { margin: 18px 0 0; padding: 12px; border: 1px solid var(--warn); border-radius: var(--radius); background: var(--surface); }
.notice p { margin: 0 0 10px; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- free / taken / yours: free slots stand out, taken ones are quiet ---- */
.mass-count { margin-left: auto; font-size: 15px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.mass-count.has-free { color: var(--ok); }
.occ { display: flex; gap: 3px; height: 8px; margin: 8px 0 2px; }
.occ i { flex: 1; border-radius: 99px; background: var(--bar-taken); }
.occ i.f { background: var(--ok); }
.occ i.m { background: var(--accent); }

.slot { border-top: 0; margin-top: 8px; padding: 10px 12px; border-radius: 10px; border-left: 5px solid transparent; }
.slot.is-taken { border-left-color: var(--bar-quiet); }
.slot.is-taken .role { color: var(--muted); font-weight: 600; }
.slot.is-taken .name { color: var(--muted); }
.state { color: var(--muted); font-size: 14px; font-weight: 600; }
.slot.is-free { border: 2px dashed var(--ok-line); border-left: 5px solid var(--ok); background: var(--ok-soft); padding: 8px 10px 8px 10px; }
.slot.is-free .role { font-size: 17px; }
.free { display: inline-flex; align-items: center; gap: 5px; margin-top: 3px; padding: 1px 10px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); font-weight: 700; font-size: 14px; }
.slot.is-mine { background: var(--mine-bg); border-left: 5px solid var(--mine-line); }
.slot.is-mine .role { color: var(--text); }
.slot.is-mine .name { color: var(--text); font-weight: 700; }
.me { background: transparent; color: var(--link); border-color: var(--mine-line); margin-left: 8px; display: inline-block; margin-top: 2px; }
.slot.match { margin-left: 0; margin-right: 0; background: var(--match); }
.card { padding-bottom: 12px; }

.footer-version { margin: 10px 0 0; font-size: 14px; color: var(--muted); }
