:root {
  --ink: #2e241f;
  --muted: #796a60;
  --line: #e3d7ca;
  --canvas: #f4eee5;
  --paper: #fffdf9;
  --soft: #faf6f0;
  --forest: #5a3827;
  --forest-soft: #eee1d4;
  --gold: #b28652;
  --hour-height: 50px;
  --timeline-start: 6;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; background: var(--canvas); overflow: hidden; }
body { min-width: 720px; }
button, select { font: inherit; }
button { color: inherit; }
.is-hidden { display: none !important; }

.app-shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.command-bar {
  flex: 0 0 84px; padding: 0 clamp(16px, 2.6vw, 38px); display: grid;
  grid-template-columns: auto auto minmax(190px, 1fr) auto; align-items: center; gap: clamp(14px, 2vw, 28px);
  border-bottom: 1px solid var(--line); background: rgba(251,247,241,.97); backdrop-filter: blur(14px);
  position: relative; z-index: 20; box-shadow: 0 8px 28px rgba(75,50,35,.055);
}
.brand { min-width: 0; display: flex; align-items: center; gap: 11px; white-space: nowrap; }
.brand > div:last-child { min-width: 0; }
.brand-mark { flex-shrink: 0; width: 42px; height: 42px; display: grid; place-items: center; overflow: hidden; border: 1px solid #cbb49d; border-radius: 50%; background: #fffaf3; box-shadow: inset 0 0 0 3px #f2e5d7, 0 3px 10px rgba(74,47,31,.09); }
.brand-mark img { width: 31px; height: 31px; display: block; object-fit: contain; mix-blend-mode: multiply; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 10px; letter-spacing: .18em; font-weight: 700; }
h1, h2 { font-family: "Newsreader", Georgia, serif; font-weight: 600; }
h1 { margin: 0; font-size: 23px; line-height: 1; }
.command-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

main { flex: 1; min-height: 0; padding: 12px clamp(14px, 2vw, 28px) 18px; display: flex; flex-direction: column; }
.date-navigation { display: flex; align-items: center; gap: 4px; padding: 4px; border: 1px solid #e4d7ca; border-radius: 14px; background: #f1e8de; }
.date-navigation .button, .date-navigation .icon-button { min-height: 36px; height: 36px; border-radius: 9px; box-shadow: none; }
.date-navigation .icon-button { width: 36px; }
.range-copy { text-align: center; min-width: 0; transform: translateY(11px); }
.range-label { margin: 0; font-family: "Newsreader", Georgia, serif; font-size: 20px; font-weight: 600; white-space: normal; overflow-wrap: anywhere; text-wrap: balance; }
.button, .icon-button { border: 1px solid var(--line); background: var(--paper); cursor: pointer; min-height: 42px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; transition: transform .16s, border-color .16s, background .16s; }
.button { padding: 0 15px; }
.icon-button { width: 42px; font-size: 20px; }
.button:hover, .icon-button:hover { border-color: #b59b85; }
.button:active, .icon-button:active { transform: scale(.97); }
.button:disabled, .icon-button:disabled { opacity: .32; cursor: default; transform: none; }
.button-primary { background: var(--forest); border-color: var(--forest); color: #fff; }
.button-quiet { background: transparent; }
.button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#googleButton svg { stroke: none; }
#googleButton svg path:nth-child(1) { fill: #4285f4; } #googleButton svg path:nth-child(2) { fill: #34a853; }
#googleButton svg path:nth-child(3) { fill: #fbbc05; } #googleButton svg path:nth-child(4) { fill: #ea4335; }
.filter-count { min-width: 19px; height: 19px; border-radius: 9px; display: grid; place-items: center; background: var(--forest); color: #fff; font-size: 10px; }

.active-filters { flex: 0 0 auto; display: flex; gap: 8px; padding: 0 0 10px; justify-content: flex-end; }
.active-filter { border: 1px solid #d5bfaa; background: #f3e9df; color: var(--forest); border-radius: 999px; padding: 6px 10px; font-size: 12px; }

.calendar-frame { flex: 1; min-height: 0; position: relative; border: 1px solid var(--line); background: var(--paper); border-radius: 17px; overflow: hidden; box-shadow: 0 16px 48px rgba(76,50,34,.08); }
.calendar-viewport { width: 100%; height: 100%; overflow-x: hidden; overflow-y: auto; touch-action: pan-y; cursor: grab; overscroll-behavior: contain; }
.calendar-viewport.is-dragging { cursor: grabbing; }
.calendar-stage { display: grid; grid-template-columns: 54px repeat(3, minmax(0, 1fr)); min-height: 900px; transition: transform .42s cubic-bezier(.22,.75,.22,1), opacity .38s ease; }
.calendar-stage.slide-left { transform: translateX(-4%); opacity: .18; }
.calendar-stage.slide-right { transform: translateX(4%); opacity: .18; }
.time-rail { border-right: 1px solid var(--line); background: var(--soft); position: relative; }
.time-rail-head { height: 76px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 7; background: var(--soft); }
.time-label { position: absolute; right: 10px; transform: translateY(-50%); font-size: 10px; color: #918276; }
.day-column { min-width: 0; border-right: 1px solid var(--line); }
.day-column:last-child { border-right: 0; }
.day-header { height: 76px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: rgba(255,253,249,.97); position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 12px; }
.day-column.is-today .day-header { background: linear-gradient(90deg, #fbf2e9 0%, rgba(255,253,249,.97) 72%); }
.day-date { flex: 0 0 auto; }
.day-name-row { min-height: 16px; display: flex; align-items: center; gap: 6px; }
.day-name { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: 10px; font-weight: 700; }
.day-number { font-family: "Newsreader", Georgia, serif; font-size: 31px; line-height: 1; margin-top: 2px; }
.day-column.is-today .day-number { color: var(--forest); }
.today-dot { flex: 0 0 auto; font-size: 8px; line-height: 1; letter-spacing: .04em; font-weight: 700; color: var(--forest); background: var(--forest-soft); padding: 3px 5px; border-radius: 999px; }
.all-day-events { flex: 1 1 auto; min-width: 0; max-height: 54px; padding: 1px 2px; display: grid; gap: 3px; overflow-y: auto; overscroll-behavior: contain; }
.all-day-event { position: relative; width: 100%; min-height: 24px; padding: 3px 8px 3px 11px; display: flex; align-items: center; gap: 7px; border: 1px solid color-mix(in srgb, var(--event-color) 28%, #ded3c9); border-radius: 7px; background: color-mix(in srgb, var(--event-color) 9%, white); color: var(--ink); text-align: left; cursor: pointer; overflow: hidden; }
.all-day-event::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--event-color); }
.all-day-event:hover { border-color: var(--event-color); }
.all-day-label { flex: 0 0 auto; color: var(--muted); font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.all-day-title { min-width: 0; overflow: hidden; color: var(--ink); font-size: 10px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.timeline { height: calc(var(--timeline-hours, 14) * var(--hour-height)); position: relative; border-bottom: 1px solid #eee7df; background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-height) - 1px), #eee7df calc(var(--hour-height) - 1px), #eee7df var(--hour-height)); }
.timeline::after { content: ""; position: absolute; inset: 0; pointer-events: none; background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-height) / 2 - 1px), rgba(234,225,216,.55) calc(var(--hour-height) / 2 - 1px), rgba(234,225,216,.55) calc(var(--hour-height) / 2), transparent calc(var(--hour-height) / 2)); background-size: 100% var(--hour-height); }
.event-card { position: absolute; min-height: 34px; border: 1px solid color-mix(in srgb, var(--event-color) 25%, #ded3c9); background: color-mix(in srgb, var(--event-color) 9%, white); border-radius: 9px; padding: 6px 6px 5px 10px; overflow: hidden; text-align: left; cursor: pointer; z-index: 2; box-shadow: 0 2px 5px rgba(63,44,32,.05); }
.event-card::before { content: ""; width: 4px; position: absolute; left: 0; top: 0; bottom: 0; background: var(--event-color); }
.event-card:hover { z-index: 4; border-color: var(--event-color); box-shadow: 0 8px 22px rgba(63,44,32,.14); }
.event-card.is-parish { background: color-mix(in srgb, var(--event-color) 15%, white); border-width: 1.5px; }
.event-overflow { background: #f2ece5; border-style: dashed; display: flex; align-items: center; justify-content: flex-start; padding: 6px 6px 6px 10px; text-align: left; }
.event-overflow .event-title { font-size: 10px; white-space: normal; overflow: visible; text-overflow: clip; }
.event-overflow-lead { font-size: 1.3em; }
.event-title { display: block; font-size: 11px; font-weight: 700; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-meta { display: block; margin-top: 3px; color: #71645b; font-size: 9px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-card.is-detailed { display: flex; flex-direction: column; justify-content: center; padding: 3px 6px 3px 10px; }
.event-card.is-detailed .event-time { margin-top: 1px; }
.event-card.is-detailed .event-room { margin-top: 0; }
.event-card.is-one-hour .event-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: clip; -webkit-line-clamp: unset; }
.event-card.is-long .event-title { display: -webkit-box; white-space: normal; text-overflow: clip; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.event-card.is-long .event-time { margin-top: 5px; }
.event-card.is-long .event-room { margin-top: 2px; }
.empty-day { position: absolute; inset: 46px 12px auto; text-align: center; color: var(--muted); font-size: 12px; }
.loading-layer { position: absolute; inset: 0; z-index: 30; background: rgba(251,247,241,.86); display: grid; place-content: center; justify-items: center; backdrop-filter: blur(4px); color: var(--muted); }
.spinner { width: 30px; height: 30px; border: 3px solid #e5d8cb; border-top-color: var(--forest); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.filter-panel { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.filter-panel.is-open { pointer-events: auto; }
.filter-backdrop { position: absolute; inset: 0; border: 0; background: rgba(46,34,27,.3); opacity: 0; transition: opacity .24s; }
.filter-sheet { position: absolute; top: 0; right: 0; width: min(430px, 90vw); height: 100%; padding: 28px; background: #fcf8f2; box-shadow: -20px 0 70px rgba(52,35,25,.18); transform: translateX(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1); display: flex; flex-direction: column; }
.filter-panel.is-open .filter-backdrop { opacity: 1; }
.filter-panel.is-open .filter-sheet { transform: translateX(0); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.sheet-header h2 { margin: 0; font-size: 32px; }
.filter-group { display: grid; gap: 8px; margin-bottom: 16px; }
.filter-group label { font-size: 12px; font-weight: 700; }
select { width: 100%; height: 48px; padding: 0 40px 0 13px; border: 1px solid var(--line); border-radius: 12px; background: white; color: var(--ink); }
.sheet-footer { margin-top: 4px; display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; }

.event-dialog { width: min(520px, calc(100vw - 40px)); border: 0; border-radius: 20px; padding: 34px; color: var(--ink); background: #fffdf9; box-shadow: 0 30px 100px rgba(45,31,23,.3); }
.event-dialog::backdrop { background: rgba(46,34,27,.38); backdrop-filter: blur(4px); }
.dialog-close { position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: #f2eae2; font-size: 20px; cursor: pointer; }
.dialog-accent { width: 34px; height: 5px; border-radius: 4px; margin-bottom: 22px; background: var(--event-color, var(--forest)); }
.event-dialog h2 { margin: 5px 40px 25px 0; font-size: 31px; line-height: 1.06; }
.event-details { display: grid; gap: 0; margin: 0; }
.event-details > div { display: grid; grid-template-columns: 92px 1fr; gap: 12px; border-top: 1px solid var(--line); padding: 13px 0; }
.event-details dt { font-size: 11px; color: var(--muted); font-weight: 700; }
.event-details dd { margin: 0; font-size: 13px; line-height: 1.45; white-space: pre-line; max-height: 290px; overflow: auto; }
.event-details dd p, .event-details dd ul, .event-details dd ol { margin: 0 0 10px; }
.event-details dd p:last-child, .event-details dd ul:last-child, .event-details dd ol:last-child { margin-bottom: 0; }
.event-details dd ul, .event-details dd ol { padding-left: 22px; }
.event-details dd a { color: var(--forest); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.event-details > .is-event-group { display: block; }
.is-event-group > dt { display: none; }
.is-event-group > dd { white-space: normal; }
.event-group-list { display: grid; gap: 12px; }
.event-group-item { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px; align-items: start; }
.event-group-time { color: var(--muted); font-size: 12px; font-weight: 700; line-height: 1.45; white-space: nowrap; }
.event-group-copy { min-width: 0; }
.toast { position: fixed; left: 50%; bottom: 25px; transform: translate(-50%, 30px); background: #4b3326; color: white; border-radius: 12px; padding: 11px 16px; opacity: 0; pointer-events: none; z-index: 80; transition: .2s; font-size: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .command-bar { grid-template-columns: auto auto minmax(150px, 1fr) auto; gap: 8px; padding-inline: 12px; }
  .brand .eyebrow { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  h1 { font-size: 19px; }
  .google-button { width: 42px; padding: 0; font-size: 0; }
  .google-button svg { margin: 0; }
  .google-button.needs-config::before { content: "G"; font-size: 16px; font-weight: 700; color: #4285f4; }
  main { padding: 10px 10px 12px; }
  .range-label { font-size: 17px; }
  .day-header { padding-inline: 10px; gap: 8px; }
  .all-day-label { display: none; }
}

@media (display-mode: standalone) {
  .command-bar { padding-top: env(safe-area-inset-top); flex-basis: calc(84px + env(safe-area-inset-top)); }
}

/* Wąskie ekrany (telefony). Poniżej 720 px znosimy `min-width` z `body`:
   bez tego przeglądarka telefonu oddala widok do 720 px szerokości, przez co
   viewport układu robi się wyższy niż `100dvh` i pod kalendarzem zostaje puste tło.
   Próg to dokładnie ta sama wartość co `min-width`, więc widok tabletowy — zawsze
   szerszy — nie zmienia się ani o piksel. */
@media (max-width: 719.98px) {
  body { min-width: 0; }

  .command-bar {
    flex: 0 0 auto; height: auto;
    padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "brand brand actions" "nav range range";
    gap: 8px 10px;
  }
  .brand { grid-area: brand; min-width: 0; }
  .brand h1 { overflow: hidden; text-overflow: ellipsis; }
  .brand-mark { width: 30px; height: 30px; }
  .brand-mark img { width: 22px; height: 22px; }
  h1 { font-size: 17px; }
  .command-actions { grid-area: actions; }
  .date-navigation { grid-area: nav; justify-self: start; }
  .range-copy { grid-area: range; text-align: right; transform: none; }
  .range-label { font-size: 15px; }

  main { padding: 8px 8px 10px; }
  .active-filters { padding-bottom: 8px; }
  .calendar-frame { border-radius: 13px; box-shadow: 0 8px 24px rgba(76,50,34,.08); }

  /* Trzy dni zostają, ale kolumna nie schodzi poniżej czytelnej szerokości:
     zamiast ściskać karty do nieczytelnych pasków, siatkę przesuwa się w bok.
     Szyna godzin zostaje wtedy przyklejona do lewej krawędzi. */
  .calendar-viewport { overflow-x: auto; touch-action: pan-x pan-y; }
  /* Układ przechodzi z siatki na flex tylko po to, żeby szyna godzin mogła zostać
     przyklejona do lewej krawędzi: przyklejony element siatki nie wychodzi poza
     własną komórkę. Kolumn nadal są trzy — tworzy je `src/app.js`. */
  .calendar-stage { display: flex; min-width: max-content; }
  .time-rail { flex: 0 0 38px; position: sticky; left: 0; z-index: 8; }
  .day-column { flex: 1 0 260px; }
  .time-label { right: 5px; }

  .day-header { flex-direction: column; align-items: stretch; justify-content: flex-start; padding: 5px 8px; gap: 2px; }
  .day-date { display: flex; align-items: baseline; gap: 6px; }
  .day-name-row { min-height: 0; gap: 5px; }
  .day-number { font-size: 20px; margin-top: 0; }
  .all-day-events { min-height: 0; max-height: none; padding: 0; align-content: start; }
  .all-day-event { min-height: 20px; padding: 2px 5px 2px 8px; gap: 4px; border-radius: 6px; }

  .filter-sheet { padding: 20px; }
  .sheet-header { margin-bottom: 16px; }
  .sheet-header h2 { font-size: 26px; }
  .event-dialog { padding: 24px; }
  .event-dialog h2 { font-size: 25px; margin-bottom: 18px; }
  .event-details > div, .event-group-item { grid-template-columns: 74px minmax(0, 1fr); gap: 10px; }
}

/* Na telefonie zakres dat ma cały wiersz, niezależny od szerokości przycisków. */
@media (max-width: 479.98px) {
  .command-bar { grid-template-areas: "brand brand actions" "nav nav nav" "range range range"; }
  .range-copy { text-align: left; }
}

/* Niskie ekrany o szerokości tabletu — w praktyce telefon w poziomie.
   Pasek górny przestaje zjadać jedną czwartą wysokości. Żaden tablet nie ma
   wysokości poniżej 480 px, więc widok tabletowy tego nie dotyka. */
@media (max-height: 480px) and (min-width: 720px) {
  .command-bar { flex-basis: 60px; padding-top: env(safe-area-inset-top); }
  .brand-mark { width: 32px; height: 32px; }
  .brand-mark img { width: 24px; height: 24px; }
  h1 { font-size: 18px; }
  .button, .icon-button { min-height: 36px; }
  .icon-button { width: 36px; }
  .date-navigation .button, .date-navigation .icon-button { min-height: 32px; height: 32px; }
  .date-navigation .icon-button { width: 32px; }
  .range-copy { transform: translateY(8px); }
  main { padding: 8px clamp(10px, 2vw, 28px) 10px; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; } }
