/* ===== Factory Shared Components =====
   리허설에서 확립된 틴더 감성 디자인 시스템의 공통 컴포넌트.
   카드, 뱃지, 프로그레스, 요약, 채팅 패턴을 모든 페이즈에서 재사용. */

/* ===== 1. Shared Card ===== */
.factory-shared-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl, 16px);
  padding: 16px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: all 200ms ease;
  overflow-wrap: break-word;
  word-break: break-word;
}

.factory-shared-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.factory-shared-card.dismissed {
  background: var(--bg-tertiary);
  border-color: transparent;
  box-shadow: none;
}

.factory-shared-card.dismissed:hover {
  transform: none;
  box-shadow: none;
}

.factory-shared-card.checked {
  background: #F0FDF4;
  border-color: #BBF7D0;
}

/* ===== 2. Shared Badge (pill) ===== */
.factory-shared-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.factory-shared-badge.critical,
.factory-shared-badge.danger {
  background: #FEE2E2;
  color: #DC2626;
}

.factory-shared-badge.warn,
.factory-shared-badge.manageable {
  background: #FEF3C7;
  color: #D97706;
}

.factory-shared-badge.info,
.factory-shared-badge.silent {
  background: #DBEAFE;
  color: #2563EB;
}

.factory-shared-badge.success {
  background: #D1FAE5;
  color: #059669;
}

.factory-shared-badge.pending {
  background: #FEF3C7;
  color: #92400E;
}

.factory-shared-badge.escaped {
  background: #EDE9FE;
  color: #5B21B6;
}

.factory-shared-badge.dismissed-badge {
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.5px;
}

.factory-shared-badge.required {
  background: #FEE2E2;
  color: #DC2626;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.factory-shared-badge.optional {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  text-transform: uppercase;
}

.factory-shared-badge.auto {
  background: #DBEAFE;
  color: #2563EB;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  text-transform: uppercase;
}

button.factory-shared-badge.auto,
button.factory-shared-badge.manual {
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
}
button.factory-shared-badge.auto:hover,
button.factory-shared-badge.manual:hover { opacity: 0.75; }

.factory-shared-badge.manual {
  background: #F3F4F6;
  color: #6B7280;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  text-transform: uppercase;
}

/* ===== 3. Shared Progress Bar ===== */
.factory-shared-progress {
  display: flex;
  flex: 1;
  height: 6px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--bg-tertiary);
}

.factory-shared-progress-segment {
  transition: width 300ms ease;
}

.factory-shared-progress-segment.accepted,
.factory-shared-progress-segment.passed {
  background: var(--accent);
}

.factory-shared-progress-segment.dismissed,
.factory-shared-progress-segment.failed {
  background: var(--text-muted);
}

.factory-shared-progress-segment.success {
  background: #059669;
}

.factory-shared-progress-segment.warn {
  background: #D97706;
}

.factory-shared-progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

/* ===== 4. Shared Summary Card (gradient) ===== */
.factory-shared-summary {
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-pink-light));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl, 16px);
  box-shadow: var(--shadow-sm);
  overflow-wrap: break-word;
  word-break: break-word;
}

.factory-shared-summary-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.factory-shared-summary-header strong {
  font-size: 16px;
}

.factory-shared-summary .factory-shared-metric {
  margin-top: 8px;
}

/* ===== Shared Metric Row ===== */
.factory-shared-metric {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-primary);
  border-radius: var(--radius-lg, 12px);
  margin-bottom: 8px;
}

.factory-shared-metric-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.factory-shared-metric-value {
  font-size: 16px;
  font-weight: 700;
  font-family: "SF Mono", "Fira Code", monospace;
}

.factory-shared-metric-value.good {
  color: #059669;
}

.factory-shared-metric-value.warn {
  color: #D97706;
}

/* ===== 5. Shared Chat Components ===== */

/* Chat message bubbles */
.factory-shared-chat-messages {
  max-height: 300px;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.factory-shared-chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.5;
}

.factory-shared-chat-msg.user {
  background: var(--accent-light);
  align-self: flex-end;
  max-width: 85%;
}

.factory-shared-chat-msg.assistant {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  max-width: 85%;
}

.factory-shared-chat-role {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.factory-shared-chat-text {
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Streaming cursor */
.factory-shared-chat-msg.assistant.streaming .factory-shared-chat-text::after {
  content: "▍";
  animation: factory-cursor-blink 1s step-end infinite;
}

/* Chat input wrapper — tinder-style pill */
.factory-shared-chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  margin-top: 8px;
  transition: border-color 200ms ease;
  flex-shrink: 0;
}

.factory-shared-chat-input:focus-within {
  border-color: var(--accent-pink, var(--accent));
}

.factory-shared-chat-input textarea {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  padding: 0;
}

.factory-shared-chat-input textarea::placeholder {
  color: var(--text-muted);
}

/* Send button — pink circle */
.factory-shared-chat-send {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full, 50%);
  background: var(--accent-pink, var(--accent));
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms;
}

.factory-shared-chat-send:hover {
  background: #E85A78;
}

.factory-shared-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Typing indicator */
.factory-shared-typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.factory-shared-typing-dots .typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s infinite;
}

.factory-shared-typing-dots .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.factory-shared-typing-dots .typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Chat overlay popup */
.factory-shared-chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.4);
  justify-content: center;
  align-items: center;
}

.factory-shared-chat-popup {
  width: min(560px, 90vw);
  max-height: 80vh;
  background: var(--bg-primary);
  border-radius: var(--radius-xl, 16px);
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0,0,0,0.2));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.factory-shared-chat-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-pink-light));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.factory-shared-chat-popup-title {
  font-size: 16px;
  font-weight: 700;
}

.factory-shared-chat-popup-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms;
}

.factory-shared-chat-popup-close:hover {
  background: var(--bg-tertiary);
}

.factory-shared-chat-popup-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 200px;
  max-height: 50vh;
}

.factory-shared-chat-popup-input {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===== 6. Shared Patterns Section ===== */
.factory-shared-patterns {
  margin-top: 10px;
}

.factory-shared-patterns-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.factory-shared-patterns ul {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.factory-shared-patterns-item {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 0;
  line-height: 1.5;
}

/* ===== 7. Shared Collapsible Toggle ===== */
.factory-shared-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: 8px;
  user-select: none;
}

.factory-shared-toggle .toggle-arrow {
  transition: transform 150ms;
  display: inline-block;
}

.factory-shared-toggle.open .toggle-arrow {
  transform: rotate(90deg);
}

.factory-shared-toggle-content {
  display: none;
  margin-bottom: 10px;
}

.factory-shared-toggle-content.open {
  display: block;
}

/* ===== 8. Shared Pill Button ===== */
.factory-shared-pill-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 16px;
  font-weight: 500;
  font-size: 12px;
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.factory-shared-pill-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
}

.factory-shared-pill-btn.pink:hover {
  border-color: var(--accent-pink);
  color: var(--accent-pink);
  background: var(--accent-pink-light);
}

.factory-shared-pill-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ===== 9. Shared Icon Button ===== */
.factory-shared-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full, 50%);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 150ms ease;
}

.factory-shared-icon-btn:hover {
  background: var(--accent-pink-light);
  border-color: var(--accent-pink);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ===== 10. Shared Loop Status ===== */
.factory-shared-loop-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 12px;
  margin-bottom: 12px;
}

.factory-shared-loop-status.material {
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  color: #92400E;
}

.factory-shared-loop-status.gate {
  background: #EDE9FE;
  border: 1px solid #C4B5FD;
  color: #5B21B6;
}

.factory-shared-loop-status.at-max {
  border-color: #F87171;
  background: #FEF2F2;
  color: #991B1B;
}

.factory-shared-loop-icon {
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
}

.factory-shared-loop-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.factory-shared-loop-round {
  font-size: 12px;
}

.factory-shared-loop-reason {
  font-size: 11px;
  opacity: 0.8;
}

.factory-shared-loop-exit-btn {
  margin-left: auto;
  padding: 5px 14px;
  border: 1px solid currentColor;
  border-radius: var(--radius-md, 6px);
  background: transparent;
  color: inherit;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 150ms;
  flex-shrink: 0;
}

.factory-shared-loop-exit-btn:hover {
  background: rgba(0,0,0,0.08);
}
