/* ═══════════════════════════════════════════════════════════════════════════
 * Kallisto Design System — Extended Components & Animations
 * New UI elements, loading states, empty states, and motion keyframes.
 * ═══════════════════════════════════════════════════════════════════════════ */

/* ── Segmented Control ─────────────────────────────────────────────────── */
.kal-seg {
  display: inline-flex; padding: 3px; border-radius: var(--r-full);
  background: var(--glass-bg); border: 1px solid var(--glass-stroke-2); gap: 2px;
}
.kal-seg__item {
  padding: 7px 16px; border-radius: var(--r-full); font-size: 12px; font-weight: 500;
  color: var(--ink-2); cursor: pointer; transition: all 0.2s ease;
  border: none; background: transparent; font-family: var(--font-sans);
}
.kal-seg__item:hover { color: var(--ink); }
.kal-seg__item--active {
  background: var(--violet); color: var(--bg-1); box-shadow: var(--shadow-sm);
}

/* ── Radio Button ──────────────────────────────────────────────────────── */
.kal-radio { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--ink); }
.kal-radio__dot {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong);
  position: relative; transition: all 0.2s; flex-shrink: 0;
}
.kal-radio--on .kal-radio__dot { border-color: var(--violet); }
.kal-radio--on .kal-radio__dot::after {
  content: ''; position: absolute; inset: 3px; border-radius: 50%; background: var(--violet);
  animation: kal-scale-in 0.2s ease;
}

/* ── Checkbox ──────────────────────────────────────────────────────────── */
.kal-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--ink); }
.kal-check__box {
  width: 18px; height: 18px; border-radius: 5px; border: 2px solid var(--line-strong);
  display: flex; align-items: center; justify-content: center; transition: all 0.2s; flex-shrink: 0;
}
.kal-check--on .kal-check__box {
  background: var(--violet); border-color: var(--violet);
  animation: kal-scale-in 0.2s ease;
}
.kal-check__tick { display: none; stroke: var(--bg-1); }
.kal-check--on .kal-check__tick { display: block; }

/* ── Range Slider ──────────────────────────────────────────────────────── */
.kal-range {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  border-radius: 3px; background: var(--line); outline: none; cursor: pointer;
}
.kal-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--violet); cursor: pointer; box-shadow: var(--shadow-md);
  border: 3px solid var(--bg-1); transition: transform 0.15s;
}
.kal-range::-webkit-slider-thumb:hover { transform: scale(1.15); }
.kal-range::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: var(--violet);
  cursor: pointer; box-shadow: var(--shadow-md); border: 3px solid var(--bg-1);
}

/* ── Bottom Navigation ─────────────────────────────────────────────────── */
.kal-bottomnav {
  display: inline-flex; align-items: center; gap: 4px; padding: 8px 16px;
  border-radius: var(--r-full); background: var(--glass-bg-strong);
  backdrop-filter: blur(20px) saturate(1.6); border: 1px solid var(--glass-stroke-2);
  box-shadow: var(--shadow-lg);
}
.kal-bottomnav__item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 18px; border-radius: var(--r-lg); font-size: 10px;
  font-family: var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink-3); cursor: pointer; transition: all 0.2s;
  border: none; background: transparent;
}
.kal-bottomnav__item:hover { color: var(--ink-2); }
.kal-bottomnav__item--active {
  background: var(--glass-bg); color: var(--violet); font-weight: 600;
}

/* ── Floating Action Button ────────────────────────────────────────────── */
.kal-fab {
  width: 48px; height: 48px; border-radius: 50%; background: var(--violet); color: var(--bg-1);
  display: flex; align-items: center; justify-content: center; cursor: pointer; border: none;
  box-shadow: var(--shadow-lg), 0 0 20px color-mix(in oklch, var(--violet) 30%, transparent);
  transition: all 0.25s cubic-bezier(0.2,0.8,0.2,1);
}
.kal-fab:hover { transform: scale(1.1) translateY(-2px); }
.kal-fab:active { transform: scale(0.95); }

/* ── Badge / Notification Dot ──────────────────────────────────────────── */
.kal-badge-wrap { position: relative; display: inline-flex; }
.kal-badge-dot {
  position: absolute; top: -2px; right: -2px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--bad); border: 2px solid var(--bg-1);
  animation: kal-badge-ping 2s cubic-bezier(0,0,0.2,1) infinite;
}
.kal-badge-count {
  position: absolute; top: -6px; right: -8px; min-width: 16px; height: 16px;
  border-radius: 8px; background: var(--bad); color: #fff; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
  border: 2px solid var(--bg-1);
}

/* ── Breadcrumbs ───────────────────────────────────────────────────────── */
.kal-crumbs {
  display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3);
  font-family: var(--font-sans);
}
.kal-crumbs__sep { opacity: 0.4; font-size: 10px; }
.kal-crumbs a { color: var(--ink-2); transition: color 0.15s; }
.kal-crumbs a:hover { color: var(--violet); }
.kal-crumbs__current { color: var(--ink); font-weight: 500; }

/* ── Select / Dropdown ─────────────────────────────────────────────────── */
.kal-select {
  padding: 10px 36px 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background-color: var(--glass-bg); color: var(--ink); font-size: 13px;
  font-family: var(--font-sans); appearance: none; cursor: pointer; transition: border-color 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.kal-select:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px color-mix(in oklch, var(--violet) 15%, transparent); }

/* ── Custom Select (KalSelect / xselect) ──────────────────────────────── */
.kal-xselect { position: relative; display: inline-block; min-width: 180px; font-family: var(--font-sans); z-index: 1; }
.kal-xselect--open { z-index: 100; }
.kal-xselect--full { display: block; width: 100%; }
/* When a dropdown is open, parent containers must not clip the menu */
.kal-card:has(.kal-xselect--open),
label:has(.kal-xselect--open),
div:has(> .kal-xselect--open) { overflow: visible !important; }
.kal-card:has(.kal-xselect--open) { z-index: 10; }
.kal-xselect__trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px 10px 14px; font-size: 13px; font-weight: 500; color: var(--ink);
  background: var(--glass-bg); backdrop-filter: blur(20px) saturate(1.5); -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid var(--glass-stroke-2, var(--line)); border-radius: var(--r-md);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), var(--shadow-sm);
  cursor: pointer; user-select: none; text-align: left;
  transition: border-color .18s var(--ease-standard), box-shadow .18s var(--ease-standard),
              transform .12s var(--ease-decelerate, ease-out), background .18s var(--ease-standard);
}
.kal-xselect__trigger:hover {
  border-color: color-mix(in oklch, var(--violet) 25%, var(--glass-stroke-2, var(--line)));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45), var(--shadow-md);
  transform: translateY(-1px);
}
.kal-xselect__trigger:focus-visible {
  outline: none; border-color: var(--violet);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45), 0 0 0 3px color-mix(in oklch, var(--violet) 18%, transparent);
}
.kal-xselect__value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kal-xselect__placeholder { color: var(--ink-3); }
.kal-xselect__chev {
  width: 14px; height: 14px; flex-shrink: 0; color: var(--ink-3);
  transition: transform .22s var(--ease-standard), color .18s;
}
.kal-xselect--open .kal-xselect__trigger {
  border-color: var(--violet);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45), 0 0 0 3px color-mix(in oklch, var(--violet) 18%, transparent);
}
.kal-xselect--open .kal-xselect__chev { transform: rotate(180deg); color: var(--violet); }
.kal-xselect__menu {
  z-index: 99999; padding: 6px; box-sizing: border-box;
  background: var(--glass-bg-opaque, rgba(255,255,255,0.94));
  backdrop-filter: blur(32px) saturate(1.8); -webkit-backdrop-filter: blur(32px) saturate(1.8);
  border: 1px solid var(--glass-stroke, rgba(255,255,255,0.85)); border-radius: var(--r-lg);
  box-shadow: 0 4px 16px rgba(60,40,110,.12), 0 16px 48px rgba(60,40,110,.16), inset 0 1px 0 rgba(255,255,255,0.5);
  transform-origin: top center; animation: kalMenuIn .18s var(--ease-decelerate, ease-out);
  max-height: 260px; overflow-y: auto; overflow-x: hidden;
}
@keyframes kalMenuIn { 0% { opacity:0; transform:translateY(-4px) scale(.98); } 100% { opacity:1; transform:translateY(0) scale(1); } }
.kal-xselect__option {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  font-size: 13px; color: var(--ink); border-radius: var(--r-sm); cursor: pointer;
  transition: background .14s var(--ease-standard), color .14s; position: relative;
}
.kal-xselect__option + .kal-xselect__option { margin-top: 2px; }
.kal-xselect__option:hover, .kal-xselect__option--active { background: color-mix(in oklch, var(--violet) 12%, transparent); }
.kal-xselect__option--selected { background: color-mix(in oklch, var(--violet) 18%, transparent); font-weight: 600; }
.kal-xselect__option--selected.kal-xselect__option--active { background: color-mix(in oklch, var(--violet) 26%, transparent); }
.kal-xselect__check {
  width: 14px; height: 14px; flex-shrink: 0; color: var(--violet);
  opacity: 0; transform: scale(.6); transition: opacity .18s, transform .18s var(--ease-decelerate, ease-out);
}
.kal-xselect__option--selected .kal-xselect__check { opacity: 1; transform: scale(1); }
.kal-xselect__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Tooltip ───────────────────────────────────────────────────────────── */
.kal-tooltip-wrap { position: relative; display: inline-flex; }
.kal-tooltip {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  padding: 6px 10px; border-radius: 8px; background: var(--ink); color: var(--bg-1);
  font-size: 11px; font-weight: 500; white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; transform: translateX(-50%) translateY(4px);
}
.kal-tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--ink);
}
.kal-tooltip-wrap:hover .kal-tooltip { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Divider ───────────────────────────────────────────────────────────── */
.kal-divider { height: 1px; background: var(--line); margin: 20px 0; }

/* ═══════════════════════════════════════════════════════════════════════════
 * LOADING ANIMATIONS
 * ═══════════════════════════════════════════════════════════════════════════ */

/* ── Skeleton ──────────────────────────────────────────────────────────── */
.kal-skel {
  background: var(--line); border-radius: var(--r-sm); position: relative; overflow: hidden;
}
.kal-skel::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--glass-bg) 50%, transparent 100%);
  animation: kal-shimmer 1.8s ease-in-out infinite;
}
.kal-skel--circle { border-radius: 50%; }
.kal-skel--text { height: 12px; border-radius: 6px; }
.kal-skel--title { height: 18px; width: 60%; border-radius: 8px; }
.kal-skel--avatar { width: 40px; height: 40px; border-radius: 50%; }
.kal-skel--btn { height: 36px; width: 100px; border-radius: var(--r-full); }

/* ── Pulse Dots ────────────────────────────────────────────────────────── */
.kal-dots { display: inline-flex; gap: 6px; align-items: center; }
.kal-dots__dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--violet);
  animation: kal-dot-pulse 1.4s ease-in-out infinite;
}
.kal-dots__dot:nth-child(2) { animation-delay: 0.2s; }
.kal-dots__dot:nth-child(3) { animation-delay: 0.4s; }

/* ── Ring Spinner (variant sizes) ──────────────────────────────────────── */
.kal-ring {
  border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--violet);
  animation: kal-spin 0.8s linear infinite;
}
.kal-ring--sm { width: 20px; height: 20px; border-width: 2px; }
.kal-ring--md { width: 32px; height: 32px; border-width: 3px; }
.kal-ring--lg { width: 48px; height: 48px; border-width: 4px; }

/* ── Bar Spinner (equalizer) ───────────────────────────────────────────── */
.kal-bar-spin { display: inline-flex; gap: 3px; align-items: flex-end; height: 24px; }
.kal-bar-spin__bar {
  width: 4px; border-radius: 2px; background: var(--violet);
  animation: kal-bar-bounce 1.2s ease-in-out infinite;
}
.kal-bar-spin__bar:nth-child(1) { animation-delay: 0s; }
.kal-bar-spin__bar:nth-child(2) { animation-delay: 0.1s; }
.kal-bar-spin__bar:nth-child(3) { animation-delay: 0.2s; }
.kal-bar-spin__bar:nth-child(4) { animation-delay: 0.3s; }
.kal-bar-spin__bar:nth-child(5) { animation-delay: 0.15s; }

/* ── Loading Bar (indeterminate) ───────────────────────────────────────── */
.kal-loadbar {
  width: 100%; height: 3px; border-radius: 2px; background: var(--line);
  overflow: hidden; position: relative;
}
.kal-loadbar::after {
  content: ''; position: absolute; height: 100%; width: 40%; border-radius: inherit;
  background: var(--violet); animation: kal-loadbar-slide 1.5s ease-in-out infinite;
}

/* ── Breathing Pulse ───────────────────────────────────────────────────── */
.kal-breathe { animation: kal-breathe 2.5s ease-in-out infinite; }

/* ── Orbit Spinner ─────────────────────────────────────────────────────── */
.kal-orbit {
  width: 40px; height: 40px; position: relative; animation: kal-spin 2s linear infinite;
}
.kal-orbit__dot {
  position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--violet);
}
.kal-orbit__dot:nth-child(1) { top: 0; left: 50%; transform: translateX(-50%); }
.kal-orbit__dot:nth-child(2) { bottom: 0; left: 50%; transform: translateX(-50%); opacity: 0.4; }

/* ═══════════════════════════════════════════════════════════════════════════
 * EMPTY STATE ANIMATIONS
 * ═══════════════════════════════════════════════════════════════════════════ */
.kal-empty-v2 {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center; color: var(--ink-3);
}
.kal-empty-v2__icon {
  width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; margin-bottom: 16px; background: var(--lavender);
  color: var(--violet); animation: kal-float 3s ease-in-out infinite;
}
.kal-empty-v2__title {
  font-size: 16px; font-weight: 600; color: var(--ink); margin-bottom: 4px;
}
.kal-empty-v2__desc { font-size: 13px; max-width: 280px; line-height: 1.5; }

/* ═══════════════════════════════════════════════════════════════════════════
 * KEYFRAMES
 * ═══════════════════════════════════════════════════════════════════════════ */
@keyframes kal-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
@keyframes kal-dot-pulse {
  0%, 100% { transform: scale(0.6); opacity: 0.3; }
  50% { transform: scale(1); opacity: 1; }
}
@keyframes kal-spin { to { transform: rotate(360deg); } }
@keyframes kal-bar-bounce {
  0%, 100% { height: 8px; opacity: 0.5; }
  50% { height: 24px; opacity: 1; }
}
@keyframes kal-loadbar-slide {
  0% { left: -40%; }
  100% { left: 100%; }
}
@keyframes kal-breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.97); }
}
@keyframes kal-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes kal-sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}
@keyframes kal-bounce-in {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes kal-fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes kal-scale-in {
  from { transform: scale(0); }
  to { transform: scale(1); }
}
@keyframes kal-badge-ping {
  0% { box-shadow: 0 0 0 0 color-mix(in oklch, var(--bad) 40%, transparent); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes kal-ripple-out {
  0% { transform: scale(0.5); opacity: 0.6; }
  100% { transform: scale(2.5); opacity: 0; }
}
@keyframes kal-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}
@keyframes kal-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}

/* ── Stagger utility (apply --i per child) ─────────────────────────────── */
.kal-stagger-v2 > * {
  animation: kal-fade-up 0.4s cubic-bezier(0,0,0.2,1) backwards;
  animation-delay: calc(80ms * var(--i, 0));
}

/* ── entrance helpers ──────────────────────────────────────────────────── */
.anim-float { animation: kal-float 3s ease-in-out infinite; }
.anim-sway { animation: kal-sway 4s ease-in-out infinite; }
.anim-breathe { animation: kal-breathe 2.5s ease-in-out infinite; }
.anim-bounce-in { animation: kal-bounce-in 0.5s cubic-bezier(0.2,0.8,0.2,1) both; }
.anim-shake { animation: kal-shake 0.5s ease-in-out; }
.anim-wiggle { animation: kal-wiggle 2s ease-in-out infinite; }
