/**
 * ╔══════════════════════════════════════════════════════════════════════════════╗
 * ║ File: plugins/consent-manager/resources/css/consent.css                      ║
 * ║ Purpose: Enterprise Styling for Consent Manager (Core Design Alignment)      ║
 * ║ Author: Jürgen Schmitt | BSBV Inc.                                           ║
 * ║ License: Proprietary © BSBV Inc. 2026                                        ║
 * ║ Version: 8.5.4 (Button Layout Fix)                                           ║
 * ║ Status: Production-Ready                                                     ║
 * ╚══════════════════════════════════════════════════════════════════════════════╝
 */

/* CONSENT CSS VERSION: 8.5.4 (Button Layout Fix) */

/* --- Core Design Tokens (scoped to consent root; survives `all: initial`) --- */
#bsbv-consent-root {
  /* IMPORTANT: must come first, otherwise it nukes tokens again */
  all: initial;

  /* --- Z-Index Scale (From Core) --- */
  --cm-z-high: 2147483647;
  --cm-z-modal: 2147483640;

  /* --- Colors (From Core Palette) --- */
  --cm-primary: #003b5c; /* Core Primary */
  --cm-primary-hover: #004b76;
  --cm-secondary: #95d600; /* Core Green */
  --cm-secondary-hover: #7ab800;

  --cm-bg: #ffffff;
  --cm-bg-panel: rgba(255, 255, 255, 0.98);
  --cm-border: #e2e8f0; /* Core Gray-200 */
  --cm-text-main: #0f172a; /* Core Slate-900 */
  --cm-text-sub: #64748b; /* Core Slate-500 */
  --cm-text-muted: #94a3b8; /* Core Slate-400 */

  /* --- Dimensions (From Core) --- */
  --cm-radius: 0.75rem; /* Core rounded-lg */
  --cm-radius-sm: 0.5rem; /* Core rounded-md */

  /* --- Spacing / Layout (Enterprise Tuned) --- */
  --cm-space-1: 0.5rem;
  --cm-space-2: 0.75rem;
  --cm-space-3: 1.125rem; /* Optimized: Luftiger */
  --cm-space-4: 1.5rem;   /* Optimized: Luftiger */
  --cm-space-5: 1.75rem;  /* Optimized: Luftiger */

  /* --- Surfaces / Shadows --- */
  --cm-surface: rgba(15, 23, 42, 0.03);
  --cm-surface-2: rgba(15, 23, 42, 0.06);
  --cm-shadow-lg: 0 20px 25px -5px rgba(0,0,0,.12), 0 10px 10px -5px rgba(0,0,0,.06);

  /* --- Base Reset (that we actually want) --- */
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  color: var(--cm-text-main);
  box-sizing: border-box;
  display: block;
}

/* --- Dark Mode (Aligned with Core Dark Mode - OS Preference) --- */
@media (prefers-color-scheme: dark) {
  #bsbv-consent-root {
    --cm-primary: #f8fafc; /* Core Dark Text */
    --cm-primary-hover: #e2e8f0;
    --cm-bg: #0f172a; /* Core Dark BG */
    --cm-bg-panel: rgba(15, 23, 42, 0.98); /* Core Dark Panel */
    --cm-border: #1e293b; /* Core Dark Border */
    --cm-text-main: #f8fafc; /* Core Dark Text */
    --cm-text-sub: #94a3b8;
    --cm-text-muted: #94a3b8;
    --cm-surface: rgba(148, 163, 184, 0.08);
    --cm-surface-2: rgba(148, 163, 184, 0.12);
  }
}

/* --- Dark Mode via App Toggle (Tailwind / Theme Switch) --- */
/* Greift, wenn euer UI die Klasse "dark" auf html/body setzt */
.dark #bsbv-consent-root {
  --cm-primary: #f8fafc;
  --cm-primary-hover: #e2e8f0;
  --cm-bg: #0f172a;
  --cm-bg-panel: rgba(15, 23, 42, 0.98);
  --cm-border: #1e293b;
  --cm-text-main: #f8fafc;
  --cm-text-sub: #94a3b8;
  --cm-text-muted: #94a3b8;
  --cm-surface: rgba(148, 163, 184, 0.08);
  --cm-surface-2: rgba(148, 163, 184, 0.12);
}

/* --- Resets (scoped, low-specificity; must NOT override component paddings) --- */
#bsbv-consent-root :where(*, *::before, *::after) {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Enterprise Polish: Ensure buttons/links inherit correctly after all: initial */
#bsbv-consent-root button { font: inherit; color: inherit; }
#bsbv-consent-root a { color: inherit; }

/* --- Utilities (From Core) --- */
.cm-hidden {
  display: none !important;
}

/* --- SHIELD BUTTON (Trigger) --- */
.cm-shield {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: var(--cm-z-high);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  background: var(--cm-bg);
  border: 2px solid var(--cm-border);
  border-radius: 9999px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--cm-text-main);
}

.cm-shield:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  border-color: var(--cm-secondary);
}

.cm-shield svg {
  width: 1.75rem;
  height: 1.75rem;
  fill: currentColor;
  transition: fill 0.2s;
}

/* --- BACKEND SHIELD OVERRIDE --- */
body[data-backend="1"] #bsbv-consent-root .cm-shield {
  left: auto;
  right: calc(1rem + env(safe-area-inset-right));
  bottom: calc(1rem + env(safe-area-inset-bottom));
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.75rem;
  border-width: 2px;
  border-color: #e2e8f0;
  background: rgba(255, 255, 255, 0.96);
  color: #0f172a;
  box-shadow: 0 10px 15px -3px rgba(15, 23, 42, 0.12), 0 4px 6px -4px rgba(15, 23, 42, 0.12);
}

body[data-backend="1"] #bsbv-consent-root .cm-shield:hover {
  transform: translateY(-1px);
  border-color: rgba(149, 214, 0, 0.45);
  background: rgba(248, 250, 252, 0.98);
  box-shadow: 0 16px 24px -8px rgba(15, 23, 42, 0.2);
}

body[data-backend="1"] #bsbv-consent-root .cm-shield svg {
  width: 1.25rem;
  height: 1.25rem;
}

.dark body[data-backend="1"] #bsbv-consent-root .cm-shield {
  border-color: #334155;
  background: rgba(15, 23, 42, 0.96);
  color: #f8fafc;
}

.dark body[data-backend="1"] #bsbv-consent-root .cm-shield:hover {
  border-color: rgba(149, 214, 0, 0.45);
  background: rgba(30, 41, 59, 0.98);
}

/* --- BANNER (Bottom Bar) --- */
.cm-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--cm-z-high);
  
  /* Mobile Polish: Safe Areas & Padding */
  padding: var(--cm-space-3);
  padding-bottom: calc(var(--cm-space-3) + env(safe-area-inset-bottom));
  padding-left: calc(var(--cm-space-3) + env(safe-area-inset-left));
  padding-right: calc(var(--cm-space-3) + env(safe-area-inset-right));
  
  pointer-events: none;
  display: flex;
  justify-content: center;
}

.cm-banner-inner {
  pointer-events: auto;
  width: 100%;
  max-width: 72rem;
  background: var(--cm-bg-panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--cm-border);
  border-bottom: 4px solid var(--cm-secondary);
  border-radius: var(--cm-radius);
  box-shadow: var(--cm-shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
}

@media (min-width: 768px) {
  .cm-banner-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.cm-banner-header {
  padding: var(--cm-space-5);
  flex: 1;
}

.cm-banner-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--cm-text-main);
  margin-bottom: 0.5rem;
}

.cm-banner-header p {
  font-size: 0.875rem;
  color: var(--cm-text-sub);
  line-height: 1.5;
  max-width: 70ch;
  margin-top: 0.25rem;
}

/* Clean Links Block */
.cm-banner-links {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cm-banner-links .cm-sep {
  color: var(--cm-text-muted);
}

.cm-banner-actions {
  padding: var(--cm-space-4) var(--cm-space-5);
  display: flex;
  flex-wrap: wrap;
  gap: var(--cm-space-2);
  justify-content: flex-start;
  background: var(--cm-surface);
}

@media (min-width: 768px) {
  .cm-banner-actions {
    justify-content: flex-end;
    background: transparent;
    padding-left: 0;
  }
}

/* Mobile First Stacking for Actions */
@media (max-width: 640px) {
  .cm-banner-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .cm-banner-actions .cm-btn {
    width: 100%;
  }
}

/* --- MODAL (Settings) --- */
.cm-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: var(--cm-z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  
  /* Mobile Polish: Inset Bottom Sheet */
  padding: var(--cm-space-3);
  padding-bottom: calc(var(--cm-space-3) + env(safe-area-inset-bottom));
}

@media (min-width: 640px) {
  .cm-modal-backdrop {
    align-items: center;
    padding: 1rem;
  }
}

.cm-modal {
  background: var(--cm-bg);
  width: 100%;
  max-width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  
  /* Fix: Border Radius consistency */
  border-radius: var(--cm-radius);
  
  box-shadow: 0 -10px 50px -12px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--cm-border);
  overflow: hidden;
}

@media (min-width: 640px) {
  .cm-modal {
    max-width: 42rem;
    max-height: 90vh;
  }
}

.cm-modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--cm-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--cm-bg);
  flex-shrink: 0;
}

.cm-modal-header h3 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--cm-text-main);
}

.cm-modal-body {
  padding: var(--cm-space-5);
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* Improved modal footer layout */
.cm-modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--cm-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--cm-bg);
  flex-shrink: 0;
}

.cm-modal-footer-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 1;
}

/* Mobile optimization for modal footer */
@media (max-width: 640px) {
  .cm-modal-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .cm-modal-footer-actions {
    width: 100%;
    flex-direction: column;
  }

  .cm-btn {
    width: 100%;
  }
}

/* --- OPTION ROW --- */
.cm-option {
  display: flex;
  align-items: flex-start;
  gap: var(--cm-space-3);
  padding: var(--cm-space-4);
  border: 1px solid var(--cm-border);
  border-radius: var(--cm-radius-sm);
  background: var(--cm-surface);
  transition: all 0.2s;
  user-select: none;
  margin-bottom: var(--cm-space-2);
}

.cm-option:hover {
  background: var(--cm-surface-2);
  border-color: var(--cm-secondary);
}

/* Added label styling for better accessibility */
.cm-option-label {
  flex: 1;
  cursor: pointer;
  display: flex; /* Ensure flex layout for switch + text */
  align-items: flex-start;
  gap: var(--cm-space-3);
  width: 100%;
}

.cm-option-large strong {
  font-size: 1.025rem;
  font-weight: 600;
  color: var(--cm-text-main);
  display: block;
  margin-bottom: 0.25rem;
}

.cm-option-large small {
  font-size: 0.9rem;
  color: var(--cm-text-sub);
  line-height: 1.4;
  display: block;
}

.cm-option em {
  font-size: 0.75rem;
  font-style: normal;
  color: var(--cm-secondary);
  font-weight: 700;
  text-transform: uppercase;
  margin-top: 0.5rem;
  display: inline-block;
  background: rgba(149, 214, 0, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

/* --- SWITCH COMPONENT --- */
.cm-switch {
  position: relative;
  display: inline-block;
  width: 3rem;
  height: 1.5rem;
  flex-shrink: 0;
  cursor: pointer;
}

.cm-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 10;
  cursor: pointer;
  margin: 0;
}

.cm-switch input:disabled {
  cursor: not-allowed;
}

.cm-switch-track {
  position: absolute;
  inset: 0;
  background-color: #cbd5e1; /* Core Gray-300 */
  border-radius: 9999px;
  transition: background-color 0.2s;
  pointer-events: none;
}

.cm-switch-dot {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.25rem;
  height: 1.25rem;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  pointer-events: none;
}

.cm-switch input:checked + .cm-switch-track {
  background-color: var(--cm-secondary);
}

.cm-switch input:checked + .cm-switch-track .cm-switch-dot {
  transform: translateX(1.5rem);
}

.cm-switch input:disabled + .cm-switch-track {
  opacity: 0.6;
  background-color: #94a3b8; /* Core Gray-400 */
}

/* --- BUTTONS --- */
.cm-btn {
  padding: 0.625rem 1.25rem;
  border-radius: var(--cm-radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cm-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cm-btn-primary {
  background: var(--cm-secondary);
  color: #0f172a;
  border-color: var(--cm-secondary);
}

#bsbv-consent-root .cm-btn-primary {
  color: #0f172a;
}

.cm-btn-primary:hover:not(:disabled) {
  background: var(--cm-secondary-hover);
  border-color: var(--cm-secondary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.cm-btn-secondary {
  background: transparent;
  border-color: var(--cm-border);
  color: var(--cm-text-main);
}

.cm-btn-secondary:hover:not(:disabled) {
  background: var(--cm-border);
}

/* Tertiary button style */
.cm-btn-tertiary {
  background: transparent;
  border-color: #dc2626; /* Core Red-600 */
  color: #dc2626;
}

.cm-btn-tertiary:hover:not(:disabled) {
  background: #dc2626;
  color: white;
}

/* --- DETAILS/SUMMARY --- */
.cm-legal {
  margin-top: 1.5rem;
  padding: 1rem;
  border: 1px solid var(--cm-border);
  border-radius: var(--cm-radius-sm);
  background: rgba(0, 0, 0, 0.02);
}

.cm-legal summary {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--cm-text-main);
  cursor: pointer;
}

.cm-legal p {
  margin-top: var(--cm-space-2);
  font-size: 0.8125rem;
  color: var(--cm-text-sub);
  line-height: 1.5;
  max-width: 70ch;
}

/* --- Links --- */
.cm-link {
  color: var(--cm-text-sub);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.2s;
}
.cm-link:hover {
  color: var(--cm-secondary);
}

/* --- Core Design Alignment --- */
/* Focus states */
.cm-btn:focus,
.cm-switch input:focus,
.cm-option:focus {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(149, 214, 0, 0.3);
}

/* Transition durations */
.cm-btn,
.cm-switch input,
.cm-option {
  transition-duration: 200ms;
}

/* Border radius */
.cm-modal,
.cm-banner-inner,
.cm-option {
  border-radius: 0.75rem; /* Core rounded-xl */
}

/* Color usage */
.cm-btn-primary {
  --tw-bg-opacity: 1;
  background-color: rgb(149 214 0 / var(--tw-bg-opacity));
}

.cm-btn-primary:hover {
  --tw-bg-opacity: 1;
  background-color: rgb(122 184 0 / var(--tw-bg-opacity));
}

/* Dark mode text colors */
.dark .cm-banner-header h2,
.dark .cm-modal-header h3 {
  color: rgb(248 250 252); /* Core dark:text-primary */
}

.dark .cm-banner-header p,
.dark .cm-legal p {
  color: rgb(148 163 184); /* Core dark:text-secondary */
}

/* --- HARD LAYOUT (guaranteed paddings) --- */
#bsbv-consent-root .cm-banner-header { padding: var(--cm-space-5) !important; }
#bsbv-consent-root .cm-banner-actions { padding: var(--cm-space-4) var(--cm-space-5) !important; }
#bsbv-consent-root .cm-modal-header { padding: var(--cm-space-4) var(--cm-space-5) !important; }
#bsbv-consent-root .cm-modal-body { padding: var(--cm-space-5) !important; }
#bsbv-consent-root .cm-modal-footer { padding: var(--cm-space-4) var(--cm-space-5) !important; }
#bsbv-consent-root .cm-option { padding: var(--cm-space-4) !important; margin-bottom: var(--cm-space-2) !important; }
#bsbv-consent-root .cm-legal { padding: var(--cm-space-4) !important; }

/* FIX: Guaranteed Button Styling (overrides all:initial) */
#bsbv-consent-root .cm-btn {
  padding: 0.75rem 1.5rem !important;
  font-size: 0.95rem !important;
  line-height: 1.5 !important;
  min-height: 2.75rem !important; /* Enterprise sizing */
}
