/**
 * Floating Posts Panel - Advance Copy Style with Hover Preview
 * Panel zawsze widoczny jako wąski pasek, rozwijany na kliknięcie
 * Hover na liście postów pokazuje preview w górnej części
 *
 * @package KartelMedia_Floating_Posts
 */

/* ====================================
   Panel Base - ZAWSZE WIDOCZNY
   ==================================== */

.kmfp-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  z-index: 9989;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
    Cantarell, "Helvetica Neue", sans-serif;
  display: flex;
  flex-direction: column;
  will-change: width;
}

/* Closed state - wąski pasek (width z admina) */
.kmfp-panel--closed {
  /* width będzie ustawiona inline z PHP */
}

/* Open state - pełna szerokość (% z admina) */
.kmfp-panel--open {
  /* width będzie ustawiona inline przez PHP */
}

/* Left position support */
.kmfp-panel--left {
  left: 0;
  right: auto;
}

/* ====================================
   Closed Panel Area - KLIKALNY
   ==================================== */

.kmfp-panel__closed-area {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition:
    opacity 0.3s ease,
    background-color 0.3s ease;
}

/* Dla prawego panelu - przyklej do prawej krawędzi */
.kmfp-panel--right .kmfp-panel__closed-area {
  justify-content: flex-start;
  padding-left: 10px;
}

/* Dla lewego panelu - przyklej do lewej krawędzi */
.kmfp-panel--left .kmfp-panel__closed-area {
  justify-content: flex-end;
  padding-right: 10px;
}

.kmfp-panel__closed-area:hover {
  opacity: 0.8;
  background-color: rgba(0, 0, 0, 0.02);
}

/* Hide when panel is open */
.kmfp-panel--open .kmfp-panel__closed-area {
  opacity: 0;
  pointer-events: none;
}

/* LIBRARY text - VERTICAL */
.kmfp-panel__toggle-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

/* ====================================
   Panel Content (pokazuje się gdy otwarty)
   ==================================== */

.kmfp-panel__content {
  opacity: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: opacity 0.4s ease;
  position: relative;
}

.kmfp-panel--open .kmfp-panel__content {
  opacity: 1;
  pointer-events: auto;
  animation: kmfp-content-fade-in 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes kmfp-content-fade-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ====================================
   Close Button - PRAWY GÓRNY RÓG
   ==================================== */

.kmfp-panel__close {
  position: absolute;
  top: 20px;
  right: 60px;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 5px;
  z-index: 10;
  transition: opacity 0.2s;
}

.kmfp-panel__close:hover {
  opacity: 0.6;
}

.kmfp-panel__close svg {
  display: block;
}

/* ====================================
   Header - LIBRARY poziomo
   ==================================== */

.kmfp-panel__header {
  padding: 20px 30px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.kmfp-panel__header-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ====================================
   INDEX Line (kategorie)
   ==================================== */

.kmfp-panel__index {
  padding: 15px 30px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  font-size: 13px;
  line-height: 1.6;
  flex-shrink: 0;
}

.kmfp-panel__index-label {
  font-weight: 600;
  margin-right: 10px;
}

.kmfp-panel__index-content {
  opacity: 0.8;
}

/* ====================================
   Preview Area (górna część ~40%)
   ==================================== */

.kmfp-panel__preview {
  height: 40%;
  min-height: 250px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}

/* Empty state */
.kmfp-panel__preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  opacity: 0.4;
}

.kmfp-panel__preview-empty p {
  margin: 0;
  font-size: 13px;
}

/* Preview content - 2 KOLUMNY */
.kmfp-panel__preview-content {
  padding: 30px;
  height: 100%;
  overflow-y: auto;
  animation: kmfp-fade-in 0.3s ease;
  display: flex;
  gap: 30px;
  align-items: flex-start;
}

@keyframes kmfp-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Lewa kolumna - tekst */
.kmfp-preview__text {
  flex: 1;
  min-width: 0; /* Fix dla flexbox text overflow */
}

/* Prawa kolumna - obrazek */
.kmfp-preview__image-wrapper {
  flex: 0 0 40%;
  max-width: 40%;
}

/* Preview image */
.kmfp-preview__image {
  width: 100%;
  height: auto;
  max-height: 250px;
  object-fit: cover;
  border-radius: 3px;
}

/* Preview title */
.kmfp-preview__title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
  margin: 0 0 15px 0;
}

/* Preview excerpt */
.kmfp-preview__excerpt {
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.8;
  margin: 0 0 20px 0;
}

/* Preview link */
.kmfp-preview__link {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: inherit;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.kmfp-preview__link:hover {
  opacity: 1;
}

/* ====================================
   List Wrapper (dolna część ~60%)
   ==================================== */

.kmfp-panel__list-wrapper {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Smooth fade in dla list wrapper po otwarciu panelu */
.kmfp-panel--open .kmfp-panel__list-wrapper {
  animation: kmfp-list-fade-in 0.6s cubic-bezier(0.4, 0, 0.2, 1) 0.1s both;
}

@keyframes kmfp-list-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Custom scrollbar */
.kmfp-panel__list-wrapper::-webkit-scrollbar {
  width: 8px;
}

.kmfp-panel__list-wrapper::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
}

.kmfp-panel__list-wrapper::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.kmfp-panel__list-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* ====================================
   Posts Table (2 kolumny)
   ==================================== */

.kmfp-posts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.kmfp-posts-table tbody tr {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.kmfp-posts-table tbody tr:last-child {
  border-bottom: none;
}

.kmfp-post-row {
  transition: background-color 0.2s;
  cursor: pointer;
}

.kmfp-post-row:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

/* Active state (gdy pokazuje się preview) */
.kmfp-post-row.kmfp-post-row--active {
  background-color: rgba(0, 0, 0, 0.05);
}

/* Clickable row styling */
.kmfp-post-row--clickable {
  cursor: pointer;
}

.kmfp-post-col--clickable-area {
  cursor: pointer;
}

/* Table Columns */
.kmfp-post-col {
  padding: 15px 12px;
  vertical-align: middle;
}

/* Column 1: Title (90%) */
.kmfp-post-col--title {
  width: 90%;
  padding-left: 30px;
}

.kmfp-post-title {
  font-weight: 500;
  transition: opacity 0.2s;
}

.kmfp-post-row:hover .kmfp-post-title {
  opacity: 0.6;
}

/* Column 2: Icon (10%) */
.kmfp-post-col--icon {
  width: 10%;
  text-align: right;
  padding-right: 30px;
}

.kmfp-icon-link {
  color: inherit;
  opacity: 0.5;
  transition: opacity 0.2s;
  display: inline-flex;
}

.kmfp-icon-link:hover {
  opacity: 1;
}

/* ====================================
   Loading State
   ==================================== */

.kmfp-panel__loading {
  text-align: center;
  padding: 40px 20px;
}

.kmfp-panel__loading td {
  border: none !important;
}

.kmfp-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-left-color: currentColor;
  border-radius: 50%;
  animation: kmfp-spin 1s linear infinite;
  margin: 0 auto 15px;
}

@keyframes kmfp-spin {
  to {
    transform: rotate(360deg);
  }
}

.kmfp-panel__loading p {
  margin: 0;
  color: rgba(0, 0, 0, 0.6);
  font-size: 13px;
}

/* ====================================
   Footer (Load More)
   ==================================== */

.kmfp-panel__footer {
  padding: 20px 30px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.kmfp-panel__load-more {
  width: 100%;
  padding: 12px 20px;
  background-color: rgba(0, 0, 0, 0.8);
  color: #ffffff;
  border: none;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.kmfp-panel__load-more:hover {
  background-color: rgba(0, 0, 0, 1);
}

.kmfp-panel__load-more:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ====================================
   Empty State
   ==================================== */

.kmfp-panel__empty {
  text-align: center;
  padding: 60px 30px;
}

.kmfp-panel__empty p {
  margin: 0;
  color: rgba(0, 0, 0, 0.6);
  font-size: 13px;
}

/* ====================================
   Full-width Post Content Overlay
   ==================================== */

.kmfp-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh; /* Will be overridden by JS for px units */
  z-index: 99999;
  display: none;
}

/* Backdrop */
.kmfp-overlay__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  animation: kmfp-overlay-fade-in 0.3s ease;
}

@keyframes kmfp-overlay-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Content wrapper */
.kmfp-overlay__content {
  position: relative;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  will-change: transform;
  /* Final position will be set via JavaScript for px units */
}

/* Overlay animation - slide from RIGHT (default) */
.kmfp-overlay--right .kmfp-overlay__content {
  animation: kmfp-overlay-slide-in-right 0.5s cubic-bezier(0.4, 0, 0.2, 1)
    forwards;
}

@keyframes kmfp-overlay-slide-in-right {
  from {
    transform: translateX(100%);
  }
  /* 'to' will be overridden by inline style for px units */
}

/* Overlay animation - slide from LEFT */
.kmfp-overlay--left .kmfp-overlay__content {
  animation: kmfp-overlay-slide-in-left 0.5s cubic-bezier(0.4, 0, 0.2, 1)
    forwards;
}

@keyframes kmfp-overlay-slide-in-left {
  from {
    transform: translateX(-100%);
  }
  /* 'to' will be overridden by inline style for px units */
}

/* Close button */
.kmfp-overlay__close {
  position: sticky;
  top: 30px;
  left: 95%;
  background: rgba(255, 255, 255, 0.95);
  border: none;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  cursor: pointer;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.kmfp-overlay__close:hover {
  background: rgba(255, 255, 255, 1);
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.kmfp-overlay__close svg {
  color: #333;
}

/* Loading state */
.kmfp-overlay__loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #ffffff;
  z-index: 100001;
  background: rgba(0, 0, 0, 0.7);
  padding: 40px 60px;
  border-radius: 8px;
}

.kmfp-overlay__loading .kmfp-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-left-color: #ffffff;
  margin: 0 auto 20px;
}

.kmfp-overlay__loading p {
  font-size: 16px;
  margin: 0;
  color: #ffffff;
  font-weight: 500;
}

/* Post content container */
.kmfp-overlay__post-content {
  width: 100%;
  min-height: 100vh;
  padding: 80px 0%;
  margin-right: 2%;
  background: #ffffff;
  animation: kmfp-content-fade-in 0.4s ease 0.2s both;
}

@keyframes kmfp-content-fade-in {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Article wrapper - for theme compatibility */
.kmfp-overlay-article {
  width: 100%;
}

/* Header - simple styling for title */
.kmfp-overlay-header {
  width: 100%;
  padding: 0 40px 30px 40px;
  margin-bottom: 30px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.kmfp-overlay-title,
.kmfp-overlay-header .entry-title {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0;
  padding: 0;
  color: #1a1a1a;
}

/* Body content - let theme styles handle this */
.kmfp-overlay-body {
  width: 93%;
  padding: 0 40px;
}

/* CRITICAL: Force gallery grid layout to work inside overlay */
.kmfp-overlay-body .blocks-gallery-grid:not(.has-nested-images),
.kmfp-overlay-body .wp-block-gallery:not(.has-nested-images) {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: flex-start !important;
}

.kmfp-overlay-body .blocks-gallery-item,
.kmfp-overlay-body .wp-block-gallery .blocks-gallery-item {
  margin: 0 1em 1em 0 !important;
  display: flex !important;
  flex-direction: column !important;
}

/* Column-specific widths for galleries */
.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-2
  > .wp-block-image,
.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-2
  > .wp-block-gallery-item {
  width: calc(50% - 1em) !important;
}

.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-3
  > .wp-block-image,
.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-3
  > .wp-block-gallery-item {
  width: calc(33.33333% - 0.83333em) !important;
}

.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-4
  > .wp-block-image,
.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-4
  > .wp-block-gallery-item {
  width: calc(25% - 0.9375em) !important;
}

.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-5
  > .wp-block-image,
.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-5
  > .wp-block-gallery-item {
  width: calc(20% - 0.95em) !important;
}

.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-6
  > .wp-block-image,
.kmfp-overlay-body
  .wp-block-gallery.has-nested-images.columns-6
  > .wp-block-gallery-item {
  width: calc(16.66667% - 0.96667em) !important;
}

/* Default 2-column layout for galleries without explicit columns */
@media (min-width: 600px) {
  .kmfp-overlay-body
    .blocks-gallery-grid:not(.has-nested-images)
    .blocks-gallery-item,
  .kmfp-overlay-body
    .wp-block-gallery:not(.has-nested-images)
    .blocks-gallery-item {
    width: calc(50% - 1em) !important;
  }

  .kmfp-overlay-body
    .blocks-gallery-grid:not(.has-nested-images)
    .blocks-gallery-item:nth-of-type(2n),
  .kmfp-overlay-body
    .wp-block-gallery:not(.has-nested-images)
    .blocks-gallery-item:nth-of-type(2n) {
    margin-right: 0 !important;
  }
}

/* Error state */
.kmfp-overlay__error {
  text-align: center;
  padding: 60px 20px;
  color: #ffffff;
}

.kmfp-overlay__error p {
  font-size: 18px;
  margin: 0;
}

/* Body class when overlay is open */
body.kmfp-overlay-open {
  overflow: hidden;
}

/* Responsive - Overlay */
@media (max-width: 768px) {
  .kmfp-overlay__close {
    top: 15px;
    left: 85%;
    width: 40px;
    height: 40px;
  }

  .kmfp-overlay__post-content {
    padding: 60px 0%;
    margin-right: 2%;
  }

  .kmfp-overlay-header {
    padding: 0 20px 20px 20px;
  }

  .kmfp-overlay-title,
  .kmfp-overlay-header .entry-title {
    font-size: 28px;
  }

  .kmfp-overlay-body {
    padding: 0 20px;
  }
}

/* ====================================
   Responsive - Mobile (Bottom Panel)
   ==================================== */

@media (max-width: 768px) {
  .kmfp-panel {
    top: auto;
    bottom: 60px;
    left: 0 !important;
    right: 0 !important;
    max-height: 80vh;
    width: 100% !important;
    /* Smooth slide animation dla mobile */
    transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: height;
  }

  /* Closed - pokazuje tylko małą belkę */
  .kmfp-panel--closed {
    height: 60px;
    width: 100% !important;
  }

  /* Open - slide up effect (panel wyjeżdża w górę) */
  .kmfp-panel--open {
    height: 70vh;
  }

  /* Content animation - fade in przy otwieraniu */
  .kmfp-panel--open .kmfp-panel__content {
    animation: kmfp-mobile-slide-in 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  }

  @keyframes kmfp-mobile-slide-in {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Mobile pixels mode - panel slides from bottom with custom top position */
  .kmfp-panel--mobile-pixels {
    /* top and height are set by JavaScript */
    bottom: 0 !important;
    max-height: none !important;
    transition:
      transform 0.5s cubic-bezier(0.4, 0, 0.2, 1),
      opacity 0.5s ease;
  }

  /* Closed state for mobile pixels mode */
  .kmfp-panel--mobile-pixels.kmfp-panel--closed {
    transform: translateY(100%);
    opacity: 0;
  }

  /* Open state for mobile pixels mode - slide up from bottom */
  .kmfp-panel--mobile-pixels.kmfp-panel--open {
    transform: translateY(0);
    opacity: 1;
  }

  /* Toggle na dole ekranu (poziomo) */
  .kmfp-panel__toggle-text {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
  }

  /* Hide preview on mobile */
  .kmfp-panel__preview {
    display: none;
  }

  /* Close button */
  .kmfp-panel__close {
    top: 15px;
    right: 20px;
  }

  .kmfp-panel__header,
  .kmfp-panel__index,
  .kmfp-panel__footer {
    padding: 15px 20px;
  }

  .kmfp-panel__header-title {
    font-size: 12px;
  }

  .kmfp-panel__index {
    font-size: 11px;
  }

  /* Table adjustments */
  .kmfp-posts-table {
    font-size: 11px;
  }

  .kmfp-post-col {
    padding: 12px 8px;
  }

  .kmfp-post-col--title {
    padding-left: 15px;
  }

  .kmfp-post-col--icon {
    padding-right: 15px;
  }

  /* Preview na mobile - jedna kolumna jeśli by był widoczny */
  .kmfp-panel__preview-content {
    flex-direction: column;
    gap: 20px;
  }

  .kmfp-preview__image-wrapper {
    flex: 0 0 auto;
    max-width: 100%;
  }
}

/* ====================================
   Smooth Transition między Desktop a Mobile
   ==================================== */

/* Dla ekranów pomiędzy 768px-800px dodajemy smooth scaling */
@media (min-width: 768px) and (max-width: 800px) {
  .kmfp-panel {
    /* Dodatkowy transition dla smooth resize */
    transition:
      width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
      height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
      top 0.4s cubic-bezier(0.4, 0, 0.2, 1),
      bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1),
      left 0.4s cubic-bezier(0.4, 0, 0.2, 1),
      right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  }
}

/* ====================================
   Accessibility
   ==================================== */

.kmfp-panel__closed-area:focus,
.kmfp-panel__close:focus,
.kmfp-panel__load-more:focus,
.kmfp-icon-link:focus {
  outline: 2px solid rgba(0, 0, 0, 0.5);
  outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .kmfp-panel,
  .kmfp-panel__content,
  .kmfp-panel__closed-area,
  .kmfp-post-row,
  .kmfp-panel__load-more,
  .kmfp-panel__preview-content,
  .kmfp-panel__list-wrapper {
    transition: none !important;
    animation: none !important;
  }

  .kmfp-spinner {
    animation: none !important;
  }

  /* Nadal pokazuj content, ale bez animacji */
  .kmfp-panel--open .kmfp-panel__content,
  .kmfp-panel--open .kmfp-panel__list-wrapper {
    opacity: 1;
    transform: none;
  }
}

/* ====================================
   Print Styles
   ==================================== */

@media print {
  .kmfp-panel {
    display: none !important;
  }
}
