/* Mitoto - cookie consent. Layout w CSS; JS tylko stan + treść. */

.cookie-consent,
#mitoto-cookie-consent {
  position: fixed !important;
  z-index: 9410;
  left: 12px !important;
  right: auto !important;
  top: auto !important;
  bottom: max(12px, env(safe-area-inset-bottom, 0px)) !important;
  width: 56px;
  height: 56px;
  margin: 0;
  padding: 0;
  font-family: var(--font-family, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
  pointer-events: none;
  transform: none !important;
}

.cookie-consent__fab {
  pointer-events: auto;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2f59ed;
  color: #fff;
  box-shadow: 0 10px 28px rgba(47, 89, 237, 0.42);
  transition: background 0.15s ease;
}

.cookie-consent.is-open .cookie-consent__fab {
  display: none;
}

.cookie-consent__fab:hover {
  background: #2548d4;
}

.cookie-consent__fab:focus-visible {
  outline: 3px solid rgba(47, 89, 237, 0.35);
  outline-offset: 2px;
}

.cookie-consent__fab-icon {
  width: 28px;
  height: 28px;
  display: block;
}

.cookie-consent__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100040;
  background: rgba(29, 29, 31, 0.28);
}

.cookie-consent__backdrop.is-open {
  display: block;
}

.cookie-consent__panel {
  position: fixed;
  z-index: 100050;
  display: none;
  flex-direction: column;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 24px));
  max-height: min(640px, calc(100dvh - 24px), calc(100vh - 24px));
  background: #fff;
  border-radius: var(--radius-lg, 18px);
  border: 1px solid var(--border-color, #e5e5ea);
  box-shadow: var(--shadow-lg, 0 12px 40px rgba(0, 0, 0, 0.12));
  box-sizing: border-box;
  overflow: hidden;
  font-family: var(--font-family, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
}

.cookie-consent__panel.is-open {
  display: flex;
}

.cookie-consent__panel.is-open.is-docked {
  left: 12px;
  top: auto;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  transform: none;
  width: 380px;
  height: min(560px, calc(100dvh - 24px), calc(100vh - 24px));
  max-height: none;
}

.cookie-consent__panel.is-open.is-mobile-full {
  inset: 0;
  transform: none;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

.cookie-consent__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #636366);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.cookie-consent__close:hover {
  color: var(--text-primary, #1d1d1f);
  background: var(--bg-secondary, #f5f5f7);
}

.cookie-consent__close[hidden] {
  display: none !important;
}

.cookie-consent__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 22px 22px calc(18px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  box-sizing: border-box;
}

.cookie-consent__panel.is-mobile-full .cookie-consent__body {
  padding: calc(28px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
}

.cookie-consent__title {
  margin: 0 36px 10px 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text-primary, #1d1d1f);
}

.cookie-consent__panel.is-docked .cookie-consent__title {
  font-size: 1.05rem;
}

.cookie-consent__text {
  margin: 0 0 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text-secondary, #636366);
}

.cookie-consent__text a {
  color: var(--accent-blue, #0066cc);
  font-weight: 600;
  text-decoration: none;
}

.cookie-consent__text a:hover {
  text-decoration: underline;
}

.cookie-consent__cats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 14px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.cookie-consent__cat {
  border: 1px solid var(--border-color, #e5e5ea);
  border-radius: 12px;
  background: transparent;
  padding: 12px 14px;
}

.cookie-consent__cat.is-compact {
  padding: 10px 12px;
}

.cookie-consent__cat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.cookie-consent__cat-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary, #1d1d1f);
}

.cookie-consent__cat.is-compact .cookie-consent__cat-title {
  font-size: 0.86rem;
}

.cookie-consent__always {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 650;
  color: #1b6e34;
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
  white-space: nowrap;
}

.cookie-consent__cat-desc {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-secondary, #636366);
}

.cookie-consent__cat.is-compact .cookie-consent__cat-desc {
  font-size: 0.74rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cookie-consent__switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.cookie-consent__switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.cookie-consent__switch-ui {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #d2d2d7;
  position: relative;
  transition: background 0.15s ease;
}

.cookie-consent__switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease;
}

.cookie-consent__switch input:checked + .cookie-consent__switch-ui {
  background: var(--accent-blue, #0066cc);
}

.cookie-consent__switch input:checked + .cookie-consent__switch-ui::after {
  transform: translateX(18px);
}

.cookie-consent__switch input:focus-visible + .cookie-consent__switch-ui {
  outline: 3px solid rgba(0, 102, 204, 0.25);
  outline-offset: 2px;
}

.cookie-consent__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  flex-shrink: 0;
}

.cookie-consent__btn {
  width: 100%;
  min-height: 40px;
  border-radius: var(--radius-sm, 12px);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 650;
  cursor: pointer;
  padding: 9px 12px;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.cookie-consent__btn--primary {
  background: var(--accent-blue, #0066cc);
  color: #fff;
  border-color: var(--accent-blue, #0066cc);
  order: -1;
}

.cookie-consent__btn--primary:hover {
  background: var(--accent-blue-hover, #0055b3);
}

.cookie-consent__btn--ghost {
  background: #fff;
  color: var(--text-primary, #1d1d1f);
  border-color: var(--border-color, #e5e5ea);
}

.cookie-consent__btn--ghost:hover {
  background: var(--bg-secondary, #f5f5f7);
}

@media (min-width: 520px) {
  .cookie-consent__panel.is-welcome .cookie-consent__actions--prefs {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .cookie-consent__panel.is-welcome .cookie-consent__actions--prefs .cookie-consent__btn {
    flex: 1 1 calc(33.33% - 6px);
    width: auto;
    order: 0;
  }

  .cookie-consent__panel.is-welcome .cookie-consent__btn--primary {
    order: 0;
  }
}

/* Desktop: początkowy panel zgody - szerszy prostokąt, niższe kafelki (1 kolumna), całość +10% */
@media (min-width: 768px) {
  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) {
    width: min(720px, calc(100vw - 48px));
    max-height: min(560px, calc(100dvh - 40px), calc(100vh - 40px));
    transform: translate(-50%, -50%) scale(1.1);
    transform-origin: center center;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__body {
    padding: 16px 20px 14px;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__title {
    margin: 0 32px 6px 0;
    font-size: 1.1rem;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__text {
    margin: 0 0 10px;
    font-size: 0.84rem;
    line-height: 1.4;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__cats {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 10px;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__cat {
    padding: 8px 12px;
    border-radius: 10px;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__cat-head {
    margin-bottom: 2px;
    gap: 8px;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__cat-title {
    font-size: 0.84rem;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__cat-desc {
    font-size: 0.72rem;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .cookie-consent__panel.is-open.is-welcome:not(.is-mobile-full) .cookie-consent__btn {
    min-height: 38px;
    font-size: 0.84rem;
    padding: 8px 12px;
  }
}

/*
 * NIE ustawiaj overflow:hidden ani height:100% na html/body —
 * na iOS/WebKit fixed panel cookies znika po 1–2 s (pasek URL).
 * Backdrop + mustDecide blokują interakcję; scroll za overlay OK.
 */
html.cookie-consent-lock,
html.cookie-must-decide {
  overscroll-behavior: none;
}
html.cookie-consent-lock body,
html.cookie-must-decide body {
  overscroll-behavior: none;
}

/* iOS: body overflow-x psuje fixed FAB (skacze przy scrollu) — tylko html */
html.is-phone,
html.is-touch {
  overflow-x: hidden;
}
html.is-phone body,
html.is-touch body {
  overflow-x: visible !important;
  position: static !important;
}

/* Inne panele chowają cookies tylko gdy decyzja już jest */
body.ai-search-open:not(.cookie-must-decide) #mitoto-cookie-consent,
body.ai-search-open:not(.cookie-must-decide) #mitoto-cookie-panel,
body.ai-search-open:not(.cookie-must-decide) #mitoto-cookie-backdrop,
body.help-chat-panel-open:not(.cookie-must-decide) #mitoto-cookie-consent,
body.help-chat-panel-open:not(.cookie-must-decide) #mitoto-cookie-panel,
body.help-chat-panel-open:not(.cookie-must-decide) #mitoto-cookie-backdrop {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

/* Pierwsza zgoda zawsze nad wszystkim — przebija też [hidden] */
html.cookie-must-decide #mitoto-cookie-panel.is-open,
body.cookie-must-decide #mitoto-cookie-panel.is-open,
html.cookie-must-decide #mitoto-cookie-panel.is-open[hidden],
body.cookie-must-decide #mitoto-cookie-panel.is-open[hidden] {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  display: flex !important;
  z-index: 100050 !important;
}

html.cookie-must-decide #mitoto-cookie-backdrop.is-open,
body.cookie-must-decide #mitoto-cookie-backdrop.is-open {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  display: block !important;
  z-index: 100040 !important;
}
