/* 정규표현식 테스터 전용 스타일 */

/* 정규식 입력 영역 */
.regex-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.regex-delim {
  font-size: 1.5rem;
  font-weight: 300;
  color: var(--text-sub);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  user-select: none;
}

#regex-pattern {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

#regex-pattern:focus {
  border-color: var(--primary);
}

#regex-pattern.invalid {
  border-color: var(--error);
}

/* 플래그 토글 */
.flag-toggles {
  display: flex;
  gap: 0.25rem;
}

.flag-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-sub);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.flag-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.flag-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* 에러 메시지 */
.regex-error {
  padding: 0.5rem 0.8rem;
  margin-bottom: 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--error);
}

.regex-error[hidden] {
  display: none;
}

/* 버튼 행 */
.btn-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

/* 모드 탭 (테스트/치환) */
.mode-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* 테스트 문자열 영역 (하이라이트 오버레이) */
.test-area {
  position: relative;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.test-area-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.test-area-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-sub);
}

.match-count {
  font-size: 0.75rem;
  color: var(--text-sub);
  font-weight: 500;
}

.match-count strong {
  color: var(--primary);
}

.highlight-container {
  position: relative;
  min-height: 200px;
}

/* 하이라이트 오버레이 (textarea 뒤에 배치) */
.highlight-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1rem;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: transparent;
  overflow: auto;
  pointer-events: none;
}

.highlight-backdrop mark {
  color: transparent;
  border-radius: 2px;
  padding: 1px 0;
}

.highlight-backdrop mark.match-even {
  background: rgba(250, 204, 21, 0.45);
}

.highlight-backdrop mark.match-odd {
  background: rgba(251, 146, 60, 0.45);
}

@media (prefers-color-scheme: dark) {
  .highlight-backdrop mark.match-even {
    background: rgba(250, 204, 21, 0.3);
  }
  .highlight-backdrop mark.match-odd {
    background: rgba(251, 146, 60, 0.3);
  }
}

#test-string {
  position: relative;
  width: 100%;
  min-height: 200px;
  padding: 1rem;
  border: none;
  outline: none;
  resize: vertical;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background: transparent;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  z-index: 1;
}

#test-string::placeholder {
  color: var(--text-sub);
  opacity: 0.6;
}

/* 치환 영역 */
.replace-section {
  margin-bottom: 1rem;
}

.replace-section[hidden] {
  display: none;
}

.replace-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.replace-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-sub);
  flex-shrink: 0;
  min-width: 40px;
}

#replace-pattern {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

#replace-pattern:focus {
  border-color: var(--primary);
}

.replace-result-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.replace-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.replace-result-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-sub);
}

#replace-result {
  padding: 1rem;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text);
  min-height: 60px;
  max-height: 300px;
  overflow: auto;
}

/* 매칭 결과 테이블 */
.match-results {
  margin-bottom: 1.5rem;
}

.match-results[hidden] {
  display: none;
}

.match-results h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.match-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.match-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.match-table th {
  padding: 0.6rem 0.8rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-sub);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.match-table td {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  word-break: break-all;
}

.match-table tr:last-child td {
  border-bottom: none;
}

.match-table tr:hover td {
  background: rgba(102, 126, 234, 0.04);
}

.group-cell {
  font-size: 0.78rem;
  color: var(--text-sub);
}

.group-label {
  font-weight: 600;
  color: var(--primary);
  margin-right: 0.25rem;
}

.no-match {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-sub);
  font-size: 0.85rem;
}

/* 퀵 레퍼런스 */
.quick-ref {
  margin-bottom: 1.5rem;
}

.quick-ref summary {
  padding: 0.7rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background 0.2s;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quick-ref summary::-webkit-details-marker {
  display: none;
}

.quick-ref summary::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid var(--text-sub);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.2s;
}

.quick-ref[open] summary::before {
  transform: rotate(90deg);
}

.quick-ref summary:hover {
  background: rgba(102, 126, 234, 0.05);
}

.ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--surface);
}

.ref-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.ref-item:hover {
  background: rgba(102, 126, 234, 0.08);
}

.ref-item code {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(102, 126, 234, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  flex-shrink: 0;
}

.ref-item span {
  font-size: 0.78rem;
  color: var(--text-sub);
}

/* 반응형 */
@media (max-width: 480px) {
  .regex-input-row {
    gap: 0.35rem;
  }

  #regex-pattern {
    min-width: 120px;
    font-size: 0.85rem;
    padding: 0.5rem 0.6rem;
  }

  .flag-btn {
    width: 32px;
    height: 32px;
    font-size: 0.78rem;
  }

  .highlight-container {
    min-height: 160px;
  }

  #test-string {
    min-height: 160px;
    font-size: 0.8rem;
  }

  .highlight-backdrop {
    font-size: 0.8rem;
  }

  .ref-grid {
    grid-template-columns: 1fr;
  }

  .match-table {
    font-size: 0.75rem;
  }

  .match-table th,
  .match-table td {
    padding: 0.4rem 0.5rem;
  }

  .btn-row .btn {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
  }
}
