/*!
 * IK Consent — Theming (ik-consent.css)
 * -----------------------------------------------------------------------------
 * Komplettes Erscheinungsbild über CSS Custom Properties anpassbar.
 * Überschreibe einfach die Variablen in deinem eigenen Stylesheet, z. B.:
 *
 *   .ikc-root {
 *     --ikc-accent: #e4002b;          ← Markenfarbe
 *     --ikc-font-family: "Inter", system-ui, sans-serif;
 *     --ikc-radius: 16px;
 *   }
 *
 * Light DOM + präfixierte Klassen (.ikc-…) – dadurch lassen sich Farben,
 * Fonts, Logos und Abstände ohne Code-Eingriff per CSS überschreiben.
 */

/* =================================================================== *
 * Design-Tokens (hier anpassen)
 * =================================================================== */
.ikc-root {
  /* — Farben (semantisch) — */
  --ikc-accent: #2563eb;                 /* Markenfarbe / Primär */
  --ikc-accent-hover: #1d4ed8;
  --ikc-accent-text: #ffffff;            /* Text auf Akzentfläche */

  --ikc-bg: #ffffff;
  --ikc-surface: #ffffff;
  --ikc-text: #1f2937;
  --ikc-muted: #5b6470;
  --ikc-border: #e3e7ee;

  --ikc-overlay: rgba(17, 24, 39, .55);  /* Modal-Hintergrund */

  /* — Buttons — gleichwertige Gestaltung (Reject ist KEIN blasser Textlink!) */
  --ikc-accept-bg: var(--ikc-accent);
  --ikc-accept-text: var(--ikc-accent-text);
  --ikc-accept-hover-bg: var(--ikc-accent-hover);

  --ikc-reject-bg: #eef1f6;
  --ikc-reject-text: #1f2937;
  --ikc-reject-hover-bg: #e2e6ee;
  --ikc-reject-border: #cfd6e2;

  --ikc-settings-bg: transparent;
  --ikc-settings-text: var(--ikc-muted);
  --ikc-settings-hover-bg: #f3f5f9;

  --ikc-link: var(--ikc-accent);

  /* — Toggles — */
  --ikc-toggle-on: #16a34a;
  --ikc-toggle-off: #767e8c;             /* >= 3:1 Kontrast zu #fff (WCAG 1.4.11) */
  --ikc-toggle-thumb: #ffffff;

  /* — Form & Größen — */
  --ikc-font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ikc-font-size: 15px;
  --ikc-line-height: 1.55;

  --ikc-radius: 14px;
  --ikc-btn-radius: 10px;

  --ikc-shadow: 0 12px 40px -8px rgba(17, 24, 39, .28), 0 2px 8px rgba(17, 24, 39, .1);
  --ikc-gap: 16px;
  --ikc-pad: 22px;
  --ikc-max-width: 460px;            /* Box-Breite (Layer 1) */
  --ikc-pm-max-width: 720px;         /* Präferenzen-Dialog (Layer 2) */
  --ikc-margin: 20px;                /* Abstand zum Viewport-Rand */
  --ikc-z: 2147483600;

  --ikc-focus: 0 0 0 3px rgba(37, 99, 235, .45);
  --ikc-transition: .22s;
}

/* =================================================================== *
 * Basis / Reset (nur innerhalb der Komponente)
 * =================================================================== */
.ikc-root, .ikc-root * { box-sizing: border-box; }
.ikc-root {
  font-family: var(--ikc-font-family);
  font-size: var(--ikc-font-size);
  line-height: var(--ikc-line-height);
  color: var(--ikc-text);
}
.ikc-root button { font-family: inherit; }
.ikc-link { color: var(--ikc-link); text-decoration: underline; text-underline-offset: 2px; }
.ikc-link:hover { text-decoration: none; }
.ikc-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }

/* =================================================================== *
 * Buttons (gleichwertig!)
 * =================================================================== */
.ikc-btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--ikc-btn-radius);
  padding: 11px 18px;
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  min-height: 44px;                  /* Touch-Target (WCAG 2.5.8) */
  transition: background-color var(--ikc-transition), border-color var(--ikc-transition), color var(--ikc-transition), transform .05s;
}
.ikc-btn:active { transform: translateY(1px); }
.ikc-btn:focus-visible { outline: none; box-shadow: var(--ikc-focus); }

.ikc-btn--accept { background: var(--ikc-accept-bg); color: var(--ikc-accept-text); }
.ikc-btn--accept:hover { background: var(--ikc-accept-hover-bg); }

.ikc-btn--reject { background: var(--ikc-reject-bg); color: var(--ikc-reject-text); border-color: var(--ikc-reject-border); }
.ikc-btn--reject:hover { background: var(--ikc-reject-hover-bg); }

.ikc-btn--save { background: var(--ikc-accent); color: var(--ikc-accent-text); }
.ikc-btn--save:hover { background: var(--ikc-accent-hover); }

.ikc-btn--settings { background: var(--ikc-settings-bg); color: var(--ikc-settings-text); border-color: transparent; text-decoration: underline; text-underline-offset: 3px; font-weight: 500; }
.ikc-btn--settings:hover { background: var(--ikc-settings-hover-bg); }

/* =================================================================== *
 * Layer 1 — Consent-Box (non-modal)
 * =================================================================== */
.ikc-cm-wrapper { position: fixed; inset: 0; pointer-events: none; z-index: var(--ikc-z); }
.ikc-cm-wrapper.ikc-show { pointer-events: none; }

.ikc-cm {
  position: fixed;
  width: calc(100% - 2 * var(--ikc-margin));
  max-width: var(--ikc-max-width);
  background: var(--ikc-surface);
  color: var(--ikc-text);
  border: 1px solid var(--ikc-border);
  border-radius: var(--ikc-radius);
  box-shadow: var(--ikc-shadow);
  padding: var(--ikc-pad);
  pointer-events: none;          /* ausgeblendet: keine Klicks abfangen (sonst blockiert es den Schild-Button) */
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--ikc-transition), transform var(--ikc-transition);
}
.ikc-cm:focus { outline: none; }
.ikc-cm-wrapper.ikc-show .ikc-cm { opacity: 1; transform: none; pointer-events: auto; }

/* Positionen */
.ikc-cm--bottom-left   { left: var(--ikc-margin);  bottom: var(--ikc-margin); }
.ikc-cm--bottom-right  { right: var(--ikc-margin); bottom: var(--ikc-margin); }
.ikc-cm--top-left      { left: var(--ikc-margin);  top: var(--ikc-margin); transform: translateY(-12px); }
.ikc-cm--top-right     { right: var(--ikc-margin); top: var(--ikc-margin); transform: translateY(-12px); }
.ikc-cm--bottom-center { left: 50%; bottom: var(--ikc-margin); transform: translate(-50%, 12px); }
.ikc-cm-wrapper.ikc-show .ikc-cm--bottom-center { transform: translateX(-50%); }
.ikc-cm--center {
  left: 50%; top: 50%; transform: translate(-50%, -48%);
  max-width: 520px;
}
.ikc-cm-wrapper.ikc-show .ikc-cm--center { transform: translate(-50%, -50%); }
/* Volle Breite (Bar) */
.ikc-cm--bar {
  left: 0; right: 0; bottom: 0; width: 100%; max-width: none;
  border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0;
}

.ikc-cm__top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.ikc-cm__top-spacer { flex: 1 1 auto; }
.ikc-branding { margin-bottom: 12px; }
.ikc-cm__top .ikc-branding { margin-bottom: 0; }
.ikc-logo { max-height: 34px; width: auto; display: inline-block; }

/* Sprach-Picker */
.ikc-pm__head-actions { display: flex; align-items: center; gap: 8px; }
.ikc-lang {
  font: inherit; font-size: .82rem; font-weight: 600; color: var(--ikc-muted);
  background-color: var(--ikc-bg); border: 1px solid var(--ikc-border); border-radius: 8px;
  padding: 5px 28px 5px 10px; cursor: pointer; line-height: 1.2; min-height: 34px;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center;
}
.ikc-lang:hover { color: var(--ikc-text); border-color: var(--ikc-accent); }
.ikc-lang:focus-visible { outline: none; box-shadow: var(--ikc-focus); }

.ikc-cm__title { margin: 0 0 8px; font-size: 1.12rem; font-weight: 700; }
.ikc-cm__title:focus { outline: none; }
.ikc-cm__desc { margin: 0 0 var(--ikc-gap); color: var(--ikc-text); }
.ikc-cm__desc p { margin: 0; }
.ikc-cm__links { display: inline-block; margin-top: 6px; color: var(--ikc-muted); font-size: .9em; }

.ikc-cm__actions { display: flex; flex-direction: column; gap: 10px; }
.ikc-cm__actions-primary { display: flex; gap: 10px; }
.ikc-cm__actions-primary .ikc-btn { flex: 1 1 0; }     /* gleichwertige Buttons: gleiche Breite */
.ikc-cm__actions .ikc-btn--settings { align-self: center; }

.ikc-cm__close {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px; border: 0; background: transparent;
  color: var(--ikc-muted); font-size: 16px; cursor: pointer; border-radius: 8px;
}
.ikc-cm__close:hover { background: var(--ikc-settings-hover-bg); }
.ikc-cm__close:focus-visible { outline: none; box-shadow: var(--ikc-focus); }

/* =================================================================== *
 * Layer 2 — Präferenzen (modal <dialog>)
 * =================================================================== */
.ikc-pm-wrapper { position: relative; z-index: calc(var(--ikc-z) + 1); }

dialog.ikc-pm {
  position: fixed;
  inset: 0;
  margin: auto;                  /* zentriert den modalen Dialog – robust auch wenn der
                                    Host (z. B. Tailwind-Preflight) `margin:0` auf * setzt */
  width: calc(100% - 2 * var(--ikc-margin));
  max-width: var(--ikc-pm-max-width);
  max-height: min(86vh, 760px);
  padding: 0;
  border: 1px solid var(--ikc-border);
  border-radius: var(--ikc-radius);
  background: var(--ikc-surface);
  color: var(--ikc-text);
  box-shadow: var(--ikc-shadow);
  overflow: hidden;
}
dialog.ikc-pm::backdrop { background: var(--ikc-overlay); backdrop-filter: blur(2px); }

/* Fallback ohne <dialog> */
.ikc-pm--fallback {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: calc(100% - 2 * var(--ikc-margin)); max-width: var(--ikc-pm-max-width);
  max-height: 86vh; overflow: hidden; display: none;
}
.ikc-pm-wrapper.ikc-show .ikc-pm--fallback { display: block; }
.ikc-pm-wrapper.ikc-show::before {
  content: ""; position: fixed; inset: 0; background: var(--ikc-overlay); z-index: -1;
}

.ikc-pm__inner { display: flex; flex-direction: column; max-height: min(86vh, 760px); }
.ikc-pm__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px var(--ikc-pad); border-bottom: 1px solid var(--ikc-border);
}
.ikc-pm__title { margin: 0; font-size: 1.18rem; font-weight: 700; }
.ikc-pm__title:focus { outline: none; }
.ikc-pm__close {
  width: 34px; height: 34px; border: 0; background: transparent; color: var(--ikc-muted);
  font-size: 17px; cursor: pointer; border-radius: 8px;
}
.ikc-pm__close:hover { background: var(--ikc-settings-hover-bg); }
.ikc-pm__close:focus-visible { outline: none; box-shadow: var(--ikc-focus); }

.ikc-pm__intro { margin: 0; padding: 16px var(--ikc-pad) 4px; color: var(--ikc-muted); }
.ikc-pm__sections { padding: 8px var(--ikc-pad) 4px; overflow-y: auto; flex: 1 1 auto; }

.ikc-cat { border: 1px solid var(--ikc-border); border-radius: 12px; padding: 14px 16px; margin: 12px 0; background: var(--ikc-bg); }
.ikc-cat__head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.ikc-cat__name { font-weight: 650; font-size: 1rem; }
.ikc-cat__desc { margin: 8px 0 0; color: var(--ikc-muted); font-size: .92rem; }

.ikc-cat__details { margin-top: 10px; }
.ikc-cat__details summary { cursor: pointer; color: var(--ikc-link); font-size: .88rem; user-select: none; }
.ikc-cat__details summary:focus-visible { outline: none; box-shadow: var(--ikc-focus); border-radius: 6px; }
.ikc-cat__details[open] summary { margin-bottom: 8px; }

/* Tabelle der Dienste */
.ikc-table-wrap { overflow-x: auto; border: 1px solid var(--ikc-border); border-radius: 8px; }
.ikc-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.ikc-table th, .ikc-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--ikc-border); vertical-align: top; }
.ikc-table th { background: var(--ikc-bg); font-weight: 650; color: var(--ikc-muted); position: sticky; top: 0; }
.ikc-table tr:last-child td { border-bottom: 0; }

.ikc-pm__footer {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end;
  padding: 16px var(--ikc-pad); border-top: 1px solid var(--ikc-border); background: var(--ikc-bg);
}
.ikc-pm__footer .ikc-btn { flex: 1 1 auto; }
@media (min-width: 560px) { .ikc-pm__footer .ikc-btn { flex: 0 1 auto; } }

/* =================================================================== *
 * Toggle-Switch
 * =================================================================== */
.ikc-toggle { position: relative; display: inline-flex; align-items: center; flex: 0 0 auto; cursor: pointer; }
.ikc-toggle__input { position: absolute; opacity: 0; width: 48px; height: 28px; margin: 0; cursor: pointer; }
.ikc-toggle__track {
  width: 48px; height: 28px; border-radius: 999px; background: var(--ikc-toggle-off);
  position: relative; transition: background-color var(--ikc-transition); display: inline-block;
}
.ikc-toggle__thumb {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--ikc-toggle-thumb); box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform var(--ikc-transition);
}
.ikc-toggle__input:checked + .ikc-toggle__track { background: var(--ikc-toggle-on); }
.ikc-toggle__input:checked + .ikc-toggle__track .ikc-toggle__thumb { transform: translateX(20px); }
.ikc-toggle__input:focus-visible + .ikc-toggle__track { box-shadow: var(--ikc-focus); }

.ikc-toggle--locked .ikc-toggle__badge {
  font-size: .78rem; font-weight: 600; color: var(--ikc-toggle-on);
  background: color-mix(in srgb, var(--ikc-toggle-on) 14%, transparent);
  padding: 5px 10px; border-radius: 999px; white-space: nowrap;
}

/* =================================================================== *
 * Persistenter Widerruf-Button (Floating)
 * =================================================================== */
.ikc-revoke {
  position: fixed; left: 18px; bottom: 18px; z-index: calc(var(--ikc-z) - 1);
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--ikc-border); background: var(--ikc-surface); color: var(--ikc-accent);
  box-shadow: 0 4px 14px rgba(17,24,39,.18); cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform var(--ikc-transition), box-shadow var(--ikc-transition);
}
.ikc-revoke:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(17,24,39,.24); }
.ikc-revoke:focus-visible { outline: none; box-shadow: var(--ikc-focus); }
.ikc-revoke__icon { line-height: 0; display: inline-flex; }
.ikc-revoke__icon svg { width: 23px; height: 23px; display: block; }
/* Schild-Button nur außerhalb des geöffneten Banners zeigen (sonst Overlap unten links) */
.ikc-cm-active .ikc-revoke { opacity: 0; pointer-events: none; transform: translateY(8px); }

/* =================================================================== *
 * Dark Mode
 * =================================================================== */
@media (prefers-color-scheme: dark) {
  .ikc-root:not(.ikc--light) {
    --ikc-bg: #161a20;
    --ikc-surface: #1e242c;
    --ikc-text: #e8ebf0;
    --ikc-muted: #a3acba;
    --ikc-border: #333b46;
    --ikc-overlay: rgba(0, 0, 0, .6);
    --ikc-reject-bg: #2a313a;
    --ikc-reject-text: #e8ebf0;
    --ikc-reject-hover-bg: #333b46;
    --ikc-reject-border: #3d4651;
    --ikc-settings-hover-bg: #262d36;
  }
}
.ikc-root.ikc--dark {
  --ikc-bg: #161a20; --ikc-surface: #1e242c; --ikc-text: #e8ebf0; --ikc-muted: #a3acba;
  --ikc-border: #333b46; --ikc-overlay: rgba(0,0,0,.6);
  --ikc-reject-bg: #2a313a; --ikc-reject-text: #e8ebf0; --ikc-reject-hover-bg: #333b46;
  --ikc-reject-border: #3d4651; --ikc-settings-hover-bg: #262d36;
}

/* =================================================================== *
 * Reduced Motion
 * =================================================================== */
@media (prefers-reduced-motion: reduce) {
  .ikc-root *, .ikc-cm, .ikc-toggle__track, .ikc-toggle__thumb { transition: none !important; }
}

/* =================================================================== *
 * Mobile
 * =================================================================== */
@media (max-width: 520px) {
  .ikc-root { --ikc-margin: 10px; --ikc-pad: 18px; }
  .ikc-cm { max-width: none; left: var(--ikc-margin); right: var(--ikc-margin); bottom: var(--ikc-margin); }
  .ikc-cm--bottom-right, .ikc-cm--top-left, .ikc-cm--top-right, .ikc-cm--bottom-center, .ikc-cm--center { left: var(--ikc-margin); right: var(--ikc-margin); top: auto; bottom: var(--ikc-margin); transform: translateY(12px); }
  .ikc-cm-wrapper.ikc-show .ikc-cm { transform: none; }
  .ikc-cm__actions-primary { flex-direction: column; }
  .ikc-pm__footer .ikc-btn { flex: 1 1 100%; }
}
