* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif; }

.nav-item { transition: all 0.15s ease; position: relative; }
.nav-item:hover { background-color: rgba(255,255,255,0.1); padding-left: 1.4rem; }
.nav-item.active { background-color: rgba(255,255,255,0.2); border-left: 3px solid #60a5fa; }

.card { background: white; border-radius: 0.75rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); transition: box-shadow 0.2s ease, transform 0.2s ease; }

/* 클릭 가능한 통계 카드 - hover 시 살짝 떠오르며 그림자 강조 */
.stat-card { cursor: pointer; user-select: none; position: relative; overflow: hidden; }
.stat-card::after {
  content: '\f105'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
  position: absolute; right: 0.9rem; top: 50%; transform: translateY(-50%) translateX(4px);
  color: #cbd5e1; opacity: 0; transition: all 0.2s ease; font-size: 0.85rem;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: 0 10px 24px rgba(0,0,0,0.12); }
.stat-card:hover::after { opacity: 1; transform: translateY(-50%) translateX(0); color: #94a3b8; }
.stat-card:active { transform: translateY(-1px) scale(0.99); }

/* 페이드 업 등장 애니메이션 (카드/행에 순차 적용) */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.fade-up { animation: fadeUp 0.45s cubic-bezier(0.16,1,0.3,1) both; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fadeIn 0.3s ease both; }

/* 테이블 행 순차 등장 */
table.data-table tbody tr.row-anim { animation: fadeUp 0.35s ease both; }
table.data-table tbody tr.clickable-row { cursor: pointer; transition: background-color 0.15s ease, transform 0.1s ease; }
table.data-table tbody tr.clickable-row:hover { background: #eff6ff !important; }
table.data-table tbody tr.clickable-row:active { transform: scale(0.997); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.data-table th { background: #f8fafc; font-weight: 600; text-align: left; padding: 0.6rem 0.75rem; border-bottom: 2px solid #e2e8f0; white-space: nowrap; }
table.data-table td { padding: 0.55rem 0.75rem; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
table.data-table tbody tr:hover { background: #f8fafc; }

.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; }

/* 상담원별 일일실적 그리드 - 좌측 이름/팀 고정 컬럼 */
table.dp-grid-table th, table.dp-grid-table td { text-align: center; }
table.dp-grid-table .dp-sticky-col { position: sticky; background: white; z-index: 2; text-align: left; }
table.dp-grid-table thead .dp-sticky-col { background: #f8fafc; z-index: 3; }
table.dp-grid-table th.dp-sticky-col:nth-child(1), table.dp-grid-table td.dp-sticky-col:nth-child(1) { left: 0; min-width: 3rem; }
table.dp-grid-table th.dp-sticky-col:nth-child(2), table.dp-grid-table td.dp-sticky-col:nth-child(2) { left: 3rem; min-width: 4.5rem; }
table.dp-grid-table th.dp-sticky-col:nth-child(3), table.dp-grid-table td.dp-sticky-col:nth-child(3) { left: 7.5rem; min-width: 4rem; box-shadow: 2px 0 4px rgba(0,0,0,0.06); }
table.dp-grid-table td.dp-cell-editable { cursor: pointer; transition: background-color 0.15s ease; }
table.dp-grid-table td.dp-cell-editable:hover { background: #eff6ff; box-shadow: inset 0 0 0 1px #93c5fd; }
table.dp-grid-table .dp-cell-input { width: 3rem; text-align: center; border: 1px solid #3b82f6; border-radius: 0.25rem; padding: 0.1rem; font-size: 0.85rem; }
table.dp-grid-table .dp-cell-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(59,130,246,0.35); }

/* 모달 - 진입 애니메이션 (배경 페이드 + 박스 스케일업) */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55); z-index: 50; display:flex; align-items:center; justify-content:center;
  animation: overlayFadeIn 0.2s ease both; backdrop-filter: blur(1px);
}
@keyframes overlayFadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: white; border-radius: 0.9rem; max-height: 90vh; overflow-y: auto;
  animation: modalPopIn 0.28s cubic-bezier(0.16,1,0.3,1) both; box-shadow: 0 25px 60px rgba(0,0,0,0.25);
}
@keyframes modalPopIn { from { opacity: 0; transform: translateY(16px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-overlay.closing { animation: overlayFadeOut 0.15s ease both; }
.modal-overlay.closing .modal-box { animation: modalPopOut 0.15s ease both; }
@keyframes overlayFadeOut { to { opacity: 0; } }
@keyframes modalPopOut { to { opacity: 0; transform: translateY(10px) scale(0.97); } }

.modal-close-btn { transition: all 0.15s ease; width: 1.9rem; height: 1.9rem; border-radius: 9999px; display:flex; align-items:center; justify-content:center; }
.modal-close-btn:hover { background: #f1f5f9; color: #ef4444 !important; transform: rotate(90deg); }

/* 상세 정보 미니 통계 뱃지 */
.detail-stat { background: #f8fafc; border-radius: 0.6rem; padding: 0.75rem 1rem; text-align: center; transition: transform 0.15s ease; }
.detail-stat:hover { transform: translateY(-2px); }

/* 토스트 알림 */
#toast-container { position: fixed; top: 1.25rem; right: 1.25rem; z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  min-width: 240px; max-width: 340px; padding: 0.75rem 1rem; border-radius: 0.6rem; color: white; font-size: 0.85rem;
  box-shadow: 0 10px 24px rgba(0,0,0,0.18); transform: translateX(120%); opacity: 0; transition: all 0.3s cubic-bezier(0.16,1,0.3,1);
  display: flex; align-items: center;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast-success { background: linear-gradient(135deg, #22c55e, #16a34a); }
.toast-error { background: linear-gradient(135deg, #ef4444, #dc2626); }
.toast-info { background: linear-gradient(135deg, #3b82f6, #2563eb); }

/* 랭킹 순위 메달 펄스 효과 */
.rank-medal { display:inline-flex; align-items:center; justify-content:center; width:1.6rem; height:1.6rem; border-radius:9999px; font-weight:700; font-size:0.75rem; }
.rank-medal.gold { background: linear-gradient(135deg,#fde047,#f59e0b); color:#7c2d12; animation: pulseGlow 2s ease-in-out infinite; }
.rank-medal.silver { background: linear-gradient(135deg,#e2e8f0,#94a3b8); color:#334155; }
.rank-medal.bronze { background: linear-gradient(135deg,#fdba74,#c2703d); color:#7c2d12; }
@keyframes pulseGlow { 0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.5);} 50% { box-shadow: 0 0 0 6px rgba(245,158,11,0);} }

/* 진행바 (달성률 등에 사용) */
.progress-track { background:#e2e8f0; border-radius:9999px; height:0.4rem; overflow:hidden; }
.progress-bar { height:100%; border-radius:9999px; transition: width 0.8s cubic-bezier(0.16,1,0.3,1); }

/* 탭 버튼 전환 애니메이션 */
.tab-btn { transition: all 0.2s ease; }

::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

.spinner { border: 3px solid #e2e8f0; border-top-color: #3b82f6; border-radius: 50%; width: 2rem; height: 2rem; animation: spin 0.8s linear infinite; }
.spinner.sm { width: 1.2rem; height: 1.2rem; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== 모바일 반응형 (768px 미만) ===================== */

/* 사이드바를 오프캔버스 드로어로 전환 */
.sidebar-overlay { display: none; }

@media (max-width: 767px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 78vw;
    max-width: 280px;
    z-index: 45;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16,1,0.3,1);
    display: flex !important;
  }
  #sidebar.sidebar-open { transform: translateX(0); box-shadow: 10px 0 30px rgba(0,0,0,0.3); }

  .sidebar-overlay {
    display: block;
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.55);
    z-index: 40;
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .sidebar-overlay.show { opacity: 1; visibility: visible; pointer-events: auto; }

  #mobile-topbar { position: sticky; top: 0; z-index: 30; }

  /* 카드 패딩 축소로 좁은 화면에서 여백 확보 */
  .card { border-radius: 0.6rem; }
  .card.p-5, .card .p-5, .stat-card.p-5 { padding: 0.9rem !important; }
  .card.p-6, .modal-box .p-6 { padding: 1.1rem !important; }

  /* 통계 카드 내부 텍스트 축소 */
  .stat-card .text-2xl { font-size: 1.25rem !important; }
  .stat-card .text-xl { font-size: 1.05rem !important; }

  /* 테이블: 가로 스크롤 유지 + 폰트/패딩 축소 */
  table.data-table { font-size: 0.78rem; }
  table.data-table th, table.data-table td { padding: 0.45rem 0.55rem; }

  /* 모달: 화면 대부분을 차지하도록 확대, 여백 최소화 */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box { width: 100% !important; max-width: 100% !important; max-height: 92vh; border-radius: 1rem 1rem 0 0; }
  @keyframes modalPopIn { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }

  /* 모달 내부 그리드: 2/3열 -> 1열 (일부 예외는 유지) */
  .modal-box .grid.grid-cols-2:not(.keep-cols),
  .modal-box .grid.grid-cols-3:not(.keep-cols),
  .modal-box .grid.grid-cols-4:not(.keep-cols) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .modal-box .detail-stat { padding: 0.6rem 0.5rem; }
  .modal-box .detail-stat p.text-xl { font-size: 1rem !important; }

  /* 토스트 알림 폭 조정 */
  #toast-container { top: 0.75rem; left: 0.75rem; right: 0.75rem; align-items: stretch; }
  .toast { min-width: 0; max-width: none; width: 100%; }

  /* 헤더 영역 컨트롤들이 줄바꿈되도록 */
  .page-header-row { flex-direction: column; align-items: stretch !important; gap: 0.75rem; }
  .page-header-row > * { width: 100%; }
  .page-header-controls { flex-wrap: wrap; }
  .page-header-controls > * { flex: 1 1 auto; }

  /* 대시보드 상단 통계 카드: 2열 유지하되 간격 축소 */
  #page-content { padding: 1rem !important; }
}

@media (max-width: 420px) {
  .modal-box .grid.grid-cols-2:not(.keep-cols),
  .modal-box .grid.grid-cols-3:not(.keep-cols),
  .modal-box .grid.grid-cols-4:not(.keep-cols) {
    grid-template-columns: 1fr;
  }
}
