/* ═══════════════════════════════════════════════════════════════════════
   BILBO GLANS · Cookie Consent Banner · FAANG Design Standards
   Apple-Inspired · Brand Identity · WCAG 2.1 AA · RTL Support

   Design System v2 Tokens:
   --b-blue:       #0057FF   Primary brand
   --b-blue-dark:  #0041CC   Hover/active
   --b-blue-deep:  #002B99   Pressed
   --b-blue-light: #4D8BFF   Soft accents
   --b-blue-pale:  #EEF4FF   Background tint
   --b-cyan:       #00D4FF   Accent
   --b-ink:        #080E2D   Primary text
   --b-ink-2:      #1A2255   Secondary text
   --b-ink-soft:   #4B5A8A   Muted text
   --b-ink-muted:  #8898BB   Placeholder text
   --b-bg:         #F7F9FF   Page background
   --b-white:      #FFFFFF   Surface
   --b-glass:      rgba(255,255,255,0.72)  Glass bg
   --b-glass-b:    rgba(0,87,255,0.10)     Glass border
   --b-line:       rgba(0,60,200,0.08)     Subtle border
   --b-line-s:     rgba(0,60,200,0.14)     Strong border

   Typography:
   --b-display:    'Sora', 'Inter', sans-serif      Headings EN
   --b-body:       'Inter', system-ui, sans-serif    Body EN
   --b-display-ar: 'IBM Plex Sans Arabic', 'Inter'  Headings AR
   --b-body-ar:    'IBM Plex Sans Arabic', 'Inter'  Body AR

   Accessibility: 4.5:1 min contrast ratio
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Container ──────────────────────────────────────────────────── */
#bilbo-cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999999;
  font-family: var(--b-body, 'Inter', system-ui, sans-serif);
  font-size: 14px;
  line-height: 1.6;
  color: var(--b-ink, #080E2D);
  display: none;
  padding: 0 16px 20px;
  pointer-events: none;
}

#bilbo-cookie-banner.visible {
  display: block;
}

/* ── Inner Card (Glassmorphism + Apple-inspired) ────────────────── */
#bilbo-cookie-banner-inner {
  max-width: 768px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(0, 60, 200, 0.08),
    0 8px 32px rgba(0, 40, 120, 0.12),
    0 24px 60px rgba(0, 20, 60, 0.08);
  padding: 24px 28px;
  pointer-events: auto;
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  transform: translateY(0);
  opacity: 1;
}

/* ── Enter animation ────────────────────────────────────────────── */
#bilbo-cookie-banner.visible #bilbo-cookie-banner-inner {
  animation: cookie-slide-up 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes cookie-slide-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ── Typography ─────────────────────────────────────────────────── */
.bilbo-cookie-header {
  margin-bottom: 4px;
}

.bilbo-cookie-header h3 {
  margin: 0 0 10px;
  font-family: var(--b-display, 'Sora', 'Inter', sans-serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--b-ink, #080E2D);
}

.bilbo-cookie-header p {
  margin: 0 0 4px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--b-ink-soft, #4B5A8A);
}

.bilbo-cookie-header a {
  color: var(--b-blue, #0057FF);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.bilbo-cookie-header a:hover {
  color: var(--b-blue-dark, #0041CC);
  text-decoration: underline;
}

.bilbo-cookie-header a:focus-visible {
  outline: 2px solid var(--b-blue, #0057FF);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Action Buttons (Apple-inspired) ────────────────────────────── */
.bilbo-cookie-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.bilbo-cookie-customize-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

.bilbo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-family: var(--b-body, 'Inter', system-ui, sans-serif);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  white-space: nowrap;
}

/* Primary — Solid brand fill */
.bilbo-btn-primary {
  background: var(--b-blue, #0057FF);
  color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 87, 255, 0.3);
}

.bilbo-btn-primary:hover {
  background: var(--b-blue-dark, #0041CC);
  box-shadow: 0 4px 12px rgba(0, 87, 255, 0.35);
  transform: translateY(-1px);
}

.bilbo-btn-primary:active {
  background: var(--b-blue-deep, #002B99);
  box-shadow: 0 1px 3px rgba(0, 87, 255, 0.2);
  transform: translateY(0);
}

.bilbo-btn-primary:focus-visible {
  outline: 3px solid var(--b-blue-light, #4D8BFF);
  outline-offset: 2px;
}

.bilbo-btn-primary:disabled {
  background: var(--b-ink-muted, #8898BB);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

/* Secondary — Light surface */
.bilbo-btn-secondary {
  background: var(--b-blue-pale, #EEF4FF);
  color: var(--b-blue, #0057FF);
}

.bilbo-btn-secondary:hover {
  background: #D6E4FF;
  transform: translateY(-1px);
}

.bilbo-btn-secondary:active {
  background: #C0D4FF;
  transform: translateY(0);
}

.bilbo-btn-secondary:focus-visible {
  outline: 3px solid var(--b-blue-light, #4D8BFF);
  outline-offset: 2px;
}

/* Text — Ghost style */
.bilbo-btn-text {
  background: transparent;
  color: var(--b-ink-soft, #4B5A8A);
  font-weight: 500;
  padding: 12px 16px;
}

.bilbo-btn-text:hover {
  color: var(--b-blue, #0057FF);
  background: rgba(0, 87, 255, 0.06);
}

.bilbo-btn-text:active {
  background: rgba(0, 87, 255, 0.12);
}

.bilbo-btn-text:focus-visible {
  outline: 3px solid var(--b-blue-light, #4D8BFF);
  outline-offset: 2px;
}

/* ── Preference Categories (Apple Settings-style) ───────────────── */
.bilbo-cookie-categories {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--b-line, rgba(0,60,200,0.08));
  background: var(--b-bg, #F7F9FF);
}

.bilbo-cookie-category {
  padding: 16px 18px;
  background: var(--b-white, #FFFFFF);
  border-bottom: 1px solid var(--b-line, rgba(0,60,200,0.08));
  transition: background 0.15s ease;
}

.bilbo-cookie-category:last-child {
  border-bottom: none;
}

.bilbo-cookie-category:hover {
  background: #FAFBFF;
}

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

.bilbo-cookie-category-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.bilbo-cookie-category-label strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--b-ink, #080E2D);
  font-family: var(--b-body, 'Inter', system-ui, sans-serif);
}

.bilbo-cookie-desc {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--b-ink-muted, #8898BB);
  max-width: 480px;
}

/* ── Badge ──────────────────────────────────────────────────────── */
.bilbo-cookie-badge {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.bilbo-badge-always {
  background: var(--b-blue-pale, #EEF4FF);
  color: var(--b-blue, #0057FF);
}

/* ── iOS-style Toggle ────────────────────────────────────────────── */
.bilbo-toggle {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
  cursor: pointer;
}

.bilbo-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.bilbo-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #E0E0E0;
  border-radius: 31px;
  transition: background 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.bilbo-toggle-slider::before {
  content: '';
  position: absolute;
  height: 27px;
  width: 27px;
  left: 2px;
  bottom: 2px;
  background: #FFFFFF;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.3s ease;
}

.bilbo-toggle input:checked + .bilbo-toggle-slider {
  background: var(--b-blue, #0057FF);
}

.bilbo-toggle input:checked + .bilbo-toggle-slider::before {
  transform: translateX(20px);
  box-shadow: 0 2px 8px rgba(0, 87, 255, 0.3);
}

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

.bilbo-toggle input:focus-visible + .bilbo-toggle-slider {
  box-shadow: 0 0 0 3px var(--b-blue-light, #4D8BFF);
}

/* ── Hover state on desktop ──────────────────────────────────────── */
@media (hover: hover) {
  .bilbo-toggle:hover .bilbo-toggle-slider::before {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .bilbo-toggle input:checked:hover + .bilbo-toggle-slider {
    background: var(--b-blue-dark, #0041CC);
  }

  .bilbo-toggle input:checked:hover + .bilbo-toggle-slider::before {
    box-shadow: 0 2px 12px rgba(0, 87, 255, 0.4);
  }
}

/* ── Back button specific ────────────────────────────────────────── */
[data-cookie-action="back"] {
  font-size: 13px;
  font-weight: 500;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #bilbo-cookie-banner {
    padding: 0 12px 12px;
  }

  #bilbo-cookie-banner-inner {
    padding: 20px 18px;
    border-radius: 14px;
  }

  .bilbo-cookie-header h3 {
    font-size: 16px;
  }

  .bilbo-cookie-actions {
    flex-direction: column;
    gap: 8px;
  }

  .bilbo-cookie-customize-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .bilbo-btn {
    width: 100%;
    padding: 14px 20px;
    border-radius: 12px;
  }

  .bilbo-cookie-category {
    padding: 14px 16px;
  }

  .bilbo-cookie-desc {
    font-size: 12px;
  }

  /* Larger touch targets on mobile */
  .bilbo-toggle {
    width: 56px;
    height: 34px;
  }

  .bilbo-toggle-slider::before {
    height: 30px;
    width: 30px;
  }

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

/* ── Tablet ──────────────────────────────────────────────────────── */
@media (min-width: 641px) and (max-width: 1024px) {
  #bilbo-cookie-banner-inner {
    max-width: 648px;
    padding: 22px 24px;
  }
}

/* ── RTL Support (Arabic) ────────────────────────────────────────── */
[dir="rtl"] #bilbo-cookie-banner {
  font-family: var(--b-body-ar, 'IBM Plex Sans Arabic', 'Inter', system-ui, sans-serif);
  direction: rtl;
}

[dir="rtl"] .bilbo-cookie-header h3,
[dir="rtl"] .bilbo-cookie-category-label strong {
  font-family: var(--b-display-ar, 'IBM Plex Sans Arabic', 'Inter', sans-serif);
}

[dir="rtl"] .bilbo-cookie-customize-actions {
  justify-content: flex-start;
}

[dir="rtl"] .bilbo-cookie-desc {
  text-align: right;
  unicode-bidi: plaintext;
}

/* ── Reduced Motion ──────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #bilbo-cookie-banner-inner {
    animation: none !important;
  }

  .bilbo-btn,
  .bilbo-toggle-slider,
  .bilbo-toggle-slider::before {
    transition: none !important;
  }

  @keyframes cookie-slide-up {
    from { opacity: 0.5; }
    to   { opacity: 1; }
  }
}

/* ── High Contrast Mode ──────────────────────────────────────────── */
@media (prefers-contrast: high) {
  #bilbo-cookie-banner-inner {
    border: 2px solid var(--b-ink, #080E2D);
    box-shadow: none;
    backdrop-filter: none;
    background: #FFFFFF;
  }

  .bilbo-btn-primary {
    border: 2px solid transparent;
  }

  .bilbo-btn-secondary {
    border: 2px solid var(--b-blue, #0057FF);
  }

  .bilbo-cookie-categories {
    border: 2px solid var(--b-ink-soft, #4B5A8A);
  }
}

/* ── Dark Mode ───────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  #bilbo-cookie-banner-inner {
    background: rgba(20, 25, 45, 0.95);
    backdrop-filter: blur(20px);
    box-shadow:
      0 0 0 1px rgba(100, 140, 255, 0.12),
      0 8px 32px rgba(0, 0, 0, 0.4);
  }

  .bilbo-cookie-header h3 {
    color: #E8ECF4;
  }

  .bilbo-cookie-header p {
    color: #8898BB;
  }

  .bilbo-cookie-categories {
    border-color: rgba(100, 140, 255, 0.1);
    background: rgba(15, 20, 40, 0.6);
  }

  .bilbo-cookie-category {
    background: rgba(25, 32, 55, 0.8);
    border-bottom-color: rgba(100, 140, 255, 0.08);
  }

  .bilbo-cookie-category:hover {
    background: rgba(30, 38, 65, 0.9);
  }

  .bilbo-cookie-category-label strong {
    color: #D0D8E8;
  }

  .bilbo-cookie-desc {
    color: #6B7DA0;
  }

  .bilbo-badge-always {
    background: rgba(0, 87, 255, 0.2);
    color: #5B9BFF;
  }

  .bilbo-btn-secondary {
    background: rgba(0, 87, 255, 0.15);
    color: #5B9BFF;
  }

  .bilbo-btn-secondary:hover {
    background: rgba(0, 87, 255, 0.25);
  }

  .bilbo-btn-text {
    color: #6B7DA0;
  }

  .bilbo-btn-text:hover {
    color: #5B9BFF;
    background: rgba(0, 87, 255, 0.1);
  }

  .bilbo-cookie-header a {
    color: #5B9BFF;
  }

  @media (prefers-contrast: high) {
    #bilbo-cookie-banner-inner {
      border: 2px solid #4B7BFF;
      background: #0A0D1A;
    }
  }
}
