/* components.css — 상태 배지·공통 컴포넌트 스타일 */

/* ── 상태 배지 (SOP Status) ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}

.badge-draft        { background: #e2e8f0; color: #64748b; }
.badge-in-review    { background: #fef3c7; color: #92400e; }
.badge-review1-done { background: #cffafe; color: #0e7490; }
.badge-review2-done { background: #ede9fe; color: #5b21b6; }
.badge-active       { background: #d1fae5; color: #065f46; }
.badge-retired      { background: #fee2e2; color: #991b1b; }
.badge-returned     { background: #ffedd5; color: #9a3412; }

/* 역할 배지 */
.role-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--radius-sm, 4px);
  font-size: .7rem;
  font-weight: 600;
}
.role-Administrator { background: #1e40af; color: #fff; }
.role-Writer        { background: #065f46; color: #fff; }
.role-Reviewer1     { background: #0e7490; color: #fff; }
.role-Reviewer2     { background: #5b21b6; color: #fff; }
.role-FinalApprover { background: #9a3412; color: #fff; }
.role-Reader        { background: #64748b; color: #fff; }

/* 계정 상태 배지 */
.user-status-active    { background: #d1fae5; color: #065f46; }
.user-status-pending   { background: #fef3c7; color: #92400e; }
.user-status-suspended { background: #fee2e2; color: #991b1b; }

/* ── 서명 단계 인디케이터 ─────────────────────────────────────── */
.sign-steps {
  display: flex;
  align-items: flex-start;
  gap: 0;
}

.sign-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  flex: 1;
  min-width: 90px;
}

.sign-step::after {
  content: '';
  position: absolute;
  top: 22px;
  left: 50%;
  right: -50%;
  height: 2px;
  background: var(--border-light, #e2e8f0);
  z-index: 0;
}

.sign-step.done::after { background: var(--color-success, #10b981); }
.sign-step:last-child::after { display: none; }

.sign-step-circle {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border-light, #e2e8f0);
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-sm); font-weight: 700;
  position: relative; z-index: 1;
  transition: box-shadow var(--transition-base);
}
.sign-step.done   .sign-step-circle { background: var(--color-success, #10b981); border-color: var(--color-success, #10b981); color: #fff; }
.sign-step.active .sign-step-circle { border-color: var(--color-primary, #1a3278); color: var(--color-primary, #1a3278); box-shadow: 0 0 0 4px rgba(26,50,120,.1); }

.sign-step-label {
  font-size: var(--text-xs);
  font-weight: 500;
  margin-top: var(--space-2);
  color: var(--text-secondary, #334155);
  text-align: center;
  line-height: 1.5;
  white-space: nowrap;
}
.sign-step-label small {
  display: block;
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--text-muted, #64748b);
}

.sign-step.done   .sign-step-label         { color: var(--color-success, #10b981); }
.sign-step.done   .sign-step-label small   { color: var(--color-success, #10b981); }
.sign-step.active .sign-step-label         { color: var(--color-primary, #1a3278); font-weight: 600; }
.sign-step.active .sign-step-label small   { color: var(--color-primary, #1a3278); }

/* ── 토스트 알림 ─────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-lg, 0 10px 15px rgba(0,0,0,.1));
  min-width: 260px;
  max-width: 380px;
  font-size: .875rem;
  font-weight: 500;
  pointer-events: auto;
  animation: toast-in .2s ease;
}

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

.toast-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.toast-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.toast-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.toast-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

.toast-close {
  margin-left: auto;
  cursor: pointer;
  opacity: .6;
  background: none; border: none; font-size: 1rem;
  color: inherit; line-height: 1;
}
.toast-close:hover { opacity: 1; }

/* ── 모달 ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  animation: fade-in .15s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal,
.modal-box {
  background: var(--bg-base, #fff);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slide-up .15s ease;
}

@keyframes slide-up { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light, #e2e8f0);
  font-size: var(--text-base, 1rem);
  font-weight: 600;
  color: var(--text-primary, #1e293b);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text-muted, #94a3b8);
  padding: 4px;
  border-radius: var(--radius-sm, 4px);
  display: flex; align-items: center; justify-content: center;
  transition: background 150ms, color 150ms;
}
.modal-close:hover { background: var(--bg-secondary, #f8fafc); color: var(--text-primary, #1e293b); }

.modal-body  { padding: 20px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid var(--border-light, #e2e8f0);
  background: var(--bg-secondary, #f8fafc);
  border-radius: 0 0 var(--radius-lg, 12px) var(--radius-lg, 12px);
}
.modal-title { padding: 20px 20px 0; font-size: var(--text-lg, 1.125rem); font-weight: 600; }

/* ── 페이지네이션 ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 24px;
}

.page-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm, 4px);
  font-size: var(--text-sm, .875rem);
  cursor: pointer;
  border: 1px solid var(--border-light, #e2e8f0);
  color: var(--text-secondary, #334155);
  background: var(--bg-base, #fff);
  text-decoration: none;
  transition: background var(--transition-base, 150ms ease);
}

.page-item:hover { background: var(--bg-tertiary, #f0f4f8); text-decoration: none; }
.page-item.active { background: var(--color-primary, #003a78); color: #fff; border-color: var(--color-primary, #003a78); }
.page-item.disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }

/* ── 드롭다운 ────────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-base, #fff);
  border: 1px solid var(--border-light, #e2e8f0);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-md, 0 4px 6px rgba(0,0,0,.07));
  min-width: 160px;
  z-index: 200;
  display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-item { display: block; padding: 8px 14px; font-size: var(--text-sm, .875rem); color: var(--text-primary, #1e293b); cursor: pointer; }
.dropdown-item:hover { background: var(--bg-secondary, #f8fafc); text-decoration: none; }
.dropdown-divider { height: 1px; background: var(--border-light, #e2e8f0); margin: 4px 0; }

/* ── 스핀너 ──────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-light, #e2e8f0);
  border-top-color: var(--color-primary, #003a78);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 로딩 오버레이 ────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 5000;
}

/* ── 토글 스위치 ──────────────────────────────────────────────── */
.toggle-wrap { display: inline-flex; align-items: center; gap: 6px; }
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px; height: 20px;
  flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #cbd5e1;
  border-radius: 20px;
  transition: background .2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 14px; width: 14px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-slider { background: var(--color-primary, #003a78); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }
.toggle-switch input:disabled + .toggle-slider { opacity: .5; cursor: not-allowed; }
.toggle-label { font-size: .75rem; color: var(--text-muted, #94a3b8); min-width: 24px; }
.toggle-label.on { color: var(--color-primary, #003a78); font-weight: 600; }

/* ── 드래그 핸들 ─────────────────────────────────────────────── */
.drag-handle {
  cursor: grab;
  color: var(--text-muted, #94a3b8);
  padding: 0 4px;
  font-size: 1rem;
  line-height: 1;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }
tr.drag-over { background: var(--bg-secondary, #f8fafc); outline: 2px dashed var(--color-primary, #003a78); }
tr.dragging { opacity: .4; }

/* ── 검토 팝업 ──────────────────────────────────────────────── */
.review-popup {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  animation: popup-enter 280ms cubic-bezier(0.25, 1, 0.5, 1) forwards;
}
@keyframes popup-enter {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes popup-exit {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(12px); }
}

.review-popup__header {
  height: 56px;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.review-popup__body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── SOP 문서 뷰어 (sop_detail 페이지) ─────────────────────── */
.sop-viewer {
  background: var(--bg-base);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  overflow: hidden;
}

.sop-viewer__toc {
  width: 190px;
  min-width: 190px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-light);
  background: oklch(98.5% 0.008 235);
  padding: var(--space-4);
  position: sticky;
  top: calc(var(--topbar-height) + var(--space-3));
  align-self: flex-start;
  max-height: calc(100vh - var(--topbar-height) - 48px);
  overflow-y: auto;
}

.sop-toc-meta {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-light);
}

.sop-toc-metarow { margin-bottom: var(--space-2); }

.sop-toc-metalabel {
  display: block;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.sop-toc-metaval {
  display: block;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-primary);
}

.sop-toc__label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.sop-toc__list { list-style: none; padding: 0; margin: 0; }
.sop-toc__list > li { margin-bottom: 1px; }

.sop-toc__link {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-decoration: none;
  padding: 5px var(--space-2);
  border-radius: var(--radius-sm);
  transition: color var(--transition-base), background var(--transition-base);
  line-height: 1.4;
}
.sop-toc__link:hover { color: var(--color-primary); background: oklch(95% 0.025 235); text-decoration: none; }
.sop-toc__link.active { color: var(--color-primary); font-weight: 600; background: oklch(95% 0.025 235); }

.sop-toc__sublist { list-style: none; padding: 0; margin: 2px 0 0; }
.sop-toc__sublist li { margin-bottom: 1px; }
.sop-toc__sublink {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 3px var(--space-2) 3px var(--space-4);
  border-radius: var(--radius-sm);
  transition: color var(--transition-base), background var(--transition-base);
  line-height: 1.4;
}
.sop-toc__sublink:hover { color: var(--color-primary); background: oklch(95% 0.025 235); text-decoration: none; }
.sop-toc__sublink.active { color: var(--color-primary); font-weight: 600; }

.sop-viewer__doc {
  flex: 1;
  padding: var(--space-6) var(--space-8);
  min-width: 0;
  overflow-x: hidden;
}

/* ── SOP 섹션 공통 (detail 뷰 + review popup) ───────────────── */
.sop-section {
  margin-bottom: 40px;
  scroll-margin-top: calc(var(--topbar-height) + 16px);
}

.sop-section-heading {
  display: flex;
  align-items: stretch;
  background: oklch(93.5% 0.032 232);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: var(--space-6);
}

.sop-section-num {
  background: oklch(27% 0.10 240);
  color: #fff;
  padding: 10px 16px;
  font-size: var(--text-sm);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
}

.sop-section-title {
  padding: 10px var(--space-6);
  font-size: var(--text-base);
  font-weight: 600;
  color: oklch(23% 0.09 240);
  display: flex;
  align-items: center;
}

.sop-section .sop-section-body {
  font-size: var(--text-base);
  line-height: 1.85;
  color: var(--text-primary);
}

.sop-section .sop-section-body p { margin-bottom: var(--space-4); }

.sop-section .sop-section-body ol,
.sop-section .sop-section-body ul {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
}

.sop-section .sop-section-body li {
  margin-bottom: 6px;
  line-height: 1.75;
}

.sop-section .sop-section-body ol ol,
.sop-section .sop-section-body ul ul,
.sop-section .sop-section-body ol ul,
.sop-section .sop-section-body ul ol {
  margin-top: 4px;
  margin-bottom: 4px;
}

/* ── 검토 팝업 TOC ──────────────────────────────────────────── */
.review-toc {
  width: 190px;
  min-width: 190px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-light);
  background: oklch(98.5% 0.008 235);
  padding: var(--space-4);
  overflow-y: auto;
}

.review-toc__meta {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-light);
}

.review-toc__metarow { margin-bottom: var(--space-2); }

.review-toc__metalabel {
  display: block;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.review-toc__metaval {
  display: block;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-primary);
}

.review-toc__label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.review-toc ul { list-style: none; padding: 0; margin: 0; }
.review-toc li { margin-bottom: 1px; }
.review-toc a {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-decoration: none;
  padding: 5px var(--space-2);
  border-radius: var(--radius-sm);
  transition: color var(--transition-base), background var(--transition-base);
  line-height: 1.4;
}
.review-toc a:hover { color: var(--color-primary); background: oklch(95% 0.025 235); text-decoration: none; }
.review-toc a.active { color: var(--color-primary); font-weight: 600; background: oklch(95% 0.025 235); }

/* ── SOP 본문 영역 (review popup content) ──────────────────── */
.review-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-8) var(--space-8);
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

/* ── 텍스트 하이라이트 ─────────────────────────────────────── */
.annotation-highlight {
  background: oklch(92% 0.07 85 / 0.65);
  border-radius: 2px;
  cursor: pointer;
  transition: background 180ms ease;
}
.annotation-highlight--active {
  background: oklch(83% 0.13 85 / 0.85);
}
.annotation-highlight.resolved {
  background: transparent;
}

/* ── 텍스트 선택 툴팁 ─────────────────────────────────────── */
.annotation-tooltip {
  position: fixed;
  background: var(--color-primary);
  color: #fff;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  z-index: 300;
  box-shadow: var(--shadow-md);
  animation: tooltip-pop 150ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  pointer-events: auto;
  white-space: nowrap;
}
@keyframes tooltip-pop {
  from { opacity: 0; transform: translateX(-50%) translateY(calc(-100% + 6px)) scale(0.9); }
  to   { opacity: 1; transform: translateX(-50%) translateY(calc(-100% - 2px)) scale(1); }
}

/* ── 댓글 패널 ─────────────────────────────────────────────── */
.comment-panel {
  width: 320px;
  border-left: 1px solid var(--border-light);
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.comment-panel__header {
  padding: var(--space-4) var(--space-4) 0;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.comment-panel__tabs {
  display: flex;
  gap: 0;
  margin-top: var(--space-2);
}

.comment-tab {
  padding: 6px var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 150ms, border-color 150ms;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.comment-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}
.comment-tab:hover:not(.active) { color: var(--text-secondary); }

.comment-panel__list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ── 댓글 버블 ─────────────────────────────────────────────── */
.comment-bubble {
  background: var(--bg-base);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  cursor: default;
  transition: border-color 180ms, box-shadow 180ms;
  animation: bubble-enter 220ms cubic-bezier(0.25, 1, 0.5, 1) forwards;
}
.comment-bubble:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}
.comment-bubble.resolved { opacity: 0.55; }

@keyframes bubble-enter {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.comment-bubble__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}
.comment-bubble__author { font-size: var(--text-xs); font-weight: 700; color: var(--text-primary); }
.comment-bubble__time   { font-size: var(--text-xs); color: var(--text-muted); }

.comment-bubble__quote {
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 4px var(--space-2);
  margin-bottom: var(--space-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.comment-bubble__text {
  font-size: var(--text-sm);
  color: var(--text-primary);
  line-height: 1.55;
}

/* ── 1단계 답글 ────────────────────────────────────────────── */
.comment-replies {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.comment-replies:empty { display: none; }

.comment-reply {
  display: flex;
  gap: var(--space-2);
  padding-left: var(--space-3);
}
.comment-reply__avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
}
.comment-reply__body { flex: 1; min-width: 0; }
.comment-reply__meta { font-size: 10px; color: var(--text-muted); margin-bottom: 2px; }
.comment-reply__text { font-size: var(--text-xs); color: var(--text-primary); line-height: 1.5; }

/* ── SVG 커넥터 오버레이 ────────────────────────────────────── */
#annotation-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.connector-line {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 1.5;
  opacity: 0.5;
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
}
