/* ── BizFlow 공통 스타일 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f172a;
  --bg2:      #1e293b;
  --bg3:      #334155;
  --border:   #334155;
  --text:     #f1f5f9;
  --text2:    #94a3b8;
  --accent:   #6366f1;
  --green:    #10b981;
  --yellow:   #f59e0b;
  --red:      #ef4444;
  --radius:   12px;
  --radius-s: 8px;
}

body {
  font-family: 'Noto Sans KR', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }

/* ── 네비게이션 ── */
#top-nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px; height: 52px;
  background: rgba(15,23,42,.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.nav-logo {
  font-size: 16px; font-weight: 700; color: var(--accent);
  display: flex; align-items: center; gap: 6px;
}
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
  padding: 6px 12px; border-radius: var(--radius-s);
  color: var(--text2); font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--bg2); color: var(--text); }
.nav-link.active { background: var(--bg2); color: var(--text); }
.nav-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* ── 버튼 ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-s);
  font-size: 13px; font-weight: 600;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-success  { background: var(--green); color: #fff; }
.btn-danger   { background: var(--red); color: #fff; }
.btn-ghost    { background: var(--bg2); color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); }

/* ── 동기화 버튼 ── */
#btn-sync {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-s);
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text2); font-size: 12px; font-weight: 600;
  transition: opacity .15s, transform .15s, background .2s, color .2s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
  /* 버튼 전체 영역이 터치 대상이 되도록 */
  position: relative;
}
/* 자식 span들이 포인터 이벤트를 가로채지 않도록 */
#btn-sync > * {
  pointer-events: none;
}
#btn-sync .sync-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text2);
  flex-shrink: 0;
}
#btn-sync.state-ok .sync-dot   { background: var(--green); }
#btn-sync.state-warn .sync-dot { background: var(--yellow); }
#btn-sync.state-err .sync-dot  { background: var(--red); }
#btn-sync.syncing .sync-dot    { background: var(--accent); animation: pulse .8s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── 배지 ── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}
.badge-active    { background: rgba(99,102,241,.2);  color: #818cf8; }
.badge-completed { background: rgba(16,185,129,.2);  color: #34d399; }
.badge-paused    { background: rgba(245,158,11,.2);  color: #fbbf24; }
.badge-dropout   { background: rgba(239,68,68,.2);   color: #f87171; }
.badge-dropout2  { background: rgba(239,68,68,.12);  color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }

/* ── 모달 ── */
.modal-bg {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.6); align-items: center; justify-content: center;
  padding: 16px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── 폼 ── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 600; }
.form-input, .form-textarea, .form-select {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-s);
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; font-family: inherit;
  outline: none; transition: border .15s;
}
.form-input:focus, .form-textarea:focus { border-color: var(--accent); }

/* ── date input: 연도 4자리 정상 렌더링 (다크모드 color-scheme 필수) ── */
input[type="date"].form-input,
input[type="date"].edit-item-date,
input[type="date"].edit-add-date,
input[type="date"].att-add-date,
input[type="date"].sd-next-input,
input[type="date"] {
  color-scheme: dark;
  /* 연도 필드 잘림 방지 — 충분한 최소 너비 확보 */
  min-width: 130px;
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── 원가/이익율 서브 입력 행 ── */
.cost-row {
  display: flex; align-items: flex-end; gap: 8px; margin-top: 6px;
}
.cost-input-wrap { flex: 1; min-width: 0; }
.cost-ratio-wrap { flex-shrink: 0; min-width: 60px; text-align: center; }
.cost-label {
  display: block; font-size: 10px; color: var(--text2);
  margin-bottom: 3px; font-weight: 500; letter-spacing: .3px;
}
.cost-input { font-size: 12px !important; padding: 6px 8px !important; height: 32px; }
.cost-ratio-badge {
  display: inline-block; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; font-weight: 600;
  color: var(--green); white-space: nowrap; min-width: 52px;
  text-align: center; line-height: 1.4;
}
.cost-ratio-badge.negative { color: var(--red); }

/* ── 색상 피커 (기본 — cp-item 방식으로 업그레이드됨) ── */
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
/* 레거시 .cp-btn (단독 사용 시) */
.cp-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid transparent; transition: border .15s;
}
.cp-btn.active { border-color: #fff; }

/* ── 토스트 ── */
#sync-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px; border-radius: 20px;
  font-size: 13px; font-weight: 500; opacity: 0;
  transition: opacity .3s, transform .3s; pointer-events: none; z-index: 999;
  white-space: nowrap;
}
#sync-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#sync-toast.ok   { border-color: var(--green); color: var(--green); }
#sync-toast.err  { border-color: var(--red);   color: var(--red); }

/* ── 접속자 드로어 ── */
#users-drawer {
  position: fixed; right: -320px; top: 52px; bottom: 0; width: 300px;
  background: var(--bg2); border-left: 1px solid var(--border);
  transition: right .25s; z-index: 150; display: flex; flex-direction: column;
}
#users-drawer.open { right: 0; }
.drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px; border-bottom: 1px solid var(--border);
  font-size: 14px; font-weight: 700;
}
.drawer-list { flex: 1; overflow-y: auto; padding: 8px; }
.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-s); margin-bottom: 4px;
}
.user-row:hover { background: var(--bg3); }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-meta { font-size: 11px; color: var(--text2); margin-top: 2px; }
.user-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.user-dot.on  { background: var(--green); }
.user-dot.off { background: var(--bg3); }
.drawer-overlay {
  display: none; position: fixed; inset: 0; z-index: 149;
  background: rgba(0,0,0,.4);
}
.drawer-overlay.open { display: block; }

/* ── 드로어 푸터 버튼 ── */
.drawer-footer {
  padding: 10px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.drawer-footer-btn {
  width: 100%; font-size: 12px; justify-content: flex-start;
  padding: 8px 12px;
}
.drawer-lock-btn {
  width: 100%; font-size: 12px; justify-content: flex-start;
  padding: 8px 12px; border-radius: var(--radius-s);
  background: rgba(239,68,68,.12); color: #f87171;
  border: 1px solid rgba(239,68,68,.25);
  transition: background .15s;
}
.drawer-lock-btn:hover { background: rgba(239,68,68,.22); }

/* ── 접속자 섹션 타이틀 ── */
.user-section-title {
  font-size: 10px; font-weight: 700; color: var(--text2);
  letter-spacing: .06em; padding: 4px 10px 2px;
  display: flex; align-items: center; gap: 5px;
  text-transform: uppercase;
}
/* ── 나 (me) 뱃지 ── */
.user-me-badge {
  font-size: 10px; color: var(--accent); font-weight: 600;
}
/* ── 내 행 강조 ── */
.user-row-me {
  background: rgba(99,102,241,.07);
  border-radius: var(--radius-s);
}

/* ── 사용자 아바타 (네비) ── */
.nav-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; cursor: pointer;
  position: relative;
}
.nav-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--green); color: #fff; font-size: 9px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px; text-align: center;
  line-height: 16px; padding: 0 3px; display: none;
}
.nav-badge.show { display: block; }

/* ── 반응형 ── */
@media (max-width: 600px) {
  #top-nav { padding: 0 12px; }
  .nav-links .nav-link span { display: none; }
  .btn-text { display: none; }
}
