File size: 30,153 Bytes
d739b1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>πŸ“‹ BADA 개발 μž‘μ—… 관리</title>
  <style>
    @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

    * { margin: 0; padding: 0; box-sizing: border-box; }

    :root {
      --bg-base: #1e1e2e;
      --bg-mantle: #181825;
      --bg-crust: #11111b;
      --bg-surface0: #313244;
      --bg-surface1: #45475a;
      --bg-surface2: #585b70;
      --text: #cdd6f4;
      --text-sub: #a6adc8;
      --text-dim: #6c7086;
      --purple: #cba6f7;
      --green: #a6e3a1;
      --blue: #89b4fa;
      --yellow: #f9e2af;
      --pink: #f5c2e7;
      --red: #f38ba8;
      --peach: #fab387;
      --teal: #94e2d5;
      --lavender: #b4befe;
      --shadow: rgba(0, 0, 0, 0.3);
    }

    body {
      font-family: 'Inter', -apple-system, sans-serif;
      background: var(--bg-base);
      color: var(--text);
      height: 100vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    /* Header */
    .header {
      background: var(--bg-mantle);
      border-bottom: 1px solid var(--bg-surface0);
      padding: 14px 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-shrink: 0;
    }

    .title-area {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .title-logo {
      font-size: 20px;
      background: linear-gradient(135deg, var(--blue), var(--pink));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      font-weight: 700;
    }

    .tabs {
      display: flex;
      background: var(--bg-crust);
      padding: 4px;
      border-radius: 8px;
      gap: 4px;
    }

    .tab-btn {
      padding: 8px 16px;
      border-radius: 6px;
      font-size: 13px;
      font-weight: 500;
      color: var(--text-sub);
      background: transparent;
      border: none;
      cursor: pointer;
      transition: all 0.2s ease;
    }

    .tab-btn:hover {
      color: var(--text);
      background: rgba(255, 255, 255, 0.05);
    }

    .tab-btn.active {
      color: var(--bg-base);
      background: linear-gradient(135deg, var(--blue), var(--pink));
      font-weight: 600;
      box-shadow: 0 4px 12px rgba(245, 194, 231, 0.2);
    }

    /* Layouts */
    .container {
      flex: 1;
      display: flex;
      position: relative;
      overflow: hidden;
    }

    .tab-content {
      flex: 1;
      display: none;
      flex-direction: column;
      padding: 24px;
      overflow-y: auto;
      height: 100%;
    }

    .tab-content.active {
      display: flex;
    }

    .card {
      background: var(--bg-mantle);
      border: 1px solid var(--bg-surface0);
      border-radius: 12px;
      padding: 20px;
      margin-bottom: 20px;
      box-shadow: 0 6px 18px var(--shadow);
    }

    .card-title {
      font-size: 16px;
      font-weight: 600;
      color: var(--lavender);
      margin-bottom: 15px;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .form-group {
      margin-bottom: 16px;
    }

    label {
      display: block;
      font-size: 13px;
      font-weight: 500;
      color: var(--text-sub);
      margin-bottom: 6px;
    }

    input, select, textarea {
      width: 100%;
      padding: 10px 14px;
      background: var(--bg-surface0);
      border: 1px solid var(--bg-surface1);
      border-radius: 8px;
      color: var(--text);
      font-size: 13px;
      outline: none;
      transition: all 0.2s ease;
    }

    textarea {
      resize: vertical;
      font-family: inherit;
    }

    input:focus, select:focus, textarea:focus {
      border-color: var(--blue);
      box-shadow: 0 0 0 2px rgba(137, 180, 250, 0.15);
    }

    .btn {
      padding: 10px 18px;
      border-radius: 8px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      border: none;
      transition: all 0.2s ease;
      white-space: nowrap;
      display: inline-flex;
      align-items: center;
      gap: 8px;
    }

    .btn-primary {
      background: linear-gradient(135deg, var(--blue), var(--pink));
      color: var(--bg-crust);
    }
    .btn-primary:hover {
      opacity: 0.9;
      transform: translateY(-1px);
    }

    .btn-secondary {
      background: var(--bg-surface1);
      color: var(--text);
      border: 1px solid var(--bg-surface2);
    }
    .btn-secondary:hover {
      background: var(--bg-surface2);
    }

    /* Kanban Board */
    .kanban-board {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 16px;
      flex: 1;
      overflow-x: auto;
      margin-top: 10px;
    }

    .kanban-col {
      background: var(--bg-crust);
      border: 1px solid var(--bg-surface0);
      border-radius: 10px;
      padding: 14px;
      display: flex;
      flex-direction: column;
      max-height: 100%;
      overflow-y: auto;
    }

    .kanban-col-title {
      font-size: 13px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      margin-bottom: 12px;
      color: var(--text-dim);
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .kanban-card-list {
      display: flex;
      flex-direction: column;
      gap: 10px;
      flex: 1;
    }

    .kanban-card {
      background: var(--bg-mantle);
      border: 1px solid var(--bg-surface0);
      border-radius: 8px;
      padding: 12px;
      box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
      cursor: grab;
      transition: all 0.2s ease;
    }

    .kanban-card:hover {
      border-color: var(--blue);
      transform: translateY(-1px);
    }

    .kanban-card-title {
      font-size: 13px;
      font-weight: 600;
      color: var(--lavender);
      margin-bottom: 6px;
    }

    .kanban-card-desc {
      font-size: 11px;
      color: var(--text-sub);
      line-height: 1.4;
      margin-bottom: 8px;
    }

    .kanban-card-meta {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 10px;
      color: var(--text-dim);
    }

    /* Troubleshoot KB list */
    .search-row {
      display: flex;
      gap: 10px;
      margin-bottom: 20px;
    }

    .troubleshoot-list {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .troubleshoot-card {
      background: var(--bg-mantle);
      border: 1px solid var(--bg-surface0);
      border-radius: 10px;
      padding: 16px;
      border-left: 4px solid var(--red);
      transition: all 0.2s ease;
    }

    .troubleshoot-card:hover {
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(243, 139, 168, 0.1);
    }

    .ts-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;
    }

    .ts-pattern {
      font-family: 'JetBrains Mono', monospace;
      font-size: 14px;
      font-weight: 600;
      color: var(--text);
    }

    .ts-details {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 15px;
      margin-top: 10px;
      padding-top: 10px;
      border-top: 1px solid var(--bg-surface0);
      font-size: 12px;
    }

    .ts-box-title {
      font-weight: 600;
      color: var(--yellow);
      margin-bottom: 4px;
    }

    /* Loading Overlay */
    .loading-overlay {
      position: absolute;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(24, 24, 37, 0.85);
      z-index: 200;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 15px;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s ease;
      backdrop-filter: blur(4px);
    }

    .loading-overlay.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .spinner {
      width: 40px;
      height: 40px;
      border: 4px solid rgba(245, 194, 231, 0.2);
      border-top-color: var(--pink);
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }

    @keyframes spin {
      to { transform: rotate(360deg); }
    }
  </style>
  <script src="src/utils/focus-restorer.js"></script>
</head>
<body>

  <!-- Header -->
  <div class="header">
    <div class="title-area">
      <div class="title-logo">πŸ“‹ BADA 개발 μž‘μ—… 관리</div>
    </div>
    <div class="tabs">
      <button class="tab-btn active" onclick="switchTab('planning')">πŸ’‘ μš”κ΅¬μ‚¬ν•­ 기획</button>
      <button class="tab-btn" onclick="switchTab('kanban')">πŸ“‹ 칸반 λ³΄λ“œ</button>
      <button class="tab-btn" onclick="switchTab('troubleshoot')">πŸ› νŠΈλŸ¬λΈ”μŠˆνŒ… 지식</button>
    </div>
  </div>

  <!-- Container -->
  <div class="container">

    <!-- Tab 1: Requirements & Planning -->
    <div id="tab-planning" class="tab-content active">
      <div class="card">
        <div class="card-title">πŸ’‘ μ‹ κ·œ κΈ°λŠ₯ 개발 기획 및 영ν–₯도 뢄석</div>
        
        <div class="form-group">
          <label>λŒ€μƒ ν”„λ‘œμ νŠΈ 선택</label>
          <select id="planningProjectSelect">
            <!-- Dynamic options -->
          </select>
        </div>

        <div class="form-group">
          <label>κΈ°νšμ„œ 제λͺ©</label>
          <input type="text" id="planTitle" placeholder="예: OAuth2 인증 둜그인 κΈ°λŠ₯ κ΅¬ν˜„" />
        </div>

        <div class="form-group">
          <label>λͺ©ν‘œ (Goal)</label>
          <input type="text" id="planGoal" placeholder="예: ꡬ글 및 넀이버 μ†Œμ…œ 둜그인 연동" />
        </div>

        <div class="form-group">
          <label>κΈ°λŠ₯ 상세 μš”κ΅¬μ‚¬ν•­ (Requirements)</label>
          <textarea id="planRequirements" rows="5" placeholder="- 둜그인 νŽ˜μ΄μ§€ λ²„νŠΌ λ…ΈμΆœ&#10;- 토큰 검증 미듀웨어 κ΅¬ν˜„&#10;- DB μ‚¬μš©μž μ €μž₯ 처리"></textarea>
        </div>

        <button class="btn btn-primary" onclick="createPlan()">βš™οΈ 기획 생성 및 μ„œλΈŒνƒœμŠ€ν¬ λΆ„ν•΄</button>
        <div class="form-group"><label for="goalPlanningBudget">κ³„νšΒ·λ°°μ • λͺ¨λΈ μ˜ˆμ‚° (USD, 선택)</label><input id="goalPlanningBudget" type="number" min="0.000001" step="any" placeholder="λ―Έμ„€μ •" /></div>
        <div class="form-group"><label for="goalPlanningReserve">κ³„νš μš”μ²­λ‹Ή μ˜ˆμ•½ (USD, 선택)</label><input id="goalPlanningReserve" type="number" min="0.000001" step="any" placeholder="μƒλž΅ν•˜λ©΄ 남은 κ³„νš μ˜ˆμ‚° μ˜ˆμ•½" /></div>
        <div class="form-group"><label for="goalExecutionBudget">μ›Œν¬ν”Œλ‘œμš° μ‹€ν–‰ μ˜ˆμ‚° (USD, 선택)</label><input id="goalExecutionBudget" type="number" min="0.000001" step="any" placeholder="κ³„νš μ˜ˆμ‚°κ³Ό 별도" /></div>
        <div class="form-group"><label for="goalExecutionReserve">μ‹€ν–‰ μš”μ²­λ‹Ή μ˜ˆμ•½ (USD, 선택)</label><input id="goalExecutionReserve" type="number" min="0.000001" step="any" placeholder="미섀정이면 κΈ°μ‘΄ λ™μž‘ μœ μ§€" /></div>
        <small>μ˜ˆμ•½μ€ μ‹€μ œ 청ꡬ μƒν•œμ΄ μ•„λ‹™λ‹ˆλ‹€. λΉ„μš© λ―ΈμƒΒ·μ˜ˆμ•½ μ΄ˆκ³ΌλŠ” κ²€ν† λ‘œ λ©ˆμΆ”λ©°, μˆ˜μ • ν›„ μž¬κ³„νšλ„ 같은 κ³„νš μ˜ˆμ‚°μ„ μ‚¬μš©ν•©λ‹ˆλ‹€.</small>
        <!-- 자율 μ—μ΄μ „νŠΈ: 각 κ³„νšμ„ κ²€ν† ν•œ λ’€ κΈ°μ‘΄ μ›Œν¬ν”Œλ‘œμš°λ₯Ό μ‹€ν–‰ν•œλ‹€. -->
        <button id="autonomousStart" class="btn btn-primary" style="background:#6d28d9;" onclick="runAutonomousGoal()">πŸš€ 자율 μ‹€ν–‰ (κ³„νšβ†’μ›Œν¬ν”Œλ‘œμš°β†’μ‹€ν–‰)</button>
        <button id="autonomousCancel" class="btn" onclick="cancelAutonomousGoal()" disabled>λͺ©ν‘œ μž‘μ—… μ·¨μ†Œ</button>
        <button id="planningCostReview" class="btn" onclick="openGoalPlanningReconciliation(document.getElementById('planningProjectSelect').value, (...args) => ipcRenderer.invoke(...args))">κ³„νšΒ·λ°°μ • λΉ„μš© κ²€ν† </button>
        <button id="learningRecoveryReview" class="btn" onclick="openGoalLearningRecovery(document.getElementById('planningProjectSelect').value, (...args) => ipcRenderer.invoke(...args))">ν•™μŠ΅ 쀑단 κ²€ν† Β·λ§ˆλ¬΄λ¦¬</button>
        <button id="planningTakeoverReview" class="btn" onclick="openGoalPlanningTakeover(document.getElementById('planningProjectSelect').value, (...args) => ipcRenderer.invoke(...args))">μ€‘λ‹¨λœ κ³„νš 이어가기</button>
        <button id="planningPricingEdit" class="btn" onclick="configureGoalPricing((...args) => ipcRenderer.invoke(...args))">이 λͺ©ν‘œμ˜ λ‹¨κ°€Β·μΆœμ²˜ μ„€μ •</button>
        <small id="planningPricingStatus">단가 μΆ”μ • λ―Έμ„€μ • Β· κΈˆμ•‘ 미보고 μš”μ²­μ€ κ²€ν† μ—μ„œ 멈μΆ₯λ‹ˆλ‹€.</small>

        <!-- 자율 μ‹€ν–‰ μ§„ν–‰ 둜그 -->
        <div id="autonomousLog" style="display:none; margin-top:16px; padding:12px; background:#1e1e2e; color:#cdd6f4; border-radius:8px; font-family:monospace; font-size:12px; max-height:280px; overflow:auto; white-space:pre-wrap;"></div>
      </div>
    </div>

    <!-- Tab 2: Kanban Board -->
    <div id="tab-kanban" class="tab-content">
      <div class="form-group" style="max-width: 300px; margin-bottom: 20px;">
        <label>ν”„λ‘œμ νŠΈ ν•„ν„°</label>
        <select id="kanbanProjectSelect" onchange="loadKanbanTasks()">
          <!-- Dynamic options -->
        </select>
      </div>

      <div class="kanban-board">
        <!-- Todo Column -->
        <div class="kanban-col">
          <div class="kanban-col-title">ν•΄μ•Ό ν•  일 <span id="count-todo" style="color: var(--blue);">0</span></div>
          <div class="kanban-card-list" id="col-todo" ondragover="allowDrop(event)" ondrop="drop(event, 'todo')">
            <!-- Cards -->
          </div>
        </div>

        <!-- In Progress Column -->
        <div class="kanban-col">
          <div class="kanban-col-title">μ§„ν–‰ 쀑 <span id="count-in_progress" style="color: var(--purple);">0</span></div>
          <div class="kanban-card-list" id="col-in_progress" ondragover="allowDrop(event)" ondrop="drop(event, 'in_progress')">
            <!-- Cards -->
          </div>
        </div>

        <!-- Completed Column -->
        <div class="kanban-col">
          <div class="kanban-col-title">μ™„λ£Œλ¨ <span id="count-completed" style="color: var(--green);">0</span></div>
          <div class="kanban-card-list" id="col-completed" ondragover="allowDrop(event)" ondrop="drop(event, 'completed')">
            <!-- Cards -->
          </div>
        </div>

        <!-- Failed Column -->
        <div class="kanban-col">
          <div class="kanban-col-title">보λ₯˜/μ‹€νŒ¨ <span id="count-failed" style="color: var(--red);">0</span></div>
          <div class="kanban-card-list" id="col-failed" ondragover="allowDrop(event)" ondrop="drop(event, 'failed')">
            <!-- Cards -->
          </div>
        </div>
      </div>
    </div>

    <!-- Tab 3: Troubleshoot KB -->
    <div id="tab-troubleshoot" class="tab-content">
      <div class="card">
        <div class="card-title">πŸ” μ—λŸ¬ νŠΈλŸ¬λΈ”μŠˆνŒ… 지식 검색</div>
        
        <div class="form-group" style="max-width: 300px;">
          <label>ν”„λ‘œμ νŠΈ ν•„ν„°</label>
          <select id="tsProjectSelect" onchange="searchTroubleshoot()">
            <!-- Dynamic options -->
          </select>
        </div>

        <div class="search-row">
          <input type="text" id="tsSearchInput" placeholder="μ—λŸ¬ μœ ν˜•, 파일λͺ…, 둜그 ν‚€μ›Œλ“œλ‘œ 지식 검색..." style="flex: 1;" />
          <button class="btn btn-primary" onclick="searchTroubleshoot()">πŸ” 검색</button>
        </div>

        <div class="troubleshoot-list" id="tsList">
          <!-- Dynamic troubleshoot entries -->
        </div>
      </div>
    </div>

    <!-- Loading Overlay -->
    <div id="loadingOverlay" class="loading-overlay">
      <div class="spinner"></div>
      <div class="loading-text" id="loadingText">영ν–₯도 λͺ¨λΈ 계산 및 μ„œλΈŒνƒœμŠ€ν¬ λΆ„ν•΄ μ§„ν–‰ 쀑...</div>
    </div>

  </div>

  <script src="goal-planning-reconciliation.js"></script>
  <script src="goal-planning-takeover.js"></script>
  <script src="usage-reconciliation.js"></script>
  <script src="goal-learning-recovery.js"></script>
  <script src="goal-planning-pricing.js"></script>
  <script>
    const { ipcRenderer } = require('electron');

    let allProjects = [];

    window.onload = async () => {
      const urlParams = new URLSearchParams(window.location.search);
      const initialTab = urlParams.get('tab') || 'planning';
      switchTab(initialTab);

      await loadProjects();
    };

    function switchTab(tabId) {
      document.querySelectorAll('.tab-btn').forEach(btn => {
        btn.classList.remove('active');
        if (btn.outerHTML.includes(tabId)) btn.classList.add('active');
      });

      document.querySelectorAll('.tab-content').forEach(content => {
        content.classList.remove('active');
      });
      document.getElementById(`tab-${tabId}`).classList.add('active');

      if (tabId === 'kanban') {
        loadKanbanTasks();
      } else if (tabId === 'troubleshoot') {
        searchTroubleshoot();
      }
    }

    async function loadProjects() {
      try {
        allProjects = await ipcRenderer.invoke('get-code-projects') || [];
        
        fillSelect('planningProjectSelect');
        fillSelect('kanbanProjectSelect');
        fillSelect('tsProjectSelect');
      } catch (err) {
        console.error('Failed to load projects:', err);
      }
    }

    function fillSelect(selectId) {
      const select = document.getElementById(selectId);
      if (!select) return;
      select.innerHTML = '';
      if (allProjects.length === 0) {
        select.innerHTML = `<option value="">λ“±λ‘λœ ν”„λ‘œμ νŠΈ μ—†μŒ</option>`;
        return;
      }
      allProjects.forEach(p => {
        select.innerHTML += `<option value="${p.id}">${escapeHtml(p.name)}</option>`;
      });
    }

    async function createPlan() {
      const projectId = document.getElementById('planningProjectSelect').value;
      const title = document.getElementById('planTitle').value.trim();
      const goal = document.getElementById('planGoal').value.trim();
      const requirements = document.getElementById('planRequirements').value.trim();

      if (!projectId) {
        alert('λŒ€μƒ ν”„λ‘œμ νŠΈλ₯Ό μ„ νƒν•΄μ£Όμ‹­μ‹œμ˜€.');
        return;
      }
      if (!title || !goal) {
        alert('κΈ°νšμ„œ 제λͺ©κ³Ό λͺ©ν‘œλ₯Ό μž…λ ₯ν•΄μ£Όμ‹­μ‹œμ˜€.');
        return;
      }

      showLoading(true, 'πŸ€– μ—μ΄μ „νŠΈ 브레인이 영ν–₯도λ₯Ό ν‰κ°€ν•˜κ³  ν•˜μœ„ 개발 단계λ₯Ό λ‚˜λˆ„κ³  μžˆμŠ΅λ‹ˆλ‹€...');
      
      try {
        const result = await ipcRenderer.invoke('create-dev-plan', projectId, title, goal, requirements);
        if (result.success) {
          alert('성곡! κΈ°νšμ„œκ°€ μœ„ν‚€ 및 λ°μ΄ν„°λ² μ΄μŠ€μ— μ μž¬λ˜μ—ˆμœΌλ©°, ν•˜μœ„ νƒœμŠ€ν¬κ°€ μΉΈλ°˜μ— λ“±λ‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€.');
          
          // 양식 μ΄ˆκΈ°ν™”
          document.getElementById('planTitle').value = '';
          document.getElementById('planGoal').value = '';
          document.getElementById('planRequirements').value = '';

          switchTab('kanban');
        } else {
          alert('기획 생성 μ‹€νŒ¨: ' + result.error);
        }
      } catch (err) {
        alert('였λ₯˜ λ°œμƒ: ' + err.message);
      } finally {
        showLoading(false);
      }
    }

    // --- 자율 μ‹€ν–‰ (Goal β†’ Plan β†’ Workflow β†’ Execute β†’ Replan) ---
    let ownedGoalId=null;
    async function cancelAutonomousGoal(){
      if(!ownedGoalId)return;
      try{const result=await ipcRenderer.invoke('cancel-autonomous-goal',ownedGoalId);if(result.success){document.getElementById('autonomousCancel').disabled=true;appendAutonomousLog('μ·¨μ†Œ μš”μ²­μ„ λ³΄λƒˆμŠ΅λ‹ˆλ‹€. μ†Œμœ  μš”μ²­μ˜ μ’…λ£ŒΒ·λΉ„μš© μ €μž₯을 ν™•μΈν•©λ‹ˆλ‹€.');}else appendAutonomousLog('ν˜„μž¬ 창이 μ†Œμœ ν•œ μ§„ν–‰ λͺ©ν‘œλ₯Ό 확인할 수 μ—†μŠ΅λ‹ˆλ‹€.');}
      catch{appendAutonomousLog('μ·¨μ†Œ μš”μ²­μ„ μ „λ‹¬ν•˜μ§€ λͺ»ν–ˆμŠ΅λ‹ˆλ‹€. ν˜„μž¬ μƒνƒœλ₯Ό ν™•μΈν•΄μ£Όμ„Έμš”.');}
    }
    function appendAutonomousLog(line) {
      const box = document.getElementById('autonomousLog');
      box.style.display = 'block';
      const ts = new Date().toLocaleTimeString();
      box.textContent += `[${ts}] ${line}\n`;
      box.scrollTop = box.scrollHeight;
    }

    // 메인 ν”„λ‘œμ„ΈμŠ€κ°€ λ³΄λ‚΄λŠ” 자율 μ‹€ν–‰ μ§„ν–‰ 이벀트λ₯Ό μˆ˜μ‹ ν•΄ λ‘œκ·Έμ— 좜λ ₯
    ipcRenderer.on('autonomous-goal-event', (event, { channel, payload }) => {
      if(channel==='goal:start'){ownedGoalId=payload.goalId;document.getElementById('autonomousCancel').disabled=false;}
      const map = {
        'goal:start': () => `πŸš€ 자율 λͺ©ν‘œ μ‹œμž‘ (μž¬κ³„νš μ΅œλŒ€ ${payload.maxReplans}회)`,
        'goal:planning': () => `🧠 [μ‹œλ„ ${payload.attempt}] λͺ©ν‘œ λΆ„ν•΄ 쀑...`,
        'goal:plan': () => `πŸ“‹ [μ‹œλ„ ${payload.attempt}] κ³„νš 수립 μ™„λ£Œ β€” λ…Έλ“œ ${payload.nodeCount}개 (workflow=${payload.workflowId})`,
        'goal:waiting': () => `πŸ“‹ [κ³„νš ${payload.attempt}] 곡톡 승인 ν™”λ©΄μ—μ„œ μŠΉμΈΒ·λ°˜λ €Β·μˆ˜μ • μ§€μ‹œλ₯Ό κΈ°λ‹€λ¦½λ‹ˆλ‹€. 봉 κ΄€μ œμ—μ„œλ„ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.`,
        'goal:running': () => `βš™οΈ [μ‹œλ„ ${payload.attempt}] μ›Œν¬ν”Œλ‘œμš° μ‹€ν–‰ 쀑 (run=${payload.runId})`,
        'goal:replan': () => `πŸ” μž¬κ³„νš β€” λ‹€μŒ μ‹œλ„ ${payload.nextAttempt}`,
        'goal:complete': () => `βœ… κ³„νš μ‹€ν–‰ μ™„λ£Œ (run=${payload.runId}, 총 ${payload.attempts}회 μ‹œλ„). λͺ©ν‘œ 좩쑱은 κ·Όκ±°λ₯Ό ν™•μΈν•΄μ£Όμ„Έμš”.`,
        'goal:pause': () => `⏸ μΌμ‹œμ •μ§€ β€” ${payload.code || 'μ›λž˜ μž‘μ—…μ„ κ²€ν† ν•΄μ£Όμ„Έμš”.'}`,
        'goal:review': () => `πŸ“‹ κ²€ν†  ν•„μš” β€” ${payload.code || '같은 싀행을 ν™•μΈν•΄μ£Όμ„Έμš”.'}`,
        'goal:fail': () => `❌ μ‹€νŒ¨ β€” ${payload.attempts}회 μ‹œλ„ μ†Œμ§„. 였λ₯˜: ${payload.error}`,
      };
      const fn = map[channel];
      if (fn) appendAutonomousLog(fn());
    });

    async function runAutonomousGoal() {
      const projectId = document.getElementById('planningProjectSelect').value;
      const title = document.getElementById('planTitle').value.trim();
      const goalText = document.getElementById('planGoal').value.trim();
      const requirements = document.getElementById('planRequirements').value.trim();

      if (!projectId) { alert('ν”„λ‘œμ νŠΈλ₯Ό μ„ νƒν•˜μ„Έμš”.'); return; }
      const goal = [title, goalText, requirements].filter(s => s).join('\n\n');
      if (!goal) { alert('λͺ©ν‘œ(제λͺ©/λͺ©ν‘œ/μš”κ΅¬μ‚¬ν•­ 쀑 ν•˜λ‚˜ 이상)λ₯Ό μž…λ ₯ν•˜μ„Έμš”.'); return; }

      const budgets={};
      for(const [field,key]of [['goalPlanningBudget','planningBudgetUsd'],['goalPlanningReserve','planningRequestReserveUsd'],['goalExecutionBudget','budgetUsd'],['goalExecutionReserve','requestReserveUsd']]){
        const value=document.getElementById(field).value.trim();if(!value)continue;
        const amount=Number(value);if(!Number.isFinite(amount)||amount<=0){alert('μ˜ˆμ‚°κ³Ό μ˜ˆμ•½μ—λŠ” μ–‘μˆ˜λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”.');return;}budgets[key]=amount;
      }
      if(budgets.planningRequestReserveUsd!=null&&(budgets.planningBudgetUsd==null||budgets.planningRequestReserveUsd>budgets.planningBudgetUsd)){alert('μš”μ²­ μ˜ˆμ•½μ€ κ³„νš μ˜ˆμ‚° μ•ˆμ—μ„œ μ„€μ •ν•΄μ£Όμ„Έμš”.');return;}

      if(budgets.requestReserveUsd!=null&&budgets.budgetUsd!=null&&budgets.requestReserveUsd>budgets.budgetUsd){alert('μ‹€ν–‰ μš”μ²­ μ˜ˆμ•½μ€ μ‹€ν–‰ μ˜ˆμ‚° μ•ˆμ—μ„œ μ„€μ •ν•΄μ£Όμ„Έμš”.');return;}
      document.getElementById('autonomousLog').textContent = '';
      document.getElementById('autonomousStart').disabled=true;
      appendAutonomousLog('μš”μ²­ 전솑...');

      try {
        const res = await ipcRenderer.invoke('run-autonomous-goal', projectId, goal, { maxReplans: 2,...budgets,planningPricingPolicies:getGoalPricingPolicies() });
        if (res && res.success) {
          appendAutonomousLog(`πŸŽ‰ μ™„λ£Œ (run=${res.runId})`);
        } else {
          appendAutonomousLog(`μ’…λ£Œ(μ‹€νŒ¨): ${res && res.error ? res.error : '원인 미상'}`);
        }
      } catch (err) {
        appendAutonomousLog(`였λ₯˜: ${err.message}`);
      } finally {
        ownedGoalId=null;document.getElementById('autonomousCancel').disabled=true;document.getElementById('autonomousStart').disabled=false;
      }
    }

    // --- Kanban Logic ---
    let draggedTaskId = null;

    async function loadKanbanTasks() {
      const projectId = document.getElementById('kanbanProjectSelect').value;
      
      // Clear cols
      const cols = ['todo', 'in_progress', 'completed', 'failed'];
      cols.forEach(col => {
        document.getElementById(`col-${col}`).innerHTML = '';
        document.getElementById(`count-${col}`).textContent = '0';
      });

      if (!projectId) return;

      try {
        const plans = await ipcRenderer.invoke('get-dev-plans', projectId);
        const colCounts = { todo: 0, in_progress: 0, completed: 0, failed: 0 };
        
        plans.forEach(plan => {
          const tasks = plan.tasks || [];
          tasks.forEach(t => {
            const status = t.status || 'todo';
            const colEl = document.getElementById(`col-${status}`);
            if (!colEl) return;

            colCounts[status]++;
            
            const card = document.createElement('div');
            card.className = 'kanban-card';
            card.draggable = true;
            card.id = `task-${t.id}`;
            card.ondragstart = (e) => {
              draggedTaskId = t.id;
              e.dataTransfer.setData('text/plain', t.id);
            };
            
            card.innerHTML = `
              <div class="kanban-card-title">${escapeHtml(t.title)}</div>
              <div class="kanban-card-desc">${escapeHtml(t.description || '상세 λ‚΄μš© μ—†μŒ')}</div>
              <div class="kanban-card-meta">
                <span>파일: ${escapeHtml(t.target_file || 'N/A')}</span>
                <span>${t.difficulty ? `λ‚œμ΄λ„: ${t.difficulty}` : ''}</span>
              </div>
            `;
            colEl.appendChild(card);
          });
        });

        // Set counts
        cols.forEach(col => {
          document.getElementById(`count-${col}`).textContent = colCounts[col];
        });

      } catch (err) {
        console.error('Failed to load kanban tasks:', err);
      }
    }

    function allowDrop(e) {
      e.preventDefault();
    }

    async function drop(e, newStatus) {
      e.preventDefault();
      const taskId = e.dataTransfer.getData('text/plain') || draggedTaskId;
      if (!taskId) return;

      try {
        const updateResult = await ipcRenderer.invoke('update-dev-task', taskId, { status: newStatus });
        if (updateResult.success) {
          loadKanbanTasks();
        } else {
          alert('νƒœμŠ€ν¬ μ—…λ°μ΄νŠΈ μ‹€νŒ¨: ' + updateResult.error);
        }
      } catch (err) {
        alert('μ—…λ°μ΄νŠΈ 쀑 였λ₯˜ λ°œμƒ: ' + err.message);
      }
    }

    // --- Troubleshoot KB ---
    async function searchTroubleshoot() {
      const projectId = document.getElementById('tsProjectSelect').value;
      const query = document.getElementById('tsSearchInput').value.trim();
      const listEl = document.getElementById('tsList');

      listEl.innerHTML = '';

      if (!projectId) {
        listEl.innerHTML = `<p style="color: var(--text-dim); text-align: center; padding: 20px 0;">쑰회 λŒ€μƒ ν”„λ‘œμ νŠΈλ₯Ό μ„ νƒν•΄μ£Όμ‹­μ‹œμ˜€.</p>`;
        return;
      }

      try {
        const entries = await ipcRenderer.invoke('search-troubleshoot-kb', projectId, query);
        if (entries.length === 0) {
          listEl.innerHTML = `<p style="color: var(--text-dim); text-align: center; padding: 20px 0;">포착된 νŠΈλŸ¬λΈ”μŠˆνŒ… 지식이 μ—†μŠ΅λ‹ˆλ‹€.</p>`;
          return;
        }

        entries.forEach(e => {
          listEl.innerHTML += `
            <div class="troubleshoot-card">
              <div class="ts-header">
                <span class="ts-pattern">${escapeHtml(e.error_pattern)}</span>
                <span class="badge badge-yellow">${e.error_type.toUpperCase()}</span>
              </div>
              <div style="font-size: 11px; color: var(--text-dim); margin-bottom: 8px;">λˆ„μ  λ°œμƒ: <strong style="color: var(--pink);">${e.hit_count || 1}</strong>회 | μ΅œμ’… λ°œμƒ: ${e.last_hit_at || e.created_at || '기둝 μ—†μŒ'}</div>
              <div class="ts-details">
                <div>
                  <div class="ts-box-title">πŸ” κ·Όλ³Έ 원인</div>
                  <div style="color: var(--text-sub); line-height: 1.4;">${escapeHtml(e.root_cause || '뢄석 쀑')}</div>
                </div>
                <div>
                  <div class="ts-box-title">πŸ’‘ ν•΄κ²°μ±… 및 패치</div>
                  <div style="color: var(--text-sub); line-height: 1.4;">${escapeHtml(e.solution)}</div>
                </div>
              </div>
              ${(e.affected_files && e.affected_files.length > 0) ? `
                <div style="margin-top: 10px; font-size: 11px; color: var(--text-dim);">
                  μ—°κ΄€ 파일: ${e.affected_files.map(f => `<code style="background: var(--bg-crust); padding: 2px 4px; border-radius: 4px;">${escapeHtml(f)}</code>`).join(' ')}
                </div>
              ` : ''}
            </div>
          `;
        });

      } catch (err) {
        listEl.innerHTML = `<p style="color: var(--red); text-align: center; padding: 20px 0;">지식 검색 쀑 μ‹€νŒ¨: ${err.message}</p>`;
      }
    }

    function showLoading(show, text = '') {
      const overlay = document.getElementById('loadingOverlay');
      const textEl = document.getElementById('loadingText');
      if (text) textEl.textContent = text;
      
      if (show) {
        overlay.classList.add('visible');
      } else {
        overlay.classList.remove('visible');
      }
    }

    function escapeHtml(str) {
      if (!str) return '';
      return str.replace(/&/g, '&amp;')
                .replace(/</g, '&lt;')
                .replace(/>/g, '&gt;')
                .replace(/"/g, '&quot;')
                .replace(/'/g, '&#039;');
    }

    ipcRenderer.on('switch-tab', (event, tabId) => {
      switchTab(tabId);
    });
  </script>
</body>
</html>