/* ═══════════════════════════════════════════════════════════════
   Cookie Consent System — Hamishona / هامشنا
   Premium SaaS-grade design (Stripe / Vercel / Notion inspired)
   ═══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  --cc-bg: #0F172A;
  --cc-surface: #1E293B;
  --cc-surface-hover: #253347;
  --cc-border: rgba(148, 163, 184, 0.12);
  --cc-border-active: rgba(99, 102, 241, 0.4);
  --cc-text: #F1F5F9;
  --cc-text-secondary: #94A3B8;
  --cc-text-muted: #64748B;
  --cc-primary: #6366F1;
  --cc-primary-hover: #818CF8;
  --cc-primary-glow: rgba(99, 102, 241, 0.25);
  --cc-success: #22C55E;
  --cc-success-glow: rgba(34, 197, 94, 0.25);
  --cc-danger: #EF4444;
  --cc-overlay: rgba(0, 0, 0, 0.6);
  --cc-radius: 16px;
  --cc-radius-sm: 12px;
  --cc-radius-xs: 8px;
  --cc-transition: cubic-bezier(0.16, 1, 0.3, 1);
  --cc-shadow-lg: 0 25px 60px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(148, 163, 184, 0.06);
  --cc-shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15), 0 0 80px rgba(99, 102, 241, 0.05);
}

/* ── Overlay ── */
.cc-overlay {
  position: fixed;
  inset: 0;
  background: var(--cc-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s var(--cc-transition), visibility 0.4s;
}

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

/* ── Banner ── */
.cc-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 99999;
  padding: 0 16px 16px;
  pointer-events: none;
  transform: translateY(110%);
  opacity: 0;
  transition: transform 0.6s var(--cc-transition), opacity 0.5s ease;
}

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

.cc-banner__inner {
  max-width: 520px;
  margin: 0 auto;
  background: var(--cc-bg);
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius);
  box-shadow: var(--cc-shadow-lg), var(--cc-shadow-glow);
  overflow: hidden;
  position: relative;
}

/* Top gradient accent line */
.cc-banner__inner::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--cc-primary), #a78bfa, var(--cc-primary));
  background-size: 200% 100%;
  animation: cc-gradient-shift 3s ease infinite;
}

@keyframes cc-gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.cc-banner__body {
  padding: 24px 24px 20px;
}

/* ── Shield Icon ── */
.cc-banner__icon {
  width: 44px;
  height: 44px;
  border-radius: var(--cc-radius-xs);
  background: linear-gradient(135deg, var(--cc-primary), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px var(--cc-primary-glow);
  flex-shrink: 0;
  animation: cc-icon-pulse 2.5s ease-in-out infinite;
}

@keyframes cc-icon-pulse {
  0%, 100% { box-shadow: 0 4px 16px var(--cc-primary-glow); }
  50% { box-shadow: 0 4px 24px rgba(99, 102, 241, 0.4); }
}

.cc-banner__icon svg {
  width: 22px;
  height: 22px;
  color: white;
}

.cc-banner__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--cc-text);
  margin: 0 0 6px;
  letter-spacing: -0.01em;
  line-height: 1.4;
}

.cc-banner__desc {
  font-size: 13.5px;
  color: var(--cc-text-secondary);
  line-height: 1.65;
  margin: 0;
}

.cc-banner__desc a {
  color: var(--cc-primary-hover);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.cc-banner__desc a:hover {
  color: var(--cc-text);
  text-decoration: underline;
}

/* ── Banner Actions ── */
.cc-banner__actions {
  display: flex;
  gap: 8px;
  padding: 0 24px 24px;
  flex-wrap: wrap;
}

.cc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--cc-radius-xs);
  border: none;
  cursor: pointer;
  transition: all 0.25s var(--cc-transition);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  line-height: 1.4;
  min-height: auto;
  min-width: auto;
}

.cc-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.cc-btn:hover::after {
  opacity: 1;
}

/* Primary CTA */
.cc-btn--accept {
  flex: 1;
  background: linear-gradient(135deg, var(--cc-primary), #818CF8);
  color: white;
  box-shadow: 0 4px 14px var(--cc-primary-glow), inset 0 1px 0 rgba(255,255,255,0.1);
}

.cc-btn--accept:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35), inset 0 1px 0 rgba(255,255,255,0.15);
}

.cc-btn--accept:active {
  transform: translateY(0);
}

/* Reject */
.cc-btn--reject {
  background: var(--cc-surface);
  color: var(--cc-text-secondary);
  border: 1px solid var(--cc-border);
}

.cc-btn--reject:hover {
  background: var(--cc-surface-hover);
  color: var(--cc-text);
  border-color: rgba(148, 163, 184, 0.2);
}

/* Settings Link */
.cc-btn--settings {
  background: transparent;
  color: var(--cc-text-muted);
  padding: 10px 12px;
  font-size: 12.5px;
}

.cc-btn--settings:hover {
  color: var(--cc-primary-hover);
  background: rgba(99, 102, 241, 0.08);
}

.cc-btn--settings svg {
  width: 14px;
  height: 14px;
  transition: transform 0.4s var(--cc-transition);
}

.cc-btn--settings:hover svg {
  transform: rotate(60deg);
}

/* ══════════════════════════════════════════
   Settings Modal
   ══════════════════════════════════════════ */

.cc-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s var(--cc-transition), visibility 0.4s;
}

.cc-modal.cc-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.cc-modal__panel {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  background: var(--cc-bg);
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius);
  box-shadow: var(--cc-shadow-lg), var(--cc-shadow-glow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.92) translateY(20px);
  transition: transform 0.5s var(--cc-transition);
  position: relative;
}

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

/* Top gradient line on modal */
.cc-modal__panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--cc-primary), var(--cc-success), var(--cc-primary));
  background-size: 200% 100%;
  animation: cc-gradient-shift 3s ease infinite;
}

/* ── Modal Header ── */
.cc-modal__header {
  padding: 24px 24px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.cc-modal__header-content {
  flex: 1;
}

.cc-modal__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--cc-text);
  margin: 0;
  letter-spacing: -0.01em;
}

.cc-modal__subtitle {
  font-size: 13px;
  color: var(--cc-text-muted);
  margin: 4px 0 0;
  line-height: 1.5;
}

.cc-modal__close {
  width: 32px;
  height: 32px;
  border-radius: var(--cc-radius-xs);
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  color: var(--cc-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  min-height: auto;
  min-width: auto;
  padding: 0;
}

.cc-modal__close:hover {
  background: var(--cc-surface-hover);
  color: var(--cc-text);
  border-color: rgba(148, 163, 184, 0.2);
}

.cc-modal__close svg {
  width: 16px;
  height: 16px;
}

/* ── Modal Body ── */
.cc-modal__body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* Scrollbar Styling */
.cc-modal__body::-webkit-scrollbar {
  width: 4px;
}

.cc-modal__body::-webkit-scrollbar-track {
  background: transparent;
}

.cc-modal__body::-webkit-scrollbar-thumb {
  background: var(--cc-surface-hover);
  border-radius: 4px;
}

/* ── Cookie Category Card ── */
.cc-category {
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius-sm);
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.3s, background 0.3s;
}

.cc-category:last-child {
  margin-bottom: 0;
}

.cc-category:hover {
  border-color: rgba(148, 163, 184, 0.18);
}

.cc-category--active {
  border-color: var(--cc-border-active);
  background: rgba(99, 102, 241, 0.04);
}

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

.cc-category__info {
  flex: 1;
  min-width: 0;
}

.cc-category__label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cc-category__icon {
  width: 32px;
  height: 32px;
  border-radius: var(--cc-radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cc-category__icon svg {
  width: 16px;
  height: 16px;
}

.cc-category__icon--necessary {
  background: rgba(34, 197, 94, 0.12);
  color: var(--cc-success);
}

.cc-category__icon--analytics {
  background: rgba(99, 102, 241, 0.12);
  color: var(--cc-primary);
}

.cc-category__icon--ads {
  background: rgba(251, 191, 36, 0.12);
  color: #FBBF24;
}

.cc-category__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--cc-text);
  display: block;
}

.cc-category__badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 6px;
  margin-inline-start: 6px;
}

.cc-category__badge--required {
  background: rgba(34, 197, 94, 0.12);
  color: var(--cc-success);
}

.cc-category__desc {
  font-size: 12.5px;
  color: var(--cc-text-muted);
  margin: 6px 0 0;
  line-height: 1.55;
  padding-inline-start: 40px;
}

/* ── Toggle Switch ── */
.cc-toggle {
  position: relative;
  flex-shrink: 0;
}

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

.cc-toggle__track {
  width: 44px;
  height: 24px;
  background: var(--cc-surface-hover);
  border: 1px solid var(--cc-border);
  border-radius: 999px;
  cursor: pointer;
  position: relative;
  transition: background 0.3s var(--cc-transition), border-color 0.3s, box-shadow 0.3s;
  display: block;
  min-height: auto;
  min-width: auto;
}

.cc-toggle__track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--cc-text-muted);
  border-radius: 50%;
  transition: transform 0.3s var(--cc-transition), background 0.3s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.cc-toggle input:checked + .cc-toggle__track {
  background: var(--cc-primary);
  border-color: var(--cc-primary);
  box-shadow: 0 0 12px var(--cc-primary-glow);
}

.cc-toggle input:checked + .cc-toggle__track::after {
  transform: translateX(20px);
  background: white;
}

/* Disabled toggle (for necessary cookies) */
.cc-toggle--locked .cc-toggle__track {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
  cursor: not-allowed;
}

.cc-toggle--locked .cc-toggle__track::after {
  background: var(--cc-success);
  transform: translateX(20px);
}

/* RTL support for toggle */
[dir="rtl"] .cc-toggle__track::after {
  left: auto;
  right: 2px;
}

[dir="rtl"] .cc-toggle input:checked + .cc-toggle__track::after {
  transform: translateX(-20px);
}

[dir="rtl"] .cc-toggle--locked .cc-toggle__track::after {
  transform: translateX(-20px);
}

/* ── Modal Footer ── */
.cc-modal__footer {
  padding: 16px 24px 24px;
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--cc-border);
}

.cc-btn--save {
  flex: 1;
  background: linear-gradient(135deg, var(--cc-primary), #818CF8);
  color: white;
  box-shadow: 0 4px 14px var(--cc-primary-glow), inset 0 1px 0 rgba(255,255,255,0.1);
}

.cc-btn--save:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35);
}

.cc-btn--accept-all-modal {
  flex: 1;
  background: var(--cc-surface);
  color: var(--cc-text);
  border: 1px solid var(--cc-border);
}

.cc-btn--accept-all-modal:hover {
  background: var(--cc-surface-hover);
  border-color: rgba(148, 163, 184, 0.2);
}

/* ══════════════════════════════════════════
   Re-open Cookie Settings Button (floating)
   ══════════════════════════════════════════ */

.cc-reopen {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 99997;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--cc-bg);
  border: 1px solid var(--cc-border);
  color: var(--cc-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: all 0.3s var(--cc-transition);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8);
  min-height: auto;
  min-width: auto;
  padding: 0;
}

.cc-reopen.cc-visible {
  opacity: 0.7;
  visibility: visible;
  transform: scale(1);
}

.cc-reopen:hover {
  opacity: 1;
  transform: scale(1.1);
  color: var(--cc-primary);
  border-color: var(--cc-border-active);
  box-shadow: 0 4px 20px var(--cc-primary-glow);
}

.cc-reopen svg {
  width: 18px;
  height: 18px;
}

[dir="rtl"] .cc-reopen {
  left: auto;
  right: 20px;
}

/* ══════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════ */

@media (max-width: 640px) {
  .cc-banner {
    padding: 0 8px 72px; /* account for mobile bottom nav */
  }

  .cc-banner__inner {
    border-radius: var(--cc-radius-sm);
  }

  .cc-banner__body {
    padding: 20px 18px 16px;
  }

  .cc-banner__icon {
    width: 38px;
    height: 38px;
    margin-bottom: 12px;
  }

  .cc-banner__icon svg {
    width: 18px;
    height: 18px;
  }

  .cc-banner__title {
    font-size: 15px;
  }

  .cc-banner__desc {
    font-size: 12.5px;
  }

  .cc-banner__actions {
    padding: 0 18px 18px;
    flex-direction: column;
  }

  .cc-btn--accept,
  .cc-btn--reject {
    width: 100%;
    padding: 12px 18px;
  }

  .cc-btn--settings {
    width: 100%;
    justify-content: center;
  }

  .cc-modal {
    padding: 8px;
    align-items: flex-end;
  }

  .cc-modal__panel {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: var(--cc-radius-sm) var(--cc-radius-sm) 0 0;
  }

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

  .cc-modal__panel {
    transform: scale(1) translateY(100%);
  }

  .cc-modal__header {
    padding: 20px 18px 0;
  }

  .cc-modal__body {
    padding: 16px 18px;
  }

  .cc-modal__footer {
    padding: 14px 18px 20px;
    flex-direction: column;
  }

  .cc-category {
    padding: 14px;
  }

  .cc-category__desc {
    padding-inline-start: 0;
    margin-top: 8px;
  }

  .cc-reopen {
    bottom: 76px; /* above mobile nav bar */
  }
}

@media (max-width: 360px) {
  .cc-banner__title {
    font-size: 14px;
  }

  .cc-banner__desc {
    font-size: 12px;
  }
}

/* ── Animations ── */
@keyframes cc-fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.cc-banner.cc-visible .cc-banner__body {
  animation: cc-fade-in 0.5s 0.1s var(--cc-transition) both;
}

.cc-banner.cc-visible .cc-banner__actions {
  animation: cc-fade-in 0.5s 0.2s var(--cc-transition) both;
}

/* ── Print: hide everything ── */
@media print {
  .cc-banner,
  .cc-modal,
  .cc-overlay,
  .cc-reopen {
    display: none !important;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .cc-banner,
  .cc-modal,
  .cc-modal__panel,
  .cc-overlay,
  .cc-toggle__track::after,
  .cc-btn,
  .cc-reopen,
  .cc-banner__icon {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
