/**
 * UI Components Styles
 * ClassGame 프로젝트 재사용 가능한 UI 컴포넌트 스타일
 */

/* ============================================
   버튼 (.btn)
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

/* 버튼 색상 변형 */
.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-dark);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.95);
}

.btn-secondary {
  background-color: var(--secondary);
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #0284c7;
}

.btn-success {
  background-color: var(--success);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background-color: #16a34a;
}

.btn-warning {
  background-color: var(--warning);
  color: white;
}

.btn-warning:hover:not(:disabled) {
  background-color: #d97706;
}

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

.btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
}

.btn-outline {
  background-color: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-outline:hover:not(:disabled) {
  background-color: var(--primary-light);
}

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

.btn-ghost:hover:not(:disabled) {
  background-color: var(--bg);
  border-color: #cbd5e1;
}

/* 버튼 크기 변형 */
.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-lg {
  padding: 14px 24px;
  font-size: 16px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
}

.btn-icon.btn-sm {
  width: 32px;
  height: 32px;
}

/* ============================================
   뱃지 (.badge)
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-primary {
  background-color: var(--primary-light);
  color: var(--primary-dark);
}

.badge-success {
  background-color: #dcfce7;
  color: #166534;
}

.badge-warning {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-danger {
  background-color: #fee2e2;
  color: #991b1b;
}

/* 게임 상태 뱃지 */
.badge-doing {
  background-color: var(--secondary);
  color: white;
}

.badge-ready {
  background-color: var(--success);
  color: white;
}

.badge-paused {
  background-color: var(--warning);
  color: white;
}

.badge-ended {
  background-color: #9ca3af;
  color: white;
}

/* ============================================
   카드 (.card)
   ============================================ */
.card {
  background-color: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: all var(--transition);
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background-color: #fafafa;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.card-body {
  padding: 16px;
}

.card-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  background-color: #fafafa;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ============================================
   폼 그룹 (.form-group)
   ============================================ */
.form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.form-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  display: block;
}

.form-label.required::after {
  content: " *";
  color: var(--danger);
}

.form-control {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background-color: var(--surface);
  transition: all var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control:disabled {
  background-color: #f5f5f5;
  color: var(--text-muted);
  cursor: not-allowed;
}

.form-control::placeholder {
  color: var(--text-muted);
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

.form-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

.form-group.has-error .form-control {
  border-color: var(--danger);
}

.form-group.has-error .form-label {
  color: var(--danger);
}

/* ============================================
   모달 (.modal)
   ============================================ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal {
  background-color: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-header .close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition);
}

.modal-header .close-btn:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background-color: #fafafa;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ============================================
   코드 입력 (.input-code)
   ============================================ */
.input-code {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 20px 0;
}

.input-code input {
  width: 50px;
  height: 50px;
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 8px;
  transition: all var(--transition);
  letter-spacing: 10px;
}

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

.input-code input::-webkit-outer-spin-button,
.input-code input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-code input[type="number"] {
  -moz-appearance: textfield;
}

/* ============================================
   진행 바 (.progress-bar)
   ============================================ */
.progress-bar-bg {
  width: 100%;
  height: 8px;
  background-color: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ============================================
   스피너 (.spinner)
   ============================================ */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.lg {
  width: 24px;
  height: 24px;
  border-width: 4px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ============================================
   빈 상태 (.empty-state)
   ============================================ */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state-description {
  font-size: 14px;
  margin-bottom: 16px;
}

/* ============================================
   아바타 (.avatar)
   ============================================ */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
}

.avatar.sm {
  width: 32px;
  height: 32px;
  font-size: 12px;
}

.avatar.lg {
  width: 56px;
  height: 56px;
  font-size: 20px;
}

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

/* ============================================
   탭 바 (.tab-bar)
   ============================================ */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  padding: 12px 16px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  transition: color var(--transition);
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
}

.tab-btn.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 3px;
  background-color: var(--primary);
}

/* ============================================
   테이블 스타일
   ============================================ */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead {
  background-color: #fafafa;
}

.table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.table tbody tr:hover {
  background-color: #fafafa;
}

/* ============================================
   알림 (.alert)
   ============================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  border-left: 4px solid;
  display: flex;
  gap: 12px;
  align-items: center;
}

.alert-primary {
  background-color: var(--primary-light);
  border-left-color: var(--primary);
  color: var(--primary-dark);
}

.alert-success {
  background-color: #dcfce7;
  border-left-color: var(--success);
  color: #166534;
}

.alert-warning {
  background-color: #fef3c7;
  border-left-color: var(--warning);
  color: #92400e;
}

.alert-danger {
  background-color: #fee2e2;
  border-left-color: var(--danger);
  color: #991b1b;
}

.alert-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.5;
  transition: opacity var(--transition);
}

.alert-close:hover {
  opacity: 1;
}

/* ============================================
   토스트 알림 (.toast)
   ============================================ */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: var(--text);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s ease;
  z-index: 2000;
  max-width: 400px;
}

@keyframes slideInRight {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.success {
  background-color: var(--success);
}

.toast.warning {
  background-color: var(--warning);
}

.toast.error {
  background-color: var(--danger);
}

/* ============================================
   로딩 스켈레톤 (.skeleton)
   ============================================ */
.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: 4px;
}

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

.skeleton.text {
  height: 12px;
  margin-bottom: 8px;
}

.skeleton.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
