:root {
  --bg-sidebar:#0a0a1a; --bg-content:#f7f7fc; --bg-card:#ffffff;
  --primary:#7c3aed; --primary-2:#6d28d9; --primary-light:#ede9fe;
  --accent:#a78bfa; --cyan:#06b6d4; --pink:#ec4899;
  --text:#1f2937; --text-muted:#6b7280; --text-inv:#e5e7eb; --border:#ececf2;
  --success:#10b981; --warning:#f59e0b; --danger:#ef4444;
  --shadow:0 1px 3px rgba(0,0,0,0.04), 0 6px 18px rgba(124,58,237,0.06);
  --ai-grad:linear-gradient(135deg,#7c3aed 0%,#a855f7 45%,#ec4899 100%);
  --ai-grad-soft:linear-gradient(135deg,#ede9fe 0%,#fce7f3 100%);
  --ai-dark:linear-gradient(135deg,#1e1b4b 0%,#4c1d95 50%,#831843 100%);
}
* { box-sizing:border-box; margin:0; padding:0; }
body { font-family:-apple-system,BlinkMacSystemFont,'Pretendard','Noto Sans KR','Segoe UI',sans-serif; background:var(--bg-content); color:var(--text); font-size:14px; overflow:hidden; }
.app { display:flex; height:100vh; }

/* ============ Sidebar ============ */
.sidebar { width:248px; background:var(--bg-sidebar); color:var(--text-inv); display:flex; flex-direction:column; flex-shrink:0; border-right:1px solid #1a1830; }
.brand { padding:20px 22px 18px; display:flex; align-items:center; gap:12px; border-bottom:1px solid #1a1830; }
.brand .logo { width:42px; height:42px; background:linear-gradient(135deg,#4c1d95,#7c3aed,#c026d3); border-radius:11px; display:flex; align-items:center; justify-content:center; box-shadow:0 4px 14px rgba(124,58,237,0.5), inset 0 0 12px rgba(168,85,247,0.4); position:relative; overflow:hidden; }
.brand .logo svg { width:30px; height:30px; position:relative; z-index:2; }
.brand .name { font-size:15px; font-weight:700; color:#fff; }
.brand .name b { background:var(--ai-grad); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; }
.brand .tag { font-size:11px; color:#9ca3af; margin-top:2px; }
.nav { flex:1; overflow-y:auto; padding:14px 10px; }
.nav-section { padding:14px 12px 6px; font-size:10px; text-transform:uppercase; letter-spacing:0.08em; color:#6b7280; font-weight:700; }
.nav a { display:flex; align-items:center; gap:10px; padding:9px 12px; color:#b1aec4; text-decoration:none; border-radius:8px; margin:2px 0; cursor:pointer; font-size:13px; transition:all 0.15s; }
.nav a:hover { background:#1a1830; color:#fff; }
.nav a.active { background:var(--ai-grad); color:#fff; box-shadow:0 4px 14px rgba(124,58,237,0.35); }
.nav a .icon { width:18px; text-align:center; font-size:14px; }
.nav a .badge { margin-left:auto; background:#2a2740; color:#cbd5e1; border-radius:10px; padding:1px 8px; font-size:10px; font-weight:700; }
.nav a.active .badge { background:rgba(255,255,255,0.25); color:white; }

/* AI promo box */
.ai-promo { margin:12px; padding:16px 90px 16px 16px; background:var(--ai-dark); border-radius:14px; position:relative; overflow:hidden; min-height:96px; }
.ai-promo::before { content:''; position:absolute; top:-30px; right:-30px; width:110px; height:110px; background:radial-gradient(circle,rgba(168,85,247,0.5),transparent 60%); }
.ai-promo h5 { font-size:13px; color:#fff; font-weight:700; margin-bottom:6px; position:relative; z-index:2; }
.ai-promo p { font-size:11px; color:#c7c2d9; line-height:1.55; position:relative; z-index:2; }
.ai-promo .promo-brain { position:absolute; right:-6px; top:50%; transform:translateY(-50%); width:88px; height:88px; opacity:0.9; filter:drop-shadow(0 0 8px rgba(168,85,247,0.6)); pointer-events:none; }

/* ============ Topbar ============ */
.main { flex:1; display:flex; flex-direction:column; overflow:hidden; }
.topbar { height:64px; background:white; border-bottom:1px solid var(--border); display:flex; align-items:center; padding:0 24px; gap:16px; }
.topbar .crumb { color:var(--text-muted); font-size:13px; cursor:pointer; user-select:none; }
.topbar .crumb .sep { margin:0 8px; color:#cbd5e1; }
.topbar .crumb .current { color:var(--text); font-weight:600; }
.topbar .crumb .ai-prefix { background:var(--ai-grad); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; font-weight:600; }
.spacer { flex:1; }
.search { width:320px; padding:9px 14px; background:var(--bg-content); border:1px solid var(--border); border-radius:9px; font-size:13px; }
.search:focus { outline:none; border-color:var(--primary); background:white; box-shadow:0 0 0 3px rgba(124,58,237,0.1); }
.icon-btn { width:38px; height:38px; border-radius:9px; border:1px solid var(--border); background:white; cursor:pointer; font-size:15px; }
.icon-btn:hover { background:var(--primary-light); border-color:var(--accent); }
.user { display:flex; align-items:center; gap:10px; padding-left:16px; border-left:1px solid var(--border); }
.avatar { width:36px; height:36px; border-radius:50%; background:var(--ai-grad); color:white; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:14px; box-shadow:0 2px 8px rgba(124,58,237,0.3); }

/* ============ Buttons ============ */
.btn { padding:9px 14px; border-radius:9px; border:1px solid var(--border); background:white; cursor:pointer; font-size:13px; font-weight:500; color:var(--text); display:inline-flex; align-items:center; gap:6px; font-family:inherit; }
.btn:hover { background:var(--bg-content); border-color:var(--accent); }
.btn.primary { background:var(--primary); color:white; border-color:var(--primary); }
.btn.primary:hover { background:var(--primary-2); }
.btn.ai { background:var(--ai-grad); color:white; border:none; box-shadow:0 4px 14px rgba(124,58,237,0.3); }
.btn.ai:hover { box-shadow:0 6px 20px rgba(124,58,237,0.45); transform:translateY(-1px); }
.btn.sm { padding:5px 10px; font-size:12px; }
.btn.success { background:var(--success); color:white; border-color:var(--success); }
.btn.danger { background:white; color:var(--danger); border-color:#fecaca; }
.btn.ghost { background:transparent; border-color:rgba(124,58,237,0.3); color:var(--primary); }

/* ============ Content / Views ============ */
.content { flex:1; overflow-y:auto; padding:24px; }
.view { display:none; }
.view.active { display:block; }
.page-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; gap:16px; flex-wrap:wrap; }
.page-title { font-size:22px; font-weight:700; display:flex; align-items:center; gap:8px; }
.page-title .ai-text { background:var(--ai-grad); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; font-weight:800; }
.page-sub { color:var(--text-muted); font-size:13px; margin-top:4px; }
.filter-bar { display:flex; gap:10px; margin-bottom:16px; flex-wrap:wrap; }
.filter-bar select, .filter-bar input { padding:8px 12px; border:1px solid var(--border); border-radius:8px; background:white; font-size:13px; font-family:inherit; }

/* ============ Kanban Board ============ */
/* 보드: 컬럼 개수와 무관하게 가로 스크롤 + 자동 폭 축소 */
.board {
  display:flex;
  gap:10px;
  min-height:calc(100vh - 240px);
  overflow-x:auto;
  overflow-y:hidden;
  padding-bottom:8px;
  scroll-snap-type:x proximity;
}
.board::-webkit-scrollbar { height:10px; }
.board::-webkit-scrollbar-track { background:transparent; }
.board::-webkit-scrollbar-thumb { background:#d1d5db; border-radius:5px; }
.board::-webkit-scrollbar-thumb:hover { background:#9ca3af; }

.col {
  flex: 0 0 240px;            /* 기본 폭 240, 신축 X — 가로스크롤 우선 */
  min-width:200px;
  max-width:280px;
  background:linear-gradient(180deg,rgba(124,58,237,0.04),rgba(124,58,237,0.01));
  border:1px solid #ececf2; border-radius:14px;
  padding:12px;
  display:flex; flex-direction:column;
  scroll-snap-align:start;
}
/* 컬럼이 적으면(≤5) 화면을 꽉 채우도록 — 동적 클래스로 보드.js에서 토글 */
.board.few-cols .col { flex: 1 1 0; max-width:none; }

.col-head { display:flex; align-items:center; justify-content:space-between; padding:2px 4px 10px; border-bottom:1px dashed #e0deea; margin-bottom:10px; min-height:34px; }
.col-head .label { display:flex; align-items:center; gap:7px; font-weight:700; font-size:12.5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.col-head .dot { width:9px; height:9px; border-radius:50%; flex-shrink:0; background:#9ca3af; }
.col-head .count { background:white; color:var(--text-muted); border-radius:11px; padding:2px 8px; font-size:11px; font-weight:700; border:1px solid var(--border); flex-shrink:0; }

.cards { display:flex; flex-direction:column; gap:8px; flex:1; }
.task-card {
  background:white; border-radius:11px; padding:11px 12px;
  border:1px solid var(--border);
  border-left:3px solid #9ca3af;     /* 색상은 board.js에서 inline override */
  cursor:pointer; box-shadow:0 1px 2px rgba(0,0,0,0.03);
  transition:all 0.15s;
}
.task-card:hover { transform:translateY(-2px); box-shadow:0 8px 24px rgba(124,58,237,0.12); border-color:var(--accent); }
.task-card .tid { font-size:10.5px; color:var(--text-muted); font-family:monospace; }
.task-card .name { font-weight:700; font-size:13px; margin:4px 0 7px; line-height:1.35; }
.task-card .meta { display:flex; justify-content:space-between; align-items:center; margin-top:7px; font-size:10.5px; color:var(--text-muted); }
.task-card .prj { display:inline-block; padding:2px 7px; border-radius:9px; background:var(--primary-light); color:var(--primary); font-size:10px; font-weight:700; }
.task-card .progress { height:4px; background:#f1f5f9; border-radius:4px; overflow:hidden; margin:7px 0 3px; }
.task-card .progress > span { display:block; height:100%; background:var(--ai-grad); }
.task-card .avatars { display:flex; margin-top:7px; }
.task-card .mini-ava { width:22px; height:22px; border-radius:50%; background:linear-gradient(135deg,#6366f1,#06b6d4); color:white; font-size:10px; font-weight:700; display:flex; align-items:center; justify-content:center; border:2px solid white; margin-left:-6px; }
.task-card .mini-ava:first-child { margin-left:0; }
.task-card .mini-ava.curr { box-shadow:0 0 0 2px var(--primary); background:var(--ai-grad); }

/* ============ Task Detail Hero ============ */
.hero { background:white; border-radius:18px; border:1px solid var(--border); padding:24px 28px; margin-bottom:18px; box-shadow:var(--shadow); position:relative; overflow:hidden; display:grid; grid-template-columns:1fr 360px; gap:24px; align-items:center; }
.hero-left { display:flex; gap:22px; align-items:center; }
.hero-ai { width:120px; height:120px; background:linear-gradient(135deg,#4c1d95,#7c3aed,#c026d3); border-radius:22px; display:flex; align-items:center; justify-content:center; box-shadow:0 12px 40px rgba(124,58,237,0.5); position:relative; overflow:hidden; flex-shrink:0; }
.hero-ai .ai-text { position:relative; z-index:2; font-size:44px; font-weight:900; color:white; text-shadow:0 0 20px rgba(255,255,255,0.5); }
.hero-tag { display:inline-block; background:var(--primary-light); color:var(--primary); padding:4px 10px; border-radius:12px; font-size:11px; font-weight:700; margin-bottom:8px; }
.hero-title { font-size:28px; font-weight:800; display:flex; align-items:center; gap:10px; }
.hero-title .ai-text { background:var(--ai-grad); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; }
.hero-sub { color:var(--text-muted); margin-top:8px; font-size:13px; }
.hero-pills { margin-top:12px; display:flex; gap:6px; flex-wrap:wrap; }
.hero-pill { padding:4px 10px; background:white; border:1px solid var(--border); border-radius:12px; font-size:11px; font-weight:600; display:inline-flex; align-items:center; gap:5px; }
.hero-insight { background:var(--ai-dark); border-radius:14px; padding:18px; color:white; position:relative; overflow:hidden; }
.hero-insight .ic-head { color:#c4b5fd; font-size:11px; font-weight:700; margin-bottom:8px; text-transform:uppercase; }
.hero-insight .ic-body { font-size:13px; line-height:1.6; position:relative; max-width:calc(100% - 130px); }
.hero-insight .brain-svg { position:absolute; right:-8px; top:50%; transform:translateY(-50%); width:150px; height:150px; opacity:0.9; filter:drop-shadow(0 0 12px rgba(168,85,247,0.5)); pointer-events:none; }
.hero-back { position:absolute; top:18px; right:24px; background:white; border:1px solid var(--border); color:var(--text-muted); padding:6px 12px; border-radius:8px; font-size:12px; cursor:pointer; z-index:5; font-family:inherit; }

/* ============ Stepper ============ */
.stepper { display:flex; background:white; border-radius:14px; padding:22px 18px; border:1px solid var(--border); margin-bottom:18px; box-shadow:var(--shadow); }
.step { flex:1; text-align:center; position:relative; cursor:pointer; padding:4px; }
.step .circle { width:56px; height:56px; margin:0 auto 10px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:22px; background:#f3f3f8; color:var(--text-muted); border:2px solid #e5e3ed; position:relative; z-index:2; transition:all 0.2s; }
.step .stage-name { font-size:13px; font-weight:700; color:var(--text-muted); }
.step .assignee { font-size:11px; color:var(--text-muted); margin-top:2px; }
.step.done .circle { background:linear-gradient(135deg,#34d399,#10b981); color:white; border-color:#10b981; }
.step.done .stage-name { color:var(--text); }
.step.active .circle { background:var(--ai-grad); color:white; border-color:var(--primary); transform:scale(1.08); box-shadow:0 0 0 6px rgba(124,58,237,0.12); }
.step.active .stage-name { color:var(--primary); }
.step::after { content:''; position:absolute; top:32px; left:calc(50% + 30px); right:calc(-50% + 30px); height:2px; background:#e5e3ed; z-index:1; }
.step:last-child::after { display:none; }
.step.done::after { background:linear-gradient(90deg,#10b981,rgba(124,58,237,0.5)); height:3px; }

/* ============ Detail body ============ */
.detail-grid { display:grid; grid-template-columns:1fr 340px; gap:16px; }
.detail-main { background:white; border-radius:14px; padding:22px; border:1px solid var(--border); box-shadow:var(--shadow); }
.detail-side { display:flex; flex-direction:column; gap:14px; }
.panel { background:white; border-radius:14px; padding:18px; border:1px solid var(--border); box-shadow:var(--shadow); }
.panel h4 { font-size:13px; font-weight:700; margin-bottom:14px; display:flex; align-items:center; gap:6px; }
.stage-content h3 { font-size:16px; font-weight:700; margin-bottom:14px; display:flex; align-items:center; gap:8px; }
.stage-pill { padding:4px 11px; border-radius:12px; font-size:11px; font-weight:700; color:white; background:var(--ai-grad); }
.stage-now { margin-left:auto; padding:3px 10px; background:var(--primary-light); color:var(--primary); border-radius:12px; font-size:11px; font-weight:700; }
.info-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-top:6px; }
.info-cell { background:var(--bg-content); border-radius:10px; padding:14px; border:1px solid var(--border); }
.info-cell .k { font-size:11px; color:var(--text-muted); text-transform:uppercase; font-weight:700; }
.info-cell .v { font-size:15px; font-weight:600; margin-top:6px; }
.info-cell .v.big { font-size:18px; }
.info-cell .v.primary { color:var(--primary); }
.info-cell .progress { height:6px; background:white; border-radius:4px; overflow:hidden; margin-top:8px; }
.info-cell .progress > span { display:block; height:100%; background:var(--ai-grad); }
.info-row { display:grid; grid-template-columns:120px 1fr; padding:9px 0; font-size:13px; border-bottom:1px dashed #f1f0f7; }
.info-row:last-child { border-bottom:none; }
.info-row .key { color:var(--text-muted); }

/* Defect items */
.defect { display:flex; align-items:center; gap:14px; padding:14px 16px; background:var(--bg-content); border-radius:10px; border-left:3px solid var(--danger); margin-bottom:10px; }
.defect .did { font-family:monospace; font-size:12px; color:var(--danger); font-weight:700; }
.defect .tag { padding:2px 8px; border-radius:6px; background:#fee2e2; color:var(--danger); font-size:10px; font-weight:700; }
.defect .desc { flex:1; }
.defect .desc .title { font-size:14px; font-weight:600; }
.defect .desc .meta { font-size:11px; color:var(--text-muted); margin-top:2px; }

/* AI 담당자 릴레이 */
.relay-list { display:flex; flex-direction:column; gap:10px; }
.relay-row { display:flex; align-items:center; gap:12px; padding:10px 12px; border-radius:10px; border:1px solid var(--border); background:var(--bg-content); }
.relay-row.done { background:white; }
.relay-row.current { background:var(--ai-grad-soft); border-color:var(--accent); box-shadow:0 4px 14px rgba(124,58,237,0.15); }
.relay-row .relay-num { width:28px; height:28px; border-radius:50%; color:white; font-size:12px; font-weight:700; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.relay-row .who { font-size:13px; font-weight:700; }
.relay-row .role { font-size:11px; color:var(--text-muted); }
.relay-row .relay-info { flex:1; }
.relay-row .relay-status { font-size:11px; font-weight:700; }
.relay-row.done .relay-status { color:var(--success); }
.relay-row.current .relay-status { color:var(--primary); }
.relay-row.todo .relay-status { color:var(--text-muted); }

/* AI 추천 액션 */
.reco-row { display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:10px; cursor:pointer; }
.reco-row:hover { background:var(--bg-content); }
.reco-num { width:22px; height:22px; border-radius:50%; background:var(--primary-light); color:var(--primary); font-size:11px; font-weight:700; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.reco-text { flex:1; font-size:12px; font-weight:600; line-height:1.45; }
.reco-score { font-size:10px; color:var(--success); font-weight:700; }

.ai-tag { display:inline-flex; align-items:center; gap:4px; padding:3px 8px; background:var(--ai-grad); color:white; border-radius:10px; font-size:10px; font-weight:700; margin-left:6px; }
.ai-card { background:var(--ai-grad-soft); border:1px solid #ddd6fe; border-radius:12px; padding:14px; }

.actions-bar { margin-top:16px; background:white; border-radius:14px; padding:16px 20px; border:1px solid var(--border); box-shadow:var(--shadow); display:flex; align-items:center; justify-content:space-between; gap:16px; }
.actions-bar .hint { font-size:12px; color:var(--text-muted); }

pre.code { background:#0f172a; color:#e2e8f0; padding:14px; border-radius:10px; font-size:12px; line-height:1.6; overflow-x:auto; font-family:'Consolas',monospace; }

/* ============ Modal ============ */
.modal-bg { position:fixed; inset:0; background:rgba(10,10,26,0.6); display:none; align-items:center; justify-content:center; z-index:1000; backdrop-filter:blur(4px); }
.modal-bg.active { display:flex; }
.modal { background:white; border-radius:16px; width:680px; max-width:95vw; max-height:90vh; overflow-y:auto; box-shadow:0 20px 50px rgba(0,0,0,0.4); }
.modal.wide { width:1000px; }
.modal-head { padding:22px 26px; border-bottom:1px solid var(--border); display:flex; justify-content:space-between; align-items:center; }
.modal-head h3 { font-size:18px; font-weight:700; }
.modal-body { padding:22px 26px; }
.modal-foot { padding:16px 26px; border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:8px; }
.close-btn { background:none; border:none; cursor:pointer; font-size:22px; color:var(--text-muted); }

.form-row { display:flex; flex-direction:column; gap:6px; margin-bottom:14px; }
.form-row label { font-size:12px; font-weight:700; color:var(--text-muted); }
.form-row input, .form-row textarea, .form-row select { padding:10px 12px; border:1px solid var(--border); border-radius:9px; font-size:13px; font-family:inherit; }
.form-row input:focus, .form-row textarea:focus, .form-row select:focus { outline:none; border-color:var(--primary); }

.stage-builder { background:var(--bg-content); border:1px solid var(--border); border-radius:12px; padding:14px; }
.stage-list { display:flex; flex-direction:column; gap:6px; }
.stage-row { display:grid; grid-template-columns:28px 1.3fr 1fr 80px; gap:8px; align-items:center; background:white; border:1px solid var(--border); border-radius:8px; padding:7px 10px; }
.stage-row .num { font-size:12px; color:var(--text-muted); font-weight:700; text-align:center; }
.stage-row .stage-info { display:flex; align-items:center; gap:6px; font-size:13px; font-weight:600; }
.stage-row .stage-info .swatch { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
.stage-row select { padding:5px 8px; border:1px solid var(--border); border-radius:6px; font-size:12px; }
.stage-row .ctrl { display:flex; gap:2px; justify-content:flex-end; }
.stage-row .ctrl button { width:22px; height:22px; border:1px solid var(--border); background:white; border-radius:4px; cursor:pointer; font-size:11px; color:var(--text-muted); font-family:inherit; }
.stage-row .ctrl .del:hover { background:#fee2e2; color:var(--danger); }
.add-stage-row { display:flex; gap:8px; align-items:center; margin-top:10px; }
.add-stage-row select { flex:1; padding:8px 10px; border:1px solid var(--border); border-radius:8px; font-size:12px; }

/* ============ 2-Column Stage Builder ============ */
.stage-builder-2col { display:grid; grid-template-columns:1fr 320px; gap:14px; background:var(--bg-content); border:1px solid var(--border); border-radius:12px; padding:14px; }
.sb-left { display:flex; flex-direction:column; gap:10px; min-height:380px; }
.sb-left-head { display:flex; justify-content:space-between; align-items:center; font-size:12px; font-weight:700; color:var(--text-muted); padding:0 4px; }
.sb-count { background:var(--primary); color:white; border-radius:10px; padding:2px 9px; font-size:11px; font-weight:700; }
.sb-left .stage-list { flex:1; min-height:280px; max-height:430px; overflow-y:auto; padding:4px; background:white; border:1px dashed var(--border); border-radius:10px; }
.sb-left-foot { display:flex; gap:6px; justify-content:space-between; }
.sb-left-foot .btn.ai { background:linear-gradient(135deg,#fef3c7,#fce7f3); color:#92400e; border:1px solid #fde68a; }

.sb-right { display:flex; flex-direction:column; gap:8px; background:white; border:1px solid var(--border); border-radius:10px; padding:12px; max-height:560px; overflow-y:auto; }
.sb-right-head { font-size:12px; font-weight:700; color:var(--text-muted); margin-bottom:4px; padding:0 2px; }
.stage-tree { display:flex; flex-direction:column; gap:8px; }
.stage-tree-group { background:var(--bg-content); border-radius:8px; padding:8px; }
.stage-tree-group-name { font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.5px; margin-bottom:6px; padding:0 4px; }
.stage-tree-item { display:flex; align-items:center; gap:7px; padding:7px 9px; background:white; border:1px solid var(--border); border-radius:7px; cursor:pointer; font-size:12px; font-weight:600; margin-bottom:4px; transition:all .12s; }
.stage-tree-item:hover { border-color:var(--primary); background:var(--ai-grad-soft); transform:translateX(2px); }
.stage-tree-item .swatch { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
.stage-tree-item .plus { margin-left:auto; color:var(--text-muted); font-weight:700; font-size:13px; }
.stage-tree-item:hover .plus { color:var(--primary); }

.preset-buttons { display:flex; flex-direction:column; gap:5px; }
.preset-btn { display:flex; align-items:center; gap:8px; padding:8px 10px; background:white; border:1px solid var(--border); border-radius:7px; cursor:pointer; font-size:12px; font-weight:600; font-family:inherit; text-align:left; }
.preset-btn:hover { border-color:var(--primary); background:var(--ai-grad-soft); }
.preset-btn .pnum { background:var(--primary); color:white; width:20px; height:20px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:11px; font-weight:700; flex-shrink:0; }
.preset-btn.fav .pnum { background:#f59e0b; }
.preset-btn .pname { flex:1; }
.preset-btn .pcount { color:var(--text-muted); font-size:11px; font-weight:400; }
.preset-btn .pdel { width:18px; height:18px; border:none; background:none; cursor:pointer; color:var(--text-muted); font-size:14px; opacity:0; transition:opacity .12s; }
.preset-btn:hover .pdel { opacity:1; }
.preset-btn .pdel:hover { color:var(--danger); }

/* ============ Bulk Create ============ */
.bulk-tabs { display:flex; gap:4px; background:white; padding:6px; border-radius:10px; border:1px solid var(--border); margin-bottom:18px; width:fit-content; }
.bulk-tab { padding:8px 16px; border-radius:7px; cursor:pointer; font-size:13px; font-weight:600; color:var(--text-muted); }
.bulk-tab.active { background:var(--ai-grad); color:white; box-shadow:0 4px 14px rgba(124,58,237,0.3); }
.bulk-panel { background:white; border-radius:14px; padding:22px; border:1px solid var(--border); box-shadow:var(--shadow); }
.bulk-tab-content { display:none; }
.bulk-tab-content.active { display:block; }
.grid-table { width:100%; border-collapse:separate; border-spacing:0; }
.grid-table th, .grid-table td { padding:10px 12px; text-align:left; border-bottom:1px solid var(--border); font-size:13px; }
.grid-table th { background:var(--bg-content); font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase; }
.grid-table td input, .grid-table td select { width:100%; padding:6px 10px; border:1px solid transparent; background:transparent; font-size:13px; border-radius:6px; font-family:inherit; }
.grid-table td input:focus, .grid-table td select:focus { outline:none; border-color:var(--primary); background:white; }
.grid-table td.idx { color:var(--text-muted); font-family:monospace; width:50px; }
.grid-table td.act { width:50px; text-align:center; }
.grid-table td.act button { background:white; border:1px solid var(--border); border-radius:6px; width:26px; height:26px; cursor:pointer; }
.preset-legend { display:flex; gap:16px; margin-top:12px; padding:12px 14px; background:var(--bg-content); border-radius:8px; font-size:12px; }
.preset-legend .legend-item { display:flex; align-items:center; gap:6px; }
.preset-legend .legend-num { width:22px; height:22px; border-radius:50%; background:var(--ai-grad); color:white; display:flex; align-items:center; justify-content:center; font-size:11px; font-weight:700; }
.drop-zone { border:2px dashed #d4d2e0; border-radius:14px; padding:60px 24px; text-align:center; cursor:pointer; background:var(--bg-content); }
.drop-zone .ic { font-size:48px; margin-bottom:12px; color:var(--accent); }
.drop-zone h4 { font-size:16px; font-weight:700; margin-bottom:6px; }
.drop-zone p { color:var(--text-muted); font-size:13px; }
.summary-card { background:var(--ai-grad-soft); border:1px solid #ddd6fe; border-radius:12px; padding:14px 18px; margin-top:16px; display:flex; align-items:center; justify-content:space-between; }
.summary-card .info b { color:var(--primary); }

/* ============ AI 미리보기 (단계 공통) ============ */
.ai-preview-card { background:white; border:1px solid var(--border); border-radius:14px; margin:18px 0; overflow:hidden; }
.ai-preview-head { display:flex; align-items:center; justify-content:space-between; padding:12px 16px; border-bottom:1px solid var(--border); background:#fafaff; }
.ai-preview-head .icon-badge { width:28px; height:28px; border-radius:8px; background:var(--ai-grad); display:flex; align-items:center; justify-content:center; font-size:13px; box-shadow:0 4px 12px rgba(124,58,237,0.3); margin-right:10px; }
.ai-preview-body { background:#f3f3f8; padding:16px; }
.ai-preview-empty { height:360px; display:flex; flex-direction:column; align-items:center; justify-content:center; color:var(--text-muted); border:2px dashed #d4d2e0; border-radius:12px; background:white; }
.ai-input-card { background:white; border:1px solid var(--border); border-radius:12px; padding:16px; }

/* ============================================================ */
/* ============   Responsive (Tablet / Mobile)   ============== */
/* ============================================================ */

/* Hamburger button (hidden on desktop) */
.mobile-menu-btn {
  display:none;
  width:38px; height:38px; border-radius:9px;
  border:1px solid var(--border); background:white;
  cursor:pointer; font-size:18px; align-items:center; justify-content:center;
  flex-shrink:0;
}
.sidebar-overlay {
  display:none;
  position:fixed; inset:0;
  background:rgba(10,10,26,0.5);
  z-index:998;
  backdrop-filter:blur(2px);
}
.sidebar-overlay.active { display:block; }

/* ============ Tablet (≤1024px) ============ */
@media (max-width: 1024px) {
  .sidebar { width:220px; }
  .hero { grid-template-columns:1fr; gap:18px; }
  .hero-insight .ic-body { max-width:calc(100% - 110px); }
  .detail-grid { grid-template-columns:1fr; }
  .stage-builder-2col { grid-template-columns:1fr; }
  .sb-right { max-height:none; }
  .search { width:200px; }
  .content { padding:18px; }
}

/* ============ Mobile (≤768px) ============ */
@media (max-width: 768px) {
  /* 모바일은 body 자체 스크롤로 — iOS Safari 주소창/홈바 때문에 100vh가 가려지는 문제 해결 */
  html, body {
    height:auto;
    min-height:100vh;
    min-height:100dvh;          /* dynamic viewport height — 주소창 변동 반영 */
    overflow:auto;
  }
  body { font-size:13px; }
  .app {
    height:auto;
    min-height:100vh;
    min-height:100dvh;
  }
  .main {
    overflow:visible;
    min-height:100dvh;
  }
  .content {
    overflow:visible;
    padding-bottom:env(safe-area-inset-bottom, 24px);
  }
  /* 추가 여백 — 홈바/주소창 영역 가림 방지 */
  .content::after {
    content:'';
    display:block;
    height:60px;
  }
  /* topbar는 sticky로 위에 고정 */
  .topbar {
    position:sticky;
    top:0;
    z-index:50;
    background:white;
  }

  /* Sidebar — off-canvas slide-in */
  .sidebar {
    position:fixed; top:0; left:0; bottom:0;
    width:260px; max-width:80vw;
    transform:translateX(-100%);
    transition:transform 0.25s ease;
    z-index:999;
    box-shadow:6px 0 24px rgba(0,0,0,0.25);
  }
  .sidebar.open { transform:translateX(0); }

  .main { width:100%; min-width:0; }

  /* Topbar */
  .mobile-menu-btn { display:inline-flex; }
  .topbar {
    height:56px; padding:0 12px; gap:8px;
    overflow:hidden;
  }
  .topbar .crumb { font-size:12px; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; flex:1; }
  .topbar .crumb .sep { margin:0 5px; }
  .search { display:none; }
  .topbar .icon-btn { width:34px; height:34px; font-size:14px; }
  .user { padding-left:8px; gap:6px; }
  .user > div:last-child { display:none; }     /* hide name/role text */
  .avatar { width:30px; height:30px; font-size:12px; }

  /* Content */
  .content { padding:12px; }
  .page-head { flex-direction:column; align-items:flex-start; gap:10px; margin-bottom:14px; }
  .page-title { font-size:18px; }
  .page-sub { font-size:12px; }
  .page-head > div:last-child { width:100%; display:flex; flex-wrap:wrap; gap:6px; }
  .page-head .btn { flex:1; min-width:auto; padding:8px 10px; font-size:12px; justify-content:center; }

  .filter-bar { gap:6px; margin-bottom:12px; }
  .filter-bar select, .filter-bar input { padding:7px 10px; font-size:12px; flex:1; min-width:120px; }

  /* Kanban Board — horizontal scroll already; narrower columns */
  .board { min-height:calc(100vh - 220px); gap:8px; }
  .col { flex:0 0 220px; min-width:200px; padding:10px; }
  .board.few-cols .col { flex:0 0 220px; }       /* keep scroll on mobile */
  .task-card { padding:10px; }
  .task-card .name { font-size:12.5px; }

  /* Hero */
  .hero { padding:16px; border-radius:14px; grid-template-columns:1fr; gap:14px; }
  .hero-left { flex-direction:column; align-items:flex-start; gap:14px; }
  .hero-ai { width:80px; height:80px; border-radius:16px; }
  .hero-ai .ai-text { font-size:30px; }
  .hero-title { font-size:20px; }
  .hero-sub { font-size:12px; }
  .hero-back { top:12px; right:12px; padding:5px 9px; font-size:11px; }
  .hero-insight { padding:14px; }
  .hero-insight .ic-body { max-width:calc(100% - 80px); font-size:12px; }
  .hero-insight .brain-svg { width:90px; height:90px; }
  .hero-pills { gap:4px; }
  .hero-pill { font-size:10px; padding:3px 8px; }

  /* Stepper — horizontal scroll for many stages */
  .stepper {
    padding:14px 8px; gap:4px;
    overflow-x:auto; overflow-y:hidden;
    -webkit-overflow-scrolling:touch;
  }
  .stepper::-webkit-scrollbar { height:4px; }
  .stepper::-webkit-scrollbar-thumb { background:#d1d5db; border-radius:2px; }
  .step { flex:0 0 80px; padding:2px; }
  .step .circle { width:44px; height:44px; font-size:17px; }
  .step .stage-name { font-size:11px; }
  .step .assignee { font-size:10px; }
  .step::after { top:24px; left:calc(50% + 24px); right:calc(-50% + 24px); }

  /* Detail */
  .detail-grid { grid-template-columns:1fr; gap:12px; }
  .detail-main { padding:16px; border-radius:12px; }
  .panel { padding:14px; border-radius:12px; }
  .info-grid { grid-template-columns:1fr; gap:8px; }
  .info-cell { padding:12px; }
  .info-row { grid-template-columns:1fr; gap:2px; padding:8px 0; }
  .info-row .key { font-size:11px; color:var(--text-muted); }

  .stage-content h3 { font-size:14px; flex-wrap:wrap; gap:6px; }
  .stage-pill, .stage-now { font-size:10px; padding:3px 8px; }

  /* Actions bar */
  .actions-bar { padding:12px; flex-direction:column; align-items:stretch; gap:10px; }
  .actions-bar > div:last-child { display:flex; flex-wrap:wrap; gap:6px; }
  .actions-bar .btn { flex:1; min-width:120px; justify-content:center; }

  /* Modal */
  .modal { width:100%; max-width:100vw; max-height:100vh; border-radius:0; }
  .modal.wide { width:100%; }
  .modal-head { padding:16px; }
  .modal-head h3 { font-size:16px; }
  .modal-body { padding:16px; }
  .modal-foot { padding:12px 16px; flex-wrap:wrap; gap:6px; }
  .modal-foot .btn { flex:1; min-width:100px; justify-content:center; }

  /* Form rows */
  .form-row { margin-bottom:10px; }
  .form-row input, .form-row textarea, .form-row select { padding:10px; font-size:14px; }   /* 14px keeps iOS from zooming */

  /* Stage builder */
  .stage-row { grid-template-columns:24px 1fr 80px; gap:6px; padding:6px 8px; }
  .stage-row select { grid-column:2 / -1; }
  .stage-row .ctrl { grid-column:3; }
  .add-stage-row { flex-wrap:wrap; }
  .add-stage-row .btn { flex:1; }

  /* Bulk panel */
  .bulk-panel { padding:14px; border-radius:12px; }
  .bulk-tabs { width:100%; }
  .bulk-tab { flex:1; padding:7px 10px; font-size:12px; text-align:center; }
  .grid-table { display:block; overflow-x:auto; -webkit-overflow-scrolling:touch; }

  /* Defect / relay rows — softer wrapping */
  .defect { flex-wrap:wrap; padding:12px; gap:8px; }
  .defect .desc { flex:1 1 100%; order:3; }
  .relay-row { padding:9px 10px; gap:8px; flex-wrap:wrap; }

  /* AI preview */
  .ai-preview-body { padding:10px; }
  .ai-preview-empty { height:240px; }

  /* Brand smaller in mobile sidebar */
  .brand { padding:16px; }
  .brand .logo { width:36px; height:36px; }
  .brand .name { font-size:14px; }

  /* Code block */
  pre.code { font-size:11px; padding:10px; }
}

/* ============ Small Mobile (≤480px) ============ */
@media (max-width: 480px) {
  .topbar { padding:0 8px; gap:6px; }
  .topbar .crumb .ai-prefix { display:none; }
  .topbar .crumb .sep:first-of-type { display:none; }
  .topbar .icon-btn:nth-of-type(1) { display:none; }    /* hide bell */
  .content { padding:10px; }
  .hero-ai { width:64px; height:64px; }
  .hero-ai .ai-text { font-size:24px; }
  .hero-title { font-size:17px; }
  .step { flex:0 0 70px; }
  .step .circle { width:38px; height:38px; font-size:15px; }
  .col { flex:0 0 200px; min-width:180px; }
}

/* Touch targets — at least 36px on mobile */
@media (max-width: 768px) and (pointer: coarse) {
  .btn { min-height:38px; }
  .nav a { padding:11px 12px; }
  .stage-tree-item, .preset-btn { min-height:38px; }
}

/* ============ Stage-specific overrides (mobile) ============ */
/* stage 들이 인라인 스타일로 grid/flex split을 많이 쓰므로 강제 stack */
@media (max-width: 768px) {
  /* 2-컬럼 인라인 grid → 1단 */
  .detail-main [style*="grid-template-columns"],
  .stage-content [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  /* 디자인 stage split view (이미지 좌/우 비교) */
  .detail-main [style*="display:flex"][style*="gap"] > [style*="flex:1"],
  .detail-main [style*="display: flex"][style*="gap"] > [style*="flex:1"] {
    min-width: 0;
  }
  /* 채팅창·업로드 카드 등 고정 너비 → 가변 */
  .detail-main [style*="width:"][style*="px"] {
    max-width: 100%;
  }
  /* 모달 (stage 내부에서 띄우는 것들) — 화면 가득 */
  .detail-main [style*="position:fixed"] > div,
  body > div[style*="position:fixed"] > div[style*="background:white"],
  body > div[style*="position:fixed"] > div[style*="background:#fff"] {
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    width: 100% !important;
  }
  /* 입력 폼 한 줄로 모이지 않게 wrap */
  .detail-main [style*="display:flex"][style*="gap"]:not([style*="flex-direction:column"]) {
    flex-wrap: wrap;
  }
  /* 디자인 stage zoom toolbar, chat header 등 → wrap */
  .detail-main [style*="display:flex"][style*="justify-content"]:not([style*="flex-direction:column"]) {
    flex-wrap: wrap;
  }
  /* 버튼 그룹 — 모바일에서 줄바꿈 */
  .detail-main [style*="display:flex"][style*="gap"] > button {
    flex: 0 1 auto;
  }
  /* 이미지 미리보기 컨테이너 → 가로 100% */
  .detail-main img, .detail-main iframe { max-width: 100%; height: auto; }
}

/* ============ Mobile 보강 (≤768px) — stage 인라인 레이아웃 깨짐 방지 ============ */
@media (max-width: 768px) {
  /* 좁은 flex 아이템에서 한 글자씩 세로로 떨어지는 문제 → 단어 단위 줄바꿈 + 최소폭 해제 */
  .detail-main, .detail-main * { min-width: 0; word-break: keep-all; overflow-wrap: anywhere; }
  .detail-main [style*="display:flex"]:not([style*="flex-direction:column"]):not([style*="flex-direction: column"]),
  .detail-main [style*="display: flex"]:not([style*="flex-direction:column"]):not([style*="flex-direction: column"]) { flex-wrap: wrap; }
  .detail-main [style*="display:flex"] > *, .detail-main [style*="display: flex"] > * { flex-shrink: 1; }
  /* 텍스트 블록이 flex 안에서 눌리지 않도록 — 글 있는 항목은 한 줄 통째로 */
  .detail-main [style*="display:flex"] > div[style*="flex:1"],
  .detail-main [style*="display:flex"] > div[style*="flex: 1"] { flex: 1 1 100% !important; }
  /* 고정 px 너비 → 가변 */
  .detail-main [style*="width:"][style*="px"]:not(img):not(svg):not(canvas) { width: auto !important; max-width: 100% !important; }
  .detail-main [style*="min-width:"][style*="px"] { min-width: 0 !important; }
  .detail-main [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .detail-main input:not([type=checkbox]):not([type=radio]), .detail-main select, .detail-main textarea { width: 100% !important; max-width: 100%; box-sizing: border-box; }
  .detail-main pre, .detail-main code { white-space: pre-wrap; overflow-x: auto; max-width: 100%; }
  .detail-main table { display: block; overflow-x: auto; max-width: 100%; }
  .detail-main button { white-space: nowrap; }
  /* 상단 카드(담당자/진행률 등) 2단 → 1단 */
  .detail-main .info-grid, .detail-main .meta-grid { grid-template-columns: 1fr !important; }
  /* 라벨·헤더 글자 크기 살짝 줄임 */
  .detail-main h3, .detail-main h4 { font-size: 14px; }
  /* 우측 사이드(릴레이/AI 추천) 는 본문 아래로 */
  .detail-side { order: 2; }
}
