/* ============================================
   KBLS 평가 앱 - 전역 스타일
   태블릿 최적화 (1024px 기준)
   ============================================ */

/* ---- 기본 리셋 & 변수 ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #1e40af;
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-warning: #d97706;
  --color-info: #0891b2;

  /* 단계별 색상 */
  --stage-0: #6b7280;
  --stage-1: #7c3aed;
  --stage-2: #1d4ed8;
  --stage-3: #15803d;
  --stage-4: #b45309;
  --stage-5: #be185d;

  /* 라이트 모드 */
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-alt: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);

  --font-size-base: 16px;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --transition: 0.15s ease;
}

/* 다크 모드 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #0f172a;
    --bg-card: #1e293b;
    --bg-card-alt: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border-color: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
  }
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    'Noto Sans KR', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- 레이아웃 ---- */
#app {
  max-width: 1024px;
  margin: 0 auto;
  padding: 1rem;
}

.page {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- 카드 ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

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

/* ---- 버튼 ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  touch-action: manipulation;
  user-select: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1e3a8a; }

.btn-success   { background: var(--color-success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger    { background: var(--color-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-warning   { background: var(--color-warning); color: #fff; }
.btn-warning:hover:not(:disabled) { background: #b45309; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--border-color);
  color: var(--text-primary);
}
.btn-outline:hover:not(:disabled) { border-color: var(--color-primary); color: var(--color-primary); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-card-alt); }

.btn-lg {
  min-height: 56px;
  padding: 0.85rem 1.75rem;
  font-size: 1.1rem;
  border-radius: var(--radius-lg);
}

.btn-sm {
  min-height: 36px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

/* ---- 입력 폼 ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input,
.form-select {
  height: 44px;
  padding: 0 0.85rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color var(--transition);
  width: 100%;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30,64,175,0.15);
}

/* ---- 체크 항목 ---- */
.check-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  touch-action: manipulation;
  min-height: 52px;
}

.check-item:hover { background: var(--bg-card-alt); }

.check-item.checked { background: rgba(22,163,74,0.06); }
.check-item.checked .check-label { color: var(--text-secondary); }

/* 체크박스 커스텀 */
.check-box {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 6px;
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  background: var(--bg-card);
  font-size: 1.1rem;
}

.check-item.mandatory .check-box   { border-color: #2563eb; }
.check-item.recommended .check-box { border-color: #d97706; }

.check-item.checked .check-box {
  background: var(--color-success);
  border-color: var(--color-success);
  color: white;
}
.check-item.recommended.checked .check-box {
  background: #d97706;
  border-color: #d97706;
  color: white;
}

.check-label {
  flex: 1;
  font-size: 0.97rem;
  color: var(--text-primary);
  line-height: 1.4;
}

/* 필수/권장 뱃지 */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}
.badge-mandatory    { background: #dbeafe; color: #1e40af; }
.badge-recommended  { background: #fef3c7; color: #92400e; }

/* ---- 단계 헤더 ---- */
.stage-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
}

.stage-0 { background: rgba(107,114,128,0.12); color: #4b5563; border-left: 4px solid #6b7280; }
.stage-1 { background: rgba(124,58,237,0.1);  color: #6d28d9; border-left: 4px solid #7c3aed; }
.stage-2 { background: rgba(29,78,216,0.1);   color: #1d4ed8; border-left: 4px solid #1d4ed8; }
.stage-3 { background: rgba(21,128,61,0.1);   color: #15803d; border-left: 4px solid #15803d; }
.stage-4 { background: rgba(180,83,9,0.1);    color: #b45309; border-left: 4px solid #b45309; }
.stage-5 { background: rgba(190,24,93,0.1);   color: #be185d; border-left: 4px solid #be185d; }

/* ---- 스톱워치 ---- */
.stopwatch-simple {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card-alt);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  margin-left: 2.5rem;
  margin-bottom: 0.25rem;
  flex-wrap: wrap;
}

.stopwatch-display {
  font-family: 'Courier New', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  min-width: 80px;
  color: var(--text-primary);
}

.stopwatch-display.running { color: var(--color-success); animation: blink 1s infinite; }
.stopwatch-display.warning { color: var(--color-danger); }

/* 연동 스톱워치 측정 중 깜빡임 */
.blink-text { animation: blink 1s infinite; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ---- 연동 스톱워치 섹션 ---- */
.linked-stopwatch-section {
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin: 0.75rem 0;
  background: var(--bg-card);
}

.linked-sw-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.linked-sw-status {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.sw-status-box {
  flex: 1;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 2px solid var(--border-color);
  text-align: center;
  transition: all var(--transition);
}

.sw-status-box.active-compress {
  border-color: var(--color-success);
  background: rgba(22,163,74,0.08);
}

.sw-status-box.active-pause {
  border-color: var(--color-danger);
  background: rgba(220,38,38,0.08);
}

.sw-status-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.sw-status-time {
  font-family: 'Courier New', monospace;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.sw-status-box.active-compress .sw-status-time { color: var(--color-success); }
.sw-status-box.active-pause .sw-status-time    { color: var(--color-danger); }

/* 사이클 테이블 */
.cycle-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.cycle-table th {
  background: var(--bg-card-alt);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-align: center;
  border-bottom: 2px solid var(--border-color);
}

.cycle-table td {
  padding: 0.45rem 0.75rem;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.cycle-table tr:last-child td { border-bottom: none; }

.cycle-table .avg-row td {
  font-weight: 700;
  background: var(--bg-card-alt);
}

.cycle-table .active-row td {
  background: rgba(22,163,74,0.05);
  font-weight: 600;
}

.time-warning { color: var(--color-danger); font-weight: 700; }
.time-ok      { color: var(--color-success); }

/* 연동 스톱워치 조작 버튼 */
.linked-sw-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.75rem;
}

/* ---- 평가 결과 배지 ---- */
.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1rem;
}

.result-badge.pass   { background: #dcfce7; color: #15803d; border: 2px solid #86efac; }
.result-badge.fail   { background: #fee2e2; color: #b91c1c; border: 2px solid #fca5a5; }
.result-badge.pending { background: var(--bg-card-alt); color: var(--text-muted); border: 2px solid var(--border-color); }

/* ---- 선택 페이지 ---- */
.select-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  gap: 2rem;
}

.select-title {
  font-size: 1.8rem;
  font-weight: 800;
  text-align: center;
  color: var(--text-primary);
}

.select-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: -1.5rem;
}

.select-cards {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.select-card {
  width: 260px;
  padding: 2rem 1.5rem;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  touch-action: manipulation;
}

.select-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0,0,0,0.12);
}

.select-card.adult:hover  { border-color: var(--color-primary); }
.select-card.infant:hover { border-color: #be185d; }

.select-card-icon { font-size: 3.5rem; margin-bottom: 1rem; }
.select-card-title { font-size: 1.3rem; font-weight: 800; margin-bottom: 0.5rem; }
.select-card-desc { font-size: 0.9rem; color: var(--text-secondary); line-height: 1.5; }

/* ---- 헤더 평가지 ---- */
.eval-header-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 600px) {
  .eval-header-grid { grid-template-columns: 1fr; }
}

.eval-result-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 2px solid var(--border-color);
  background: var(--bg-card-alt);
}

/* ---- 내비게이션 바 ---- */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.navbar-brand {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--color-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.navbar-actions {
  display: flex;
  gap: 0.5rem;
}

/* ---- 관리 페이지 ---- */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table th {
  background: var(--bg-card-alt);
  padding: 0.65rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-align: left;
  border-bottom: 2px solid var(--border-color);
}

.admin-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.admin-table tr:hover td { background: var(--bg-card-alt); cursor: pointer; }

.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1rem;
}

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

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  color: white;
  min-width: 200px;
}

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

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.toast.success { background: var(--color-success); }
.toast.error   { background: var(--color-danger); }
.toast.info    { background: var(--color-info); }

/* ---- 모달 ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 480px;
  width: 100%;
  padding: 1.5rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* ---- 메모 영역 ---- */
.memo-textarea {
  width: 100%;
  min-height: 100px;
  padding: 0.75rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.95rem;
  resize: vertical;
  font-family: inherit;
  transition: border-color var(--transition);
}

.memo-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30,64,175,0.12);
}

/* ---- 로딩 ---- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text-muted);
  gap: 0.75rem;
  font-size: 1rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---- 빈 상태 ---- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state-text { font-size: 1rem; }

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

/* ---- 유틸 ---- */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.flex        { display: flex; }
.flex-wrap   { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2       { gap: 0.5rem; }
.gap-3       { gap: 0.75rem; }
.mt-1        { margin-top: 0.25rem; }
.mt-2        { margin-top: 0.5rem; }
.mb-2        { margin-bottom: 0.5rem; }
.font-bold   { font-weight: 700; }
.text-sm     { font-size: 0.875rem; }
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }

/* ---- 태블릿 최적화 ---- */
@media (min-width: 768px) {
  #app { padding: 1.25rem; }
  .select-card { width: 300px; }
}

/* ---- 인쇄 숨기기 ---- */
@media print {
  .no-print { display: none !important; }
}

/* ============================================
   로그인 페이지
   ============================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 40%, #1d4ed8 100%);
  padding: 1.5rem;
}

.login-card {
  background: var(--bg-card);
  border-radius: 1rem;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

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

.login-logo-icon {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: 0.5rem;
}

.login-logo-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.login-logo-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* 네비 - 사용자 정보 배지 */
.nav-user-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 99px;
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.nav-user-badge .role-tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 99px;
  font-weight: 700;
}

.nav-user-badge .role-tag.admin {
  background: #fef3c7;
  color: #92400e;
}

.nav-user-badge .role-tag.teacher {
  background: #e0f2fe;
  color: #075985;
}

/* 계정 목록 테이블 (관리자 페이지) */
.account-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.account-table th,
.account-table td {
  padding: 0.6rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.account-table th {
  background: var(--bg-card-alt);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.account-table tr:hover td {
  background: var(--bg-card-alt);
}

/* 권한 배지 */
.role-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 700;
}

.role-badge.admin {
  background: #fef3c7;
  color: #92400e;
}

.role-badge.teacher {
  background: #e0f2fe;
  color: #075985;
}

/* ---- 관리 페이지 탭 ---- */
.admin-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 2px solid var(--border-color);
}

.admin-tab {
  padding: 0.6rem 1.25rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.15s, border-color 0.15s;
}

.admin-tab:hover {
  color: var(--text-primary);
}

.admin-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--color-primary);
  color: white;
  line-height: 1;
}

/* ---- 이관 배너 ---- */
.migration-banner {
  background: linear-gradient(135deg, #1e40af, #1d4ed8);
  color: white;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.85rem;
  font-size: 0.88rem;
  font-weight: 600;
}

/* ---- 이관 완료 행 ---- */
.admin-table tr.row-synced td {
  opacity: 0.55;
}

.admin-table tr.row-synced:hover td {
  opacity: 0.8;
}
