/* ═══════════════════════════════════════════════════════════════════════════
   BLUE HORIZON · Team Hub — Formular-Komponenten
   Ersetzt die Browser-Defaults für Checkbox, Radio, Select, Datum, Zahl
   und Farbe. Alles Progressive Enhancement: ohne JS bleiben die nativen
   Controls sichtbar und funktionsfähig.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Restliche native Elemente (Scrollbars, verbleibende Picker) dunkel halten */
:root { color-scheme: dark; }

/* ── 1. Checkbox & Radio ───────────────────────────────────────────────── */
.checkbox input[type="checkbox"],
.radio input[type="radio"],
input.cbox {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 18px; height: 18px;
  margin: 1px 0 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  cursor: pointer;
  position: relative;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.radio input[type="radio"] { border-radius: 50%; }

.checkbox input[type="checkbox"]:hover,
.radio input[type="radio"]:hover,
input.cbox:hover { border-color: var(--accent); }

.checkbox input[type="checkbox"]:checked,
input.cbox:checked {
  background-color: var(--accent-cta);
  border-color: var(--accent-cta);
  /* Häkchen als Maske, damit es die Textfarbe erbt */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FFFFFF' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-size: 13px;
  background-position: center;
  background-repeat: no-repeat;
}

.radio input[type="radio"]:checked {
  border-color: var(--accent-cta);
  background: var(--surface-2);
}
.radio input[type="radio"]:checked::after {
  content: '';
  position: absolute; inset: 3px;
  border-radius: 50%;
  background: var(--accent-cta);
}

.checkbox input[type="checkbox"]:focus-visible,
.radio input[type="radio"]:focus-visible,
input.cbox:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 147, 255, .18);
}

.checkbox input:disabled, .radio input:disabled { opacity: .45; cursor: not-allowed; }

/* Ganze Zeile als Klickfläche, dezent hinterlegt */
.checkbox, .radio {
  border-radius: var(--r-md);
  padding: var(--s-2);
  margin-left: calc(var(--s-2) * -1);
  transition: background .15s ease;
}
.checkbox:hover, .radio:hover { background: rgba(255, 255, 255, .03); }

/* Radio-Gruppe mit sichtbarer Auswahl (Serien-Geltungsbereich) */
.radio:has(input:checked), .checkbox:has(input:checked) {
  background: rgba(139, 147, 255, .07);
}

/* ── 1b. Chip als Mehrfachauswahl (Wochentage) ─────────────────────────── */
.chip-check {
  position: relative;
  cursor: pointer;
  user-select: none;
  min-width: 44px; min-height: 36px;
  justify-content: center;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.chip-check input {
  position: absolute; opacity: 0;
  width: 100%; height: 100%; left: 0; top: 0;
  margin: 0; cursor: pointer;
}
.chip-check:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip-check:has(input:checked) {
  background: rgba(139, 147, 255, .15);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.chip-check:has(input:focus-visible) {
  box-shadow: 0 0 0 3px rgba(139, 147, 255, .18);
}

/* ── 2. Schalter (Toggle) ──────────────────────────────────────────────── */
.switch { display: flex; align-items: center; gap: var(--s-3); cursor: pointer; min-height: 44px; }
.switch input {
  appearance: none; -webkit-appearance: none;
  width: 40px; height: 22px; flex-shrink: 0; margin: 0;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  position: relative; cursor: pointer;
  transition: background .18s ease, border-color .18s ease;
}
.switch input::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-tertiary);
  transition: transform .18s cubic-bezier(.16, 1, .3, 1), background .18s ease;
}
.switch input:checked { background: var(--accent-cta); border-color: var(--accent-cta); }
.switch input:checked::after { transform: translateX(18px); background: #FFFFFF; }
.switch input:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(139, 147, 255, .18); }

/* ── 3. Select ─────────────────────────────────────────────────────────── */
/* Solange JS nicht gelaufen ist, bleibt das native Select sichtbar. */
.cselect { position: relative; }
.cselect > select { position: absolute; opacity: 0; pointer-events: none; width: 100%; height: 36px; }

.cselect-trigger {
  display: flex; align-items: center; gap: var(--s-2);
  width: 100%; min-height: 36px;
  padding: 8px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  color: var(--text-primary);
  font-size: 13px; line-height: 19.5px; text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.cselect-trigger:hover { border-color: var(--border-strong); }
.cselect-trigger:focus-visible,
.cselect[data-open="true"] .cselect-trigger {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 147, 255, .1);
}
.cselect-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cselect-value.is-placeholder { color: var(--text-muted); }
.cselect-chevron { flex-shrink: 0; color: var(--text-tertiary); transition: transform .18s ease; }
.cselect[data-open="true"] .cselect-chevron { transform: rotate(180deg); }

/* position: fixed, weil das Menü sonst von overflow-Containern (Modal,
   Tabellen-Wrapper) abgeschnitten würde. Position kommt aus dem JS. */
.cselect-menu {
  position: fixed; z-index: 500;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  padding: var(--s-1);
  max-height: 280px; overflow-y: auto;
  display: none;
  animation: popIn .14s cubic-bezier(.16, 1, .3, 1);
}
.cselect[data-open="true"] .cselect-menu { display: block; }

@keyframes popIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.cselect-search {
  width: 100%; min-height: 32px;
  padding: 6px 10px; margin-bottom: var(--s-1);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary); font-size: 13px;
}
.cselect-search:focus { outline: none; border-color: var(--accent); }

.cselect-option {
  display: flex; align-items: center; gap: var(--s-2);
  min-height: 34px; padding: 6px 10px;
  border-radius: var(--r-md);
  color: var(--text-secondary); font-size: 13px;
  cursor: pointer;
}
.cselect-option:hover, .cselect-option.is-active { background: var(--surface-3); color: var(--text-primary); }
.cselect-option.is-selected { color: var(--accent); }
.cselect-option.is-selected::after {
  content: '';
  margin-left: auto; flex-shrink: 0;
  width: 14px; height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
}
.cselect-option[hidden] { display: none; }
.cselect-empty { padding: var(--s-3) 10px; color: var(--text-muted); font-size: 12px; text-align: center; }

/* ── 4. Datum & Uhrzeit ────────────────────────────────────────────────── */
.cdate { position: relative; }
.cdate > input { position: absolute; opacity: 0; pointer-events: none; width: 100%; height: 36px; }

.cdate-trigger {
  display: flex; align-items: center; gap: var(--s-2);
  width: 100%; min-height: 36px;
  padding: 8px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  color: var(--text-primary);
  font-size: 13px; text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.cdate-trigger:hover { border-color: var(--border-strong); }
.cdate-trigger:focus-visible,
.cdate[data-open="true"] .cdate-trigger {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 147, 255, .1);
}
.cdate-icon { flex-shrink: 0; color: var(--text-tertiary); }
.cdate-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cdate-value.is-placeholder { color: var(--text-muted); }
.cdate-clear {
  flex-shrink: 0; width: 20px; height: 20px;
  display: none; place-items: center;
  border: none; background: transparent; padding: 0;
  color: var(--text-muted); border-radius: 50%; cursor: pointer;
}
.cdate:hover .cdate-clear { display: grid; }
.cdate-clear:hover { background: var(--surface-3); color: var(--error); }

.cdate-panel {
  position: fixed; z-index: 500;
  width: 296px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  padding: var(--s-3);
  display: none;
  animation: popIn .14s cubic-bezier(.16, 1, .3, 1);
}
.cdate[data-open="true"] .cdate-panel { display: block; }

.cdate-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-2); margin-bottom: var(--s-3);
}
.cdate-nav-btn {
  width: 28px; height: 28px; flex-shrink: 0;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; color: var(--text-tertiary); cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.cdate-nav-btn:hover { background: var(--surface-3); color: var(--text-primary); }
.cdate-title {
  flex: 1; text-align: center;
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  background: none; border: 0; cursor: pointer; border-radius: var(--r-md);
  min-height: 28px;
}
.cdate-title:hover { color: var(--accent); }

.cdate-dow, .cdate-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cdate-dow span {
  text-align: center; font-size: 10px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; padding-bottom: 4px;
}
.cdate-day {
  aspect-ratio: 1;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; color: var(--text-secondary);
  font-size: 12px; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.cdate-day:hover { background: var(--surface-3); color: var(--text-primary); }
.cdate-day.is-outside { color: var(--text-muted); opacity: .5; }
.cdate-day.is-today { border-color: var(--accent); color: var(--accent); }
.cdate-day.is-selected { background: var(--accent-cta); border-color: var(--accent-cta); color: #FFFFFF; font-weight: 600; }
.cdate-day:disabled { opacity: .25; cursor: not-allowed; }

/* Monats- und Jahresauswahl */
.cdate-months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.cdate-month {
  min-height: 40px; border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent;
  color: var(--text-secondary); font-size: 12px; cursor: pointer;
}
.cdate-month:hover { background: var(--surface-3); color: var(--text-primary); }
.cdate-month.is-selected { background: var(--accent-cta); color: #FFFFFF; }

.cdate-time {
  display: flex; align-items: center; gap: var(--s-2);
  margin-top: var(--s-3); padding-top: var(--s-3);
  border-top: 1px solid var(--border);
}
.cdate-time-label { font-size: 12px; color: var(--text-tertiary); flex: 1; }
.cdate-spin {
  display: flex; align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.cdate-spin input {
  width: 34px; min-height: 30px; padding: 0;
  background: transparent; border: 0; color: var(--text-primary);
  font-size: 13px; text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.cdate-spin input::-webkit-outer-spin-button,
.cdate-spin input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cdate-spin input:focus { outline: none; background: var(--surface-3); }
.cdate-spin-sep { color: var(--text-muted); font-size: 13px; }

.cdate-foot {
  display: flex; gap: var(--s-2);
  margin-top: var(--s-3); padding-top: var(--s-3);
  border-top: 1px solid var(--border);
}
.cdate-quick {
  flex: 1; min-height: 30px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: transparent; color: var(--text-secondary);
  font-size: 12px; cursor: pointer;
  transition: all .15s ease;
}
.cdate-quick:hover { border-color: var(--accent); color: var(--accent); }

/* ── 5. Zahl mit Stepper ───────────────────────────────────────────────── */
.cnum { display: flex; align-items: stretch; }
.cnum input {
  flex: 1; min-width: 0;
  border-radius: var(--r-lg) 0 0 var(--r-lg);
  border-right: 0;
  text-align: left;
  -moz-appearance: textfield;
}
.cnum input::-webkit-outer-spin-button,
.cnum input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cnum-btns { display: flex; flex-direction: column; width: 28px; flex-shrink: 0; }
.cnum-btn {
  flex: 1;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-tertiary);
  cursor: pointer; padding: 0; font-size: 10px; line-height: 1;
  transition: background .15s ease, color .15s ease;
}
.cnum-btn:first-child { border-radius: 0 var(--r-lg) 0 0; border-bottom: 0; }
.cnum-btn:last-child  { border-radius: 0 0 var(--r-lg) 0; }
.cnum-btn:hover { background: var(--surface-3); color: var(--accent); }
.cnum-btn:active { background: var(--accent-cta); color: #FFFFFF; }

/* ── 6. Farbauswahl ────────────────────────────────────────────────────── */
.ccolor { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.ccolor > input[type="color"] { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.ccolor-swatch {
  width: 28px; height: 28px;
  border-radius: var(--r-md);
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
  cursor: pointer; padding: 0;
  transition: transform .12s ease, border-color .12s ease;
}
.ccolor-swatch:hover { transform: scale(1.1); }
.ccolor-swatch.is-selected { border-color: var(--text-primary); }
.ccolor-custom {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  border: 1px dashed var(--border-strong);
  background: transparent; color: var(--text-tertiary);
  cursor: pointer; padding: 0;
}
.ccolor-custom:hover { border-color: var(--accent); color: var(--accent); }
.ccolor-value {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-muted); margin-left: var(--s-1);
}

/* ── 7. Mobile: Panels als zentriertes Sheet ───────────────────────────── */
@media (max-width: 639px) {
  /* !important, weil die Desktop-Position aus dem JS als Inline-Style kommt */
  .cselect[data-open="true"] .cselect-menu,
  .cdate[data-open="true"] .cdate-panel {
    position: fixed;
    top: auto !important; bottom: 0 !important;
    left: 0 !important; right: 0 !important;
    width: auto !important; max-height: 70vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-bottom: 0;
    padding: var(--s-4);
    animation: sheetUp .2s cubic-bezier(.16, 1, .3, 1);
  }
  @keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

  .cdate-day { font-size: 14px; }
  .cselect-option { min-height: 44px; }
  .cdate-quick { min-height: 40px; }

  /* Abdunkelung hinter dem Sheet */
  .form-sheet-scrim {
    position: fixed; inset: 0; z-index: 390;
    background: rgba(0, 0, 0, .6);
  }
}

@media (min-width: 640px) {
  .form-sheet-scrim { display: none; }
}
