/* 앱 전역 색상과 셸 크기만 한곳에서 관리합니다.
   Bootstrap 기본값을 크게 벗어나지 않아 기존 화면의 안정성을 유지합니다. */
:root {
  --app-sidebar-width: 256px;
  --app-mobile-header-height: 60px;
  --app-desktop-header-height: 64px;
  --app-canvas: #f6f7f9;
  --app-surface: #ffffff;
  --app-border: #e3e7ec;
  --app-text: #20242b;
  --app-muted: #687180;
  --app-primary: #3558c7;
  --app-primary-soft: #eef2ff;
  --app-radius: 0.75rem;
  --app-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --bs-primary: #3558c7;
  --bs-primary-rgb: 53, 88, 199;
  --bs-link-color-rgb: 53, 88, 199;
  --bs-link-hover-color-rgb: 42, 70, 159;
  --bs-body-color: var(--app-text);
  --bs-body-bg: var(--app-canvas);
  --bs-border-color: var(--app-border);
}

/* 기본 배경과 키보드 포커스를 모든 화면에서 일관되게 제공합니다.
   포커스는 마우스 클릭 때는 나타나지 않고 키보드 탐색 때만 표시됩니다. */
body {
  min-width: 320px;
  color: var(--app-text);
  background: var(--app-canvas);
  -webkit-font-smoothing: antialiased;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid rgba(var(--bs-primary-rgb), 0.28);
  outline-offset: 2px;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
  box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.16);
}

/* 기존 템플릿이 공통으로 쓰는 반 단계 간격을 Bootstrap 규칙에 맞춰 보완합니다.
   무시되던 클래스만 정의해 화면별 인라인 보정 없이 동일한 간격을 유지합니다. */
.gap-0\.5 { gap: 0.125rem !important; }
.gap-1\.5 { gap: 0.375rem !important; }
.gap-2\.5 { gap: 0.625rem !important; }
.p-1\.5 { padding: 0.375rem !important; }
.px-1\.5 { padding-right: 0.375rem !important; padding-left: 0.375rem !important; }
.px-2\.5 { padding-right: 0.625rem !important; padding-left: 0.625rem !important; }
.px-3\.5 { padding-right: 0.875rem !important; padding-left: 0.875rem !important; }
.py-0\.5 { padding-top: 0.125rem !important; padding-bottom: 0.125rem !important; }
.py-1\.5 { padding-top: 0.375rem !important; padding-bottom: 0.375rem !important; }
.py-2\.5 { padding-top: 0.625rem !important; padding-bottom: 0.625rem !important; }
.py-3\.5 { padding-top: 0.875rem !important; padding-bottom: 0.875rem !important; }
.mt-0\.5 { margin-top: 0.125rem !important; }
.mt-1\.5 { margin-top: 0.375rem !important; }
.mb-1\.5 { margin-bottom: 0.375rem !important; }
.min-w-0 { min-width: 0 !important; }

/* 로고는 모바일과 데스크톱에서 동일한 형태를 재사용합니다.
   과한 그라데이션과 그림자를 피하고 브랜드 식별만 남깁니다. */
.app-brand {
  color: var(--app-text);
  text-decoration: none;
}

.app-brand:hover {
  color: var(--app-text);
}

.app-brand-mark {
  display: inline-flex;
  width: 2rem;
  height: 2rem;
  flex: 0 0 2rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.55rem;
  color: #fff;
  background: linear-gradient(135deg, #5b7bea, var(--app-primary));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  font-size: 1rem;
  font-weight: 700;
}

.app-brand-mark-sm {
  width: 1.75rem;
  height: 1.75rem;
  flex-basis: 1.75rem;
  border-radius: 0.45rem;
  font-size: 0.875rem;
}

/* 모바일 헤더와 오프캔버스는 작은 화면에서 콘텐츠를 가리지 않습니다.
   사이드바 폭은 화면보다 커지지 않도록 제한합니다. */
.app-mobile-header {
  height: var(--app-mobile-header-height);
  background: rgba(248, 249, 251, 0.92);
  backdrop-filter: blur(8px);
}

.app-mobile-spacer {
  width: 2rem;
  flex: 0 0 2rem;
}

.app-sidebar-canvas {
  width: min(var(--app-sidebar-width), 88vw) !important;
}

.app-sidebar-header {
  min-height: var(--app-desktop-header-height);
}

/* 사이드바는 옅은 회색 패널 위에 활성 메뉴만 흰 카드+좌측 강조선으로 띄웁니다.
   섹션 라벨은 작고 옅게 두어 메뉴 항목이 먼저 읽히도록 합니다.
   아이콘은 기본 회색, 호버·활성 시 본문색/주색으로 바뀝니다. */
.app-sidebar-panel {
  background: #f8f9fb !important;
}

.sidebar-section-label {
  margin: 1.5rem 0 0.35rem;
  padding: 0 0.75rem;
  color: #a0a7b3;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.sidebar-section-label:first-child {
  margin-top: 0.25rem;
}

.sidebar-link {
  position: relative;
  display: flex;
  min-height: 2.5rem;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.125rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 0.6rem;
  color: #5d6673;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.sidebar-link:hover {
  color: var(--app-text);
  background: #eef0f4;
}

.sidebar-link.active,
.sidebar-link.active:hover {
  color: var(--app-text);
  border-color: var(--app-border);
  background: var(--app-surface);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-weight: 650;
}

.sidebar-link.active::before {
  position: absolute;
  top: 0.6rem;
  bottom: 0.6rem;
  left: -1px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--app-primary);
  content: "";
}

.sidebar-link svg {
  width: 1.1rem;
  height: 1.1rem;
  flex: 0 0 1.1rem;
  color: #8a93a0;
  transition: color 0.15s ease;
}

.sidebar-link:hover svg {
  color: var(--app-text);
}

.sidebar-link.active svg {
  color: var(--app-primary);
}

.sidebar-link .sidebar-external {
  width: 0.8rem;
  height: 0.8rem;
  flex-basis: 0.8rem;
  margin-left: auto;
  opacity: 0.6;
}

/* 로그인 사용자의 이름과 권한을 좁은 사이드바에서도 안전하게 표시합니다.
   긴 이메일은 말줄임하고 로그아웃 버튼의 클릭 영역은 유지합니다. */
.app-user-card {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem;
  border-radius: 0.6rem;
  transition: background-color 0.15s ease;
}

.app-user-card:hover {
  background: #eef0f4;
}

.app-user-avatar {
  display: inline-flex;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 2.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, #5b7bea, var(--app-primary));
  font-size: 0.875rem;
  font-weight: 700;
}

.app-user-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.app-user-name {
  overflow: hidden;
  color: var(--app-text);
  font-size: 0.825rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-user-role {
  margin-top: 0.1rem;
  color: var(--app-muted);
  font-size: 0.72rem;
}

.app-logout-button {
  display: inline-flex;
  width: 2rem;
  height: 2rem;
  align-items: center;
  justify-content: center;
  flex: 0 0 2rem;
}

.app-logout-button svg {
  width: 1.1rem;
  height: 1.1rem;
}

/* 상단 경로와 본문 여백은 셸에서만 제어합니다.
   데이터 화면 내부의 카드와 그리드 스타일은 그대로 유지합니다. */
.main-content {
  min-width: 0;
}

/* 상단 헤더는 사이드바와 같은 패널 톤·높이를 써서 하나의 프레임으로 보이게 합니다.
   현재 위치는 진하게, 상위 경로는 옅게 두고 구분자는 ›로 가볍게 표시합니다.
   우측 라벨은 사이드바 활성 메뉴와 같은 흰 카드 형태로 맞춥니다. */
.app-topbar {
  height: var(--app-desktop-header-height);
  background: #f8f9fb;
}

.app-breadcrumb {
  --bs-breadcrumb-divider: "›";
  --bs-breadcrumb-divider-color: #b4bac4;
  --bs-breadcrumb-item-padding-x: 0.6rem;
  --bs-breadcrumb-item-active-color: var(--app-text);
  margin: 0;
  font-size: 0.85rem;
}

.app-breadcrumb .breadcrumb-item.active {
  font-weight: 650;
}

.app-breadcrumb a {
  color: var(--app-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.app-breadcrumb a:hover {
  color: var(--app-primary);
}

.app-context-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  color: #505966;
  background: var(--app-surface);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-size: 0.75rem;
  font-weight: 600;
}

.app-context-label::before {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--app-primary);
  content: "";
}

.app-main {
  margin-top: var(--app-mobile-header-height);
  padding: 1rem;
}

/* 대시보드 전용 카드에 절제된 강조와 충분한 정보 간격을 제공합니다.
   링크 카드만 호버 효과를 사용해 클릭 가능 여부를 분명히 합니다. */
.app-page-title {
  color: var(--app-text);
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.app-page-description {
  max-width: 44rem;
  color: var(--app-muted);
  font-size: 0.9rem;
}

.app-stat-card,
.app-dashboard-panel {
  border: 1px solid var(--app-border) !important;
  border-radius: var(--app-radius) !important;
  background: var(--app-surface);
  box-shadow: var(--app-shadow);
}

.app-interactive-card {
  display: block;
  height: 100%;
  border-radius: var(--app-radius);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.app-interactive-card:hover {
  color: inherit;
  transform: translateY(-2px);
}

.app-interactive-card:hover .app-stat-card,
.app-interactive-card:focus-visible .app-stat-card {
  border-color: #cbd4e4 !important;
  box-shadow: 0 5px 14px rgba(16, 24, 40, 0.07);
}

/* KPI 타일은 아이콘+라벨 한 줄 헤더 아래 큰 숫자와 보조값을 둡니다.
   숫자 뒤 단위는 작게 낮춰 값이 먼저 읽히도록 합니다.
   아이콘은 작은 soft 배경 사각형으로 색 신호만 남깁니다. */
.app-stat-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.app-stat-icon {
  display: inline-flex;
  width: 1.75rem;
  height: 1.75rem;
  flex: 0 0 1.75rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
}

.app-stat-icon svg {
  width: 0.95rem;
  height: 0.95rem;
}

.app-stat-label {
  color: var(--app-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.app-stat-value {
  margin: 0 0 0.25rem;
  color: var(--app-text);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.2;
}

.app-stat-value small {
  margin-left: 0.15rem;
  color: var(--app-muted);
  font-size: 0.85rem;
  font-weight: 600;
}

/* 운영 패널 보조 요소: 실패·복구 요약 칩과 API 사용량 대표 숫자. */
.app-health-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  color: var(--app-muted);
  background: #f8f9fb;
  font-size: 0.75rem;
  font-weight: 600;
}

.app-health-chip i {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
}

.app-health-chip strong {
  color: var(--app-text);
}

.app-usage-value {
  color: var(--app-text);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-link-hint {
  color: var(--app-muted);
  font-size: 0.75rem;
  font-weight: 650;
}

.app-section-title {
  color: var(--app-text);
  font-size: 1rem;
  font-weight: 700;
}

.app-section-description,
.app-meta-text {
  color: var(--app-muted);
  font-size: 0.8rem;
}

/* 최근 수집 이력은 단순한 세로 흐름으로 상태와 시간을 함께 보여줍니다.
   장식보다 읽기 순서를 우선해 작은 화면에서도 한 열을 유지합니다. */
.app-timeline {
  position: relative;
  margin-left: 0.5rem;
  padding-left: 1.25rem;
  border-left: 1px solid var(--app-border);
}

.app-timeline-item {
  position: relative;
}

.app-timeline-item:not(:last-child) {
  margin-bottom: 1.25rem;
}

.app-timeline-dot {
  position: absolute;
  top: 0.3rem;
  left: -1.6rem;
  width: 0.65rem;
  height: 0.65rem;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--app-border);
}

/* 큰 화면에서만 고정 사이드바와 넓은 본문 여백을 적용합니다.
   모바일은 한 열을 유지해 가로 스크롤과 콘텐츠 가림을 방지합니다. */
@media (min-width: 992px) {
  .sidebar-fixed {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1020;
    width: var(--app-sidebar-width);
  }

  .main-content {
    margin-left: var(--app-sidebar-width);
  }

  .app-main {
    margin-top: 0;
    padding: 1.5rem;
  }
}

@media (max-width: 575.98px) {
  .app-page-actions {
    display: grid;
    width: 100%;
  }
}

/* 동작 축소 설정을 존중해 이동·전환 효과를 제거합니다.
   콘텐츠와 기능은 그대로 유지하면서 불필요한 움직임만 줄입니다. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* HTMX Swapping 시 부드러운 투명도 트랜지션을 주어 폴링 시 화면 깜빡임을 제어합니다. */
/* htmx-swapping 클래스가 추가될 때 투명도를 서서히 조절하여 시각적 불편함을 낮춥니다. */
/* 레이아웃의 급격한 끊김이나 시선 분산을 완화하는 자연스러운 모션 제어 기법입니다. */
.htmx-swapping {
  opacity: 0;
  transition: opacity 150ms ease-out;
}

/* 태블릿과 모바일 브라우저에서 가로 스크롤바가 숨지 않고 적절한 두께로 유지되도록 보완합니다. */
/* 스크롤 가능한 요소의 존재를 즉각적으로 전달하고, 스크롤 조작에 유동성을 불어넣습니다. */
/* 윈도우/맥OS/모바일 OS 전반에서 보기 편한 연한 회색의 라운디드 트랙과 섬을 조합합니다. */
.table-responsive::-webkit-scrollbar {
  height: 6px;
}
.table-responsive::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 3px;
}
.table-responsive::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}
.table-responsive::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}
