/* View: Logowanie, rejestracja, reset, wybór roli (js/views/auth.js).
   Phone: brand row with "Wypróbuj demo", a compact live preview (one vignette at a time, tap = next, dots), then the form card —
   the submit button stays above the fold at 360 × 780. Desktop ≥ 761: paper-2 hero (headline, preview on a stack of sheets with
   pointer tilt + parallax, caption, tabs with a progress rule) beside the form.
   Motion: .is-entering (first show) = staggered entrance; .is-swapping = the card after a mode switch; vignettes cross-fade
   (.is-on / .is-out) and their rows, stamp, bars play when they become active. Transform / opacity only; reduced motion = static. */
@layer views {
.auth-root { position: fixed; inset: 0; z-index: 80; overflow-y: auto; overflow-x: hidden; background: var(--paper); }
.auth { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; }
.auth-single { grid-template-columns: minmax(0, 1fr); align-content: stretch; }

/* ---- hero (phone: brand row + compact preview) ---- */
.auth-hero { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: calc(440px + 2 * var(--gutter)); margin: 0 auto; padding: calc(8px + var(--safe-t)) var(--gutter) 0; min-width: 0; }
.auth-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.auth-brand .brand-mark { width: 34px; height: 34px; font-size: 21px; }
.auth-brand .brand-name { font-size: 21px; }
.auth-demo-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px 0 16px; border-radius: var(--r-pill);
  background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; box-shadow: inset 0 0 0 1.5px var(--accent-line);
  transition: transform var(--t-fast) var(--ease-out), background-color var(--t-fast);
}
.auth-demo-link .ico { transition: transform var(--t-base) var(--ease-out); }
.auth-demo-link:active { transform: scale(.96); }
.auth-headline, .auth-lead, .ap-foot, .ap-sheet { display: none; }
.hw { display: inline-block; }
.auth-accent { color: var(--accent); }

/* ---- live preview ---- */
.ap { min-width: 0; }
.ap-scene { position: relative; }
.ap-stage {
  position: relative; display: block; width: 100%; padding: 12px 14px 20px; text-align: left; color: var(--ink); cursor: pointer;
  background: var(--widget-bg); border: 1px solid var(--widget-border); border-radius: var(--widget-radius); -webkit-tap-highlight-color: transparent;
  transition: transform 260ms var(--ease-out), border-color var(--t-base);
}
.ap-stage:active { transform: scale(.985); }
.ap-vs { display: grid; }
.ap-v {
  grid-area: 1 / 1; display: flex; flex-direction: column; min-width: 0; opacity: 0; visibility: hidden; transform: translate3d(0, 10px, 0);
  transition: opacity 240ms ease, transform 380ms var(--ease-out), visibility 0s linear 380ms;
}
.ap-v.is-out { transform: translate3d(0, -8px, 0); }
.ap-v.is-on { opacity: 1; visibility: visible; transform: none; transition: opacity 320ms ease 90ms, transform 520ms var(--ease-spring) 60ms, visibility 0s; }
.ap-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 4px; min-width: 0; }
.ap-head .kicker { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ap-meta { flex: none; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.ap-meta b { color: var(--ink); font-weight: 600; }
.ap-main { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ap-main b { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ap-main span { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* today */
.ap-row { display: grid; grid-template-columns: 40px 3px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 5px 0; }
.ap-row + .ap-row { border-top: 1px solid var(--rule); }
.ap-tm { display: flex; flex-direction: column; line-height: 1.2; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 13px; }
.ap-tm b { font-weight: 600; } .ap-tm span { font-size: 11.5px; color: var(--ink-3); }
.ap-row > i, .ap-lesson > i { align-self: stretch; border-radius: 2px; background: var(--hue); }
/* confirmed lesson: the "Odbyta" seal */
.ap-lesson { position: relative; display: grid; grid-template-columns: 3px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 0; }
.ap-stamp {
  position: absolute; left: 52%; top: 50%; display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px 5px 7px;
  border: 2px solid var(--good-ink); border-radius: 9px; color: var(--good-ink); background: var(--surface);
  font-size: var(--fs-mark); font-weight: 700; letter-spacing: var(--ls-mark); text-transform: uppercase; white-space: nowrap;
  transform: translate(-50%, -50%) rotate(-8deg);
}
.ap-note { margin-top: 4px; padding-top: 6px; border-top: 1px dashed var(--rule-2); font-size: 12.5px; color: var(--ink-2); line-height: 1.35; }
.ap-note b { color: var(--ink); font-weight: 600; }
/* who owes */
.ap-owe { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 5px 0; }
.ap-owe + .ap-owe { border-top: 1px solid var(--rule); }
.ap-remind { margin-top: 6px; font-size: 12.5px; font-weight: 600; color: var(--accent); }
/* week strip */
.ap-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; padding-top: 4px; }
.ap-day { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11.5px; color: var(--ink-3); line-height: 1; }
.ap-bar { display: flex; align-items: flex-end; width: 100%; max-width: 28px; height: 40px; border-radius: 6px; background: var(--paper-2); overflow: hidden; }
.ap-bar i { width: 100%; height: calc(var(--v, 0) * 100%); background: var(--rule-3); transform-origin: bottom; }
.ap-day b { font: 600 12px/1 var(--font-num); color: var(--ink-2); }
.ap-day.is-today .ap-bar i { background: var(--ink); }
.ap-day.is-today > span, .ap-day.is-today b { color: var(--ink); font-weight: 700; }
/* phone dots (tap = next) */
.ap-dots { position: absolute; left: 0; right: 0; bottom: 8px; display: flex; justify-content: center; gap: 6px; }
.ap-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--rule-2); transition: transform var(--t-base) var(--ease-settle), background-color var(--t-base); }
.ap-dots i.is-on { background: var(--ink); transform: scale(1.5); }

/* what plays when a vignette becomes active */
.ap-v.is-on :is(.ap-row, .ap-owe, .ap-note, .ap-remind) { animation: ap-in 440ms var(--ease-out) backwards; animation-delay: calc(140ms + var(--i, 0) * 80ms); }
.ap-v.is-on :is(.ap-note, .ap-remind) { --i: 3; }
@keyframes ap-in { from { opacity: 0; transform: translate3d(0, 8px, 0); } }
.ap-v.is-on .ap-stamp { animation: ap-stamp 480ms var(--ease-stamp) 360ms backwards; }
@keyframes ap-stamp {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-18deg) scale(1.9); }
  60% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(.92); }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(-8deg); }
}
.ap-v.is-on .ap-bar i { animation: grow-y 560ms var(--ease-settle) backwards; animation-delay: calc(160ms + var(--i, 0) * 40ms); }

/* ---- form column ---- */
.auth-panel { display: grid; align-items: start; justify-items: center; padding: 14px var(--gutter) calc(32px + var(--safe-b)); }
.auth-single .auth-panel { padding-top: calc(32px + var(--safe-t)); }
.auth-card { width: 100%; max-width: 440px; display: flex; flex-direction: column; padding: 20px 18px 18px; }   /* outline: components/widget.css */
.auth-card-brand { margin-bottom: 18px; }
.auth-card-brand .brand-mark { width: 48px; height: 48px; border-radius: 14px; font-size: 30px; }
.auth-hero ~ .auth-panel .auth-card-brand { display: none; }   /* phone: the brand row above carries the seal */
.auth-card h1 { font-size: 30px; line-height: 1.1; }
.auth-sub { color: var(--ink-2); margin: 6px 0 18px; }
#auth-form { display: flex; flex-direction: column; }
#auth-form .field { margin-bottom: 16px; }
.auth .field-label { transition: color var(--t-fast); }
.auth .field:focus-within > .field-label { color: var(--accent); }
.auth .input { transition: border-color var(--t-fast), background-color var(--t-fast), box-shadow var(--t-base) var(--ease-out); }
.auth .input:focus { box-shadow: 0 0 0 4px var(--accent-soft); }
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 52px; }
.pw-eye { position: absolute; right: 2px; top: 50%; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--ink-3); transform: translateY(-50%); }
.pw-eye .ico { transition: transform var(--t-fast) var(--ease-out); }
.pw-eye:active .ico { transform: scale(.86); }
.pw-eye .pw-hide, .pw-eye[aria-pressed="true"] .pw-show { display: none; }
.pw-eye[aria-pressed="true"] .pw-hide { display: block; }
.auth .btn-lg { position: relative; overflow: hidden; }
.auth-submit { gap: 10px; }
.auth-go { transition: transform var(--t-base) var(--ease-out); }
.auth .btn.is-busy:disabled { opacity: 1; }
.auth .btn.is-busy::after { content: ""; position: absolute; left: 0; bottom: 0; width: 36%; height: 3px; background: currentColor; opacity: .55; animation: splash-bead 1100ms cubic-bezier(.65, 0, .35, 1) infinite; }
.auth-msg { min-height: 0; font-size: var(--fs-caption); }
.auth-msg:not(:empty) { margin: -6px 0 14px; animation: ap-in 260ms var(--ease-out); }
.auth-msg.err { color: var(--danger); }
.auth-msg.ok { color: var(--good); }
.auth-links { display: flex; justify-content: center; margin-top: 8px; }
.auth-links .link-btn, .auth-switch .link-btn { min-height: 44px; padding: 0 4px; }
.auth-or { display: flex; align-items: center; gap: 12px; color: var(--ink-3); font-size: var(--fs-caption); margin: 8px 0 16px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
/* Official Google "G" (brand guidelines require the full-colour mark on sign-in buttons). */
.g-mark { width: 18px; height: 18px; flex: none; display: inline-flex; }
.g-mark svg { width: 100%; height: 100%; }
.auth-switch { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0 4px; margin-top: 10px; color: var(--ink-2); font-size: var(--fs-caption); text-align: center; }
.auth-switch .link-btn { font-size: var(--fs-caption); }
/* demo: an inviting two-line entry with an arrow that nudges once */
.auth-demo {
  margin-top: 12px; min-height: 64px; justify-content: space-between; gap: 12px; padding: 10px 16px 10px 18px; white-space: normal; text-align: left;
  border-color: var(--ink-3); color: var(--ink); transition: transform var(--t-fast) var(--ease-out), border-color var(--t-base), background-color var(--t-base);
}
.auth-demo-in { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.auth-demo-in b { font-weight: 600; font-size: var(--fs-body); }
.auth-demo-in span { font-size: var(--fs-caption); font-weight: 400; color: var(--ink-2); }
.auth-demo-ico { flex: none; color: var(--accent); transition: transform var(--t-base) var(--ease-out); animation: demo-nudge 1000ms var(--ease-out) 1300ms; }
@keyframes demo-nudge { 30% { transform: translateX(5px); } 55% { transform: none; } 75% { transform: translateX(3px); } }

/* ---- role cards (register, role chooser) ---- */
.role-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.role-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; align-items: center; text-align: left;
  min-height: 64px; padding: 12px 14px; background: var(--paper-2); border: 1px solid var(--widget-border); border-radius: var(--r-group);
  transition: border-color var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out);
}
.role-card .role-ico { grid-row: 1 / span 2; color: var(--ink-2); }
.role-card b { font-weight: 600; }
.role-card > span { font-size: var(--fs-caption); color: var(--ink-2); line-height: 1.35; }
.role-card.active, .role-card[aria-checked="true"] { border-color: var(--accent); background: var(--surface); box-shadow: inset 0 0 0 1px var(--accent); }
.role-card.active .role-ico { color: var(--accent); }
.auth-card > .role-grid { margin-bottom: 14px; }

/* ---- entrance ---- */
.auth.is-entering .ae { animation: ae-in 560ms var(--ease-out) backwards; animation-delay: calc(60ms + var(--ai, 0) * 70ms); }
.auth.is-entering .hw { animation: hw-in 620ms var(--ease-out) backwards; animation-delay: calc(130ms + var(--wi, 0) * 70ms); }
.auth.is-entering .brand-mark { animation: splash-seal 620ms var(--ease-stamp) 40ms backwards; }
.auth.is-entering .auth-card { animation: ae-in 520ms var(--ease-out) 160ms backwards; }
.auth.is-entering .auth-card > * { animation: ae-in 460ms var(--ease-out) backwards; animation-delay: calc(220ms + var(--ci, 0) * 40ms); }
.auth-card > :nth-child(2) { --ci: 1; } .auth-card > :nth-child(3) { --ci: 2; } .auth-card > :nth-child(4) { --ci: 3; }
.auth-card > :nth-child(5) { --ci: 4; } .auth-card > :nth-child(6) { --ci: 5; } .auth-card > :nth-child(7) { --ci: 6; }
.auth-card > :nth-child(8) { --ci: 7; } .auth-card > :nth-child(n+9) { --ci: 8; }
.auth-card.is-swapping { animation: ae-in 340ms var(--ease-out); }
@keyframes ae-in { from { opacity: 0; transform: translate3d(0, 14px, 0); } }
@keyframes hw-in { from { opacity: 0; transform: translate3d(0, .45em, 0) rotate(2deg); } }

@media (hover: hover) and (pointer: fine) {
  .auth-demo-link:hover { background: var(--accent-soft-2); }
  .auth-demo-link:hover .ico, .auth-submit:hover:not(:disabled) .auth-go { transform: translateX(3px); }
  .auth .input:hover:not(:focus) { border-color: var(--ink-3); }
  .pw-eye:hover { color: var(--ink); }
  .auth-demo:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
  .auth-demo:hover:not(:disabled) .auth-demo-ico { transform: translateX(4px); }
  .ap-stage:hover { border-color: var(--widget-border-hover); }
  .role-card:hover { border-color: var(--widget-border-hover); } .role-card.active:hover { border-color: var(--accent); }
}

/* ---- phone ---- */
/* Phone: just the sign-in — brand row and the form; the live preview and the top demo pill are desktop-only
   (the demo entry stays inside the form). wirePreview() does not start the carousel while .ap is hidden. */
@media (max-width: 760px) {
  .auth-hero .ap, .auth-top .auth-demo-link { display: none; }
}
@media (max-width: 380px) {
  .auth-card h1 { font-size: 27px; }
  .auth-card { padding: 18px 14px 16px; }
}

/* ---- desktop: hero beside the form ---- */
@media (min-width: 761px) {
  .auth { grid-template-columns: 1.1fr 1fr; align-content: stretch; }
  .auth-single { grid-template-columns: minmax(0, 1fr); }
  .auth-hero {
    justify-content: center; align-items: center; gap: 24px; max-width: none; margin: 0; padding: 40px clamp(32px, 4vw, 64px);
    background: var(--paper-2); border-right: 1px solid var(--rule);
  }
  .auth-hero > * { width: 100%; max-width: 500px; }
  .auth-brand .brand-name { font-size: 22px; }
  .auth-headline { display: block; font-size: clamp(40px, 3.6vw, 52px); line-height: 1.05; text-wrap: balance; }
  .auth-lead { display: block; color: var(--ink-2); }
  .auth-card-brand { display: block; }
  .auth-hero ~ .auth-panel .auth-card-brand { display: block; }
  /* the preview sits on a small stack of paper; the stack follows the pointer (--px --py), the top sheet tilts (--rx --ry) */
  .ap-scene { perspective: 1100px; margin: 0 22px 22px 0; }
  .ap-sheet {
    display: block; position: absolute; inset: 0; border: 1px solid var(--rule-2); border-radius: var(--widget-radius); background: var(--surface);
    transition: transform 320ms var(--ease-out);
  }
  .ap-sheet-1 { opacity: .85; transform: translate3d(calc(10px - var(--px, 0) * 5px), calc(10px - var(--py, 0) * 5px), 0) rotate(1.4deg); }
  .ap-sheet-2 { opacity: .55; transform: translate3d(calc(20px - var(--px, 0) * 10px), calc(20px - var(--py, 0) * 10px), 0) rotate(2.8deg); }
  .ap-stage { padding: 18px 22px; transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); }
  .ap-stage:active { transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(.985); }
  .ap-dots { display: none; }
  .ap-head { margin-bottom: 8px; }
  .ap-row { grid-template-columns: 48px 3px minmax(0, 1fr) auto; gap: 12px; padding: 9px 0; }
  .ap-tm { font-size: 14px; }
  .ap-main b { font-size: 15.5px; } .ap-main span { font-size: var(--fs-caption); }
  .ap-lesson, .ap-owe { padding: 9px 0; }
  .ap-bar { height: 76px; }
  .ap-foot { display: grid; gap: 10px; }
  .ap-cap { display: grid; margin: 0; }
  .ap-cap > span { grid-area: 1 / 1; color: var(--ink-2); opacity: 0; transform: translate3d(0, 6px, 0); transition: opacity 240ms ease, transform 320ms var(--ease-out); }
  .ap-cap > span.is-on { opacity: 1; transform: none; transition-delay: 120ms; }
  .ap-cap b { display: block; color: var(--ink); font-weight: 600; }
  .ap-tabs { order: -1; display: flex; gap: 2px; margin: -6px 0 0 -12px; }
  .ap-tabs button { position: relative; min-height: 44px; padding: 0 12px; font-weight: 600; font-size: var(--fs-caption); color: var(--ink-3); transition: color var(--t-fast); }
  .ap-tabs button.is-on { color: var(--ink); }
  .ap-tabs i { position: absolute; left: 12px; right: 12px; bottom: 6px; height: 2px; border-radius: 2px; background: var(--rule); overflow: hidden; }
  .ap-tabs i::after { content: ""; position: absolute; inset: 0; background: var(--ink); transform: scaleX(0); transform-origin: left; }
  .ap-tabs .is-on i::after { transform: none; }
  .ap.is-auto .ap-tabs .is-on i::after { animation: ap-progress 4200ms linear both; }
  .ap.is-paused .ap-tabs .is-on i::after { animation-play-state: paused; }
  @keyframes ap-progress { from { transform: scaleX(0); } to { transform: none; } }
  .auth-panel { align-items: center; padding: 60px 48px; }
  .auth-card { padding: 32px 30px 26px; }
  .role-grid { grid-template-columns: 1fr 1fr; }
}
/* tall desktop windows: the hero stays in view while a long form (register) scrolls */
@media (min-width: 761px) and (min-height: 760px) { .auth-hero { position: sticky; top: 0; align-self: start; min-height: 100dvh; } }
@media (min-width: 761px) and (hover: hover) and (pointer: fine) {
  .ap-tabs button:hover { color: var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  .auth *, .auth *::before, .auth *::after { animation: none !important; }
  .auth .ap-stage, .auth .ap-sheet { transform: none !important; }
}
}
