/* 거래처 관리 시스템 스타일 */
* { box-sizing: border-box; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0891b2;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-light: #64748b;
}

body {
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
}

/* 헤더 */
.header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: white;
  padding: 0 1.5rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.875rem;
}

/* 사이드바 */
.layout {
  display: flex;
  min-height: calc(100vh - 64px);
}

.sidebar {
  width: 240px;
  background: white;
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.sidebar-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-menu li a, .sidebar-menu li button {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.sidebar-menu li a:hover, .sidebar-menu li button:hover {
  background: #eff6ff;
  color: var(--primary);
  border-left-color: var(--primary);
}

.sidebar-menu li.active a, .sidebar-menu li.active button {
  background: #eff6ff;
  color: var(--primary);
  font-weight: 600;
  border-left-color: var(--primary);
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 1rem;
}

/* 메인 콘텐츠 */
.main-content {
  flex: 1;
  padding: 1.5rem;
  overflow-x: hidden;
}

/* 카드 */
.card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafafa;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.card-body {
  padding: 1.5rem;
}

/* 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #b45309; }
.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #0e7490; }
.btn-secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }

/* 폼 */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.875rem; font-weight: 600; color: var(--text); margin-bottom: 0.375rem; }
.form-label span.required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--text);
  background: white;
  transition: all 0.2s;
  outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.form-control::placeholder { color: #94a3b8; }
textarea.form-control { resize: vertical; min-height: 100px; }

/* 테이블 */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text);
  vertical-align: middle;
}

tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }

/* 배지 */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0f2fe; color: #0c4a6e; }
.badge-secondary { background: #f1f5f9; color: #475569; }

/* 로그인 화면 */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #3b82f6 100%);
  padding: 1rem;
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo .icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.login-logo h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 0.25rem;
}

.login-logo p { color: var(--text-light); font-size: 0.875rem; margin: 0; }

/* 모달 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(2px);
}

.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  border-radius: 16px 16px 0 0;
  position: sticky;
  top: 0;
}

.modal-title { font-size: 1.1rem; font-weight: 700; margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-light);
  padding: 0.25rem;
  border-radius: 4px;
  transition: all 0.2s;
}
.modal-close:hover { background: #f1f5f9; color: var(--text); }

.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  background: #f8fafc;
  border-radius: 0 0 16px 16px;
}

/* 검색 패널 */
.search-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

/* 페이지네이션 */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 1rem;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  background: white;
  color: var(--text);
  transition: all 0.2s;
}

.page-btn:hover { background: #eff6ff; border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); font-weight: 600; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* 알림 팝업 */
.alert-popup {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.alert-header {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  color: white;
  padding: 1.25rem 1.5rem;
  border-radius: 16px 16px 0 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ===== D-day 만료 필터 버튼 ===== */
.expiry-filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.expiry-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border: 2px solid transparent;
  background: #f1f5f9;
  color: #475569;
  transition: all 0.18s;
  white-space: nowrap;
}
.expiry-btn:hover { filter: brightness(0.95); }

/* 전체 버튼 */
.expiry-btn.active-all {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #7dd3fc;
  font-weight: 700;
}

/* 만료됨 */
.expiry-btn-expired         { background: #f3f4f6; color: #6b7280; border-color: #d1d5db; }
.expiry-btn-expired.selected{ background: #6b7280; color: #fff; border-color: #4b5563; }

/* D-30 이내 (빨간) */
.expiry-btn-critical         { background: #fff1f2; color: #be123c; border-color: #fda4af; }
.expiry-btn-critical.selected{ background: #dc2626; color: #fff; border-color: #b91c1c; }

/* D-31~60 (노란) */
.expiry-btn-warning          { background: #fffbeb; color: #92400e; border-color: #fcd34d; }
.expiry-btn-warning.selected { background: #d97706; color: #fff; border-color: #b45309; }

/* D-61 이상 정상 (초록) */
.expiry-btn-normal           { background: #f0fdf4; color: #166534; border-color: #86efac; }
.expiry-btn-normal.selected  { background: #16a34a; color: #fff; border-color: #15803d; }

/* 색상 점 */
.dday-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-red    { background: #dc2626; }
.dot-yellow { background: #d97706; }
.dot-green  { background: #16a34a; }

/* 통계 카드 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.stat-value { font-size: 1.75rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-light); margin-top: 0.25rem; }

/* 토스트 알림 */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.875rem 1.25rem;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 280px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: toastIn 0.3s ease;
}

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

.toast-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.toast-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.toast-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.toast-info { background: #e0f2fe; color: #0c4a6e; border: 1px solid #7dd3fc; }

/* 모바일 메뉴 */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.375rem;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* 반응형 */
@media (max-width: 768px) {
  .mobile-menu-btn { display: block; }
  
  .sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: 4px 0 12px rgba(0,0,0,0.15);
  }
  
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  
  .main-content { padding: 1rem; }
  .search-grid { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .modal { max-height: 95vh; }
  
  .table-wrapper { margin: 0 -1rem; border-radius: 0; }
  
  thead th, tbody td {
    padding: 0.625rem 0.75rem;
    font-size: 0.8rem;
  }
  
  .hide-mobile { display: none; }
  
  .header-title span { display: none; }
}

@media (max-width: 480px) {
  .search-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .modal { border-radius: 12px; }
  .login-card { padding: 2rem 1.5rem; }
  .toast-container { left: 1rem; right: 1rem; }
  .toast { min-width: auto; }
}

/* 프린트 스타일 */
@media print {
  .header, .sidebar, .sidebar-overlay, .btn, .modal-overlay,
  .toast-container, .pagination, .search-panel, .no-print { display: none !important; }
  
  .layout { display: block; }
  .main-content { padding: 0; }
  
  table { font-size: 0.75rem; }
  thead th { background: #e5e7eb !important; -webkit-print-color-adjust: exact; }
  
  .card { border: 1px solid #000; box-shadow: none; }
  .badge { border: 1px solid currentColor; }
  
  @page { margin: 1cm; size: landscape; }
}

/* 유틸리티 */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-light); }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.flex-wrap { flex-wrap: wrap; }
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text-light);
  gap: 0.75rem;
}
.spinner {
  width: 24px; height: 24px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-light);
}
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: 0.3; }

/* 계약 만료 행 색상 */
.expiry-row-expired td  { background: #f3f4f6 !important; color: #6b7280; }
.expiry-row-critical td { background: #fff1f2 !important; }
.expiry-row-warning td  { background: #fffbeb !important; }

/* 만료됨 배지 */
.badge-expired { background: #e5e7eb; color: #4b5563; }

/* 폼 그리드 */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 576px) {
  .form-grid { grid-template-columns: 1fr; }
}
.form-grid .form-group-full { grid-column: 1 / -1; }

/* 구분선 */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}
