/* ============================================
   FIDEM Components
   Buttons, inputs, modals, toasts
   ============================================ */

/* --- Button base --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: var(--btn-height);
  min-width: var(--touch-min);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--font-size-base);
  transition: background var(--transition-fast),
              transform var(--transition-fast),
              opacity var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* --- Primary --- */
.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

/* --- Danger --- */
.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

/* --- Ghost --- */
.btn-ghost {
  background: transparent;
  color: var(--text-sub);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--text);
}

/* --- Icon button --- */
.btn-icon {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  padding: var(--space-sm);
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--surface-alt);
}

.btn-icon svg {
  width: 24px;
  height: 24px;
}

/* --- Large button (CTA) --- */
.btn-lg {
  width: 100%;
  min-height: 56px;
  font-size: var(--font-size-lg);
  border-radius: var(--radius-md);
}

/* --- Button group --- */
.btn-group {
  display: flex;
  gap: var(--space-sm);
  width: 100%;
}

.btn-group .btn {
  flex: 1;
}

/* --- Input base --- */
.input {
  width: 100%;
  min-height: var(--btn-height);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--font-size-base);
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
}

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

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}

.input.error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15);
}

/* --- Input group (label + input + error) --- */
.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  width: 100%;
}

.input-label {
  font-size: var(--font-size-sm);
  color: var(--text-sub);
  font-weight: 500;
}

.input-error {
  font-size: var(--font-size-xs);
  color: var(--danger);
  min-height: 16px;
}

/* --- Select --- */
.select {
  width: 100%;
  min-height: var(--btn-height);
  padding: var(--space-sm) var(--space-md);
  padding-right: var(--space-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--font-size-base);
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}

/* --- Checkbox --- */
.checkbox {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  cursor: pointer;
  min-height: var(--touch-min);
  padding: var(--space-xs) 0;
}

.checkbox input[type="checkbox"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 1px;
  border: 2px solid var(--text-sub);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}

.checkbox input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid var(--bg);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.checkbox-label {
  font-size: var(--font-size-sm);
  color: var(--text-sub);
  line-height: 1.5;
}

.checkbox-label a {
  color: var(--accent);
  text-decoration: underline;
}

/* --- Modal (bottom sheet on mobile) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: var(--z-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal),
              visibility var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-lg);
  padding-bottom: calc(var(--space-lg) + var(--safe-bottom));
  z-index: var(--z-modal);
  transform: translateY(100%);
  transition: transform var(--transition-normal);
  max-height: 80dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  margin: 0 auto var(--space-md);
}

.modal-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  margin-bottom: var(--space-md);
}

@media (min-width: 1024px) {
  .modal {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%) scale(0.95);
    width: min(var(--max-width), 90vw);
    border-radius: var(--radius-lg);
    max-height: 80vh;
  }

  .modal-overlay.active .modal {
    transform: translate(-50%, -50%) scale(1);
  }

  .modal-handle {
    display: none;
  }
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  top: calc(var(--space-md) + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: min(calc(100% - var(--space-lg) * 2), var(--max-width));
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: 0 4px 16px var(--shadow);
  pointer-events: auto;
  animation: toast-in 300ms ease-out forwards;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--font-size-sm);
}

.toast.toast-out {
  animation: toast-out 300ms ease-in forwards;
}

.toast-success {
  border-left: 3px solid var(--success);
}

.toast-error {
  border-left: 3px solid var(--danger);
}

.toast-info {
  border-left: 3px solid var(--accent);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-16px);
  }
}

/* --- Progress bar --- */
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--transition-normal);
}

/* --- Badge --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent);
}

.badge-danger {
  background: rgba(255, 107, 107, 0.15);
  color: var(--danger);
}

/* --- Divider --- */
.divider {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: var(--space-md) 0;
}

/* --- Avatar placeholder --- */
.avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  font-weight: 600;
  flex-shrink: 0;
}

/* --- Card --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

/* --- Countdown / Timer --- */
.timer {
  font-size: var(--font-size-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* --- Status dot --- */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--success);
  display: inline-block;
}

.status-dot.offline {
  background: var(--text-dim);
}

/* --- Call action buttons --- */
.btn-call-action {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast),
              opacity var(--transition-fast);
}

.btn-call-action:active {
  transform: scale(0.92);
}

.btn-call-mic {
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text);
}

.btn-call-mic.muted {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-call-hangup {
  background: var(--danger);
  color: #fff;
}

.btn-call-hangup:hover {
  background: var(--danger-hover);
}

/* --- Skeleton loader --- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--surface-alt) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
