/* ──────────────────────────────────────────
   CareNara 글로벌 스타일 & 디자인 토큰
   ────────────────────────────────────────── */
:root {
  --color-primary:       #2563eb;
  --color-primary-dark:  #1d4ed8;
  --color-primary-light: #eff6ff;
  --color-secondary:     #64748b;
  --color-success:       #16a34a;
  --color-success-bg:    #dcfce7;
  --color-warning:       #d97706;
  --color-warning-bg:    #fef3c7;
  --color-danger:        #dc2626;
  --color-danger-bg:     #fee2e2;
  --color-bg:            #f8fafc;
  --color-surface:       #ffffff;
  --color-border:        #e2e8f0;
  --color-text:          #1e293b;
  --color-text-muted:    #64748b;
  --color-text-light:    #94a3b8;

  --sidebar-width:        220px;
  --sidebar-width-md:     220px;
  --sidebar-collapsed:    60px;
  --content-padding-x:    20px;
  --content-padding-x-md: 20px;
  --content-padding-y:    28px;
  --header-height:        56px;

  /* 컴팩트 레이아웃 토큰 */
  --gap-sm:     8px;
  --gap:        12px;
  --row-h:      44px;
  --font-sm:    11px;
  --font-md:    13px;
  --radius:   8px;
  --radius-lg: 12px;
  --shadow:   0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --transition: .15s ease;
}

/* 리셋 */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img, svg { display: block; max-width: 100%; }
input, button, select, textarea { font: inherit; }

/* 기반 */
html { scroll-behavior: smooth; }

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont,
               'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── 레이아웃 — 상단 네비바 기반 ── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* 네비바 컨테이너 */
#navbar-container {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 200;
}

/* 레거시 사이드바 — 완전 제거 */
#sidebar-container { display: none !important; }

#main-content {
  flex: 1;
  min-width: 0;
  padding: var(--content-padding-y) var(--content-padding-x);
  overflow-y: auto;
  overflow-x: hidden;
}

/* 모든 페이지 공통 내부 래퍼 — max-width 제한 + 중앙 정렬 */
.sa-page-inner {
  max-width: 1600px;
  margin: 0 auto;
}

/* 로그인·회원가입·랜딩 페이지 — 풀스크린이므로 래퍼 제약 해제 */
body.page-login  #navbar-container { display: none; }
body.page-login  #main-content { padding: 0; }
body.page-login  .sa-page-inner { max-width: none; margin: 0; }
body.page-landing #navbar-container { display: none; }
body.page-landing #main-content { padding: 0; min-height: 100vh; }
body.page-landing .sa-page-inner { max-width: none; margin: 0; }

/* ── 페이지 헤더 ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--color-text);
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ── 버튼 ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition),
              transform var(--transition);
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 0.8125rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-block { width: 100%; }

.btn-primary  { background: var(--color-primary);  color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-border); color: var(--color-text); }
.btn-secondary:hover:not(:disabled) { background: #d1d5db; }
.btn-danger   { background: var(--color-danger);   color: #fff; }
.btn-danger:hover:not(:disabled)   { background: #b91c1c; }
.btn-outline  { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover:not(:disabled)  { background: var(--color-bg); }
.btn-ghost    { background: transparent; color: var(--color-primary); }
.btn-ghost:hover { background: var(--color-primary-light); }

/* ── 카드 ── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* ── 통계 카드 그리드 ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 14px 10px 18px;  /* 좌측 accent bar 공간 포함 */
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  /* 가로 배치: 아이콘 | 레이블+숫자 */
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--stat-color, var(--color-primary));
  border-radius: var(--radius) 0 0 var(--radius);
}

.stat-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: var(--stat-bg, var(--color-primary-light));
}

.stat-label {
  font-size: var(--font-sm, 11px);
  color: var(--color-text-muted);
  margin-bottom: 2px;
  white-space: nowrap;
}

.stat-value {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
}

.stat-unit {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-weight: 400;
}

/* ── 테이블 ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  /* 스크롤바 항상 표시 (우측 컬럼이 잘렸음을 시각적으로 인지) */
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.table-wrap::-webkit-scrollbar        { height: 6px; }
.table-wrap::-webkit-scrollbar-track  { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb  { background: #cbd5e1; border-radius: 3px; }

table {
  width: 100%;
  min-width: 760px;    /* 가로 스크롤 보장 — 이 너비 이하에서 scrollbar 표시 */
  border-collapse: collapse;
  font-size: 0.875rem;
  white-space: nowrap;
}

th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  font-size: var(--font-md, 13px);
  color: var(--color-text-muted);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 1;
  height: 36px;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: var(--font-md, 13px);
  white-space: normal;
  word-break: keep-all;
  height: var(--row-h, 44px);
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }
/* sticky 컬럼도 hover 시 동일 배경 */
tbody tr:hover .table-wrap td:last-child,
tbody tr:hover td:last-child { background: #f8fafc; }

/*
 * card.style.overflow='hidden' (JS 인라인) 오버라이드:
 * table-wrap이 있는 카드는 overflow: visible 로 전환해야
 * (1) 가로 스크롤 scrollbar가 card 아래에 표시되고
 * (2) sticky 관리 컬럼이 card 경계에서 잘리지 않는다.
 * !important 는 인라인 스타일보다 낮지만 :has() 선택자가 더 구체적이므로
 * 대부분의 현대 브라우저에서 !important 없이도 작동하나 안전을 위해 명시.
 */
.card:has(.table-wrap) {
  overflow: visible !important;
}

/*
 * 마지막 컬럼(관리) 우측 고정 — card가 overflow:visible 일 때 작동.
 * z-index 는 sticky header(th, z-index:1) 보다 높게.
 */
.table-wrap th:last-child,
.table-wrap td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
}
.table-wrap th:last-child {
  background: var(--color-bg);
  box-shadow: -3px 0 6px rgba(0, 0, 0, .06);
}
.table-wrap td:last-child {
  background: var(--color-surface);
  box-shadow: -3px 0 6px rgba(0, 0, 0, .04);
}
tbody tr:hover .table-wrap td:last-child { background: #f8fafc; }

/* 테이블 내 버튼 그룹 */
.action-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── 배지 ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: .01em;
}
.badge-success  { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning  { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger   { background: var(--color-danger-bg);  color: var(--color-danger); }
.badge-muted    { background: #f1f5f9; color: var(--color-text-muted); }
.badge-primary  { background: var(--color-primary-light); color: var(--color-primary); }

/* ── 폼 ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid .span-2 { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}
.form-label .required { color: var(--color-danger); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-input::placeholder { color: var(--color-text-light); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-error {
  font-size: 0.8125rem;
  color: var(--color-danger);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

/* ── 검색바 ── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-input-wrap svg {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}
.search-input-wrap .form-input { padding-left: 34px; }

/* ── 빈 상태 ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
  text-align: center;
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: .5;
}
.empty-title { font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.empty-desc  { font-size: 0.875rem; }

/* ── 로딩 ── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row td {
  text-align: center;
  padding: 40px;
}

/* ── 유틸 ── */
.text-muted   { color: var(--color-text-muted); }
.text-danger  { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-sm      { font-size: 0.875rem; }
.text-xs      { font-size: 0.75rem; }
.fw-600       { font-weight: 600; }
.mt-4         { margin-top: 16px; }
.mb-4         { margin-bottom: 16px; }
.gap-2        { gap: 8px; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.w-full       { width: 100%; }

/* ── 페이지네이션 ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
  font-size: 0.875rem;
}
.pagination-info { color: var(--color-text-muted); }

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

/* ── 섹션 타이틀 ── */
.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--color-text);
}

/* ── 날짜 분할 입력 (년 / 월 / 일) ── */
.split-date {
  display: flex;
  align-items: center;
  gap: 4px;
}
.split-date-sep {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  flex-shrink: 0;
  user-select: none;
}
.split-date .form-input {
  text-align: center;
  min-width: 0;
  padding-left: 6px;
  padding-right: 6px;
}

/* ── 폼 섹션 구분 헤더 ── */
.form-section-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}
.form-section-header span {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.form-section-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}
