/* ============================================================
   COMPONENTS.CSS — UI Components
   PWA CSS Library by CSTRSK
   ============================================================ */

/* ── BUTTONS ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--tap-min);
  padding: 0 var(--space-5);
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  border-radius: var(--radius-lg);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn:disabled,
.btn.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Ripple */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-default);
}
.btn:active::after { opacity: 0.1; }

/* Variants */
.btn--primary {
  background: var(--interactive-primary);
  color: var(--interactive-primary-text);
  border-color: var(--interactive-primary);
}
.btn--primary:hover:not(:disabled) {
  background: var(--interactive-primary-hover);
  border-color: var(--interactive-primary-hover);
  box-shadow: var(--shadow-md);
}

.btn--secondary {
  background: var(--interactive-secondary);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--interactive-secondary-hover);
}

.btn--outline {
  background: transparent;
  color: var(--interactive-primary);
  border-color: var(--interactive-primary);
}
.btn--outline:hover:not(:disabled) {
  background: var(--color-brand-50);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn--ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn--danger {
  background: var(--interactive-destructive);
  color: var(--color-neutral-0);
  border-color: var(--interactive-destructive);
}
.btn--danger:hover:not(:disabled) {
  filter: brightness(0.9);
}

/* Sizes */
.btn--sm {
  height: 36px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
}

.btn--lg {
  height: 52px;
  padding: 0 var(--space-8);
  font-size: var(--text-md);
  border-radius: var(--radius-xl);
}

.btn--full { width: 100%; }
.btn--icon {
  width: var(--tap-min);
  padding: 0;
  border-radius: var(--radius-full);
}
.btn--icon.btn--sm {
  width: 36px;
  height: 36px;
}

/* Loading state */
.btn.is-loading .btn__text { opacity: 0; }
.btn.is-loading::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(var(--bottombar-height) + var(--space-4) + var(--safe-bottom));
  right: calc(var(--space-4) + var(--safe-right));
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--interactive-primary);
  color: white;
  box-shadow: var(--shadow-xl);
  z-index: var(--z-sticky);
  transition: var(--transition-normal);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:hover { transform: scale(1.05); box-shadow: var(--shadow-2xl); }
.fab:active { transform: scale(0.96); }

/* ── FORM INPUTS ────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1-5);
}

.field__label {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.field__error {
  font-size: var(--text-xs);
  color: var(--color-error);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.input {
  display: block;
  width: 100%;
  height: var(--tap-min);
  padding: 0 var(--space-3);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-lg);
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow   var(--duration-fast) var(--ease-default);
}

.input::placeholder { color: var(--text-tertiary); }

.input:focus {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-brand);
  outline: none;
}

.input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-subtle);
}

.input.is-error { border-color: var(--color-error); }
.input.is-error:focus { box-shadow: 0 0 0 3px rgba(220,38,38,.2); }

.input.is-success { border-color: var(--color-success); }

/* Textarea */
.input--textarea {
  height: auto;
  min-height: 100px;
  padding: var(--space-3);
  resize: vertical;
  line-height: var(--leading-relaxed);
}

/* Input with icon */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .input {
  padding-left: var(--space-10);
}

.input-group .input-group__icon {
  position: absolute;
  left: var(--space-3);
  color: var(--icon-default);
  pointer-events: none;
  width: 20px; height: 20px;
}

.input-group .input-group__action {
  position: absolute;
  right: var(--space-2);
}

/* Search input */
.input--search {
  border-radius: var(--radius-full);
  padding-left: var(--space-10);
}

/* Select */
.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' viewBox='0 0 24 24'%3E%3Cpath stroke='%2371717a' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-10);
}

/* Toggle / Checkbox / Radio */
.toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  user-select: none;
}

.toggle__switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  transition: background var(--duration-normal) var(--ease-default);
  flex-shrink: 0;
}

.toggle__switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: white;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-normal) var(--ease-spring);
}

.toggle input:checked ~ .toggle__switch {
  background: var(--interactive-primary);
}
.toggle input:checked ~ .toggle__switch::after {
  transform: translateX(20px);
}

.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }

/* ── CARDS ──────────────────────────────────────────────────── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.card--elevated {
  border: none;
  box-shadow: var(--shadow-md);
}

.card--interactive {
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
  -webkit-tap-highlight-color: transparent;
}
.card--interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.card--interactive:active {
  transform: translateY(0);
}

.card__media {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.card__body {
  padding: var(--space-4);
}

.card__header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-default);
}

.card__footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border-default);
  background: var(--bg-subtle);
}

.card__title {
  font-size: var(--text-md);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.card__subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ── BADGES ─────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0-5) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-full);
  line-height: 1.4;
}

.badge--default  { background: var(--bg-subtle); color: var(--text-secondary); }
.badge--brand    { background: var(--color-brand-100); color: var(--color-brand-700); }
.badge--success  { background: var(--color-success-bg); color: var(--color-success); }
.badge--warning  { background: var(--color-warning-bg); color: var(--color-warning); }
.badge--error    { background: var(--color-error-bg);   color: var(--color-error); }
.badge--info     { background: var(--color-info-bg);    color: var(--color-info); }

/* Dot variant */
.badge--dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
  flex-shrink: 0;
}

/* Notification count */
.badge--count {
  min-width: 20px;
  height: 20px;
  padding: 0 var(--space-1-5);
  background: var(--interactive-destructive);
  color: white;
  font-size: 11px;
}

/* ── LIST ITEMS ─────────────────────────────────────────────── */

.list {
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-default);
  transition: background var(--duration-fast) var(--ease-default);
  -webkit-tap-highlight-color: transparent;
}

.list-item:last-child { border-bottom: none; }

.list-item--interactive {
  cursor: pointer;
}
.list-item--interactive:hover { background: var(--bg-subtle); }
.list-item--interactive:active { background: var(--bg-subtle); }

.list-item__icon   { flex-shrink: 0; width: 40px; height: 40px; }
.list-item__body   { flex: 1; min-width: 0; }
.list-item__title  { font-weight: var(--font-weight-medium); color: var(--text-primary); truncate; }
.list-item__sub    { font-size: var(--text-sm); color: var(--text-secondary); truncate; }
.list-item__trail  { flex-shrink: 0; color: var(--text-tertiary); }

/* ── AVATAR ─────────────────────────────────────────────────── */

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--color-brand-100);
  color: var(--color-brand-700);
  font-weight: var(--font-weight-semibold);
  flex-shrink: 0;
}

.avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
}

.avatar--xs { width: 24px; height: 24px; font-size: var(--text-xs); }
.avatar--sm { width: 32px; height: 32px; font-size: var(--text-sm); }
.avatar--md { width: 40px; height: 40px; font-size: var(--text-base); }
.avatar--lg { width: 48px; height: 48px; font-size: var(--text-md); }
.avatar--xl { width: 64px; height: 64px; font-size: var(--text-lg); }
.avatar--2xl{ width: 96px; height: 96px; font-size: var(--text-xl); }

/* Avatar group */
.avatar-group {
  display: flex;
}
.avatar-group .avatar {
  border: 2px solid var(--bg-surface);
  margin-left: -8px;
}
.avatar-group .avatar:first-child { margin-left: 0; }

/* ── PROGRESS / SKELETON ────────────────────────────────────── */

.progress {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: var(--interactive-primary);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

.progress--thin   { height: 3px; }
.progress--thick  { height: 10px; }

.skeleton {
  background: var(--color-neutral-200);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}

@media (prefers-color-scheme: dark) {
  .skeleton { background: var(--color-neutral-800); }
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,.15) 50%,
    transparent 100%
  );
  animation: shimmer 1.5s ease-in-out infinite;
  background-size: 200% 100%;
}

@keyframes shimmer {
  from { background-position: -200% 0; }
  to   { background-position:  200% 0; }
}

/* ── DIVIDER WITH LABEL ─────────────────────────────────────── */

.divider-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}
.divider-label::before,
.divider-label::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border-default);
}

/* ── ICON BUTTON ────────────────────────────────────────────── */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: var(--radius-full);
  color: var(--icon-default);
  transition: var(--transition-fast);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--bg-subtle); color: var(--text-primary); }
.icon-btn:active { background: var(--interactive-secondary-hover); }

/* ── CHIP / TAG ─────────────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1-5) var(--space-3);
  background: var(--bg-subtle);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.is-active {
  background: var(--color-brand-100);
  border-color: var(--color-brand-300);
  color: var(--color-brand-700);
}

/* ── STAT / KPI CARD ────────────────────────────────────────── */

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
}

.stat-card__label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-2);
}

.stat-card__value {
  font-size: var(--text-3xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--space-1);
}

.stat-card__change {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
}
.stat-card__change--up   { color: var(--color-success); }
.stat-card__change--down { color: var(--color-error); }

/* ── EMPTY STATE ────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-16) var(--space-6);
  text-align: center;
}

.empty-state__icon {
  width: 64px; height: 64px;
  color: var(--text-tertiary);
}

.empty-state__title {
  font-size: var(--text-md);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.empty-state__text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  max-width: 280px;
}
