/* ============================================
   공통 UI 컴포넌트 스타일시트
   ============================================ */

/* ==========================================
   Design Tokens (Material 3 inspired, dark theme)
   색상·타이포 스케일의 단일 원천.
   기존 --accent 는 base.html 에서 정의되므로 fallback 만 선언.
   ========================================== */
:root {
  /* Brand */
  --color-primary: var(--accent, #fb923c);
  --color-primary-hover: #f97316;
  --color-primary-container: rgba(251, 146, 60, 0.12);
  --color-on-primary: #1a0a00;

  /* Surface elevation (dark theme — Material 3 tonal surfaces) */
  --color-surface: #060606;
  --color-surface-1: rgba(255, 255, 255, 0.03);
  --color-surface-2: rgba(255, 255, 255, 0.05);
  --color-surface-3: rgba(255, 255, 255, 0.08);
  --color-surface-4: rgba(255, 255, 255, 0.11);

  /* Foreground (on-surface) */
  --color-on-surface: rgba(255, 255, 255, 0.95);
  --color-on-surface-variant: rgba(255, 255, 255, 0.72);
  --color-on-surface-muted: rgba(255, 255, 255, 0.55);

  /* Semantic (WCAG AA on dark bg) */
  --color-success: #34d399;
  --color-success-container: rgba(16, 185, 129, 0.14);
  --color-error: #f87171;
  --color-error-container: rgba(239, 68, 68, 0.14);
  --color-warning: #fbbf24;
  --color-warning-container: rgba(234, 179, 8, 0.14);
  --color-info: #60a5fa;
  --color-info-container: rgba(59, 130, 246, 0.14);

  /* Outline */
  --color-outline: rgba(255, 255, 255, 0.14);
  --color-outline-variant: rgba(255, 255, 255, 0.08);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* Elevation shadow (dark surface) */
  --elevation-1: 0 2px 6px rgba(0, 0, 0, 0.35);
  --elevation-2: 0 8px 24px rgba(0, 0, 0, 0.4);
  --elevation-3: 0 16px 40px rgba(0, 0, 0, 0.5);

  /* Motion */
  --motion-fast: 150ms;
  --motion-med: 250ms;
  --motion-slow: 400ms;
  --motion-easing: cubic-bezier(0.2, 0, 0, 1);

  /* Typography scale (Material 3 — condensed) */
  --font-display: clamp(2rem, 4vw, 2.75rem);  /* Display */
  --font-headline: 1.5rem;                     /* Headline */
  --font-title: 1.125rem;                      /* Title */
  --font-body: 0.9375rem;                      /* Body */
  --font-label: 0.8125rem;                     /* Label */
  --font-label-sm: 0.6875rem;                  /* Label Small */
}

/* ==========================================
   버튼 스타일
   ========================================== */

/* 기본 버튼 (Primary) */
.btn,
button:not([class*="bg-"]):not([class*="text-"]),
input[type="button"]:not([class*="bg-"]),
input[type="submit"]:not([class*="bg-"]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.btn-primary,
.btn:not(.btn-secondary):not(.btn-danger):not(.btn-ghost) {
  background: linear-gradient(135deg, var(--color-primary), #ff9a56);
  color: var(--color-on-primary);
  min-height: 44px;
}

.btn-primary:hover:not(:disabled),
.btn:hover:not(.btn-secondary):hover:not(.btn-danger):not(.btn-ghost):not(
    :disabled
  ) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(251, 146, 60, 0.4);
}

.btn-primary:active:not(:disabled),
.btn:active:not(.btn-secondary):not(.btn-danger):not(.btn-ghost):not(
    :disabled
  ) {
  transform: translateY(0);
}

.btn-primary:focus:not(:disabled),
.btn:focus:not(.btn-secondary):not(.btn-danger):not(.btn-ghost):not(:disabled) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Secondary 버튼 */
.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-on-surface);
  border: 1px solid var(--color-outline);
  min-height: 44px;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-surface-3);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-secondary:focus:not(:disabled) {
  outline: 2px solid rgba(255, 255, 255, 0.3);
  outline-offset: 2px;
}

/* Danger 버튼 */
.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.btn-danger:focus:not(:disabled) {
  outline: 2px solid #ef4444;
  outline-offset: 2px;
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--accent);
  color: white;
}

.btn-ghost:focus:not(:disabled) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Disabled 상태 */
.btn:disabled,
button:disabled,
input[type="button"]:disabled,
input[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Small 사이즈 */
.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* Large 사이즈 */
.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

/* Block (full width) */
.btn-block {
  width: 100%;
  display: flex;
}

/* ==========================================
   로딩 상태 표시
   ========================================== */

.loading-spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  border-top-color: var(--color-primary);
  animation: spin 0.8s linear infinite;
}

.loading-spinner.sm {
  width: 1rem;
  height: 1rem;
  border-width: 2px;
}

.loading-spinner.lg {
  width: 2rem;
  height: 2rem;
  border-width: 4px;
}

.btn .loading-spinner {
  margin-right: 0.5rem;
}

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

/* 전체 화면 로딩 오버레이 */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

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

.loading-overlay-content {
  text-align: center;
  padding: 2.5rem;
  border-radius: 2rem;
  background: rgba(30, 30, 30, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.loading-overlay-spinner {
  width: 3rem;
  height: 3rem;
  border: 4px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

.loading-overlay-text {
  font-size: 1rem;
  color: var(--color-on-surface-variant);
  font-weight: 600;
}

/* ==========================================
   에러/알림 메시지 (Dark theme)
   ========================================== */

.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  border-left: 4px solid;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: var(--color-surface-2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--color-on-surface);
}

.alert[role="alert"] {
  /* Announced to assistive tech — keep polite by default */
}

.alert-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-title {
  font-weight: 700;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
  color: var(--color-on-surface);
}

.alert-message {
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-on-surface-variant);
}

/* Success */
.alert-success {
  background-color: var(--color-success-container);
  border-color: var(--color-success);
}
.alert-success .alert-title,
.alert-success .alert-icon {
  color: var(--color-success);
}

/* Error */
.alert-error {
  background-color: var(--color-error-container);
  border-color: var(--color-error);
}
.alert-error .alert-title,
.alert-error .alert-icon {
  color: var(--color-error);
}

/* Warning */
.alert-warning {
  background-color: var(--color-warning-container);
  border-color: var(--color-warning);
}
.alert-warning .alert-title,
.alert-warning .alert-icon {
  color: var(--color-warning);
}

/* Info */
.alert-info {
  background-color: var(--color-info-container);
  border-color: var(--color-info);
}
.alert-info .alert-title,
.alert-info .alert-icon {
  color: var(--color-info);
}

/* 닫기 버튼 */
.alert-close {
  background: none;
  border: none;
  color: currentColor;
  cursor: pointer;
  font-size: 1.5rem;
  padding: 0;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.2s;
}

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

/* ==========================================
   토스트 알림 (Snackbar)
   ========================================== */

.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  background: rgba(20, 20, 20, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-outline);
  color: var(--color-on-surface);
  box-shadow: var(--elevation-2);
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 300px;
  max-width: min(420px, calc(100vw - 4rem));
  z-index: 999;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

.toast.hide {
  animation: slideOut 0.3s ease forwards;
}

.toast-success {
  border-left: 4px solid var(--color-success);
  background: var(--color-success-container);
}

.toast-error {
  border-left: 4px solid var(--color-error);
  background: var(--color-error-container);
}

.toast-warning {
  border-left: 4px solid var(--color-warning);
  background: var(--color-warning-container);
}

.toast-info {
  border-left: 4px solid var(--color-info);
  background: var(--color-info-container);
}

/* ==========================================
   빈 상태 / 로딩 스켈레톤 / 에러-복구
   (Material Feedback, Google perceived performance)
   ========================================== */

/* Empty state — 일러스트 + 제목 + 설명 + CTA 3단 구성 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  gap: 0.75rem;
  background: var(--color-surface-1);
  border: 1px dashed var(--color-outline);
  border-radius: var(--radius-xl);
  color: var(--color-on-surface);
}

.empty-state__icon {
  font-size: 2.5rem;
  line-height: 1;
  margin-bottom: 0.25rem;
  opacity: 0.85;
}

.empty-state__title {
  font-size: var(--font-title);
  font-weight: 800;
  color: var(--color-on-surface);
  margin: 0;
}

.empty-state__desc {
  font-size: var(--font-body);
  color: var(--color-on-surface-variant);
  max-width: 42ch;
  margin: 0;
  line-height: 1.5;
}

.empty-state__action {
  margin-top: 0.75rem;
}

/* Skeleton 로더 — 실제 카드 모양을 모사해 인지 로딩 시간 단축 */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.09) 50%,
    rgba(255, 255, 255, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
  border-radius: var(--radius-md);
}

.skeleton--text {
  height: 0.75rem;
  margin-bottom: 0.5rem;
}

.skeleton--title {
  height: 1.25rem;
  width: 70%;
  margin-bottom: 1rem;
}

.skeleton--block {
  height: 12rem;
  border-radius: var(--radius-xl);
}

.skeleton-card {
  background: var(--color-surface-1);
  border: 1px solid var(--color-outline-variant);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 12rem;
}

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

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    background: rgba(255, 255, 255, 0.06);
  }
}

/* Error-recovery panel — offline/timeout 등 복구 플로우 */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2.5rem 1.5rem;
  gap: 0.75rem;
  background: var(--color-error-container);
  border: 1px solid var(--color-error);
  border-radius: var(--radius-lg);
  color: var(--color-on-surface);
}

.error-state__title {
  font-size: var(--font-title);
  font-weight: 800;
  color: var(--color-error);
  margin: 0;
}

.error-state__desc {
  font-size: var(--font-body);
  color: var(--color-on-surface-variant);
  max-width: 42ch;
  margin: 0;
  line-height: 1.5;
}

/* Mobile */
@media (max-width: 640px) {
  .toast {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
    min-width: auto;
  }

  .btn {
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
  }

  .alert {
    padding: 0.875rem;
    gap: 0.5rem;
  }

  .alert-icon {
    font-size: 1.25rem;
  }

  .alert-title {
    font-size: 0.75rem;
  }

  .alert-message {
    font-size: 0.75rem;
  }
}
