/* ==========================================================================
   Cookie Consent — cemodan.md
   Modern, GDPR-compliant cookie consent banner & settings modal.
   Standalone, no dependencies. Integrates with oct_deals theme variables.
   v5 — Equal visual weight filled buttons (Law 195/2024 Art.7 compliance)
   ========================================================================== */

/* --- CSS Custom Properties --- */
:root {
  --cc-bg: rgba(255, 255, 255, 0.97);
  --cc-text: #1a1a1a;
  --cc-text-secondary: #5a5a5a;
  --cc-border: #e8e8e8;
  --cc-primary: var(--ds-interactive-color, #2381e9);
  --cc-primary-hover: var(--ds-interactive-hover-color, #1a6fd4);
  --cc-primary-text: #fff;
  --cc-toggle-off: #c4c4c4;
  --cc-toggle-on: var(--cc-primary);
  --cc-overlay-bg: rgba(0, 0, 0, 0.45);
  --cc-radius: 16px;
  --cc-radius-sm: 10px;
  --cc-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
  --cc-modal-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  --cc-backdrop: blur(16px);
  --cc-z-backdrop: 19999;
  --cc-z-banner: 20000;
  --cc-z-overlay: 20001;
  --cc-transition: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  --cc-cookie-list-bg: #f5f5f5;
}

.dark-theme {
  --cc-bg: rgba(28, 28, 32, 0.97);
  --cc-text: #e8e8e8;
  --cc-text-secondary: #a0a0a0;
  --cc-border: #3a3a3e;
  --cc-toggle-off: #555;
  --cc-overlay-bg: rgba(0, 0, 0, 0.6);
  --cc-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
  --cc-modal-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  --cc-cookie-list-bg: #2a2a2e;
}

/* ==========================================================================
   BANNER — full-width bottom bar
   ========================================================================== */

.cc-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--cc-z-banner);
  pointer-events: none;
  transform: translateY(100%);
  opacity: 0;
  transition: transform var(--cc-transition), opacity 0.3s ease;
}

.cc-banner.cc-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Hide banner when site modal is open (cart, login, etc.)
   Prevents banner from blocking checkout button — avoids cookie wall. */
body.modal-open .cc-banner {
  display: none;
}

.cc-banner-inner {
  background: var(--cc-bg);
  border-top: 1px solid var(--cc-border);
  box-shadow: var(--cc-shadow);
  backdrop-filter: var(--cc-backdrop);
  -webkit-backdrop-filter: var(--cc-backdrop);
  padding: 24px 40px;
}

.cc-banner-content-wrap {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
}

.cc-banner-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--cc-text-secondary);
}

.cc-banner-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* ==========================================================================
   LINK
   ========================================================================== */

.cc-link {
  color: var(--cc-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.2s;
}

.cc-link:hover {
  color: var(--cc-primary-hover);
  text-decoration: none;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.cc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.4;
  min-height: 40px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cc-btn:active {
  transform: scale(0.97);
}

.cc-btn:focus-visible {
  outline: 2px solid var(--cc-primary);
  outline-offset: 2px;
}

/* Primary & Secondary — equal visual weight for GDPR/Law 195/2024 compliance.
   Both buttons use site brand color (#2381e9) — cannot be accused of psychological tricks.
   Conversion is driven by position (Accept first on mobile via order: -1). */
.cc-btn-primary,
.cc-btn-secondary {
  background: #2381e9;
  color: #fff;
  border: 2px solid transparent;
}

.cc-btn-primary:hover,
.cc-btn-secondary:hover {
  background: #fff;
  color: #2381e9;
  border: 2px solid #2381e9;
}

/* Text link button ("Customize") — always visible */
.cc-btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--cc-text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.cc-btn-link:hover {
  color: var(--cc-primary);
}

.cc-btn-link:focus-visible {
  outline: 2px solid var(--cc-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   MODAL OVERLAY
   ========================================================================== */

.cc-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--cc-z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--cc-overlay-bg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  overscroll-behavior: contain;
  overflow: hidden;
  max-width: 100%;
}

.cc-overlay.cc-visible {
  opacity: 1;
  visibility: visible;
}

/* ==========================================================================
   MODAL
   ========================================================================== */

.cc-modal {
  width: 100%;
  max-width: 500px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  background: var(--cc-bg);
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius);
  box-shadow: var(--cc-modal-shadow);
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.cc-overlay.cc-visible .cc-modal {
  transform: scale(1) translateY(0);
}

/* --- Modal Header --- */

.cc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--cc-border);
  flex-shrink: 0;
}

.cc-modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--cc-text);
}

.cc-modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--cc-text-secondary);
  font-size: 20px;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
  padding: 0;
  flex-shrink: 0;
}

.cc-modal-close:hover {
  background: var(--cc-cookie-list-bg);
  color: var(--cc-text);
}

.cc-modal-close:focus-visible {
  outline: 2px solid var(--cc-primary);
  outline-offset: 2px;
}

/* --- Modal Body --- */

.cc-modal-body {
  overflow-y: auto;
  padding: 8px 24px;
  flex: 1;
  overscroll-behavior: contain;
}

/* --- Controller info --- */

.cc-controller {
  padding: 12px 0;
  border-bottom: 1px solid var(--cc-border);
  font-size: 12px;
  color: var(--cc-text-secondary);
}

/* --- Category --- */

.cc-category {
  padding: 14px 0;
  border-bottom: 1px solid var(--cc-border);
}

.cc-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cc-category-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.cc-category-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--cc-text);
}

.cc-category-desc {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--cc-text-secondary);
}

.cc-category-opt-out {
  margin: 4px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--cc-primary);
  font-style: italic;
}

.cc-category-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--cc-text-secondary);
}

.cc-cookie-list {
  margin-top: 6px;
  padding: 4px 8px;
  background: var(--cc-cookie-list-bg);
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  color: var(--cc-text-secondary);
  word-break: break-all;
}

/* --- Rights section (Art.13(2)) --- */

.cc-rights {
  padding: 14px 0 4px;
}

.cc-rights-title {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--cc-text);
}

.cc-rights-text {
  margin: 0 0 4px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--cc-text-secondary);
}

.cc-rights .cc-link {
  font-size: 11px;
}

/* --- Badge "Always active" --- */

.cc-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  white-space: nowrap;
}

.cc-badge-always {
  background: rgba(35, 129, 233, 0.1);
  color: var(--cc-primary);
}

.dark-theme .cc-badge-always {
  background: rgba(35, 129, 233, 0.2);
}

/* ==========================================================================
   TOGGLE SWITCH
   ========================================================================== */

.cc-toggle {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}

.cc-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.cc-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--cc-toggle-off);
  border-radius: 12px;
  transition: background 0.25s ease;
}

.cc-toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.cc-toggle input:checked + .cc-toggle-slider {
  background: var(--cc-toggle-on);
}

.cc-toggle input:checked + .cc-toggle-slider::before {
  transform: translateX(20px);
}

.cc-toggle input:focus-visible + .cc-toggle-slider {
  outline: 2px solid var(--cc-primary);
  outline-offset: 2px;
}

.cc-toggle input:disabled + .cc-toggle-slider {
  opacity: 0.5;
  cursor: not-allowed;
}

.cc-toggle input:disabled ~ * {
  cursor: not-allowed;
}

/* --- Modal Footer --- */

.cc-modal-footer {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--cc-border);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.cc-modal-footer .cc-btn {
  flex: 1;
}

/* ==========================================================================
   FOOTER LINK
   ========================================================================== */

.cc-footer-link {
  cursor: pointer;
}

/* ==========================================================================
   RESPONSIVE — Tablet (541-768px)
   ========================================================================== */

@media (max-width: 768px) {
  .cc-banner-inner {
    padding: 14px 16px;
  }

  .cc-banner-content-wrap {
    gap: 14px;
  }

  .cc-btn {
    min-height: 44px;
  }
}

/* ==========================================================================
   RESPONSIVE — Mobile (<540px) — Bottom Sheet
   ========================================================================== */

@media (max-width: 540px) {
  .cc-banner-inner {
    border-top: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
    padding: 12px 16px 16px;
  }

  .cc-banner-content-wrap {
    flex-direction: column;
    align-items: stretch;
    gap: 20px;
  }

  .cc-banner-text {
    text-align: left;
  }

  .cc-banner-actions {
    flex-direction: column;
    gap: 0;
  }

  /* Mobile order & spacing: Accept → 12px → Reject → 8px → Settings */
  .cc-banner-actions .cc-btn-primary {
    order: -2;
  }

  .cc-banner-actions .cc-btn-secondary {
    order: -1;
    margin-top: 12px;
  }

  .cc-banner-actions .cc-btn-link {
    order: 1;
    margin-top: 6px;
  }

  .cc-btn {
    width: 100%;
    min-height: 44px;
    font-size: 15px;
    padding: 10px 20px;
  }

  /* Settings text link — full width on mobile */
  .cc-btn-link {
    width: 100%;
  }

  /* Modal as bottom sheet */
  .cc-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .cc-modal {
    border-radius: var(--cc-radius) var(--cc-radius) 0 0;
    max-height: 90vh;
    max-height: 90dvh;
    border: none;
    border-top: 1px solid var(--cc-border);
  }

  .cc-modal-header {
    padding: 16px 16px 12px;
  }

  .cc-modal-body {
    padding: 4px 16px;
  }

  .cc-modal-footer {
    padding: 12px 16px 16px;
    flex-direction: column;
    gap: 8px;
  }

  .cc-modal-footer .cc-btn {
    min-height: 48px;
    font-size: 15px;
    width: 100%;
  }
}

/* ==========================================================================
   ACCESSIBILITY — Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .cc-banner,
  .cc-overlay,
  .cc-modal,
  .cc-toggle-slider,
  .cc-toggle-slider::before,
  .cc-btn {
    transition-duration: 0.01ms !important;
  }
}
