/* ==========================================================================
   IVEACER PDPA Cookie Consent Banner & Preferences Dialog
   Aligned with DESIGN.md tokens across Light, Dark, High Contrast,
   Grayscale, Reduced Motion, and Print modes.
   ========================================================================== */

.iveacer-cookie-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 1090;
  max-width: 1040px;
  margin-inline: auto;
  padding: 18px 22px;
  border-radius: 14px;
  background-color: var(--iveacer-surface, #ffffff);
  color: var(--iveacer-text-main, #1e293b);
  border: 1px solid var(--iveacer-border, #dce6df);
  box-shadow: 0 18px 44px rgba(2, 44, 34, 0.16), 0 2px 10px rgba(0, 0, 0, 0.06);
  font-family: 'Sarabun', 'Prompt', sans-serif;
  line-height: 1.6;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
}

.iveacer-cookie-banner[hidden],
.iveacer-cookie-fab[hidden] {
  display: none !important;
}

.iveacer-cookie-copy {
  flex: 1 1 360px;
  min-width: 0;
}

.iveacer-cookie-title {
  margin: 0 0 4px;
  font-family: 'Prompt', 'Sarabun', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--iveacer-heading, #064E3B);
  display: flex;
  align-items: center;
  gap: 8px;
}

.iveacer-cookie-desc {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--iveacer-text-muted, #475569);
}

.iveacer-cookie-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.iveacer-cookie-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 9999px;
  font-family: 'Prompt', 'Sarabun', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  border: 1px solid var(--iveacer-border, #dce6df);
  background-color: var(--iveacer-surface, #ffffff);
  color: var(--iveacer-text-main, #0F172A);
  transition: background-color 180ms ease-out,
              border-color 180ms ease-out,
              color 180ms ease-out,
              transform 180ms var(--iveacer-ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
              box-shadow 180ms ease-out;
}

.iveacer-cookie-btn--primary {
  background-color: var(--iveacer-brand-green, #065F46);
  border-color: var(--iveacer-brand-green, #065F46);
  color: #ffffff;
}

.iveacer-cookie-btn--secondary {
  background-color: var(--iveacer-surface-soft, #f1f8f4);
  border-color: var(--iveacer-border, #dce6df);
  color: var(--iveacer-heading, #064E3B);
}

.iveacer-cookie-btn--link {
  background-color: transparent;
  border-color: transparent;
  color: var(--iveacer-heading, #065F46);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding-inline: 10px;
}

@media (hover: hover) and (pointer: fine) {
  .iveacer-cookie-btn--primary:hover {
    background-color: var(--iveacer-brand-deep, #064E3B);
    border-color: var(--iveacer-brand-deep, #064E3B);
    transform: translate3d(0, -1px, 0);
  }

  .iveacer-cookie-btn--secondary:hover {
    background-color: var(--iveacer-surface-subtle, #e8f5e9);
    border-color: var(--iveacer-brand-green, #065F46);
  }

  .iveacer-cookie-btn--link:hover {
    color: var(--iveacer-brand-deep, #022C22);
  }
}

.iveacer-cookie-btn:active {
  transform: scale(0.96);
}

.iveacer-cookie-btn:focus-visible,
.iveacer-cookie-fab:focus-visible,
.iveacer-cookie-close:focus-visible,
.iveacer-cookie-toggle input:focus-visible + .iveacer-cookie-switch {
  outline: 3px solid var(--iveacer-focus-ring, #b8941f);
  outline-offset: 3px;
}

/* Re-open Preferences Pill (bottom-left to avoid back-to-top & news toast on bottom-right) */
.iveacer-cookie-fab {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 1040;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 9999px;
  border: 1px solid var(--iveacer-border, #dce6df);
  background-color: var(--iveacer-surface, #ffffff);
  color: var(--iveacer-heading, #064E3B);
  box-shadow: 0 6px 18px rgba(2, 44, 34, 0.12);
  font-family: 'Prompt', 'Sarabun', sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 180ms ease-out,
              border-color 180ms ease-out,
              color 180ms ease-out,
              transform 180ms var(--iveacer-ease-out, cubic-bezier(0.23, 1, 0.32, 1));
}

@media (hover: hover) and (pointer: fine) {
  .iveacer-cookie-fab:hover {
    background-color: var(--iveacer-surface-soft, #f1f8f4);
    border-color: var(--iveacer-brand-green, #065F46);
    transform: translate3d(0, -1px, 0);
  }
}

.iveacer-cookie-fab:active {
  transform: scale(0.96);
}

/* Native <dialog> Preferences & PDPA Policy Modal */
#iveacer-cookie-dialog {
  width: min(580px, calc(100vw - 24px));
  max-height: 88vh;
  margin: auto;
  padding: 0;
  border: 1px solid var(--iveacer-border, #dce6df);
  border-radius: 16px;
  background-color: var(--iveacer-surface, #ffffff);
  color: var(--iveacer-text-main, #1e293b);
  box-shadow: 0 24px 60px rgba(2, 44, 34, 0.24);
  font-family: 'Sarabun', 'Prompt', sans-serif;
  overflow: hidden;
}

#iveacer-cookie-dialog::backdrop {
  background: rgba(2, 44, 34, 0.58);
  backdrop-filter: blur(4px);
}

.iveacer-cookie-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--iveacer-border, #dce6df);
}

.iveacer-cookie-dialog-head h2 {
  margin: 0;
  font-family: 'Prompt', 'Sarabun', sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--iveacer-heading, #064E3B);
}

.iveacer-cookie-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 9999px;
  border: 1px solid var(--iveacer-border, #dce6df);
  background: transparent;
  color: var(--iveacer-text-main, #1e293b);
  font-size: 1.25rem;
  cursor: pointer;
}

.iveacer-cookie-dialog-body {
  padding: 18px 22px;
  overflow-y: auto;
  max-height: calc(88vh - 150px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.iveacer-cookie-intro {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--iveacer-text-muted, #475569);
  line-height: 1.65;
}

.iveacer-cookie-group {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--iveacer-border, #dce6df);
  background-color: var(--iveacer-surface-soft, #f1f8f4);
}

.iveacer-cookie-group-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.iveacer-cookie-group-title {
  margin: 0;
  font-family: 'Prompt', 'Sarabun', sans-serif;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--iveacer-heading, #064E3B);
}

.iveacer-cookie-group-desc {
  margin: 0;
  font-size: 0.875rem;
  color: var(--iveacer-text-muted, #475569);
  line-height: 1.6;
}

.iveacer-cookie-pill-fixed {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 9999px;
  font-family: 'Prompt', 'Sarabun', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  background-color: rgba(6, 95, 70, 0.12);
  color: var(--iveacer-heading, #065F46);
}

.iveacer-cookie-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 48px;
  min-height: 44px;
  cursor: pointer;
}

.iveacer-cookie-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.iveacer-cookie-switch {
  width: 48px;
  height: 26px;
  border-radius: 9999px;
  background-color: #94a3b8;
  position: relative;
  transition: background-color 180ms ease-out;
}

.iveacer-cookie-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 9999px;
  background-color: #ffffff;
  transition: transform 180ms var(--iveacer-ease-out, cubic-bezier(0.23, 1, 0.32, 1));
}

.iveacer-cookie-toggle input:checked + .iveacer-cookie-switch {
  background-color: var(--iveacer-brand-green, #065F46);
}

.iveacer-cookie-toggle input:checked + .iveacer-cookie-switch::after {
  transform: translateX(22px);
}

.iveacer-cookie-pdpa-note {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--iveacer-text-muted, #53665b);
  line-height: 1.6;
}

.iveacer-cookie-dialog-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--iveacer-border, #dce6df);
  background-color: var(--iveacer-surface-soft, #f8fafc);
}

/* Dark Mode */
html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-banner,
html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-fab,
html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) #iveacer-cookie-dialog {
  background-color: #112217;
  color: #f8fafc;
  border-color: #2e4936;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
}

html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) :is(
  .iveacer-cookie-title,
  .iveacer-cookie-dialog-head h2,
  .iveacer-cookie-group-title,
  .iveacer-cookie-fab,
  .iveacer-cookie-btn--link
) {
  color: #BEF264;
}

html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) :is(
  .iveacer-cookie-desc,
  .iveacer-cookie-intro,
  .iveacer-cookie-group-desc,
  .iveacer-cookie-pdpa-note
) {
  color: #adc1b2;
}

html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-group,
html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-dialog-foot {
  background-color: #142a1d;
  border-color: #2e4936;
}

html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-btn--primary {
  background-color: #A3E635;
  border-color: #A3E635;
  color: #022C22;
}

html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-btn--secondary,
html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-close {
  background-color: #142a1d;
  border-color: #2e4936;
  color: #f8fafc;
}

html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-pill-fixed {
  background-color: rgba(163, 230, 53, 0.16);
  color: #BEF264;
}

html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-toggle input:checked + .iveacer-cookie-switch {
  background-color: #A3E635;
}

html:is([data-theme="dark"], [data-bs-theme="dark"], .dark) .iveacer-cookie-toggle input:checked + .iveacer-cookie-switch::after {
  background-color: #022C22;
}

/* High Contrast Mode */
html:is([data-contrast="high"], .high-contrast) :is(
  .iveacer-cookie-banner,
  .iveacer-cookie-fab,
  #iveacer-cookie-dialog,
  .iveacer-cookie-group,
  .iveacer-cookie-dialog-foot,
  .iveacer-cookie-btn--secondary,
  .iveacer-cookie-close
) {
  background: #000000 !important;
  color: #ffffff !important;
  border: 2px solid #ffffff !important;
  box-shadow: none !important;
}

html:is([data-contrast="high"], .high-contrast) .iveacer-cookie-btn--primary {
  background: #ffff00 !important;
  color: #000000 !important;
  border: 2px solid #ffffff !important;
}

html:is([data-contrast="high"], .high-contrast) :is(.iveacer-cookie-title, .iveacer-cookie-btn--link, .iveacer-cookie-pill-fixed) {
  color: #ffff00 !important;
}

/* Reduced Motion */
html:is([data-reduced-motion="true"], .reduce-motion) :is(.iveacer-cookie-btn, .iveacer-cookie-fab, .iveacer-cookie-switch, .iveacer-cookie-switch::after) {
  transition-property: background-color, border-color, color, opacity !important;
  transition-duration: 120ms !important;
}

html:is([data-reduced-motion="true"], .reduce-motion) :is(.iveacer-cookie-btn, .iveacer-cookie-fab):is(:hover, :active) {
  transform: none !important;
}

@media (prefers-reduced-motion: reduce) {
  html:not([data-reduced-motion="false"]) :is(.iveacer-cookie-btn, .iveacer-cookie-fab, .iveacer-cookie-switch, .iveacer-cookie-switch::after) {
    transition-property: background-color, border-color, color, opacity !important;
    transition-duration: 120ms !important;
  }
  html:not([data-reduced-motion="false"]) :is(.iveacer-cookie-btn, .iveacer-cookie-fab):is(:hover, :active) {
    transform: none !important;
  }
}

@media (max-width: 639px) {
  .iveacer-cookie-banner {
    left: 10px;
    right: 10px;
    bottom: 10px;
    padding: 16px;
  }
  .iveacer-cookie-actions {
    width: 100%;
  }
  .iveacer-cookie-actions .iveacer-cookie-btn--primary,
  .iveacer-cookie-actions .iveacer-cookie-btn--secondary {
    flex: 1 1 auto;
  }
  .iveacer-cookie-fab {
    left: 10px;
    bottom: 10px;
  }
}

@media print {
  .iveacer-cookie-banner,
  .iveacer-cookie-fab,
  #iveacer-cookie-dialog {
    display: none !important;
  }
}
